From 181266d7d4ba9292cc21a5fc166d6832fecc0b9c Mon Sep 17 00:00:00 2001 From: Lance Walters Date: Fri, 27 Nov 2026 00:09:11 -0500 Subject: [PATCH] fix(networking): make the public gateway :8080 WireGuard-only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- docs/internal-wireguard-services.md | 7 ++- .../internal/host-firewall/README.md | 29 +++++++++-- .../internal-gw-firewall.service | 2 +- .../host-firewall/rpi-ufw-internal-gw.sh | 9 ++-- .../host-firewall/siriussec-internal-gw.nft | 49 +++++++++++++------ 5 files changed, 70 insertions(+), 26 deletions(-) diff --git a/docs/internal-wireguard-services.md b/docs/internal-wireguard-services.md index 46842df..d73de29 100644 --- a/docs/internal-wireguard-services.md +++ b/docs/internal-wireguard-services.md @@ -52,7 +52,10 @@ only". Consequences: Public traffic has no path here: the only public ingress is the cloudflared tunnel, whose ingress list is an explicit allow-list of hostnames pointing at `http://10.10.0.2:8080` (the `public` gateway). Nothing points at 8081, and -`*.lab.internal` resolves nowhere publicly. +`*.lab.internal` resolves nowhere publicly. `:8080` itself is in the +`internal_gw` WG-only set as well (since 2026-11-27): the tunnel origin reaches +it from `10.10.0.1` over the mesh, so the LAN has no plain-HTTP path to the +public hostnames. ## 2. The pieces @@ -61,7 +64,7 @@ tunnel, whose ingress list is an explicit allow-list of hostnames pointing at | `Gateway internal/internal` | `infrastructure/networking/internal/gateway.yaml` (Flux: `infrastructure`) | listener `http-internal`, **port 8081**, `allowedRoutes: All` so any namespace can attach. **One bare-IP service only** (Grafana) — see the merge gotcha above | | `Gateway internal/hubble-ui` | `infrastructure/networking/internal/gateway-hubble-ui.yaml` | listener `http-internal`, **port 8084**, its own RouteConfiguration, so its hostname-less route cannot merge with Grafana's | | `HTTPRoute ` | the app's own tree (e.g. `monitoring/controllers/home/httproute.yaml`, `infrastructure/networking/cilium/hubble-ui-httproute.yaml`) | `parentRefs: /internal#http-internal`, **no `hostnames`** | -| `table inet internal_gw` + `internal-gw-firewall.service` | siriussec host (`/etc/nftables.d/internal-gw.nft`) | drop `:8081`+`:8084` from everything but `10.10.0.0/24`, `10.244.0.0/16`, `lo`; the accept rules carry `counter`s so "traffic arrived and was allowed" is provable, not inferred from a 200 | +| `table inet internal_gw` + `internal-gw-firewall.service` | siriussec host (`/etc/nftables.d/internal-gw.nft`) | drop `:8080` (the `public` gateway — Cloudflare tunnel origin only), `:8081`, `:8084`–`:8087` from everything but `10.10.0.0/24`, `10.244.0.0/16`, `lo`; the accept rules carry `counter`s so "traffic arrived and was allowed" is provable, not inferred from a 200. `:8080` is WG-only because the only legitimate client is `cloudflared` on rpi, which connects to `10.10.0.2:8080` over the mesh — a LAN client could otherwise spoof a `Host:` header and get Forgejo and every public site over plain HTTP, bypassing Cloudflare TLS/WAF/rate limits | | ufw rules (inserted above the LAN catch-all) | rpi host | **inert since 2026-10-27** — left in place as a belt-and-braces guard in case the Pi is ever relabelled `gateway=true`, but nothing binds those ports on rpi any more, so they just make stale `10.10.0.1:8081` clients time out instead of being refused | | `infrastructure/networking/internal/host-firewall/` | repo | the host artifacts + install/verify instructions | diff --git a/infrastructure/networking/internal/host-firewall/README.md b/infrastructure/networking/internal/host-firewall/README.md index e03fd2e..fe9a001 100644 --- a/infrastructure/networking/internal/host-firewall/README.md +++ b/infrastructure/networking/internal/host-firewall/README.md @@ -21,12 +21,26 @@ exactly one node. | siriussec (10.10.0.2) — **load bearing** | nftables table `inet internal_gw`, loaded by a oneshot unit (same pattern as `k8s-api-firewall.service`) | `siriussec-internal-gw.nft`, `internal-gw-firewall.service` | | rpi (10.10.0.1) — **inert guard** | ufw rules inserted above the `allow from 192.168.1.0/24` catch-all | `rpi-ufw-internal-gw.sh` | -Effective policy for `:8081` (Grafana), `:8084` (Hubble UI) and `:8085` -(Metabase): +Effective policy for `:8080` (the `public` gateway — Cloudflare tunnel origin), +`:8081` (Grafana), `:8084` (Hubble UI), `:8085` (Metabase) and `:8086`/`:8087` +(Customer 1 lab replica): **accept from 10.10.0.0/24 and 10.244.0.0/16, accept on lo, drop everything else** (LAN, tailscale, public). Envoy binds every listener on `0.0.0.0`, so a -new internal listener port is a LAN exposure until it is added here. The -accept rules carry `counter`s: `nft list table inet internal_gw` shows packets +new listener port is a LAN exposure until it is added here. + +**`:8080` is in the WG-only set too, and that is deliberate** (2026-11-27, +audit finding F2). `gateway-system/public` has no hostname restriction +(`allowedRoutes.namespaces.from: All`), so before this the LAN could +`curl -H 'Host: forgejo.siriusdevops.com' http://192.168.1.179:8080/` and get +Forgejo over plain HTTP — no Cloudflare TLS, WAF, rate limits or bot +protection, and credentials on the wire inside 192.168.1.0/24. The only +legitimate client is `cloudflared` on rpi, which connects **over the mesh** +(`ss` on siriussec shows `10.10.0.1:* -> 10.10.0.2:8080 ESTABLISHED`), so the +`10.10.0.0/24` accept covers production. Do not treat the public gateway as +LAN-reachable just because it is "public": it is public *through Cloudflare*, +and the tunnel origin is on the overlay. + +The accept rules carry `counter`s: `nft list table inet internal_gw` shows packets that reached the host and were allowed, which is the only way to tell "the firewall accepted it and Envoy answered" from "the client never got there" — rpi's ufw accept rules read 0 packets while requests to `10.10.0.1:8081` were @@ -63,10 +77,17 @@ ufw status | grep -E '8081|8084|8085' Negative test from the LAN must be a timeout (DROP), never 200: ```bash +curl -m 3 -sS -o /dev/null -w '%{http_code}\n' http://192.168.1.179:8080/ # empty/000 curl -m 3 -sS -o /dev/null -w '%{http_code}\n' http://192.168.1.179:8081/ # empty/000 curl -m 3 -sS -o /dev/null -w '%{http_code}\n' http://192.168.1.125:8081/ # empty/000 ``` +Positive test from the mesh must still be 200 (this is what cloudflared does): + +```bash +curl -m 5 -sS -o /dev/null -w '%{http_code}\n' -H 'Host: siriusdevops.com' http://10.10.0.2:8080/ +``` + When a new internal listener port is added, add it to the `tcp dport { … }` set in `siriussec-internal-gw.nft` and to `PORTS` in `rpi-ufw-internal-gw.sh` (which inserts one deny for the port plus mesh and pod-CIDR allows above the LAN diff --git a/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service b/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service index c46890b..9489acc 100644 --- a/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service +++ b/infrastructure/networking/internal/host-firewall/internal-gw-firewall.service @@ -4,7 +4,7 @@ # Flux-managed); the file lives in git at # infrastructure/networking/internal/host-firewall/. [Unit] -Description=Restrict the internal Gateway listeners (8081, 8084, 8085) to WireGuard +Description=Restrict the Gateway listeners (8080 public origin, 8081/8084-8087 internal) to WireGuard + pods After=network-online.target Wants=network-online.target diff --git a/infrastructure/networking/internal/host-firewall/rpi-ufw-internal-gw.sh b/infrastructure/networking/internal/host-firewall/rpi-ufw-internal-gw.sh index f20e0f8..186621c 100644 --- a/infrastructure/networking/internal/host-firewall/rpi-ufw-internal-gw.sh +++ b/infrastructure/networking/internal/host-firewall/rpi-ufw-internal-gw.sh @@ -5,18 +5,21 @@ # 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), +# 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 internal listener port to PORTS; the loop is idempotent, so +# 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:-8081 8084 8085 8086 8087}" +PORTS="${PORTS:-8080 8081 8084 8085 8086 8087}" for port in $PORTS; do if ufw status | grep -q "${port}/tcp"; then diff --git a/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft b/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft index 6f07915..863a9fc 100644 --- a/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft +++ b/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft @@ -1,16 +1,32 @@ #!/usr/sbin/nft -f -# Internal (WireGuard-only) gateway listeners: TCP 8081 (Grafana), 8084 -# (Hubble UI), 8085 (Metabase) and 8086/8087 (Customer 1 lab replica: Odoo, -# Metabase). +# Gateway listener host firewall on siriussec: the listeners that must answer +# the WireGuard mesh and the pod network only, never the LAN. # -# Cilium's hostNetwork Envoy binds every Gateway listener on 0.0.0.0, so the -# internal listeners are open on the LAN interface the moment the Gateway is -# programmed. This table makes them answer only from the WireGuard mesh and the -# pod network. DROP (not reject) so a LAN scan sees a timeout, not a port that -# tells you something is listening. +# Ports and who they serve: +# 8080 public — Cloudflare tunnel origin (cloudflared runs on rpi) +# 8081 internal — Grafana +# 8084 internal — Hubble UI +# 8085 internal — Metabase +# 8086 internal — Customer 1 lab Odoo +# 8087 internal — Customer 1 lab Metabase # -# Adding an internal service: add its listener port to the set in all three -# rules below, reinstall this file, then +# Cilium's hostNetwork Envoy binds every Gateway listener on 0.0.0.0, so every +# listener is open on the LAN interface the moment the Gateway is programmed. +# This table makes them answer only from the WireGuard mesh and the pod network. +# DROP (not reject) so a LAN scan sees a timeout, not a port that tells you +# something is listening. +# +# 8080 is in this set on purpose. `gateway-system/public` serves the public +# hostnames and used to answer 192.168.1.0/24 over plain HTTP; a spoofed +# `Host:` header then served Forgejo and every public site without Cloudflare's +# TLS, WAF, rate limits or bot protection, and put credentials on the wire +# inside the LAN. The only legitimate client of :8080 is the tunnel origin — +# cloudflared on rpi (10.10.0.1), which connects to 10.10.0.2:8080 over the +# WireGuard mesh — so the saddr rule below covers it. Nothing may reach :8080 +# from the LAN. +# +# Adding a listener: add its port to the set in all three rules below, +# reinstall this file, then # `systemctl reload-or-restart internal-gw-firewall.service`. The same list # must also be added to the rpi ufw rules (rpi-ufw-internal-gw.sh). # @@ -23,13 +39,14 @@ table inet internal_gw { type filter hook input priority filter; policy accept; # local process / kubelet probes - tcp dport { 8081, 8084, 8085, 8086, 8087 } iifname "lo" counter accept + tcp dport { 8080, 8081, 8084, 8085, 8086, 8087 } iifname "lo" counter accept - # WireGuard mesh (Legion = 10.10.0.3, nodes, remote hub spokes) - # and the pod network (in-cluster scrapers, probes) - tcp dport { 8081, 8084, 8085, 8086, 8087 } ip saddr { 10.10.0.0/24, 10.244.0.0/16 } counter accept + # WireGuard mesh (Legion = 10.10.0.3, nodes, remote hub spokes; + # 10.10.0.1 = the cloudflared tunnel origin) and the pod network + # (in-cluster probes, gateway to service traffic) + tcp dport { 8080, 8081, 8084, 8085, 8086, 8087 } ip saddr { 10.10.0.0/24, 10.244.0.0/16 } counter accept # everything else: LAN, tailscale, public - tcp dport { 8081, 8084, 8085, 8086, 8087 } counter drop + tcp dport { 8080, 8081, 8084, 8085, 8086, 8087 } counter drop } -} \ No newline at end of file +} -- 2.52.0