From 8939cbdd78abe75c682aee6f51dfccd2eeab8d45 Mon Sep 17 00:00:00 2001 From: Lance Walters Date: Tue, 27 Oct 2026 00:35:37 -0400 Subject: [PATCH] grafana: serve it on the bare WireGuard IP (drop HTTPRoute hostnames) A phone cannot edit /etc/hosts, so it sends Host: 10.10.0.2:8081, matches no .lab.internal route and gets a 404 from Envoy. With no hostnames on the route any Host on the internal listener matches, so http://10.10.0.2:8081/ serves Grafana and the named URL keeps working. Port 8081 stays Grafana-only; docs now state the bare-IP rule and the phone-path tests. --- docs/internal-wireguard-services.md | 58 +++++++++++++++------- monitoring/controllers/home/httproute.yaml | 15 ++++-- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/docs/internal-wireguard-services.md b/docs/internal-wireguard-services.md index 561b18d..bdff747 100644 --- a/docs/internal-wireguard-services.md +++ b/docs/internal-wireguard-services.md @@ -31,8 +31,16 @@ only". Consequences: `192.168.1.179:8081` and the public interface the moment it is Programmed. - The Gateway object cannot enforce the network boundary. **The host firewall is the enforcement point.** That is the whole trick. -- Routing on the internal listener is hostname-based, so the service is reached - as `http://.lab.internal:8081` with an `/etc/hosts` entry on the client. +- The service is reached as **`http://10.10.0.2:/`** — no `/etc/hosts` + entry, no `Host` header. The HTTPRoute must therefore carry **no + `hostnames`**, or a phone (which cannot edit a hosts file) sends + `Host: 10.10.0.2:8081`, matches no `.lab.internal` route, and Envoy answers + **404**. A hostname-less route matches any `Host` on its listener, so the + named `http://.lab.internal:8081` URL keeps working for laptops that + do have the hosts line. +- **One service per listener port.** Two hostname-less routes on one listener + make precedence ambiguous, so the next internal service takes a new port + (and its own firewall rules, §5) instead of sharing 8081. 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 @@ -55,25 +63,31 @@ address (and the other node answers 503, which still proves a listener exists). ## 3. Current internal services -| Service | URL (over WireGuard) | Client `/etc/hosts` line | Route | +| Service | URL (over WireGuard) | Optional client `/etc/hosts` line | Route | |---|---|---|---| -| Grafana | `http://grafana.lab.internal:8081/` | `10.10.0.2 grafana.lab.internal` | `monitoring/grafana` | +| Grafana | **`http://10.10.0.2:8081/`** (also `http://grafana.lab.internal:8081/`) | `10.10.0.2 grafana.lab.internal` | `monitoring/grafana` | -Always use **siriussec's** address (`10.10.0.2`) in the hosts file, not the -Pi's: Envoy on a node that does not run the backend pods completes the TCP -handshake and then hangs (SYN-ACK back, no ACK — see the co-location pitfall in -the `home-k8s` skill). The backends are pinned to siriussec, so 10.10.0.2 is -the only origin that works. +**The rule: every internal service must be reachable as +`http://10.10.0.2:/` with no `Host` header and no hosts-file entry**, +because phones cannot edit `/etc/hosts`. The bare-IP URL is the one to hand +out; the named URL is a convenience for machines that already have the line. + +Always use **siriussec's** address (`10.10.0.2`), not the Pi's: Envoy on a node +that does not run the backend pods completes the TCP handshake and then hangs +(SYN-ACK back, no ACK — see the co-location pitfall in the `home-k8s` skill). +The backends are pinned to siriussec, so 10.10.0.2 is the only origin that +works. ## 4. Add the next internal service 1. **Confirm the port is firewalled.** `:8081` is closed to the LAN already; a - new listener port needs its own rules (see §5). Reuse 8081 unless two - services must be distinguished by port. + new listener port needs its own rules (see §5). **Do not reuse 8081** — one + listener port carries exactly one internal service, so a second + hostname-less route can never compete with Grafana's. 2. **Deploy the workload** in its own namespace, pinned with `nodeSelector: {kubernetes.io/hostname: siriussec}` (amd64 + local-path; the Pi is arm64 and its listener only serves pods scheduled on the Pi). -3. **Add the route** next to the workload: +3. **Add the route** next to the workload — **without `hostnames`**: ```yaml apiVersion: gateway.networking.k8s.io/v1 @@ -85,9 +99,7 @@ the only origin that works. parentRefs: - name: internal namespace: internal - sectionName: http-internal - hostnames: - - .lab.internal + sectionName: http-internal- # its own listener on its own port rules: - matches: - path: {type: PathPrefix, value: /} @@ -99,11 +111,12 @@ the only origin that works. A `ReferenceGrant` is only needed for cross-namespace *backends*; the route itself is allowed by `allowedRoutes: All` on the listener. 4. Commit, push, reconcile (repo → `gitrepository`, then the app's - `kustomization`), then **prove it from the mesh**: + `kustomization`), then **prove it from the mesh** — bare IP first, because + that is the phone path: ```bash - curl -sS -o /dev/null -w '%{http_code}\n' \ - -H 'Host: .lab.internal' http://10.10.0.2:8081/ + curl -sS -o /dev/null -w '%{http_code}\n' http://10.10.0.2:/ # -> 200/302, never 404 + curl -sSL -m 6 http://10.10.0.2:/login | head -c 200 # -> HTML, no absolute redirect ``` 5. Add the row to the table in §3. @@ -132,12 +145,19 @@ ufw insert 2 allow from 10.244.0.0/16 to any port proto tcp comment 'inte ## 6. Negative tests (run these after every change) ```bash +# 0. From a mesh host: the BARE-IP phone path, and the login page via it. +# Grafana must not hard-redirect to a .internal name (no root_url/domain set). +curl -sS -m 6 -o /dev/null -w '%{http_code}\n' http://10.10.0.2:8081/ # -> 302 (login), never 404 +curl -sSL -m 6 -o /dev/null -w '%{http_code} redirects=%{num_redirects}\n' \ + http://10.10.0.2:8081/login # -> 200, no absolute Location +curl -sS -m 6 -D- -o /dev/null http://10.10.0.2:8081/ | grep -i '^location:' # -> /login (relative) + # 1. From a LAN host (Legion on 192.168.1.0/24, or rpi toward siriussec): # DROP = timeout, not connection-refused and never 200. curl -m 3 -sS -o /dev/null -w '%{http_code}\n' http://192.168.1.179:8081/ # -> 000 (timed out) curl -m 3 -sS -o /dev/null -w '%{http_code}\n' http://192.168.1.125:8081/ # -> 000 (timed out) -# 2. From a mesh host, the listener must still work: +# 2. From a mesh host, the named URL must still work: curl -sS -o /dev/null -w '%{http_code}\n' -H 'Host: grafana.lab.internal' http://10.10.0.2:8081/ # -> 302 (login) # 3. Not in the public tunnel's ingress list (run on rpi): diff --git a/monitoring/controllers/home/httproute.yaml b/monitoring/controllers/home/httproute.yaml index 45e8b5b..fb18718 100644 --- a/monitoring/controllers/home/httproute.yaml +++ b/monitoring/controllers/home/httproute.yaml @@ -2,8 +2,17 @@ # one, fed by the Cloudflare tunnel). There is no Cloudflare ingress entry for # this hostname and there must never be one. # -# Reachable at http://grafana.lab.internal:8081 over WireGuard: -# Legion /etc/hosts: 10.10.0.2 grafana.lab.internal +# Reachable over WireGuard, and deliberately WITHOUT a Host header mapping: +# phones: http://10.10.0.2:8081/ +# laptops: http://grafana.lab.internal:8081/ (10.10.0.2 grafana.lab.internal) +# +# `hostnames` is intentionally ABSENT: a phone sends `Host: 10.10.0.2:8081`, +# which matches no `.lab.internal` hostname, and Envoy answers 404. A route +# with no hostnames matches any Host on the listener, so both URLs work. +# Port 8081 is Grafana's alone — do not attach a second hostname-less route to +# `http-internal`: two bare routes on one listener make precedence ambiguous, +# so any future internal service gets its own listener port. +# # The listener answers only on 10.10.0.0/24 + the pod CIDR — the host firewall # (see docs/internal-wireguard-services.md) drops :8081 everywhere else. apiVersion: gateway.networking.k8s.io/v1 @@ -16,8 +25,6 @@ spec: - name: internal namespace: internal sectionName: http-internal - hostnames: - - grafana.lab.internal rules: - matches: - path: