homek8s/infrastructure/networking/internal/host-firewall/rpi-ufw-internal-gw.sh
Lance Walters 7ca85669b2 hubble: bare-IP listener (8082) for the UI + WireGuard-only firewall on both gateway nodes
Operator addendum: internal services must be reachable by bare IP+port, because
a phone cannot edit /etc/hosts. A hostname-scoped route does not match
`Host: 10.10.0.2:8081` (Envoy 404), and a hostname-less `PathPrefix /` cannot
share a listener with it — so hubble-ui gets its own listener (`hubble-ui`, port
8082) with a route that sets no hostnames. http://10.10.0.2:8082/ and
http://hubble.lab.internal:8082/ both hit the UI.

Firewall: siriussec nft table now matches `dport { 8081, 8082 }` and starts with
`destroy table` so re-running the unit replaces (not appends) the rules; the rpi
ufw script is generalised to a PORTS list and inserts each port above the LAN
catch-all. Both hosts applied and verified before the listener was programmed.

docs: internal gateway section, host-firewall README.
2026-10-27 00:35:16 -04:00

31 lines
1.2 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: 8081 = Grafana (`internal` Gateway listener http-internal),
# 8082 = Hubble UI (`internal` Gateway listener hubble-ui).
# Add a new internal 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:-8081 8082}"
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