Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
W

wag

> 安全
Open source

Simple Wireguard 2FA

724 stars0 likes0 views
WebsiteGitHub

About

Simple Wireguard 2FA

Wag

Wag adds MFA, route restriction and device enrolment to wireguard.

Key Features:

  • Define routes which require MFA authorisation, or public always accessible routes
  • Easy API for registering new clients
  • High Availability
  • Real time user updates and notifications
  • Multiple MFA integrations
    • Security Key
    • SSO
    • PAM
    • TOTP

Documentation

Administration

User UI

Sponsorship

This work was very kindly supported by:

Requirements

Forwarding must be enabled in sysctl.

bash
sysctl -w net.ipv4.ip_forward=1
#Or for ipv6

sysctl -w net.ipv6.conf.all.forwarding=1
sysctl -w net.ipv6.conf.all.accept_ra=2
sysctl -w net.ipv6.conf.all.accept_redirects=1
sysctl -w net.ipv6.conf.all.accept_source_route=1

Setup instructions

Docker Compose

Please find the docker compose here, you will need to define a configuration file in /cfg:

yaml
---
services:
  wag:
    image: wagvpn/wag:latest # ghcr.io/nhas/wag:unstable # Unstable branch
    container_name: wag
    restart: always
    cap_add:
      - NET_ADMIN
     ports:
      - '4433:4433/tcp' # Admin page
      - '8081:8081/tcp' # Public registration page
      - '53230:53230/udp' # Wireguard port
    volumes:
      - ./wag/config/:/cfg/:z
      - ./wag/data/:/data:z
    devices:
      - /dev/net/tun:/dev/net/tun

Manual

iptables and libpam must be installed.
Wag must be run as root, to manage iptables and the wireguard device.

Binary release (requires glibc 2.31+):

bash
curl -L $(curl -s https://api.github.com/repos/NHAS/wag/releases/latest | jq -M -r '.assets[0].browser_download_url') -o wag
chmod o+x wag
sudo ./wag start -config 

From source (will require go1.23.1, npm):

bash
git clone [email protected]:NHAS/wag.git
cd wag
make

cp example_config.json config.json

sudo ./wag start

Management

UI

After you have set up wag and enabled the administrative user interface, it will create the first admin for you, the password will be output to STDOUT. Then you can log in and manage users there.

CLI

The root user is able to manage the wag server with the following command:

bash
wag subcommand [-options]

Supported commands: start, version, firewall, registration, devices, users, webadmin

start: starts the wag server

bash
Usage of start:
  Start wag server (does not daemonise)
  -join string
        Cluster join token
  -config string
        Configuration file location (default "./config.json")

registration: Deals with creating, deleting and listing the registration tokens

…

devices: Manages devices

bash
Usage of devices:
  -address string
        Address of device
  -del
        Remove device and block wireguard access
  -list
        List wireguard devices
  -lock
        Lock device access to mfa routes
  -mfa_sessions
        Get list of devices with active authorised sessions
  -socket string
        Wag control socket to act on (default "/tmp/wag.sock")
  -unlock
        Unlock device
  -username string
        Owner of device (indicates that command acts on all devices owned by user)

users: Manages users MFA and can delete all users devices

bash
Usage of users:
  -del
        Delete user and all associated devices
  -list
        List users, if '-username' supply will filter by user
  -lockaccount
        Lock account disable authention from any device, deauthenticates user active sessions
  -reset-mfa
        Reset MFA details, invalids all session and set MFA to be shown
  -socket string
        Wag socket location, (default "/tmp/wag.sock")
  -unlockaccount
        Unlock a locked account, does not unlock specific device locks (use device -unlock -username <> for that)
  -username string
        Username to act upon

webadmin: Manages the administrative users for the web UI

bash
Usage of webadmin:
  -add
        Add web administrator user (requires -password)
  -del
        Delete admin user
  -list
        List web administration users, if '-username' supply will filter by user
  -lockaccount
        Lock admin account disable login for this web administrator user
  -password string
        Username to act upon
  -socket string
        Wag instance control socket (default "/tmp/wag.sock")
  -unlockaccount
        Unlock a web administrator account
  -username string
        Admin Username to act upon

Administration guide

Manual installation of Wag

  1. Copy wag, config.json to /opt/wag
  2. Generate a wireguard private key with wg genkey set PrivateKey in the example config to it
  3. Copy (or link) wag.service to /etc/systemd/system/ and start/enable the service

Creating new registration tokens

First generate a token.

bash
# ./wag registration -add -username tester
token,username
e83253fd9962c68f73aa5088604f3f425d58a963bfb5c0889cca54d63a34b2e3,tester

Then curl said token.

bash
curl http://public.server.address:8080/register_device?key=e83253fd9962c68f73aa5088604f3f425d58a963bfb5c0889cca54d63a34b2e3

The service will return a fully templated response:

ini
[Interface]
PrivateKey = 
Address = 192.168.1.1

[Peer]
Endpoint =  public.server.address:51820
PublicKey = pnvl40WiRt++0NucEGexlpfwWA8QzBYg2+8ZWZJvejA=
AllowedIPs = 10.7.7.7/32, 192.168.1.1/32, 192.168.3.4/32, 192.168.3.5/32
PersistentKeepAlive = 10

Which can then be written to a config file.

Entering MFA

To authenticate the user should browse to the servers vpn address, in the example, case 192.168.1.1:8080, where they will be prompted for their 2fa code.
The configuration file specifies how long a session can live for, before expiring.

Signing in to the Management console

Make sure that you have Webserver.Management.Enabled set as true, then do the following from the console:

bash
sudo ./wag webadmin -add -username  -password 

Then browse to your management listening address and enter your credentials.

The web interface itself cannot add administrative users.

Configuration file reference

NumberProxies: The number of trusted reverse proxies before the client, makes wag respect the X-Forward-For directive and parses the client IP from it correctly

Socket: Wag control socket, changing this will allow multiple wag instances to run on the same machine
GID: The group ID that the wag control socket (/tmp/wag*) should be set to

NAT: Turn on or off masquerading. If enabled, all traffic appears as if it was originated from the VPN server.
NATExcludeRanges: (only relevant if NAT=true) - an array of CIDR ranges to exclude from NAT. For example, if you set this to ["10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"], then NAT will only be applied to traffic flowing to the public internet, but not to private networks. ExposePorts: Expose ports on the VPN server to the client (adds rules to IPtables) example: [ "443/tcp", "100-200/udp" ]
CheckUpdates: If enabled (off by default) the management UI will show an alert if a new version of wag is available. This talks to api.github.com

Acls: Defines the Groups and Policies that restrict routes, this is only respected on first run, use the web UI to edit them during runtime.
Policies: A map of group or user names to policy objects which contain the wag firewall & route capture rules. The most specific match governs the type of access a user has to a route, e.g if you have a /16 defined as MFA, but one ip address in that range as allow that is /32 then the /32 will take precedence over the /16
Policies..Mfa: The routes and services that require Mfa to access
Policies..Public: Routes and services that do not require authorisation Policies..Deny: Deny access to this route

Webserver: Object that contains the public and tunnel listening addresses of the webserver

WebServer.Acme: Object to contain the ACME details, such as email and CA provider WebServer.Acme.CAProvider: The provider for your ACME certs, defaults to https://acme-staging-v02.api.letsencrypt.org/directory
WebServer.Acme.CloudflareDNSToken: The cloudflare DNS token to do DNS-01 ACME, optional, if not defined then HTTP-01 will be used. You'll have to define your DNS A/AAAA records to point to the public web address.

Webserver.Lockout: Number of times a person can attempt mfa authentication before their account locks

WebServer.Public.ListenAddress: Listen address for the public registration endpoint WebServer.Public.Domain: Domain for the registration API
WebServer.Public.TLS: Boolean, enable TLS on this endpoint (will automatically use ACME if configured with preference to static certificates)
WebServer.Public.CertificatePath: Path to certificate to load in on first run
WebServer.Public.PrivateKeyPath: Path to private key to load into wag on first run WebServer.Public.ExternalAddress: External address to be baked in to generated wireguard configs, i.e where your wireguard connections connect to.
WebServer.Public.DownloadConfigFileName: The config name to serve toe clients, defaults to wg0.conf

WebServer.Tunnel: Object that contains configurations for the MFA portal and the MFA methods wag provides
WebServer.Tunnel.Domain: Domain for the MFA portal tunnel
WebServer.Tunnel.TLS: Boolean, enable TLS on this endpoint (will automatically use ACME if configured with preference to static certificates)
WebServer.Tunnel.CertificatePath: Path to certificate to load in on first run
WebServer.Tunnel.PrivateKeyPath: Path to private key to load into wag on first run WebServer.Tunnel.Port: Port for in-vpn-tunnel webserver, this does not take a full IP address, as the tunnel listener should never be outside the wireguard device WebServer.Tunnel.Domain: The domain of your MFA portal
WebServer.Tunnel.MaxSessionLifetimeMinutes: How long a session can last, if -1, timeout is disabled
WebServer.Tunnel.SessionInactivityTimeoutMinutes: How long a device can be idle before it has to reauthenticate, if -1 timeout is disabled
WebServer.Tunnel.HelpMail: Help mail to display on the UI
WebServer.Tunnel.DefaultMethod: String, default method the user will be presented, if not specified a list of methods is displayed to the user (possible values: webauth, totp, oidc, pam)
WebServer.Tunnel.Issuer: OTP issuer, the name that will get added to the TOTP app or Webauthn device WebServer.Tunnel.Methods: String array, enabled authentication methods, e.g ["totp","webauthn","oidc", "pam"].

WebServer.Tunnel.OIDC: Object that stores the OIDC settings
WebServer.Tunnel.OIDC.IssuerURL: The URL of your identity provider , e.g http://localhost:8080/realms/account
WebServer.Tunnel.OIDC.ClientID: OIDC identifier for application
WebServer.Tunnel.OIDC.ClientSecret: OIDC client secret
WebServer.Tunnel.OIDC.DeviceUsernameClaim: The claim within the oidc token that contains the users device name
WebServer.Tunnel.OIDC.Scopes: Array of scopes to request from your identity provider, defaults to openid
WebServer.Tunnel.OIDC.GroupsClaimName: Claim that contains user groups to map into wag groups

WebServer.Tunnel.PAM: Object that stores the PAM settings WebServer.Tunnel.PAM.ServiceName: Name of PAM-Auth file in /etc/pam.d/ will default to /etc/pam.d/login if unset or empty

WebServer.Management: Object that contains configurations for the webadministration portal. It is not recommend to expose this portal, I recommend setting ListenAddress to 127.0.0.1/localhost and then use ssh forwarding to expose it
WebServer.Management.Enabled: Enable the web UI
WebServer.Management.Domain: Domain for the management interface
WebServer.Management.TLS: Boolean, enable TLS on this endpoint (will automatically use ACME if configured with preference to static c

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Go2fafirewalllinuxmanagement-portal

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category安全
PricingOpen source

> Related tools

O
OWASP ZAP
开源 Web 应用安全扫描器
O
owasp-wstg-tracker
Simple web app to track OWASP WSTG security testing progress
H
homebridge-mi-gateway-security
XiaoMi Gateway Security plugin for HomeBridge.