homek8s/infrastructure/networking/internal/host-firewall/rpi-ufw-internal-gw.sh
Lance Walters 181266d7d4 fix(networking): make the public gateway :8080 WireGuard-only
Finding F2 of the 2026-11-27 cluster netsec audit: cilium-envoy on siriussec
binds gateway-system/public on 0.0.0.0:8080, so anyone on 192.168.1.0/24 could
`curl -H 'Host: forgejo.siriusdevops.com' http://192.168.1.179:8080/` and get
Forgejo (and every public site) over plain HTTP — no Cloudflare TLS, WAF, rate
limits or bot protection, and credentials on the wire inside the LAN. Live:
200 / 14609 B before this change.

The `internal_gw` nft table that already makes 8081/8084-8087 WG-only simply
did not list 8080. Add it to all three rules (lo, mesh+pods, drop), and to the
rpi ufw guard so a future `gateway=true` relabel on the Pi cannot re-open it.

Nothing legitimate needs the LAN path: cloudflared runs on rpi and connects to
10.10.0.2:8080 from 10.10.0.1 over the mesh (`ss` on siriussec shows
`10.10.0.1:* -> 10.10.0.2:8080 ESTABLISHED`), which the 10.10.0.0/24 accept
covers. 10.244.0.0/16 stays accepted for in-cluster probes.

Verified both polarities: LAN 192.168.1.179:8080 -> timeout/DROP (from two
vantage points), mesh 10.10.0.2:8080 -> 200 for all five public hostnames, and
all five public URLs still 200 through Cloudflare.
2026-11-27 00:09:14 -05:00

37 lines
No EOL
1.7 KiB
Shell

#!/bin/bash
# rpi: restrict the internal Gateway listeners to WireGuard + pods.
#
# ufw on rpi already has `allow from 192.168.1.0/24` (any port), so the deny has
# to sit ABOVE it — hence `ufw insert`, not `ufw allow/deny` (which appends).
# Final order per port: allow 10.10.0.0/24, allow 10.244.0.0/16, deny the rest.
#
# Ports: 8080 = the `public` Gateway listener (the Cloudflare tunnel origin) —
# the tunnel's only legitimate client is cloudflared on this Pi
# reaching 10.10.0.2:8080 over the mesh, never the Pi's LAN IP,
# 8081 = Grafana (`internal` Gateway listener http-internal),
# 8084 = Hubble UI (`internal` Gateway listener hubble-ui),
# 8085 = Metabase (`metabase` Gateway listener http-internal),
# 8086 = Customer 1 lab Odoo (`customer1-odoo` Gateway),
# 8087 = Customer 1 lab Metabase (`customer1-metabase` Gateway).
# Add a new listener port to PORTS; the loop is idempotent, so
# re-running after a port is already firewalled only adds what is missing.
#
# Run as root on rpi (192.168.1.125).
set -euo pipefail
PORTS="${PORTS:-8080 8081 8084 8085 8086 8087}"
for port in $PORTS; do
if ufw status | grep -q "${port}/tcp"; then
echo "$port rules already present:"
ufw status | grep "${port}/tcp"
continue
fi
ufw insert 1 deny to any port "$port" proto tcp comment 'internal gateway: wg only'
ufw insert 1 allow from 10.10.0.0/24 to any port "$port" proto tcp comment 'internal gateway (wg mesh)'
ufw insert 2 allow from 10.244.0.0/16 to any port "$port" proto tcp comment 'internal gateway (pods)'
echo "$port rules installed:"
ufw status | grep "${port}/tcp" || true
done