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:
parent
5898e508e5
commit
2116ad28e1
1 changed files with 98 additions and 8 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue