Skip to content

Commit 536238a

Browse files
authored
feat(wireguard): bringing wireguard to UI (#1370)
1 parent 0bf33f4 commit 536238a

File tree

7 files changed

+978
-511
lines changed

7 files changed

+978
-511
lines changed

config/luci.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ CONFIG_PACKAGE_luci-proto-ppp=y
1919
CONFIG_PACKAGE_luci-theme-bootstrap=y
2020
CONFIG_PACKAGE_rpcd-mod-luci=y
2121
CONFIG_PACKAGE_luci-app-adblock=y
22-
CONFIG_PACKAGE_luci-app-mwan3=y
23-
CONFIG_PACKAGE_luci-app-wireguard=y
22+
CONFIG_PACKAGE_luci-app-mwan3=
23+
CONFIG_PACKAGE_luci-app-wireguard=m
2424
CONFIG_PACKAGE_luci-proto-3g=y
25-
CONFIG_PACKAGE_luci-proto-wireguard=y
25+
CONFIG_PACKAGE_luci-proto-wireguard=m
2626
CONFIG_PACKAGE_luci-mod-dashboard=y
2727
CONFIG_PACKAGE_luci-app-banip=y
2828

packages/ns-api/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
include $(TOPDIR)/rules.mk
77

88
PKG_NAME:=ns-api
9-
PKG_VERSION:=3.3.2
9+
PKG_VERSION:=3.4.0
1010
PKG_RELEASE:=1
1111

1212
PKG_BUILD_DIR:=$(BUILD_DIR)/ns-api-$(PKG_VERSION)
@@ -21,7 +21,7 @@ define Package/ns-api
2121
CATEGORY:=NethSecurity
2222
TITLE:=NethSecurity REST API
2323
URL:=https://github.com/NethServer/nethsecurity-controller/
24-
DEPENDS:=+python3-nethsec +python3-openssl +python3-urllib +python3-idna +python3-requests +sshpass
24+
DEPENDS:=+python3-nethsec +python3-openssl +python3-urllib +python3-idna +python3-requests +sshpass +wireguard-tools
2525
PKGARCH:=all
2626
endef
2727

@@ -180,6 +180,7 @@ define Package/ns-api/install
180180
$(INSTALL_BIN) ./files/post-commit/configure-netifyd.py $(1)/usr/libexec/ns-api/post-commit
181181
$(INSTALL_BIN) ./files/post-commit/reload-ipsets.py $(1)/usr/libexec/ns-api/post-commit
182182
$(INSTALL_BIN) ./files/post-commit/restart-cron.py $(1)/usr/libexec/ns-api/post-commit
183+
$(INSTALL_BIN) ./files/post-commit/restart-wireguard.py $(1)/usr/libexec/ns-api/post-commit
183184
$(INSTALL_BIN) ./files/pre-commit/clean-network.py $(1)/usr/libexec/ns-api/pre-commit
184185
$(INSTALL_BIN) ./files/remove-pppoe-keepalive $(1)/usr/share/ns-api
185186
$(INSTALL_DIR) $(1)/etc/uci-defaults

packages/ns-api/README.md

Lines changed: 170 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -8201,18 +8201,13 @@ Response example:
82018201
82028202
## ns.wireguard
82038203
8204-
Configure WireGuard VPN both in Road Warrior and site-to-site mode.
8204+
Configure WireGuard VPN in site-to-site mode.
82058205
8206-
### list-instances
8206+
### import-configuration
82078207
8208-
List all WireGuard instances:
8209-
```
8210-
api-cli ns.wireguard list-instances
8208+
Import a WireGuard configuration file, must be base64 encoded:
82118209
```
8212-
8213-
Response example:
8214-
```json
8215-
{"instances": ["wg1", "wg2"]}
8210+
api-cli ns.wireguard import-configuration --data '{"config": "BASE64_ENCODED_FILE_CONTENT"}'
82168211
```
82178212
82188213
### get-instance-defaults
@@ -8224,126 +8219,231 @@ api-cli ns.wireguard get-instance-defaults
82248219
82258220
Response example:
82268221
```json
8227-
{"listen_port": 51821, "instance": "wg2", "network": "10.210.112.0/24", "routes": ["192.168.100.0/24"], "public_endpoint": "185.96.1.1"}
8222+
{
8223+
"listen_port": 51822,
8224+
"instance": "wg3",
8225+
"network": "10.245.149.0/24",
8226+
"public_endpoint": "79.19.71.172"
8227+
}
82288228
```
82298229
8230-
### get-configuration
8230+
### list-servers
82318231
8232-
Return current instance configuration:
8232+
List all WireGuard tunnel servers:
82338233
```
8234-
api-cli ns.wireguard get-configuration --data '{"instance": "wg1"}'
8234+
api-cli ns.wireguard list-servers
82358235
```
82368236
82378237
Response example:
82388238
```json
8239-
{"proto": "wireguard", "private_key": "oBwTyCkOgUz29UEvuJZstuAjB87SH4x26MVLxAj152M=", "listen_port": "51820", "addresses": ["10.103.1.1"], "ns_network": "10.103.1.0/24", "ns_public_endpoint": "192.168.122.49", "ns_routes": ["192.168.100.0/24"], "ns_name": "wg1", "disabled": "0", "ns_client_to_client": false, "ns_route_all_traffic": false, "enabled": true}
8239+
{
8240+
"instances": [
8241+
{
8242+
"id": "wg1",
8243+
"name": "HQ",
8244+
"listen_port": 51820,
8245+
"address": "10.1.122.1",
8246+
"network": "10.1.122.0/24",
8247+
"public_endpoint": "127.0.0.1",
8248+
"enabled": true,
8249+
"peers": [
8250+
{
8251+
"id": "wg1_ns_76e103f5_peer",
8252+
"enabled": true,
8253+
"name": "iPhone di Tommaso",
8254+
"pre_shared_key": true,
8255+
"route_all_traffic": true,
8256+
"remote_networks": [],
8257+
"local_networks": [],
8258+
"reserved_ip": "10.1.122.2",
8259+
"config": "[Interface]\n# Name = iPhone di Tommaso\nPrivateKey = XXX\nAddress = 10.1.122.2\n# DNS not configured\n\n[Peer]\n# Name = HQ\nPublicKey = XXX\nPresharedKey = XXX\nAllowedIPs = 0.0.0.0/0, ::/0\nEndpoint = 127.0.0.1:51820\nPersistentKeepalive = 25\n",
8260+
"active": true,
8261+
"latest_handshake": "2025-09-30T08:52:29+00:00"
8262+
}
8263+
],
8264+
"mtu": 0,
8265+
"dns": []
8266+
}
8267+
]
8268+
}
82408269
```
82418270
8242-
### set-instance
82438271
8244-
Create a new instance or configure an existing one:
8245-
```
8246-
api-cli ns.wireguard set-instance --data '{"listen_port": 51820, "name": "wg1", "instance": "wg1", "enabled": true, "network": "10.103.1.0/24", "routes": ["192.168.100.0/24"], "public_endpoint": "192.168.122.49", "dns": [], "user_db": ""}'
8247-
```
8272+
### add-server
82488273
8249-
Response example:
8250-
```json
8251-
{"result": "success"}
8274+
Add a new WireGuard tunnel server:
8275+
```
8276+
api-cli ns.wireguard add-server --data '{"enabled": true, "name": "Cool Server", "public_endpoint": "wireguard.example.com", "listen_port": 51822, "network": "10.1.85.0/24", "mtu": "1420", "dns": ["192.168.1.1"]}'
82528277
```
82538278
82548279
Parameters:
8255-
- `listen_port`: the port where the WireGuard server listens
8256-
- `name`: the name of the instance, it must be unique and it's the name of the interface on the system, it must be a valid interface name and start with `wg`
8257-
- `enabled`: `true` to enable the instance, `false` to disable it
8258-
- `network`: the network of the WireGuard instance, this is the network where the clients will be connected
8259-
- `routes`: the routes that the clients will receive when connected, this parameter is used during the client configuration creation
8280+
- `enabled`: create the instance as active if `true`, inactive if `false`
8281+
- `name`: the name of the instance
82608282
- `public_endpoint`: the public endpoint of the WireGuard server, it can be an IP address or a domain name, it's used during the client configuration creation
8261-
- `dns`: the DNS servers that the clients will receive when connected, it's used during the client configuration creation; this option is honored only if the peer
8262-
has the `ns_route_all_traffic` option set to `1`
8263-
- `user_db`: the user database to use for authentication; if empty, the instance will not be connected to an existing user db and the WireGuard peer will be
8264-
indipendent; if the user db is set, each new peer must be have a user with the same name in the user db
8283+
- `listen_port`: the port where the WireGuard server listens
8284+
- `network`: the network of the WireGuard instance, this is the client subnet
8285+
- `mtu`: the MTU of the WireGuard interface, if kept empty auto-detection will be used
8286+
- `dns`: the DNS servers that the clients can use to avoid dns bleeding
82658287
8266-
### remove-instance
8288+
### edit-server
82678289
8268-
Remove an existing instance and all associated peers:
8290+
Edit the wireguard instance
82698291
```
8270-
api-cli ns.wireguard remove-instance --data '{"instance": "wg1"}'
8292+
api-cli ns.wireguard edit-server --data '{"instance": "wgX",enabled": true, "name": "Cool Server", "public_endpoint": "wireguard.example.com", "listen_port": 51822, "network": "10.1.85.0/24", "mtu": "1420", "dns": ["192.168.1.1"]}'
82718293
```
82728294
8273-
Response example:
8274-
```json
8275-
{"result": "success"}
8276-
```
8295+
Parameters:
8296+
- `instance`: the name of the WireGuard instance, the instance must exist
82778297
8278-
### set-peer
8298+
All other parameters are the same as in `add-server`.
82798299
8280-
Create or configure a peer.
8300+
### delete-server
82818301
8282-
Example to create a Road Warrior peer:
8302+
Remove an existing instance and all associated peers:
82838303
```
8284-
api-cli ns.wireguard set-peer --data '{"instance": "wg1", "account": "user1", "enabled": true, "route_all_traffic": false, "client_to_client": false, "ns_routes": [], "preshared_key": true}'
8304+
api-cli ns.wireguard delete-server --data '{"instance": "wg1"}'
82858305
```
82868306
8287-
Example to create a Site-to-Site peer:
8307+
### get-peer-defaults
8308+
8309+
Generate defaults for a new WireGuard peer:
82888310
```
8289-
api-cli ns.wireguard set-peer --data '{"instance": "wg1", "account": "site1", "enabled": true, "route_all_traffic": true, "client_to_client": true, "ns_routes": ["192.168.100.0/24"], "preshared_key": true}'
8311+
api-cli ns.wireguard get-peer-defaults --data '{"instance": "wg1"}
82908312
```
82918313
8314+
Parameters:
8315+
- `instance`: the name of the WireGuard instance, the instance must exist
8316+
82928317
Response example:
82938318
```json
8294-
{"result": "success"}
8319+
{
8320+
"local_networks": [
8321+
"10.0.1.0/24",
8322+
"192.168.100.0/24"
8323+
],
8324+
"reserved_ip": "10.1.85.2"
8325+
}
8326+
```
8327+
8328+
### add-peer
8329+
8330+
Add a new WireGuard peer to an existing instance:
8331+
```
8332+
api-cli ns.wireguard add-peer --data '{"instance": "wg3", "enabled": true, "name": "HQ Milan", "reserved_ip": "10.1.85.2", "pre_shared_key": true, "route_all_traffic": false, "local_networks": ["10.0.1.0/24", "192.168.100.0/24"], "remote_networks": [""]}'
82958333
```
82968334
82978335
Parameters:
82988336
- `instance`: the name of the WireGuard instance, the instance must exist
8299-
- `account`: the name of the peer, it must be unique for the instance; if the instance is connected to a user db, the account must be the name of an existing user
83008337
- `enabled`: `true` to enable the peer, `false` to disable it
8301-
- `route_all_traffic`: `true` to route all the traffic of the peer through the WireGuard tunnel, `false` to route only the traffic for the `ns_routes` through the tunnel; if this option is set the `dns` option in the instance configuration will be honored
8302-
- `client_to_client`: `true` to allow the peer to communicate with other peers connected to the same instance, `false` to disallow it; it must be set to `true`
8303-
if the `route_all_traffic` is set to `true` when the client is not a Road Warrior user but another firewall for a site-to-site connection
8304-
- `ns_routes`: the routes that the peer will receive when connected, this parameter is used during the client configuration creation
8305-
- `preshared_key`: `true` to generate a new preshared key for the peer, `false` to not use it
8338+
- `name`: the name of the peer
8339+
- `reserved_ip`: the reserved IP address for the peer, it must be in the network of the instance and unique
8340+
- `pre_shared_key`: `true` to generate a new preshared key for the peer
8341+
- `route_all_traffic`: `true` to route all the traffic of the peer through the WireGuard tunnel, this will effectively ignore the local networks param
8342+
- `local_networks`: the local networks that the peer will be able to access, this parameter is used during the client configuration creation
8343+
- `remote_networks`: the networks that the peer will route through the WireGuard tunnel, this parameter is used during the client configuration creation
83068344
8307-
### remove-peer
83088345
8309-
Remove an existing peer:
8346+
### edit-peer
8347+
8348+
Edit an existing WireGuard peer:
83108349
```
8311-
api-cli ns.wireguard remove-peer --data '{"instance": "wg1", "account": "user1"}'
8350+
api-cli ns.wireguard add-peer --data '{"instance": "wg3", "id": "peerid", "enabled": true, "name": "HQ Milan", "reserved_ip": "10.1.85.2", "pre_shared_key": true, "route_all_traffic": false, "local_networks": ["10.0.1.0/24", "192.168.100.0/24"], "remote_networks": [""]}'
83128351
```
83138352
8314-
Response example:
8315-
```json
8316-
{"result": "success"}
8353+
Parameters:
8354+
- `id`: the id of the peer, it can be found in the `list-servers` output
8355+
8356+
All other parameters are the same as in `add-peer`
8357+
8358+
### delete-peer
8359+
8360+
Delete a peer:
8361+
```
8362+
api-cli ns.wireguard delete-peer --data '{"id": "peerid"}'
83178363
```
83188364
8319-
### download-peer-config
8365+
Parameters:
8366+
- `id`: the id of the peer, it can be found in the `list-servers` output
8367+
83208368
8321-
Download the configuration of a peer:
8369+
### list-tunnels
8370+
8371+
List all Wireguard tunnels used as clients
83228372
```
8323-
api-cli ns.wireguard download-peer-config --data '{"instance": "wg1", "account": "user1"}'
8373+
api-cli ns.wireguard list-tunnels
83248374
```
83258375
83268376
Response example:
83278377
```json
8328-
{"config": "# Account: user1 for wg1\n[Interface]\nPrivateKey = 4OoVRqKW0Tur511IL6ttX6iz/EnxrbKzUcAX89bUxlU=\nAddress = 10.103.1.2\n# Custom DNS disabled\n\n[Peer]\nPublicKey = gm1cTae6ub4QGvQcknrb3FbN46x1tbaXJjOQbwX/siM=\nPreSharedKey = /3EbK9a8DW3D7vn0SFp3oK2XSoem05DpG4IxEZ4qoyU=\nAllowedIPs = 192.168.100.0/24,10.103.1.0/24\nEndpoint = 192.168.122.49:51820\nPersistentKeepalive = 25", "qrcode": "G1s0MDszNzs..."}
8378+
{
8379+
"tunnels": [
8380+
{
8381+
"active": true,
8382+
"address": "10.1.122.2",
8383+
"dns": [
8384+
"192.168.1.1"
8385+
],
8386+
"enabled": true,
8387+
"endpoint": "wireguard.example.com",
8388+
"id": "wg2",
8389+
"latest_handshake": "2025-09-30T09:07:25+00:00",
8390+
"name": "imported_wg2",
8391+
"network_routes": [],
8392+
"peer_id": "wg2_ns_5454129c_peer",
8393+
"peer_private_key": "XXX",
8394+
"pre_shared_key": "XXX",
8395+
"route_all_traffic": true,
8396+
"server_public_key": "XXX",
8397+
"udp_port": 51820
8398+
}
8399+
]
8400+
}
83298401
```
83308402
8331-
Output parameters:
8332-
- `config`: the configuration of the peer, it's in clear text; remember to encode it to base64 before importing it into another firewall
8333-
- `qrcode`: the QR code of the configuration, it's a base64 encoded image; it can be used to import the configuration into a mobile app
8403+
### add-tunnel
83348404
8335-
### import-configuration
8405+
Add a wireguard tunnel as a client
8406+
```
8407+
api-cli ns.wireguard add-tunnel --data '{"enabled": true, "name": "HQ Milan", "reserved_ip": "10.2.13.4", "server_public_key": "XXX", "peer_private_key": "XXX", "pre_shared_key": "XXX", "route_all_traffic": true, "network_routes": [""], "endpoint": "wireguard.example.com", "udp_port": 51121, "dns": ["192.168.1.1"]}'
8408+
```
8409+
8410+
Parameters:
8411+
- `enabled`: create the tunnel as active if `true`, inactive if `false`
8412+
- `name`: the name of the tunnel
8413+
- `reserved_ip`: the reserved IP address for the tunnel
8414+
- `server_public_key`: the public key of the server
8415+
- `peer_private_key`: the private key of the peer
8416+
- `pre_shared_key`: the preshared key, it can be empty if not used
8417+
- `route_all_traffic`: `true` to route all the traffic of the peer through the WireGuard tunnel, `false` to route only the traffic for the `network_routes` through the tunnel
8418+
- `network_routes`: the networks that the peer will route through the WireGuard tunnel
8419+
- `endpoint`: the public endpoint of the WireGuard server, it can be an IP address or a domain name
8420+
- `udp_port`: the port where the WireGuard server listens
8421+
- `dns`: the DNS servers that the clients can use to avoid dns bleeding
8422+
8423+
8424+
### edit-tunnel
83368425
8337-
Import a WireGuard configuration:
8426+
Edit an existing WireGuard tunnel:
83388427
```
8339-
api-cli ns.wireguard import-configuration --data '{"config": "base64encodedconfig"}'
8428+
api-cli ns.wireguard edit-tunnel --data '{"id": "wg4", "peer_id": "wg4_ns_884e488b_peer", "enabled": true, "name": "HQ Milan", "reserved_ip": "10.2.13.4", "server_public_key": "XXX", "peer_private_key": "XXX", "pre_shared_key": "XXX", "route_all_traffic": true, "network_routes": [""], "endpoint": "wireguard.example.com", "udp_port": 51121, "dns": ["192.168.1.1"]}'
83408429
```
83418430
8342-
Response example:
8343-
```json
8344-
{"result": "success"}
8431+
Parameters:
8432+
- `id`: the id of the tunnel, it can be found in the `list-tunnels` output
8433+
- `peer_id`: the id of the peer, it can be found in the `list-tunnels` output
8434+
8435+
All other parameters are the same as in `add-tunnel`.
8436+
8437+
### delete-tunnel
8438+
8439+
Delete a tunnel:
8440+
```
8441+
api-cli ns.wireguard delete-tunnel --data '{"id": "wg4"}'
83458442
```
83468443
8444+
Parameters:
8445+
- `id`: the id of the tunnel, it can be found in the `list-tunnels` output
8446+
83478447
### ns.ha
83488448
83498449
The following APIs are available for managing High Availability (HA) configuration.

0 commit comments

Comments
 (0)