41 lines
1.9 KiB
Text
41 lines
1.9 KiB
Text
|
|
#!/usr/sbin/nft -f
|
||
|
|
# Garage inbound guard — defence in depth for the S3/metrics listeners.
|
||
|
|
#
|
||
|
|
# WHY THIS EXISTS AND WHY IT IS NOT JUST ufw:
|
||
|
|
# Docker publishes container ports through a DNAT rule in the `nat`
|
||
|
|
# PREROUTING chain. That traversal never reaches ufw's INPUT chain, so a
|
||
|
|
# compose typo that publishes `0.0.0.0:3900:3900` would be reachable from the
|
||
|
|
# LAN and (worse) from anywhere the router forwards, with ufw still reporting
|
||
|
|
# "default deny (incoming)". This table sits in PREROUTING at priority -140 —
|
||
|
|
# after mangle (-150), before DNAT (-100) — so it drops the packet BEFORE
|
||
|
|
# Docker can rewrite it, whatever address compose asked for.
|
||
|
|
#
|
||
|
|
# Effective policy for 3900-3903: accept from WireGuard (wg0, the remote hub
|
||
|
|
# link wg-remote) and loopback, drop everything else (LAN eth0/wlan0, tailscale,
|
||
|
|
# public). DROP rather than REJECT so an off-mesh scan sees a filtered port and
|
||
|
|
# learns nothing.
|
||
|
|
#
|
||
|
|
# Scope is deliberately narrow: only Garage's ports. Do not widen this table
|
||
|
|
# into a general host firewall — the Pi's ufw already owns that, and moving
|
||
|
|
# k8s/wgportal/DNS traffic here would strand the cluster.
|
||
|
|
#
|
||
|
|
# Loaded by garage-firewall.service. `destroy` (not `delete`) so re-running the
|
||
|
|
# unit replaces the table instead of appending a duplicate copy, and does not
|
||
|
|
# fail on first install.
|
||
|
|
#
|
||
|
|
# Changing Garage's ports means changing this set AND docker-compose.yml AND
|
||
|
|
# the rpi ufw rules in one go; a port in one place only is how you get a
|
||
|
|
# listener that answers on the LAN.
|
||
|
|
destroy table inet garage_guard
|
||
|
|
table inet garage_guard {
|
||
|
|
chain prerouting {
|
||
|
|
type filter hook prerouting priority -140; policy accept;
|
||
|
|
|
||
|
|
# WireGuard only: the mesh hub link and loopback.
|
||
|
|
iifname { "lo", "wg0", "wg-remote" } tcp dport { 3900, 3901, 3902, 3903 } counter accept
|
||
|
|
|
||
|
|
# Anything else — LAN, tailscale, public, or a future interface that
|
||
|
|
# nobody remembered to add above.
|
||
|
|
tcp dport { 3900, 3901, 3902, 3903 } counter drop
|
||
|
|
}
|
||
|
|
}
|