Compare commits
No commits in common. "5686aa1a019c30a322681d0ef89142ae35c3db5c" and "93892224b7efedf57f3aa021604d1aab8efdc96c" have entirely different histories.
5686aa1a01
...
93892224b7
@ -114,33 +114,6 @@ rec {
|
|||||||
};
|
};
|
||||||
home.v6 = "2a0e:97c0:4d0::/48";
|
home.v6 = "2a0e:97c0:4d0::/48";
|
||||||
};
|
};
|
||||||
|
|
||||||
firewallForwards = aa: [
|
|
||||||
{
|
|
||||||
port = "http";
|
|
||||||
dst = aa.middleman.internal.ipv4.address;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
port = "https";
|
|
||||||
dst = aa.middleman.internal.ipv4.address;
|
|
||||||
}
|
|
||||||
{
|
|
||||||
port = 8448;
|
|
||||||
dst = aa.middleman.internal.ipv4.address;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
port = 2456;
|
|
||||||
dst = aa.valheim-oci.internal.ipv4.address;
|
|
||||||
proto = "udp";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
port = 2457;
|
|
||||||
dst = aa.valheim-oci.internal.ipv4.address;
|
|
||||||
proto = "udp";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
fstrimConfig = {
|
fstrimConfig = {
|
||||||
enable = true;
|
enable = true;
|
||||||
# backup happens at 05:00
|
# backup happens at 05:00
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{ lib }:
|
{ lib }:
|
||||||
let
|
let
|
||||||
inherit (builtins) length match elemAt filter replaceStrings;
|
inherit (builtins) length match elemAt filter;
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
genAttrs mapAttrsToList filterAttrsRecursive nameValuePair types
|
genAttrs mapAttrsToList filterAttrsRecursive nameValuePair types
|
||||||
mkOption mkOverride mkForce mkIf mergeEqualOption optional
|
mkOption mkOverride mkForce mkIf mergeEqualOption optional
|
||||||
@ -123,12 +123,6 @@ rec {
|
|||||||
home-manager = mkOpt' (enum [ "unstable" "stable" "mine" "mine-stable" ]) "unstable" "Branch of home-manager to use.";
|
home-manager = mkOpt' (enum [ "unstable" "stable" "mine" "mine-stable" ]) "unstable" "Branch of home-manager to use.";
|
||||||
};
|
};
|
||||||
|
|
||||||
nft = rec {
|
|
||||||
ipEscape = replaceStrings ["." ":"] ["-" "-"];
|
|
||||||
natFilterChain = ip: "filter-fwd-${ipEscape ip}";
|
|
||||||
dnatChain = ip: "fwd-${ipEscape ip}";
|
|
||||||
};
|
|
||||||
|
|
||||||
mkVLAN = name: vid: {
|
mkVLAN = name: vid: {
|
||||||
"25-${name}" = {
|
"25-${name}" = {
|
||||||
netdevConfig = {
|
netdevConfig = {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib.my) net;
|
inherit (lib.my) net;
|
||||||
inherit (lib.my.c.colony) domain prefixes firewallForwards;
|
inherit (lib.my.c.colony) domain prefixes;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ ./vms ];
|
imports = [ ./vms ];
|
||||||
@ -351,7 +351,6 @@ in
|
|||||||
|
|
||||||
firewall = {
|
firewall = {
|
||||||
trustedInterfaces = [ "vms" ];
|
trustedInterfaces = [ "vms" ];
|
||||||
nat.forwardPorts."${allAssignments.estuary.internal.ipv4.address}" = firewallForwards allAssignments;
|
|
||||||
extraRules = ''
|
extraRules = ''
|
||||||
define cust = { vm-mail, vm-darts }
|
define cust = { vm-mail, vm-darts }
|
||||||
table inet filter {
|
table inet filter {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
let
|
let
|
||||||
inherit (builtins) elemAt;
|
inherit (builtins) elemAt;
|
||||||
inherit (lib.my) net mkVLAN;
|
inherit (lib.my) net mkVLAN;
|
||||||
inherit (lib.my.c.colony) pubV4 domain prefixes firewallForwards;
|
inherit (lib.my.c.colony) pubV4 domain prefixes;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
nixos = {
|
nixos = {
|
||||||
@ -356,7 +356,32 @@ in
|
|||||||
nat = {
|
nat = {
|
||||||
enable = true;
|
enable = true;
|
||||||
externalInterface = "wan";
|
externalInterface = "wan";
|
||||||
forwardPorts."${assignments.internal.ipv4.address}" = firewallForwards allAssignments;
|
externalIP = assignments.internal.ipv4.address;
|
||||||
|
forwardPorts = [
|
||||||
|
{
|
||||||
|
port = "http";
|
||||||
|
dst = allAssignments.middleman.internal.ipv4.address;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
port = "https";
|
||||||
|
dst = allAssignments.middleman.internal.ipv4.address;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
port = 8448;
|
||||||
|
dst = allAssignments.middleman.internal.ipv4.address;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
port = 2456;
|
||||||
|
dst = allAssignments.valheim-oci.internal.ipv4.address;
|
||||||
|
proto = "udp";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
port = 2457;
|
||||||
|
dst = allAssignments.valheim-oci.internal.ipv4.address;
|
||||||
|
proto = "udp";
|
||||||
|
}
|
||||||
|
];
|
||||||
};
|
};
|
||||||
extraRules =
|
extraRules =
|
||||||
let
|
let
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib.my) net nft;
|
inherit (lib.my) net;
|
||||||
inherit (lib.my.c.colony) domain prefixes firewallForwards;
|
inherit (lib.my.c.colony) domain prefixes;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = [ ./containers ];
|
imports = [ ./containers ];
|
||||||
@ -151,7 +151,6 @@ in
|
|||||||
firewall = {
|
firewall = {
|
||||||
tcp.allowed = [ 19999 ];
|
tcp.allowed = [ 19999 ];
|
||||||
trustedInterfaces = [ "ctrs" ];
|
trustedInterfaces = [ "ctrs" ];
|
||||||
nat.forwardPorts."${allAssignments.estuary.internal.ipv4.address}" = firewallForwards allAssignments;
|
|
||||||
extraRules = ''
|
extraRules = ''
|
||||||
table inet filter {
|
table inet filter {
|
||||||
chain forward {
|
chain forward {
|
||||||
@ -159,17 +158,6 @@ in
|
|||||||
iifname vms oifname ctrs accept
|
iifname vms oifname ctrs accept
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
table inet nat {
|
|
||||||
# Hack to fix our NAT situation with internal routing
|
|
||||||
# We need to snat to our public IP, otherwise on the return path from e.g. middleman it will
|
|
||||||
# try to forward packet directly with its own IP, bypassing our carefully crafted DNAT...
|
|
||||||
chain ${nft.dnatChain allAssignments.estuary.internal.ipv4.address} {
|
|
||||||
ct mark set 0x1337
|
|
||||||
}
|
|
||||||
chain postrouting {
|
|
||||||
ct mark 0x1337 snat ip to ${assignments.internal.ipv4.address}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
{ lib, options, config, ... }:
|
{ lib, options, config, ... }:
|
||||||
let
|
let
|
||||||
inherit (builtins) typeOf attrNames;
|
inherit (lib) optionalString concatStringsSep concatMapStringsSep optionalAttrs mkIf mkDefault mkMerge mkOverride;
|
||||||
inherit (lib)
|
|
||||||
optionalString concatStringsSep concatMapStringsSep mapAttrsToList optionalAttrs mkIf
|
|
||||||
mkDefault mkMerge mkOverride;
|
|
||||||
inherit (lib.my) isIPv6 mkOpt' mkBoolOpt';
|
inherit (lib.my) isIPv6 mkOpt' mkBoolOpt';
|
||||||
|
|
||||||
allowICMP = ''
|
allowICMP = ''
|
||||||
@ -66,8 +63,8 @@ in
|
|||||||
|
|
||||||
nat = with options.networking.nat; {
|
nat = with options.networking.nat; {
|
||||||
enable = mkBoolOpt' true "Whether to enable IP forwarding and NAT.";
|
enable = mkBoolOpt' true "Whether to enable IP forwarding and NAT.";
|
||||||
inherit externalInterface;
|
inherit externalInterface externalIP;
|
||||||
forwardPorts = mkOpt' (either (listOf (submodule forwardOpts)) (attrsOf (listOf (submodule forwardOpts)))) [ ] "IPv4 port forwards";
|
forwardPorts = mkOpt' (listOf (submodule forwardOpts)) [ ] "List of port forwards.";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -140,9 +137,6 @@ in
|
|||||||
chain postrouting {
|
chain postrouting {
|
||||||
type nat hook postrouting priority srcnat;
|
type nat hook postrouting priority srcnat;
|
||||||
}
|
}
|
||||||
chain input {
|
|
||||||
type nat hook input priority srcnat;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
${cfg.extraRules}
|
${cfg.extraRules}
|
||||||
@ -150,16 +144,11 @@ in
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
(mkIf cfg.nat.enable (
|
(mkIf cfg.nat.enable {
|
||||||
let
|
|
||||||
iifForward = typeOf cfg.nat.forwardPorts == "list" && cfg.nat.forwardPorts != [ ];
|
|
||||||
dipForward = typeOf cfg.nat.forwardPorts == "set" && cfg.nat.forwardPorts != { };
|
|
||||||
in
|
|
||||||
{
|
|
||||||
assertions = [
|
assertions = [
|
||||||
{
|
{
|
||||||
assertion = with cfg.nat; iifForward -> (externalInterface != null);
|
assertion = with cfg.nat; (forwardPorts != [ ]) -> (externalInterface != null);
|
||||||
message = "my.firewall.nat.forwardPorts as list requires my.firewall.nat.externalInterface";
|
message = "my.firewall.nat.forwardPorts requires my.firewall.nat.external{Interface,IP}";
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -182,75 +171,43 @@ in
|
|||||||
|
|
||||||
my.firewall.extraRules =
|
my.firewall.extraRules =
|
||||||
let
|
let
|
||||||
inherit (lib.my.nft) natFilterChain dnatChain;
|
|
||||||
ipK = ip: "ip${optionalString (isIPv6 ip) "6"}";
|
|
||||||
|
|
||||||
makeFilter = f:
|
makeFilter = f:
|
||||||
"${ipK f.dst} daddr ${f.dst} ${f.proto} dport ${toString f.dstPort} accept";
|
let
|
||||||
|
v6 = isIPv6 f.dst;
|
||||||
|
in
|
||||||
|
"ip${optionalString v6 "6"} daddr ${f.dst} ${f.proto} dport ${toString f.dstPort} accept";
|
||||||
makeForward = f:
|
makeForward = f:
|
||||||
"${f.proto} dport ${toString f.port} dnat ${ipK f.dst} to ${f.dst}:${toString f.dstPort}";
|
let
|
||||||
|
v6 = isIPv6 f.dst;
|
||||||
dnatJumps = ''
|
in
|
||||||
${optionalString
|
"${f.proto} dport ${toString f.port} dnat ip${optionalString v6 "6"} to ${f.dst}:${toString f.dstPort}";
|
||||||
iifForward
|
|
||||||
"iifname ${cfg.nat.externalInterface} jump iif-port-forward"}
|
|
||||||
${optionalString
|
|
||||||
dipForward
|
|
||||||
(concatMapStringsSep "\n " (ip: "${ipK ip} daddr ${ip} jump ${dnatChain ip}") (attrNames cfg.nat.forwardPorts))}
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
''
|
''
|
||||||
table inet filter {
|
table inet filter {
|
||||||
${optionalString iifForward ''
|
chain filter-port-forwards {
|
||||||
chain filter-iif-port-forwards {
|
|
||||||
${concatMapStringsSep "\n " makeFilter cfg.nat.forwardPorts}
|
${concatMapStringsSep "\n " makeFilter cfg.nat.forwardPorts}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
''}
|
|
||||||
${optionalString
|
|
||||||
dipForward
|
|
||||||
(concatStringsSep "\n" (mapAttrsToList (ip: fs: ''
|
|
||||||
chain ${natFilterChain ip} {
|
|
||||||
${concatMapStringsSep "\n " makeFilter fs}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
'') cfg.nat.forwardPorts))}
|
|
||||||
|
|
||||||
chain forward {
|
chain forward {
|
||||||
${optionalString
|
${optionalString
|
||||||
iifForward
|
(cfg.nat.externalInterface != null)
|
||||||
"iifname ${cfg.nat.externalInterface} jump filter-iif-port-forwards"}
|
"iifname ${cfg.nat.externalInterface} jump filter-port-forwards"}
|
||||||
${optionalString
|
|
||||||
dipForward
|
|
||||||
(concatMapStringsSep "\n " (ip: "${ipK ip} daddr ${ip} jump ${natFilterChain ip}") (attrNames cfg.nat.forwardPorts))}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table inet nat {
|
table inet nat {
|
||||||
${optionalString iifForward ''
|
chain port-forward {
|
||||||
chain iif-port-forward {
|
|
||||||
${concatMapStringsSep "\n " makeForward cfg.nat.forwardPorts}
|
${concatMapStringsSep "\n " makeForward cfg.nat.forwardPorts}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
''}
|
|
||||||
${optionalString
|
|
||||||
dipForward
|
|
||||||
(concatStringsSep "\n" (mapAttrsToList (ip: fs: ''
|
|
||||||
chain ${dnatChain ip} {
|
|
||||||
${concatMapStringsSep "\n " makeForward fs}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
'') cfg.nat.forwardPorts))}
|
|
||||||
|
|
||||||
chain prerouting {
|
chain prerouting {
|
||||||
${dnatJumps}
|
${optionalString
|
||||||
}
|
(cfg.nat.externalInterface != null)
|
||||||
chain output {
|
"${if (cfg.nat.externalIP != null) then "ip daddr ${cfg.nat.externalIP}" else "iifname ${cfg.nat.externalInterface}"} jump port-forward"}
|
||||||
${dnatJumps}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
}))
|
})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
meta.buildDocsInSandbox = false;
|
meta.buildDocsInSandbox = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user