Skip to main content

WireGuard manager to connect two or more peers in a star VPN

Project description

wgstarman

WireGuard manager written in Python 3 to connect two or more peers in a star VPN, i.e. having a central peer which routes the traffic within the VPN. It includes a DHCP-like IP address allocation mechanism.

It currently supports IPv6 only, but IPv4 is in the plans (it needs a proper IP address release logic).

It has been designed and tested on Linux, specifically due to the paths and commands used, but it should work on any POSIX / UNIX operating systems (like MacOS).

Security

The VPN can be accessed only knowing a pre-shared key, generated by the server / central node the first time it is being executed. In case of PSK exposure, the --refresh-psk might be used to generate a new one.

Every message exchanged with the protocol is encrypted and decrypted via the given PSK.

Once the peer joins the network, the WireGuard asymmetric encryption secures the connection between the peers.

Software requirement

  • WireGuard kernel's module (it should be enabled by default)
  • wg and wg-quick commands (provided by most Linux distributions via the wireguard-tools package)

Setting up the server

wgstarman server --ipv6-network fdxx:xxxx:xxxx:yyyy:zzzz:zzzz::/64
                 [--device-name wg0]
                 [--listen-address-4 0.0.0.0]
                 [--listen-address-6 ::]
                 [--listen-port 1194]
                 [--enable-listen-ipv6]
                 [--refresh-psk]
                 [--debug]
  • --ipv6-network the IPv6 network to use for the VPN, i.e. fdxx:xxxx:xxxx:yyyy:zzzz:zzzz::/64
  • --device-name the name of both the network device and the configuration file (default: wg0)
  • --listen-address-4 the address IPv4 on which the address manager will listen on (default: 0.0.0.0)
  • --listen-address-6 the address IPv6 on which the address manager will listen on; requires --enable-listen-ipv6 (default: ::)
  • --listen-port the port on which WireGuard (UDP) and the address manager (TCP) will listen on (default: 1194)
  • --enable-listen-ipv6 enable address manager to listen on {listen_address_6}:{listen_port}
  • --refresh-psk force the refresh of the pre-shared key
  • --debug enable debug log

The manager will output the pre-shared key (PSK), to be used for interacting with it and connect new peers.

The central peer will assign to itself the first IP of the network.

NOTE: the pre-shared key is being stored in /etc/wgstarman/wgstarman.conf and is formatted in the following way:

{server_public_key} = {pre-shared key}

The server's public key is generated at runtime the first time the network is being configured.

sysctl configurations

The following sysctl configurations must be set:

  • net.ipv6.conf.all.disable_ipv6=0 to enable IPv6 addresses
  • net.ipv6.conf.all.forwarding=1 to allow the packets routing via IPv6

docker caps

In case the server is run in docker, the following caps must be set:

  • NET_ADMIN
  • SYS_MODULE

Setting up the peers

wgstarman peer --server-address xx.yy.zz.kk
               [--server-port 1194]
               --device-name wg0
               --psk ODjCtWVtBzAq11clgtEwYxhHfEz8asGmnzwEQsqIZTU=
               [--host-name peer-name]
               [--keep-alive]
               [--overwrite]
               [--debug]
  • --server-address the server's public IP (either IPv4 or IPv6)
  • --server-port (default 1194) the port on which the server is listening (see server configuration)
  • --device-name the device and configuration file WireGuard will use for this VPN
  • --psk the pre-shared key, given by the server at startup
  • --host-name name of the peer, resolvable via wgstarman resolv (optional)
  • --keep-alive keep the connection to the server alive (to avoid connection drop in case of NAT)
  • --overwrite overwrite if a configuration already exists
  • --debug enable debug log

Once the command is given and throws no errors, a configuration file is being written in /etc/wireguard/[device-name].conf and the connection is established; the VPN connection can thus be upped or downed via the wg-quick commands.

In case wgstarman is used again specifying an already configured device name, it will connect to the wgstarman server again and verify its address / public key against the server's configuration: in case the server doesn't have the peer's record, it will assign a new IP and the peer will overwrite its own configuration.

Resolving VPN names

As WireGuard supports only layer 3 of the ISO/OSI stack, peers can't use multicast messages to share their positions (for instance using ZeroConf's mDNS protocol).

The tool also intentionally doesn't change the system's resolv configuration, as each system may vary and this might lead to unwanted behaviours (i.e. removing company's name servers etc).

As a result, the tool supports a DNS-like mechanism to resolve host names into their VPN IP addresses. This sub-command can be used as regular users.

The server replying to the resolv requests is the same which assigns the IP addresses, so it always knows which host have which address.

wgstarman resolv --device-name, -d wg0
                 [--resolv-port, -p 1195]
                 {host_name}
  • --device-name, -d the device associated with the network
  • --resolv-port, -p the resolv port (server listen port + 1)
  • {host_name} the host name to query

The resolv command will output the list of the found address(es) connected to the central peer, one address per line. In case of error, an error will be logged in stderr.

Exit codes:

  • 0 no error
  • 1 resolv server error
  • 2 unable to connect to resolv server

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wgstarman-0.1.10.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wgstarman-0.1.10-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file wgstarman-0.1.10.tar.gz.

File metadata

  • Download URL: wgstarman-0.1.10.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for wgstarman-0.1.10.tar.gz
Algorithm Hash digest
SHA256 ae029eb3910ab0f6f4e02d5cfcb166d84987a008aed12f1ea7c27e535d300870
MD5 d04d174114d1535aaf48f8ba2c24562e
BLAKE2b-256 0586b6a3a54244bf0af3d0bfbb24957101c633956920b5e015e1f808f0dc4c93

See more details on using hashes here.

File details

Details for the file wgstarman-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: wgstarman-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 25.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for wgstarman-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 934f29b785f7c3523ef50cada4ec2bad9a5aa9cc686468d1febb7414758d5d5d
MD5 0d9894027c1ad7a09e7b12f76ee0ad83
BLAKE2b-256 44427bc2e930d92ab0db5b8711923e6f93a192a0fe2b52ea2fee13722b5cf13a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page