WireGuard server module for mothership
This commit is contained in:
parent
57f3d7645b
commit
dc9f54fb76
6 changed files with 51 additions and 65 deletions
|
@ -185,6 +185,7 @@
|
||||||
];
|
];
|
||||||
secrets = {
|
secrets = {
|
||||||
"cachix" = {};
|
"cachix" = {};
|
||||||
|
"mothership-wireguard-private-key" = {};
|
||||||
"git-workspace-tokens".owner = "ccr";
|
"git-workspace-tokens".owner = "ccr";
|
||||||
"magit-forge-github-token".owner = "ccr";
|
"magit-forge-github-token".owner = "ccr";
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
}: {
|
}: {
|
||||||
imports = fleetModules [
|
imports = fleetModules [
|
||||||
"common"
|
"common"
|
||||||
|
"wireguard-server"
|
||||||
"ssh"
|
"ssh"
|
||||||
"ccr"
|
"ccr"
|
||||||
"nix"
|
"nix"
|
||||||
|
|
39
modules/wireguard-server/default.nix
Normal file
39
modules/wireguard-server/default.nix
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
config,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
|
networking.nat.enable = true;
|
||||||
|
networking.nat.externalInterface = "enp5s0"; # mothership network interface, shouldn't be hardcoded here
|
||||||
|
networking.nat.internalInterfaces = ["wg0"];
|
||||||
|
networking.firewall = {
|
||||||
|
allowedUDPPorts = [51820];
|
||||||
|
};
|
||||||
|
|
||||||
|
networking.wireguard.interfaces = {
|
||||||
|
wg0 = {
|
||||||
|
ips = ["10.100.0.1/24"];
|
||||||
|
|
||||||
|
listenPort = 51820;
|
||||||
|
|
||||||
|
postSetup = ''
|
||||||
|
${pkgs.iptables}/bin/iptables -t nat -A POSTROUTING -s 10.100.0.0/24 -o eth0 -j MASQUERADE
|
||||||
|
'';
|
||||||
|
|
||||||
|
postShutdown = ''
|
||||||
|
${pkgs.iptables}/bin/iptables -t nat -D POSTROUTING -s 10.100.0.0/24 -o eth0 -j MASQUERADE
|
||||||
|
'';
|
||||||
|
|
||||||
|
privateKeyFile = config.age.secrets."${config.networking.hostName}-wireguard-private-key".path;
|
||||||
|
|
||||||
|
peers = [
|
||||||
|
{
|
||||||
|
# thinkpad
|
||||||
|
publicKey = "g8wId6Rl0olRFRtAnQ046ihPRYFCtMxOJ+/Z9ARwIxI=";
|
||||||
|
# List of IPs assigned to this peer within the tunnel subnet. Used to configure routing.
|
||||||
|
allowedIPs = ["10.100.0.2/32"];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
|
@ -1,64 +0,0 @@
|
||||||
# FIXME For some reson this doesnt' work
|
|
||||||
{
|
|
||||||
config,
|
|
||||||
lib,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
networking.firewall = {
|
|
||||||
allowedUDPPorts = [51820]; # Clients and peers can use the same port, see listenport
|
|
||||||
};
|
|
||||||
networking.wireguard.interfaces = {
|
|
||||||
# "wg0" is the network interface name. You can name the interface arbitrarily.
|
|
||||||
wg0 = {
|
|
||||||
# Determines the IP address and subnet of the client's end of the tunnel interface.
|
|
||||||
ips = ["10.100.0.2/24"];
|
|
||||||
listenPort = 51820; # to match firewall allowedUDPPorts (without this wg uses random port numbers)
|
|
||||||
|
|
||||||
# Path to the private key file.
|
|
||||||
#
|
|
||||||
# Note: The private key can also be included inline via the privateKey option,
|
|
||||||
# but this makes the private key world-readable; thus, using privateKeyFile is
|
|
||||||
# recommended.
|
|
||||||
privateKeyFile = "/home/ccr/wg-private"; #TODO use agenix
|
|
||||||
|
|
||||||
peers = [
|
|
||||||
# For a client configuration, one peer entry for the server will suffice.
|
|
||||||
|
|
||||||
{
|
|
||||||
# Public key of the server (not a file path).
|
|
||||||
publicKey = "fCwjd75CefC9A7WqO7s3xfOk2nRcoTKfnAzDT6Lc5AA=";
|
|
||||||
|
|
||||||
# Forward all the traffic via VPN.
|
|
||||||
allowedIPs = ["0.0.0.0/0"];
|
|
||||||
# Or forward only particular subnets
|
|
||||||
#allowedIPs = [ "10.100.0.1" "91.108.12.0/22" ];
|
|
||||||
|
|
||||||
# Set this to the server IP and port.
|
|
||||||
endpoint = "ccr.ydns.eu:51820"; # ToDo: route to endpoint not automatically configured https://wiki.archlinux.org/index.php/WireGuard#Loop_routing https://discourse.nixos.org/t/solved-minimal-firewall-setup-for-wireguard-client/7577
|
|
||||||
|
|
||||||
# Send keepalives every 25 seconds. Important to keep NAT tables alive.
|
|
||||||
persistentKeepalive = 25;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
networking.wg-quick.interfaces = {
|
|
||||||
wg0 = {
|
|
||||||
address = ["10.0.0.2/24" "fdc9:281f:04d7:9ee9::2/64"];
|
|
||||||
dns = ["10.0.0.1" "fdc9:281f:04d7:9ee9::1"];
|
|
||||||
privateKeyFile = "/home/ccr/wg-private";
|
|
||||||
|
|
||||||
peers = [
|
|
||||||
{
|
|
||||||
publicKey = "fCwjd75CefC9A7WqO7s3xfOk2nRcoTKfnAzDT6Lc5AA=";
|
|
||||||
# presharedKeyFile = "/root/wireguard-keys/preshared_from_peer0_key";
|
|
||||||
allowedIPs = ["0.0.0.0/0" "::/0"];
|
|
||||||
endpoint = "ccr.ydns.eu:51820";
|
|
||||||
persistentKeepalive = 25;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
|
@ -12,6 +12,6 @@ in {
|
||||||
"git-workspace-tokens.age".publicKeys = [users.ccr hosts.test hosts.mothership];
|
"git-workspace-tokens.age".publicKeys = [users.ccr hosts.test hosts.mothership];
|
||||||
|
|
||||||
# WireGuard
|
# WireGuard
|
||||||
|
|
||||||
"thinkpad-wireguard-private-key.age".publicKeys = [hosts.thinkpad];
|
"thinkpad-wireguard-private-key.age".publicKeys = [hosts.thinkpad];
|
||||||
|
"mothership-wireguard-private-key.age".publicKeys = [hosts.mothership];
|
||||||
}
|
}
|
||||||
|
|
9
secrets/mothership-wireguard-private-key.age
Normal file
9
secrets/mothership-wireguard-private-key.age
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
age-encryption.org/v1
|
||||||
|
-> ssh-ed25519 q+UPnA 7RAJbAW7p/kUyAG7VQlVG2Ri86F13GCVw7uOGck5Yms
|
||||||
|
KJQCDEH6PQF8H4uUFp5cuvtLb4Yldvl35NXqbYyxUYQ
|
||||||
|
-> 2x%m?X4r-grease [L7Jb/. xgMVomN[
|
||||||
|
in0zvAfoC0s/CLqNviUa2NfGJR1R4BjbkKCzNYsjJd7JUG+R1hda7Vku7SQ5yA1D
|
||||||
|
SzSeDISN7PK6dVBDlt2vzgqZnJpNswnSu23qdlfiQ2f9N/LA7gKD9uB5YF5wac2h
|
||||||
|
rgY
|
||||||
|
--- 3m0T9+VQCfTh6uuvoilEvtu57x6UbXsRf73k40O2v9k
|
||||||
|
¢‘]jòßí¦£SUt<NJ_¹}ïÉœe0ÉŽºž/n7AÜòÙa™©þ¼'úÂhDz¨c-C4B?ÿ¾LŽû:½–Unu\Aö½ÚMÂ6
|
Loading…
Add table
Reference in a new issue