safer bridge mode

This commit is contained in:
ari committed 2026-09-23 19:29:28 -04:00
1 parent b5d59c34ac
commit d5afd6510f
7 files changed
+337 -120

No files matched your search

+44 -5
View File
@@ -36,6 +36,10 @@ let
type = lib.types.bool;
default = false;
};
nameservers = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
};
nftables = {
enable = lib.mkOption {
type = lib.types.bool;
@@ -65,6 +69,10 @@ let
};
};
};
systemd.services = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
default = { };
};
systemd.network = {
networks = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
@@ -91,6 +99,13 @@ let
network = {
externalInterface = "eno1";
inherit bridged;
}
// lib.optionalAttrs bridged {
# Bridged mode is static-only: guest address, host address on
# the bridge, and the LAN router.
lanAddress = "10.7.7.50";
hostLanAddress = "10.7.7.2";
lanGateway = "10.7.7.1";
};
allowLan = false;
publish = [
@@ -146,7 +161,7 @@ let
"nat: bridge netdev exists" =
nat.config.systemd.network.netdevs."10-hermes-br".netdevConfig.Kind == "bridge";
# --- bridged mode: the guest is directly on the LAN ----------------
# --- bridged mode: the guest is directly on the LAN, static-only -----
"bridged: bridge-family table exists" = brNft ? "hermenix-bridge" && brBr.family == "bridge";
"bridged: guest traffic is marked as it enters the tap" = has "meta mark set 18501" brBr.content;
"bridged: inbound from the LAN is open on every port" =
@@ -155,18 +170,42 @@ let
has "ip daddr 192.168.1.50 tcp dport 11434 accept" brBr.content;
"bridged: private-space egress is dropped unless allowlisted" =
has "192.168.0.0/16" brBr.content && has "fc00::/7" brBr.content;
"bridged: guest DHCP is confined to the bridge, can't race the LAN router" =
has "udp sport 68 udp dport 67 drop" brBr.content
&& has "udp sport 67 udp dport 68 drop" brBr.content;
"bridged: no DNAT for publish" =
!(has "dnat to" brNat.content) && !(has "chain prerouting" brNat.content);
"bridged: scoped fallback masquerade remains" = has "masquerade" brNat.content;
"bridged: input rules match the mark, not the unknown DHCP address" =
"bridged: input rules match the mark, not an address" =
has "meta mark 18501 tcp dport 5000 accept" brInput
&& has "meta mark 18501 tcp dport 8188 accept" brInput
&& !(has "ip saddr 10.77.0.2" brInput);
"bridged: publish forward rules are dropped" =
!(has "ip daddr 10.77.0.2 tcp dport 8080 accept" brForward);
"bridged: bridge keeps the service net and takes LAN DHCP" =
brNetworks."10-hermes-br".address == [ "10.77.0.1/24" ]
&& brNetworks."10-hermes-br".networkConfig.DHCP == "ipv4";
"bridged: bridge carries only static addresses, never a DHCP lease" =
brNetworks."10-hermes-br".address == [
"10.77.0.1/24"
"10.7.7.2/24"
]
&& (brNetworks."10-hermes-br".networkConfig.DHCP or null) == null
&& !(has "DHCP" (builtins.toJSON brNetworks."10-hermes-br"));
"bridged: host gateway and DNS are static on the bridge" =
brNetworks."10-hermes-br".networkConfig.Gateway == "10.7.7.1"
&& brNetworks."10-hermes-br".networkConfig.DNS == [ "10.7.7.1" ];
"bridged: guest is handed lanAddress by the bridge DHCP server" =
let
dhcp = br.config.systemd.services."hermes-lan-dhcp".script;
in
has "--interface=hermes-br" dhcp
&& has "--dhcp-range=10.7.7.50,10.7.7.50,255.255.255.0,12h" dhcp
&& has "--dhcp-host=02:00:00:7e:00:01,10.7.7.50" dhcp
&& has "--dhcp-option=option:router,10.7.7.1" dhcp
&& has "--port=0" dhcp;
"bridged: uplink MAC is cloned onto the bridge, host keeps its identity" =
let
mac = br.config.systemd.services."hermes-bridge-mac".script;
in
has "ip link set dev hermes-br address" mac && has "/sys/class/net/eno1/address" mac;
"bridged: uplink is a bridge port" = brNetworks."12-eno1".networkConfig.Bridge == "hermes-br";
"bridged: tap is still a bridge port" =
brNetworks."11-vm-hermes".networkConfig.Bridge == "hermes-br";