summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2021-10-10 14:11:18 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2021-10-10 14:11:18 +0200
commitfd0d76cff24790194a27c8ed3ff47d83fedc8245 (patch)
tree91f469b3a2020b385610ed10596f908683c81e0f /modules
parentd85f16d75ae44cf94f0500fdbfbde2b8233b8cc5 (diff)
downloadnixos-fd0d76cff24790194a27c8ed3ff47d83fedc8245.tar
nixos-fd0d76cff24790194a27c8ed3ff47d83fedc8245.tar.gz
nixos-fd0d76cff24790194a27c8ed3ff47d83fedc8245.tar.bz2
nixos-fd0d76cff24790194a27c8ed3ff47d83fedc8245.tar.xz
nixos-fd0d76cff24790194a27c8ed3ff47d83fedc8245.zip
yggdrasil-wg: ...
Diffstat (limited to 'modules')
-rw-r--r--modules/yggdrasil-wg/default.nix31
-rw-r--r--modules/yggdrasil-wg/udp2raw-secret36
2 files changed, 64 insertions, 3 deletions
diff --git a/modules/yggdrasil-wg/default.nix b/modules/yggdrasil-wg/default.nix
index e7ecf709..db7780fb 100644
--- a/modules/yggdrasil-wg/default.nix
+++ b/modules/yggdrasil-wg/default.nix
@@ -86,7 +86,28 @@ in {
86 systemd.services = listToAttrs (filter ({ value, ...}: value != null) (imap0 (ix: opts@{to, from, ...}: let other = if from == hostName then to else from; in nameValuePair "yggdrasil-udp2raw@${other}" (if opts ? "endpointHost" && (from == hostName || to == hostName) then { 86 systemd.services = listToAttrs (filter ({ value, ...}: value != null) (imap0 (ix: opts@{to, from, ...}: let other = if from == hostName then to else from; in nameValuePair "yggdrasil-udp2raw@${other}" (if opts ? "endpointHost" && (from == hostName || to == hostName) then {
87 path = with pkgs; [iptables]; 87 path = with pkgs; [iptables];
88 serviceConfig = { 88 serviceConfig = {
89 ExecStart = "${pkgs.udp2raw}/bin/udp2raw ${if from == hostName then "-c -l 127.0.0.1:${toString (udp2rawPort + ix)} -r ${opts.endpointHost}:${toString (udp2rawPort + ix)}" else "-s -l 0.0.0.0:${toString (udp2rawPort + ix)} -r 127.0.0.1:${toString listenPort}"} -k tmpkey --auth-mode hmac_sha1 --raw-mode faketcp -a"; 89 RuntimeDirectory = ["config"];
90 ExecStartPre = pkgs.writeShellScript "udp2raw-mkconfig-${other}.sh" ''
91 secret=$(cat ${config.sops.secrets."yggdrasil-udp2raw-secret".path})
92 cat >''${RUNTIME_DIRECTORY}/udp2raw.conf <<EOF
93 ${if from == hostName then ''
94 -c
95 -l 127.0.0.1:${toString (udp2rawPort + ix)}
96 -r ${opts.endpointHost}:${toString (udp2rawPort + ix)}
97 '' else ''
98 -s
99 -l 0.0.0.0:${toString (udp2rawPort + ix)}
100 -r 127.0.0.1:${toString listenPort}
101 ''}
102 -k $secret
103 --auth-mode hmac_sha1
104 --raw-mode faketcp
105 -a
106 --retry-on-error
107 EOF
108 '';
109 ExecStart = "${pkgs.udp2raw}/bin/udp2raw --conf-file \${RUNTIME_DIRECTORY}/udp2raw.conf";
110 Restart = "always";
90 }; 111 };
91 } else null)) links)) // { 112 } else null)) links)) // {
92 "wireguard-yggdrasil" = { 113 "wireguard-yggdrasil" = {
@@ -96,11 +117,15 @@ in {
96 firewall.path = optionals isRouter [pkgs.procps]; 117 firewall.path = optionals isRouter [pkgs.procps];
97 }; 118 };
98 119
99 sops.secrets = mkIf (pathExists privateKeyPath) { 120 sops.secrets = {
100 "yggdrasil-wg.priv" = { 121 "yggdrasil-wg.priv" = mkIf (pathExists privateKeyPath) {
101 format = "binary"; 122 format = "binary";
102 sopsFile = privateKeyPath; 123 sopsFile = privateKeyPath;
103 }; 124 };
125 "yggdrasil-udp2raw-secret" = mkIf (any (opts@{to, from, ...}: (to == hostName || from == hostName) && opts ? "endpointHost") links) {
126 format = "binary";
127 sopsFile = ./udp2raw-secret;
128 };
104 }; 129 };
105 130
106 networking.hosts = mkIf inNetwork (listToAttrs (concatMap ({name, value}: map (ip: nameValuePair (stripSubnet ip) ["${name}.yggdrasil"]) value) (mapAttrsToList nameValuePair hostIPs))); 131 networking.hosts = mkIf inNetwork (listToAttrs (concatMap ({name, value}: map (ip: nameValuePair (stripSubnet ip) ["${name}.yggdrasil"]) value) (mapAttrsToList nameValuePair hostIPs)));
diff --git a/modules/yggdrasil-wg/udp2raw-secret b/modules/yggdrasil-wg/udp2raw-secret
new file mode 100644
index 00000000..bed8de83
--- /dev/null
+++ b/modules/yggdrasil-wg/udp2raw-secret
@@ -0,0 +1,36 @@
1{
2 "data": "ENC[AES256_GCM,data:GOriV+Kb7gKgEBaqgN5XysKvJl9PbImG5ZdelRpdZcw9,iv:TmRuxpm7Hl3xEu/Zm+Tzl7/Jvg92DUiBlw5oT1p9XhU=,tag:UCKKpPDJ7jloplM5jsc9Dg==,type:str]",
3 "sops": {
4 "kms": null,
5 "gcp_kms": null,
6 "azure_kv": null,
7 "hc_vault": null,
8 "age": null,
9 "lastmodified": "2021-10-10T12:04:09Z",
10 "mac": "ENC[AES256_GCM,data:z0YkHarF33dgtWXCziVUmhDZPF9nMbnAb4fUGbg7e2w66Rv29lB2tTGd0mmAHku0ZO9BQ+b19zWslKUAcSxTRbtYx+BY/4QZBQ6kxeo3ujg9xFCqv28oc7Vf/MTnDXj/ViZP+twuw9jsHLQ5hY5N1Unh8/hTNS+lHq+Tiso8dcM=,iv:9pezJ4vFVokWcVcXzBT/jtJyicfDdykUHB9nZQ0V/74=,tag:wmXnYnd6//NAy/aWU9SMyg==,type:str]",
11 "pgp": [
12 {
13 "created_at": "2021-10-10T12:04:08Z",
14 "enc": "-----BEGIN PGP MESSAGE-----\n\nhF4Dgwm4NZSaLAcSAQdAEnoWy2jZG0Jf1+4G3heV7MTNlur4dqX5fSJZRN6khw8w\ngab9Z73+fCsYm0fmYBJ8EyHLLjhHKP4KiE5pwFW4dNu6XBcHtRHSptZK/zTMMStv\n0l4BCt7PF5q0dPatuqWZ0+2Ns8LSXT/YZVwUkvy3KS8UcZQq7xSwDdBqSTVc1lsz\nb6OI+b3sDHdmzK3MVHAgNEF74wx2or/ccbQT7n5EZxRkGoNbS9Fa7CY3DnJFVEkl\n=jCLU\n-----END PGP MESSAGE-----\n",
15 "fp": "F1AF20B9511B63F681A14E8D51AEFBCD1DEF68F8"
16 },
17 {
18 "created_at": "2021-10-10T12:04:08Z",
19 "enc": "-----BEGIN PGP MESSAGE-----\n\nhF4DyFKFNkTVG5oSAQdAlsp51HC3CZphu7rZ1hdWk9NzUlkn0DzcWwQ7UcNd524w\nAI4RpCSmOdRy/dy8oMV+9Kv8YgqmChynN/kIgFkHbS5pdbBl50o2xzOhjB26WoJh\n0l4BbkK1QSZkzUCcQzlunqn5N3pvkCjPdBW2DOkAIrNwvEs7A8nPmrrn9AHQrLlq\nEdDYPkREA5TXftnhmu4BAQ01zsoKp2Ny6gAdHMBlLAcS4PM+ugdplYGBAlALtl2P\n=Zrhp\n-----END PGP MESSAGE-----\n",
20 "fp": "7ED22F4AA7BB55728B643DC5471B7D88E4EF66F8"
21 },
22 {
23 "created_at": "2021-10-10T12:04:08Z",
24 "enc": "-----BEGIN PGP MESSAGE-----\n\nhF4DbYDvGI0HDr0SAQdA7KxnxC4ZvSLm91bBavRzmTnJwq5Ed+XAPR3Xv1l4X3ww\nQjmDqbJB2av+PJCltta3I4LWh6SOMJ9AOjav6pBPrpFncqkTJoW3CoA9PA4SG4cC\n0l4BG37XFitMYEJdPliwoWcCBoCmKtRBlgwuY9yuyzkTE8pgzbYy+Wa9E7wZJsXD\n3rdziltY8/33Zx9bQvK0VnEsMIZHE3mHHItWcJ0pPUbIZH7QjetweB4oVhBo8CZu\n=PL3V\n-----END PGP MESSAGE-----\n",
25 "fp": "A1C7C95E6CAF0A965CB47277BCF50A89C1B1F362"
26 },
27 {
28 "created_at": "2021-10-10T12:04:08Z",
29 "enc": "-----BEGIN PGP MESSAGE-----\n\nhF4DXxoViZlp6dISAQdAF2b1Qg/tPPI4Iyz8QutxrWlOetqN7HzkKEfhtfFO504w\nQtEf0ki8xXsnb03WLknONFFw9SXsTAy7d4xcCuYYbjSID0SwC9OsM6jS/LIXxayI\n0l4BbD6PKAu0vihO1Yrar8HaVX9ybafP48PN8cHGF23AELlFdxMZG94pBN4gzKBN\nxn2XtQSjI8xidnE2fEoZKA6YogDdK5Lig21RRFnRaoytJGtNCTIwYaG88WuObUHD\n=qwAT\n-----END PGP MESSAGE-----\n",
30 "fp": "30D3453B8CD02FE2A3E7C78C0FB536FB87AE8F51"
31 }
32 ],
33 "unencrypted_suffix": "_unencrypted",
34 "version": "3.7.1"
35 }
36} \ No newline at end of file