nats: runtime k8s runs the queue and its auth callout as one pod
This commit is contained in:
parent
1c8798a3ca
commit
a2db26d344
1 changed files with 1487 additions and 842 deletions
41
nix/host-modules/lib/swarm-nats-raw-rules.nix
Normal file
41
nix/host-modules/lib/swarm-nats-raw-rules.nix
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# The iptables rules that give the queue pod's `hostPort`s the reach the
|
||||
# queue's container has. A `hostPort` is a DNAT rule, and what a DNAT rule
|
||||
# rewrites is forwarded, never delivered to the host: the INPUT rules (the
|
||||
# firewall's `allowedTCPPorts` and per-interface rules) never see it, and the
|
||||
# cluster's own forwarding rules accept it. The raw table is read before the
|
||||
# DNAT and before any of those, so a rule there reads the original
|
||||
# destination, as INPUT does for the container's listener.
|
||||
#
|
||||
# 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`. The exporter's port answers with every client's
|
||||
# name, so it is dropped for all but the host's own loopback.
|
||||
#
|
||||
# Pure function — NOT a NixOS module. Returns the text for the firewall's
|
||||
# `extraCommands`.
|
||||
{ lib }:
|
||||
{
|
||||
chain,
|
||||
clientPort,
|
||||
metricsPort,
|
||||
trusted,
|
||||
openClient,
|
||||
}:
|
||||
let
|
||||
rule = "iptables -t raw -A ${chain}";
|
||||
local = "-m addrtype --dst-type LOCAL -j DROP";
|
||||
in
|
||||
''
|
||||
iptables -t raw -N ${chain} 2>/dev/null || iptables -t raw -F ${chain}
|
||||
${rule} -p tcp --dport ${toString metricsPort} -i lo -j RETURN
|
||||
${rule} -p tcp --dport ${toString metricsPort} ${local}
|
||||
${lib.optionalString (!openClient) ''
|
||||
${lib.concatMapStrings (i: ''
|
||||
${rule} -p tcp --dport ${toString clientPort} -i ${i} -j RETURN
|
||||
'') trusted}
|
||||
${rule} -p tcp --dport ${toString clientPort} ${local}
|
||||
''}
|
||||
iptables -t raw -D PREROUTING -j ${chain} 2>/dev/null || true
|
||||
iptables -t raw -I PREROUTING -j ${chain}
|
||||
''
|
||||
Loading…
Reference in a new issue