Watch
0
0
Fork
You've already forked hyperhive
0

swarm-nats: the pod's raw rule lets through the interfaces the firewall opens the client port on

The hostPort's raw-table drop for the queue's client port let through only the host's loopback, the bridge and the pods' interfaces, so a hive on another host, reaching the queue over wg0 where the firewall's own rule opens the port, timed out. The rule now also returns for every interface whose networking.firewall.interfaces entry opens the port. semi-spread dumps the queue's network state when the hive cannot reach it, and asserts the port answers over wg0 and not on the public address.
This commit is contained in:
atlas 2026-11-26 23:32:02 +01:00 • committed by maia
commit 7ad74b494f
2 changed files with 98 additions and 8 deletions

View file

@ -9,8 +9,9 @@
#
# The client port is dropped for a packet addressed to the host unless it
# arrives on one of `trusted` (the host's loopback, the hive bridge and the
# pods' interfaces), or `openClient` is set, which is
# `deploy.nats.openFirewall`.
# pods' interfaces), on an interface whose `networking.firewall.interfaces`
# entry opens the port (`firewallInterfaces`, the option's value), or
# `openClient` is set, which is `deploy.nats.openFirewall`.
#
# Pure function — NOT a NixOS module. Returns the text for the firewall's
# `extraCommands`.
@ -19,18 +20,24 @@
chain,
clientPort,
trusted,
firewallInterfaces,
openClient,
}:
let
rule = "iptables -t raw -A ${chain}";
local = "-m addrtype --dst-type LOCAL -j DROP";
opens =
i:
lib.elem clientPort i.allowedTCPPorts
|| lib.any (r: r.from <= clientPort && clientPort <= r.to) i.allowedTCPPortRanges;
opened = lib.attrNames (lib.filterAttrs (_: opens) firewallInterfaces);
in
''
iptables -t raw -N ${chain} 2>/dev/null || iptables -t raw -F ${chain}
${lib.optionalString (!openClient) ''
${lib.concatMapStrings (i: ''
${rule} -p tcp --dport ${toString clientPort} -i ${i} -j RETURN
'') trusted}
'') (lib.unique (trusted ++ opened))}
${rule} -p tcp --dport ${toString clientPort} ${local}
''}
iptables -t raw -D PREROUTING -j ${chain} 2>/dev/null || true

View file

@ -1308,8 +1308,9 @@ in
address the other hives reach.
The pod's published port has the same reach: a rule in the firewall's raw
table drops it from every interface but the host's loopback, the bridge
and the pods' unless this is set.
table drops it from every interface but the host's loopback, the bridge,
the pods' and those that {option}`networking.firewall.interfaces` opens
the port on, unless this is set.
'';
};
@ -1585,6 +1586,7 @@ in
networkCfg.bridgeName
]
++ deployCfg.k8s.cniInterfaces;
firewallInterfaces = config.networking.firewall.interfaces;
openClient = deployCfg.nats.openFirewall;
}
);