homek8s/infrastructure/garage-linode/host/wal-archive-firewall.nft

41 lines
2 KiB
Text
Raw Permalink Normal View History

#!/usr/sbin/nft -f
# WAL-archive inbound guard — defence in depth for Garage on the Linode hub.
#
# WHY THIS EXISTS AND WHY UFW ALONE IS NOT ENOUGH:
# On the Pi the risk is docker's DNAT bypassing ufw's INPUT chain. Here the
# store runs under podman with Network=host, so there is no DNAT to bypass —
# but the same rule shape is kept anyway, because the next person who adds a
# port mapping (or a second container that proxies this one) must not be able
# to reach 3900 from eth0 by accident. This table is evaluated in PREROUTING
# at priority -140, before any DNAT, so it binds the exposure to the transport
# rather than to how the listener was published.
#
# Effective policy for 3900 (S3 API) and 3903 (metrics/admin):
# accept from WireGuard (wg0) and loopback — incl. pod traffic arriving from
# the mesh with a 10.244.x source — drop everything else (eth0, LAN, public).
# DROP not REJECT: an off-mesh scan sees `filtered` and learns nothing.
#
# Note this is *in addition to* ufw, which on this host allows 22 from
# 10.20.0.0/24 and any from 10.10.0.0/24 / 10.244.0.0/16. ufw's own default is
# deny incoming, so the LAN path is already closed; this table keeps it closed
# even if someone later opens ufw wider for a different service.
#
# `destroy` (not `delete`) so re-running the unit replaces the table instead of
# appending a duplicate, and does not fail on first install.
destroy table inet wal_archive_guard
table inet wal_archive_guard {
chain prerouting {
type filter hook prerouting priority -140; policy accept;
# WireGuard mesh + hub link, and loopback (the garage CLI talks to
# 127.0.0.1:3901 inside this host namespace).
iifname { "lo", "wg0" } tcp dport { 3900, 3903 } counter accept
# Pods on this node reach the dummy-k8s address from the pod network.
ip saddr 10.244.0.0/16 tcp dport { 3900, 3903 } counter accept
# Everything else — eth0/public, any future interface nobody added above.
tcp dport { 3900, 3903 } counter drop
}
}