fix(networking): make the public gateway :8080 WireGuard-only (F2) (#41)
This commit is contained in:
commit
d874d4afaf
5 changed files with 70 additions and 26 deletions
|
|
@ -52,7 +52,10 @@ only". Consequences:
|
||||||
Public traffic has no path here: the only public ingress is the cloudflared
|
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
|
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
|
`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
|
## 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/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 |
|
| `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 <svc>` | the app's own tree (e.g. `monitoring/controllers/home/httproute.yaml`, `infrastructure/networking/cilium/hubble-ui-httproute.yaml`) | `parentRefs: <gateway>/internal#http-internal`, **no `hostnames`** |
|
| `HTTPRoute <svc>` | the app's own tree (e.g. `monitoring/controllers/home/httproute.yaml`, `infrastructure/networking/cilium/hubble-ui-httproute.yaml`) | `parentRefs: <gateway>/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 |
|
| 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 |
|
| `infrastructure/networking/internal/host-firewall/` | repo | the host artifacts + install/verify instructions |
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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` |
|
| 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` |
|
| 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`
|
Effective policy for `:8080` (the `public` gateway — Cloudflare tunnel origin),
|
||||||
(Metabase):
|
`: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
|
**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
|
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
|
new listener port is a LAN exposure until it is added here.
|
||||||
accept rules carry `counter`s: `nft list table inet internal_gw` shows packets
|
|
||||||
|
**`: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
|
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" —
|
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
|
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:
|
Negative test from the LAN must be a timeout (DROP), never 200:
|
||||||
|
|
||||||
```bash
|
```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.179:8081/ # empty/000
|
||||||
curl -m 3 -sS -o /dev/null -w '%{http_code}\n' http://192.168.1.125: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
|
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
|
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
|
inserts one deny for the port plus mesh and pod-CIDR allows above the LAN
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
# Flux-managed); the file lives in git at
|
# Flux-managed); the file lives in git at
|
||||||
# infrastructure/networking/internal/host-firewall/.
|
# infrastructure/networking/internal/host-firewall/.
|
||||||
[Unit]
|
[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
|
After=network-online.target
|
||||||
Wants=network-online.target
|
Wants=network-online.target
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,18 +5,21 @@
|
||||||
# to sit ABOVE it — hence `ufw insert`, not `ufw allow/deny` (which appends).
|
# 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.
|
# 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),
|
# 8084 = Hubble UI (`internal` Gateway listener hubble-ui),
|
||||||
# 8085 = Metabase (`metabase` Gateway listener http-internal),
|
# 8085 = Metabase (`metabase` Gateway listener http-internal),
|
||||||
# 8086 = Customer 1 lab Odoo (`customer1-odoo` Gateway),
|
# 8086 = Customer 1 lab Odoo (`customer1-odoo` Gateway),
|
||||||
# 8087 = Customer 1 lab Metabase (`customer1-metabase` 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.
|
# re-running after a port is already firewalled only adds what is missing.
|
||||||
#
|
#
|
||||||
# Run as root on rpi (192.168.1.125).
|
# Run as root on rpi (192.168.1.125).
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
PORTS="${PORTS:-8081 8084 8085 8086 8087}"
|
PORTS="${PORTS:-8080 8081 8084 8085 8086 8087}"
|
||||||
|
|
||||||
for port in $PORTS; do
|
for port in $PORTS; do
|
||||||
if ufw status | grep -q "${port}/tcp"; then
|
if ufw status | grep -q "${port}/tcp"; then
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,32 @@
|
||||||
#!/usr/sbin/nft -f
|
#!/usr/sbin/nft -f
|
||||||
# Internal (WireGuard-only) gateway listeners: TCP 8081 (Grafana), 8084
|
# Gateway listener host firewall on siriussec: the listeners that must answer
|
||||||
# (Hubble UI), 8085 (Metabase) and 8086/8087 (Customer 1 lab replica: Odoo,
|
# the WireGuard mesh and the pod network only, never the LAN.
|
||||||
# Metabase).
|
|
||||||
#
|
#
|
||||||
# Cilium's hostNetwork Envoy binds every Gateway listener on 0.0.0.0, so the
|
# Ports and who they serve:
|
||||||
# internal listeners are open on the LAN interface the moment the Gateway is
|
# 8080 public — Cloudflare tunnel origin (cloudflared runs on rpi)
|
||||||
# programmed. This table makes them answer only from the WireGuard mesh and the
|
# 8081 internal — Grafana
|
||||||
# pod network. DROP (not reject) so a LAN scan sees a timeout, not a port that
|
# 8084 internal — Hubble UI
|
||||||
# tells you something is listening.
|
# 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
|
# Cilium's hostNetwork Envoy binds every Gateway listener on 0.0.0.0, so every
|
||||||
# rules below, reinstall this file, then
|
# 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
|
# `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).
|
# 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;
|
type filter hook input priority filter; policy accept;
|
||||||
|
|
||||||
# local process / kubelet probes
|
# 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)
|
# WireGuard mesh (Legion = 10.10.0.3, nodes, remote hub spokes;
|
||||||
# and the pod network (in-cluster scrapers, probes)
|
# 10.10.0.1 = the cloudflared tunnel origin) and the pod network
|
||||||
tcp dport { 8081, 8084, 8085, 8086, 8087 } ip saddr { 10.10.0.0/24, 10.244.0.0/16 } counter accept
|
# (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
|
# everything else: LAN, tailscale, public
|
||||||
tcp dport { 8081, 8084, 8085, 8086, 8087 } counter drop
|
tcp dport { 8080, 8081, 8084, 8085, 8086, 8087 } counter drop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue