Crates.io | wg_netmanager |
lib.rs | wg_netmanager |
version | 0.5.1 |
source | src |
created_at | 2022-01-05 16:47:28.749135 |
updated_at | 2022-02-12 17:00:18.135502 |
description | Wireguard network manager |
homepage | |
repository | https://github.com/gin66/wg_netmanager |
max_upload_size | |
id | 508546 |
size | 203,779 |
Situation is a couple of vps, some IoT devices in the home network and couple of roaming laptops/iPads/smartphones. Till now a quite complex setup involving wireguard, openvpn, ssh'ing from box to box was in use.
Using wireguard all the time is not an option, because then the Laptop in the home network would route traffic to the box one meter away via the long route (the vps somewhere in the Internet), instead of using the short path within the home network.
An alternative could have been tinc, but tinc - licensed under GPL v2 - may never hit iOs/iPadOS AppStore. So not a solution.
Use wireguard and add the missing management part. This shall:
Instead of manually creating keys (which is still the case in gui versions) the network uses one file to be distributed to all participants. Here a work in progress example (filename net.yaml):
network:
sharedKey: YDUBM6FhERePZ4gPlxzAbCN7K61BPjy7HApWYL+P128=
subnet: 10.1.1.0/8
peers:
- endPoint: 192.168.1.70:50000
adminPort: 55555
wgIp: 10.1.1.1
- endPoint: 192.168.1.212:50000
adminPort: 55555
wgIp: 10.1.1.2
The sharedKey can be created with wg genkey
.
Unfortunately there is still the need to define at least ONE static peer.
Bring up e.g. alice, bob and charlie would be just:
ALICE'S BOX> wg_netmanager -c net.yaml -i wg0 -a 10.1.1.1 -n alice
BOB'S BOX> wg_netmanager -c net.yaml -i wg0 -a 10.1.1.16 -n bob
CHARLIE'S BOX> wg_netmanager -c net.yaml -i wg0 -a 10.1.1.21 -n charlie
with alice being reachable on 192.168.1.70
Node support:
OS-Support
Wireguard-Interface
Network
Routing
System integration
Admin
As it works on my setup, the development will now slow down and will focus more on bugfixing.
My test setup is:
Alpha-VPS Internet Beta-VPS
behind firewall ---------+--------- public IP
|
|
|
Router
|
192.168.x.x |
Charlie ------------------------ Delta
Alpha-VPA and Beta-VPS use old linux version without wireguard kernel driver. So wireguard-go is in use.
After start of wg_manager on all four machines, three wireguard connections are setup quickly:
In addition the following gateway rules are added:
Shortly afterwards Charlie/Delta discover the local connection possibility. So the wireguard connections/routes change to:
Alpha-VPS <=> Beta-VPS
Charlie <=> Beta-VPS
Delta <=> Beta-VPS
Charlie <=> Delta
Alpha-VPS ==> Charlie/Delta via Gateway Beta-VPS
Charlie ==> Alpha-VPS via Gateway Beta-VPS
Delta ==> Alpha-VPS via Gateway Beta-VPS
After the one or other minute, NAT traversal is set up. And only wireguard connections exist without any gateway:
Actually, the tendency to go to one-to-one connections causes a new problem. The required amount of keep alive packages (to keep firewall ports persistent) between nodes increases nearly quadratically with the number of nodes in the net....
Not so much a problem in my setup, but still something to be addressed in the long run.
A second setup is:
Alpha-VPS Internet Beta-VPS
behind firewall ---------+--------- public IP
|
|
|
=====Router 1====Masquerade+Firewall
|
192.168.1.x |
Charlie -------------+---------- Delta
|
|
=====Router 2====Masquerade+Firewall
192.168.2.x |
With rust installed, just issue
cargo install wg_netmanager
The packages wireguard-tools and iproute/iproute2 need to be installed.
If kernel driver does not exist (e.g. VPS), then either wireguard-go
or boringtun
should be installed and in the path (using sudo
).
The packages wireguard-tools and wireguard-go need to be installed e.g. via brew.
The package wireguard-tools and kmod-wireguard need to be installed:
opkg install wireguard-tools kmod-wireguard
Generally, a shared key needs to be created and stored under sharedKey in your local copy of network.yaml. This can be done by:
wg genkey
and copy the result in the network.yaml
Then modify the peers list to accommodate your setup. At least one peer with a static address is needed. For dyndns-reachable servers, use the hostname instead of an ip.
If the subnet 10.1.1.0/8 does not suit your needs, then change it. All wireguard IPs need to be included in the chosen subnet.
Then copy the final yaml file to all your nodes and start the wg_netmanager with:
wg_netmanager -c network.yaml <wireguard-interface> <wireguard-ip> <name>
or - in case your sudo requires password:
sudo wg_netmanager -c network.yaml <wireguard-interface> <wireguard-ip> <name>
Eventually use further -v
or a -t
.
For vps, which do not support wireguard as network interface, either boringtun or wireguard-go can be used. wg_netmanager will try to run first wireguard-go and then boringtun. If this fails, but wireguard interface can be created by other means, then inform wg_netmanager about the existing wireguard interface with the -e
commandline switch.
For a list of commandline options, just use --help
as usual.
The required command line options for wireguard interface (-i), address (-a) and name (-n), can be stored in a peer.yaml file like this:
name: alice
wgIp: 10.1.1.1
wgInterface: wg0
existingInterface: false
The last one is actually only needed, if set to true.
Using namespaces several boxes can be simulated on one linux machine. See as example
wg_manager will add and delete routes on demand on two levels:
ip route add <ip>/32 dev <wg_dev>
In case one node of this wireguard network is compromised, then the implications are severe. The symmetric key can be distributed and any attacker's node can join the network.
With the current implementation an attacker could even issue this command:
ATTACKER'S BOX> wg_netmanager -c net.yaml wg0 8.8.8.8 alice
And ALL network participants will start to route any DNS request addressed to 8.8.8.8 to the ATTACKER's box.
This is actually a very cool feature and on the other hand quite frightening.
Depending on the linux version, ip route add
wants to find an interface with the corresponding subnet. If not successful, then it will throw a "no such process error".
Remedy is, that the wireguard interface is associated with IP and resp. netmask. without adding a route:
ip addr add 10.1.1.1/24 dev wg0 noprefixroute
Consequently, in the config-file the subnet has to specified. If the subnet does not include 8.8.8.8, then other nodes will not accept it - unless the defined subnet includes 8.8.8.8
The code of this crate is licensed according to MIT. To learn about the licenses of included crates, please check cargo license
.