homek8s/docs/internal-wireguard-services.md

804 lines
41 KiB
Markdown
Raw Normal View History

---
title: Internal (WireGuard-only) services on the home cluster
created: 2026-10-27
updated: 2026-10-27
author: Lance Walters (written with Hermes devops agent)
tags: [homelab, kubernetes, wireguard, cilium, gateway-api, observability]
status: current
verified: 2026-10-27T05:20Z
---
# Internal (WireGuard-only) services
How a service in this cluster is exposed **to the WireGuard mesh and nothing
else** — not to the LAN, not to the internet — and how to add the next one.
First user: Grafana (`monitoring`). Second: Hubble UI (`kube-system`).
Related: [[Home-Lab-Kubernetes-Cluster]], `docs/cluster-overview.md`,
`infrastructure/networking/internal/`.
---
## 1. Why this is not just "an HTTPRoute without a hostname"
Cilium's Gateway implementation runs **one hostNetwork Envoy per gateway node**
(`cilium-envoy` DaemonSet, node selector `node-role.kubernetes.io/gateway=true`
— **`siriussec` 10.10.0.2 only**, since 2026-10-27) and binds **every**
listener port on `0.0.0.0`. There is no Gateway API field for "listen on wg0
only". Consequences:
- A listener on port 8081 is reachable on `192.168.1.179:8081` (siriussec's
LAN address) and on siriussec's WG address the moment it is Programmed.
Nothing binds `:8081` on rpi: it lost the `gateway=true` label on 2026-10-27,
so `10.10.0.1:8081` is a **closed port**, not a second origin.
- The Gateway object cannot enforce the network boundary. **The host firewall
is the enforcement point.** That is the whole trick.
- The service is reached as **`http://10.10.0.2:<port>/`** — 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://<name>.lab.internal:8081` URL keeps working for laptops that
do have the hosts line.
- **One service per listener port AND per Gateway.** Two hostname-less routes
on one listener make precedence ambiguous — and worse, Cilium renders **one
RouteConfiguration per Gateway**, shared by all of that Gateway's listeners,
so two hostname-less routes merge into a single route with `weightedClusters`
weight 1/1: every request then hits a random backend, on *every* port of the
gateway. Splitting them onto different ports of the same Gateway does not
help. Each bare-IP service therefore gets its own **Gateway** (its own port,
its own RouteConfiguration) — see `gateway-hubble-ui.yaml` and §9.
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.
## 2. The pieces
| Object / unit | Where | Purpose |
|---|---|---|
| `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 <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 |
| 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 |
Only siriussec runs `cilium-envoy`, so only its `internal_gw` table is load
bearing. **If a second node is ever given `gateway=true`**, it needs the same
firewall rules *and* its backends co-located, or it will serve 503s for
everything (see §7).
## 3. Current internal services
| Service | URL (over WireGuard) | Optional client `/etc/hosts` line | Route | Port |
|---|---|---|---|---|
| Grafana | **`http://10.10.0.2:8081/`** (also `http://grafana.lab.internal:8081/`) | `10.10.0.2 grafana.lab.internal` | `monitoring/grafana` | 8081 |
| Hubble UI | **`http://10.10.0.2:8084/`** (also `http://hubble.lab.internal:8084/`) | `10.10.0.2 hubble.lab.internal` | `kube-system/hubble-ui` | 8084 |
**The rule: every internal service must be reachable as
`http://10.10.0.2:<port>/` 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.
**`10.10.0.2` is the only serving address.** The Gateways' `status.addresses`
lists *every* node InternalIP (`10.10.0.1`, `10.10.0.2`, `10.10.0.5`) regardless
of which nodes run `cilium-envoy`, and Cilium ignores `spec.addresses`
(cilium#29060), so the status list is **not** a load-balanced VIP and not a
"try either IP" guide. `10.10.0.1` and `10.10.0.5` have no listener;
`10.10.0.1` times out (ufw DROP), `10.10.0.5` is reachable only as a mesh
address. Hand out the bare-IP URL on 10.10.0.2 and nothing else.
Historical note (fixed 2026-10-27): while rpi carried `gateway=true` its Envoy
completed the TCP handshake but could never finish a request to a backend pod
on siriussec — every request to `10.10.0.1:8081`/`:8084` hung 5 s and returned
**503**, *including from the Pi's own `127.0.0.1`*. That is the co-location
fault (SYN-ACK back, no ACK on `reserved:ingress`), and it is why the label now
lives on siriussec alone.
## 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). **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 Gateway** (its own object, its own port, its own
RouteConfiguration) — copy `infrastructure/networking/internal/gateway-hubble-ui.yaml`:
```yaml
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: <svc>
namespace: internal
spec:
gatewayClassName: cilium
listeners:
- name: http-internal
protocol: HTTP
port: <port> # unique; firewalled first, see §5
allowedRoutes: {namespaces: {from: All}}
```
Then the route next to the workload — **without `hostnames`**:
```yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: <svc>
namespace: <ns>
spec:
parentRefs:
- name: <svc> # the Gateway above, NOT `internal`
namespace: internal
sectionName: http-internal
rules:
- matches:
- path: {type: PathPrefix, value: /}
backendRefs:
- name: <service>
port: <port>
```
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** — bare IP first, because
that is the phone path:
```bash
curl -sS -o /dev/null -w '%{http_code}\n' http://10.10.0.2:<port>/ # -> 200/302, never 404
curl -sSL -m 6 http://10.10.0.2:<port>/login | head -c 200 # -> HTML, no absolute redirect
```
5. Add the row to the table in §3.
## 5. Firewall changes for a new port
siriussec — add the same three lines with the new port to
`/etc/nftables.d/internal-gw.nft` and `systemctl reload-or-restart
internal-gw-firewall.service` (it is a oneshot `nft -f`, so re-running is safe):
```
tcp dport <port> iifname "lo" accept
tcp dport <port> ip saddr { 10.10.0.0/24, 10.244.0.0/16 } accept
tcp dport <port> counter drop
```
rpi — the ufw equivalents, inserted **above** the `allow from 192.168.1.0/24`
catch-all (`ufw insert`, never plain `ufw allow`, or the LAN allow matches
first):
```bash
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)'
```
## 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 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):
curl -s http://127.0.0.1:20241/config | python3 -c \
"import json,sys; d=json.load(sys.stdin)['config']; print([i.get('hostname') for i in d['ingress']])"
# 4. The public gateway is untouched:
curl -sS -o /dev/null -w '%{http_code}\n' -H 'Host: forgejo.siriusdevops.com' http://10.10.0.2:8080/
```
## 7. Gotchas
- **A `cluster.local`-style name will not resolve.** Use the bare-IP URL (no
DNS at all); an `/etc/hosts` entry plus `http://<name>.lab.internal:<port>/`
is a laptop-only convenience. There is no internal DNS zone yet.
- **Cilium merges hostname-less routes across listeners of the same Gateway.**
Giving the second bare-IP service its own *listener port* is not enough:
Cilium compiled both hostname-less `PathPrefix /` routes into one route
table, so `10.10.0.2:8081` and `:8082` each answered for **either** backend
(measured 9/11 split over 20 requests pre-fix). Each bare-IP service needs
its **own Gateway object** (`internal`/8081 → Grafana, `internal/hubble-ui`
on 8082 → Hubble), not just its own listener.
- **After adding/moving a listener, restart `cilium-envoy`** — the stale route
stayed programmed on the old port until
`kubectl -n kube-system delete pod -l k8s-app=cilium-envoy` (the pods were
6 days old). Verify per port with a repeated-request loop, not a single curl:
a 50/50 mix of two backends looks like a flaky service, not a config bug.
- **Do not add these hostnames to the cloudflared tunnel** "to make them easier
to reach". That is a public exposure of a service that has no authentication
story beyond Grafana's own. The tunnel ingress list is the public allow-list.
- **`sudo nft -f` is not persistent by itself** — it must go through
`internal-gw-firewall.service` (enabled at boot), same as
`k8s-api-firewall.service`.
- Changing the `internal` Gateway's `allowedRoutes` does not need an Envoy
restart; Cilium reconciles the route table. Changing the **listener** (port,
protocol) does need the `cilium-envoy` pods restarted
(`kubectl -n kube-system delete pod -l k8s-app=cilium-envoy`).
- **Only `siriussec` carries `node-role.kubernetes.io/gateway=true`.** Keep it
that way: `kubectl get nodes -l node-role.kubernetes.io/gateway=true` must
return exactly one node. A 503-after-exactly-5.0 s on a node's own IP (even
`127.0.0.1`) means Envoy is running there but the backend pod is not on that
node — remove the label rather than firewalling around it. Removing the label
deletes the `cilium-envoy` DaemonSet pod on that node within seconds and the
ports go with it; no restart of the remaining pod is needed (the Gateway
object is unchanged).
- **The probe in `monitoring/controllers/home/gateway-probe.yaml` is the flap
detector**: blackbox-exporter + a `Probe` for `http://10.10.0.2:8081/` and
`:8084/` every 30 s, alerting `InternalGatewayUnreachable`
(`probe_success == 0` for 3 min) and `InternalGatewayProbeMissing`
(`absent()`) as a `PrometheusRule`. Watch it in Prometheus `/alerts` or
Grafana → Alerting. There is no Alertmanager in the stack yet, so nothing is
*paged*; the alert is visible, not pushed.
## 8. Verification log — 2026-10-27 (Grafana)
Commit `d3741df` on `master`, reconciled by Flux (`gitrepository` first, then
`kustomization flux-system`, which created `kustomization monitoring`).
```
# flux
NAME READY STATUS
monitoring True Applied revision: master@sha1:d3741df...
# helm + workloads
kube-prometheus-stack True Helm install succeeded for release monitoring/kube-prometheus-stack.v1 with chart kube-prometheus-stack@92.14.0
prometheus-kube-prometheus-stack-prometheus-db-... Bound 10Gi RWO local-path
pods: grafana 3/3, kube-state-metrics 1/1, operator 1/1, node-exporter 1/1, prometheus 2/2 (all on siriussec)
Prometheus CR: retention 7d / retentionSize 8GB, replicas 1, remoteWrite none, PVC 10Gi local-path
active scrape targets: 18 up / 0 down
# positive — from Legion over WireGuard
$ curl -sS -o /dev/null -w '%{http_code}' -L http://grafana.lab.internal:8081/
200 (POST /login with the secret creds -> 200 "Logged in"; /api/user -> admin)
$ curl -sS -o /dev/null -w '%{http_code}' http://10.10.0.2:8081/ # no Host match
404 (SUPERSEDED 2026-10-27 04:35Z by §9 — the route now has no
hostnames, so this same request is a 302 to /login)
# negative 1 — LAN (from Legion, 192.168.1.0/24)
$ curl -m 3 http://192.168.1.179:8081/ -> timed out (curl 28), http_code 000
$ curl -m 3 http://192.168.1.125:8081/ -> timed out (curl 28), http_code 000
(nft table inet internal_gw counts the drops on siriussec; ufw rules at
positions 1-3 on rpi sit above `allow from 192.168.1.0/24`)
# negative 2 — internet
cloudflared ingress (9 entries): siriusdevops.com, www., forgejo., paaas.,
piedmonthomesvc.com, www., siriusgrowthsolutions.com, www., 404-catch-all
-> no grafana/lab.internal entry; and `curl -H 'Host: grafana.lab.internal'
http://10.10.0.2:8080/` returns 404 (the public gateway has no such route).
# regression — public ingress intact (from rpi)
$ curl -H 'Host: forgejo.siriusdevops.com' http://10.10.0.2:8080/ -> 200
# grafana provisioning
24 dashboards in Grafana (includes Node Exporter / Nodes, Kubernetes /
Compute Resources / Pod, ... / Cluster, ... / Namespace); datasource
`kube-prometheus-stack-grafana-datasource` -> Prometheus; anonymous disabled,
allow_sign_up false; admin creds from Secret monitoring/grafana-admin
(admin-user / admin-password).
```
## 9. Verification log — 2026-10-27 (bare-IP fix: Grafana on `http://10.10.0.2:8081/`)
Commits `8939cbd` (Grafana: drop `hostnames` from the route) and, from the
concurrent Hubble card, `dcb708d` (Hubble moved to its own Gateway object —
required, see §7). Flux `monitoring` applied `master@sha1:dcb708d…`, which
contains `8939cbd`.
```
# the change
$ kubectl -n monitoring get httproute grafana -o yaml | sed -n '/^spec:/,/^status:/p'
spec:
parentRefs:
- {group: gateway.networking.k8s.io, kind: Gateway, name: internal, namespace: internal, sectionName: http-internal}
rules:
- backendRefs: [{group: "", kind: Service, name: kube-prometheus-stack-grafana, port: 80, weight: 1}]
matches: [{path: {type: PathPrefix, value: /}}]
# no `hostnames:` — any Host on the listener matches
$ kubectl -n flux-system get kustomizations | grep monitoring
monitoring True Applied revision: master@sha1:dcb708dff4cd3952436f4d5887e071dbde703945
# PHONE PATH — bare IP, no hosts entry, no Host header. From Legion (mesh):
$ curl -sS -D- -o /dev/null http://10.10.0.2:8081/
HTTP/1.1 302 Found
location: /login # relative — no absolute .internal redirect
server: envoy
$ curl -sSL -o /dev/null -w '%{http_code} final=%{url_effective} redirects=%{num_redirects}\n' \
http://10.10.0.2:8081/login
200 final=http://10.10.0.2:8081/login redirects=0
<title>Grafana # real login HTML, 0 redirects
# same request from rpi (source 10.10.0.1) and from a pod in the cluster:
$ ssh sirius@192.168.1.125 'curl -sS -o /dev/null -w "%{http_code}" http://10.10.0.2:8081/' -> 302
$ kubectl -n monitoring run gw-probe --rm -i --image=curlimages/curl:8.10.1 -- \
curl -sS -o /dev/null -w 'pod_bare=%{http_code}' http://10.10.0.2:8081/
pod_bare=302
# named URL still works
$ curl -sS -o /dev/null -w '%{http_code}' -H 'Host: grafana.lab.internal' http://10.10.0.2:8081/ -> 302
# port ownership — 8081 is Grafana's alone (15 consecutive requests, no hubble)
8081: grafana=15 hubble=0 other=0
$ kubectl -n internal get gateway internal -o jsonpath='{range .status.listeners[*]}{.name} attached={.attachedRoutes}{"\n"}{end}'
http-internal attached=1
# negative 1 — LAN (echoed from Legion, 192.168.1.126 on the LAN, while on WG too)
$ curl -m 4 http://192.168.1.179:8081/ -> curl: (28) timed out, http_code 000
$ curl -m 4 http://192.168.1.125:8081/ -> curl: (28) timed out, http_code 000
# negative 2 — internet (cloudflared ingress on rpi: still 8 hostnames + 404 catch-all)
siriusdevops.com, www., forgejo., paaas., piedmonthomesvc.com, www.,
siriusgrowthsolutions.com, www., -> http_status:404
-> no grafana/lab.internal entry
$ curl -H 'Host: grafana.lab.internal' http://10.10.0.2:8080/ -> 404 (public gateway has no such route)
# regression — public ingress intact (from rpi)
$ curl -H 'Host: forgejo.siriusdevops.com' http://10.10.0.2:8080/ -> 200
# phone peer at the time of the fix (Pi hub): still offline, reconnect required
$ sudo wg show wg0 latest-handshakes
A1NSWT7K9Dz…("Peer SiriusMobile", 10.10.0.4) age=570919s (~6.6 days)
```
**The URL to use on the phone: `http://10.10.0.2:8081/`** — tunnel connected,
client `AllowedIPs` covering `10.10.0.0/24`.
## 10. Verification log — 2026-10-27 (Hubble UI on `http://10.10.0.2:8084/`)
Hubble relay + UI are chart values in `infrastructure/networking/cilium/values.yaml`
(`hubble.relay.enabled`, `hubble.ui.enabled`, both pinned to siriussec); the UI
is exposed by `internal/hubble-ui` (port **8084**, own Gateway, no `hostnames`).
**Port choice cost a cycle.** The first attempt used 8082, which is free on
siriussec but held on **rpi** by the leftover `handyman-site` Docker container
(`127.0.0.1:8082`; its nginx holds `127.0.0.1:8083`). Cilium binds the listener
`0.0.0.0:8082` on *both* gateway nodes, so rpi's Envoy rejected the config
(`cannot bind '0.0.0.0:8082': Address already in use`, ~640 lines/s) and
restart-looped the node that fronts the public ingress. 8084 was verified free
on both nodes before the move. **Check `ss -lntH "sport = :<port>" | wc -l` = 0
on every node with `k8s-app=cilium-envoy`, not just the control-plane.**
```
# values -> rendered config (not a guess)
$ kubectl -n kube-system get hr cilium -o jsonpath='{.status.conditions[?(@.type=="Ready")].status} {.status.lastAttemptedRevision}'
True 1.20.1 # Ready=True
$ kubectl -n kube-system get cm cilium-values-* -o jsonpath='{.data.values\.yaml}' | grep -A2 ' relay:'
relay: {enabled: true, replicas: 1, nodeSelector: {kubernetes.io/hostname: siriussec}}
$ kubectl -n kube-system get cm cilium-config -o jsonpath='{.data.hubble-metrics}'
flow drop tcp port-distribution icmp httpV2 dns # + hubble-metrics-server :9965
$ kubectl -n kube-system get pods | grep -E 'hubble'
hubble-relay-6f87554656-wznnw 1/1 Running
hubble-ui-567ccf4fbd-skkwm 2/2 Running
$ kubectl -n kube-system logs deploy/hubble-relay --tail=3
msg=Connecting address=10.10.0.1:4244 tls=true peer=rpi
msg=Connected address=10.10.0.2:4244 tls=true peer=siriussec
msg=Connected address=10.10.0.5:4244 tls=true peer=linode
# scrape targets (Prometheus CR selects label release=kube-prometheus-stack)
serviceMonitor/kube-system/hubble/0 up 10.10.0.1:9965 / 10.10.0.2:9965 / 10.10.0.5:9965
serviceMonitor/kube-system/hubble-relay/0 up 10.244.0.75:9966
serviceMonitor/kube-system/cilium-operator/0 up 10.10.0.2:9963
23 active targets, 23 up / 0 down (was 18/18 before this card)
# flows are real (Prometheus)
hubble_flows_processed_total = 4586 hubble_drop_total = 8
hubble_tcp_flags_total = 1471 hubble_icmp_total = 36
hubble_flows_processed_total{type="PolicyVerdict"} = 178 # policy-verdict data
hubble_http_requests_total = 281
# relay's own view: hubble_relay_pool_peer_connection_status{status="READY"} = 3
# PHONE PATH — bare IP, no hosts entry, no Host header (from Legion)
$ curl -sS -o /dev/null -w '%{http_code}' http://10.10.0.2:8084/ -> 200
$ curl -sS http://10.10.0.2:8084/ | grep -o '<title>.*</title>' -> <title>Hubble UI</title>
$ curl -sS -o /dev/null -w '%{http_code}' http://10.10.0.2:8081/ -> 302 (Grafana, unbroken)
# the UI actually works, not just its shell: headless Chromium against the bare IP
# /?namespace=kube-system -> service map rendered, status dot green,
# "64.7 flows/s", "3/3 nodes", flow table populated
# backend log: GetEventsRequest parsed (ServiceMapStream) + watcher is running
# (ControlStream) -> hubble-relay:80, FlowStream streaming
$ kubectl -n kube-system logs deploy/hubble-ui -c backend --tail=2 | grep -c Stream
2
# negative 1 — LAN (from Legion, 192.168.1.0/24)
$ curl -m 3 http://192.168.1.179:8084/ -> 000 (timeout) # siriussec nft
$ curl -m 3 http://192.168.1.125:8084/ -> 000 (timeout) # rpi ufw
# negative 2 — internet: no hubble/lab.internal entry in the cloudflared ingress
# (9 hostnames, all public sites), and no tunnel points at 8084.
# regression: forgejo.siriusdevops.com -> 200 through the tunnel; Grafana 302.
# envoy health after the move
kubectl -n kube-system get pods -l k8s-app=cilium-envoy # both 1/1, RESTARTS 0
logs <rpi pod> --since=60s | grep -c 'cannot bind' # 0
```
**Only `10.10.0.2` answers.** As of 2026-10-27 that is true structurally, not
just in practice: `10.10.0.1:8081/:8084` have **no listener** (rpi lost
`gateway=true` — see §12); before the fix they returned **503 after exactly
5 s, even from rpi's own `127.0.0.1`**, because Envoy on a node that does not
run the backend completes the TCP handshake and never ACKs. The Gateway status
still lists all three node addresses (Cilium ignores `spec.addresses`); the
serving address is the one the backends are pinned to, `10.10.0.2`.
## 11. Internal DNS: the `lab.internal` zone
Facts: zone `lab.internal`, resolver `10.10.0.1` (and `10.20.0.2`), records
`grafana.lab.internal` and `hubble.lab.internal` → `10.10.0.2`, configured by
`infrastructure/networking/internal/dns/`. The record does **not** carry a
port: Grafana stays on `:8081`, Hubble UI on `:8084`, so the URLs are
`http://grafana.lab.internal:8081/` and `http://hubble.lab.internal:8084/`.
### 11.1 What "split DNS" can and cannot mean here
The WireGuard clients in use (Android, iOS, and the desktop clients) hand the
tunnel's DNS server to the OS as **the device resolver for everything while
the tunnel is up**. There is no client-side per-domain split, and nothing on
the server side can create one. So:
- the resolver on the hub **answers `lab.internal` itself** (authoritative,
`local=/lab.internal/`, never forwarded), and
- **forwards every other query** to the upstreams in the Pi's
`/etc/resolv.conf` (today `100.100.100.100` = Tailscale MagicDNS, which
forwards to the ISP resolvers `137.118.204.9` / `137.118.1.32`).
Public resolution therefore keeps working *through* the tunnel resolver — it
is not "split on the client", it is "one resolver that knows one private zone
and forwards the rest". Public names stay on public DNS; there are no
split-horizon records for `siriusdevops.com`, `piedmonthomesvc.com` or
`siriusgrowthsolutions.com` and there must not be.
**The risk this creates:** while the tunnel is up, a dead resolver is a dead
internet connection for that device. Rollback is in §11.6.
### 11.2 Where it runs, and why not in the cluster
`dnsmasq` **on rpi** — the WireGuard hub, `10.10.0.1` on `wg0` and `10.20.0.2`
on `wg-remote`. It is a host service, deliberately **not** behind Cilium's
internal Gateway: those listeners have their own failure mode (`t_e9564aa3`,
Envoy on the wrong node answers 503 after 5 s) and DNS must not inherit it.
Host ports on the Pi over WireGuard work (SSH on `10.10.0.1:22` is proof).
dnsmasq was already the Pi's resolver (it also answers `.rpi.local`), so this
extends it instead of adding a second resolver on port 53. Artifacts:
| File | Installed to | Purpose |
|---|---|---|
| `dns/lab-internal.conf` | `/etc/dnsmasq.d/lab-internal.conf` | zone authority, `addn-hosts`, bind list |
| `dns/lab-internal.hosts` | `/etc/dnsmasq-lab-internal.hosts` | the records (hosts(5) syntax) |
| `dns/rpi-ufw-dns.sh` | — | ufw allow/deny for `:53` |
| `dns/install-rpi-dns.sh` | — | installs all of the above, restarts, prints bind view |
The hosts file lives **outside** `/etc/dnsmasq.d` on purpose: the unit passes
`-7 /etc/dnsmasq.d`, so every file in that directory is parsed as config, and a
hosts file there fails the start with `bad option at line 9`.
Install / re-install (host artifacts — a Pi reinstall has to re-run this):
```bash
bash infrastructure/networking/internal/dns/install-rpi-dns.sh # as root on rpi
```
### 11.3 Listen addresses and the firewall boundary
`bind-dynamic` + `interface=lo`, `interface=wg0`, `interface=wg-remote`:
53 is bound on `127.0.0.1`, `10.10.0.1`, `10.20.0.2` (and `::1`) and **nowhere
else** — not on `192.168.1.125`, not on the tailscale address. `bind-dynamic`
also means a WireGuard interface that is down at boot is picked up when it
appears, with no restart and no hard `Requires=` on a `wg-quick@` template unit.
ufw is the second layer (and the one that produces the DROP evidence), inserted
above the `allow from 192.168.1.0/24` catch-all:
```
53/udp,tcp ALLOW IN 10.10.0.0/24 # mesh (siriussec, Pi-hub peers)
53/udp,tcp ALLOW IN 10.20.0.0/24 # remote hub + its spokes (the phone, Legion)
53/udp,tcp ALLOW IN 10.244.0.0/16 # pods
53/udp,tcp DENY IN Anywhere # LAN, tailscale, internet
```
`10.20.0.0/24` is not optional: the phone and Legion are spokes of the
**linode** hub (`10.20.0.1`), so their DNS packets reach the Pi on `wg-remote`
with source `10.20.0.3` / `10.20.0.5`. With only the mesh subnet allowed, the
hub-spoke clients time out (§11.7 negative 3).
No Cloudflare change: the tunnel's ingress list is an allow-list of HTTP
hostnames pointing at `:8080`; UDP/TCP 53 is not proxied by it and there is no
port-forward on the LAN edge. `*.lab.internal` has no public record.
### 11.4 Adding a record
1. Add one line to `dns/lab-internal.hosts` — `<address>\t<name>` — commit it.
2. On rpi: `sudo install -m 0644 dns/lab-internal.hosts /etc/dnsmasq-lab-internal.hosts
&& sudo systemctl reload dnsmasq` (a reload re-reads `addn-hosts`; no restart,
no dropped queries).
3. Verify: `dig +short <name> @10.10.0.1`.
Only `lab.internal` is authoritative. A query for anything else, *including*
`siriusdevops.com`, is forwarded — do not add public names here.
Which address to record: **`10.10.0.2`** today, because siriussec is the only
node carrying `node-role.kubernetes.io/gateway=true` and therefore the only one
with a listener that can complete a request to the backends. If that changes
(the label moving back to rpi once the arm64/Envoy co-location issue is solved),
it is a one-line change in `dns/lab-internal.hosts` + reload.
### 11.5 Client configuration
The phone is **`Pixel 9 Pro`**, WireGuard peer `10.20.0.3` on the **linode**
hub (`10.20.0.1:51820`) — not a `wg0` peer of the Pi: its handshake is
seconds old on the linode hub, while the Pi's `wg0` peer `10.10.0.4`
(`Peer SiriusMobile`) has been stale for days. Its DNS therefore has to be set
in the phone's own WireGuard profile. The Pi's `wg0.conf` peers (and the
`wgportal` DB) are *not* where the phone's DNS lives, and wgportal is not even
running on the Pi today (`docker ps` has no wgportal container) — so nothing on
the server side can push this; do not go looking for a portal toggle.
**Android (WireGuard app) — 3 steps:**
1. Open the WireGuard app → tap the tunnel → pencil (Edit) → **Interface**
section → **DNS servers** → enter `10.10.0.1` (leave "Excluded applications"
alone).
2. Save, then toggle the tunnel **off and on** (Android keeps the old
`resolver1` until the tunnel restarts).
3. Check: browser to `http://grafana.lab.internal:8081/` → login page; and any
public site still loads (proof forwarding works).
If that profile's `AllowedIPs` does not cover `10.10.0.0/24`, use **`10.20.0.2`**
(the Pi's address on the hub subnet) instead — both answer, both are the same
resolver.
**iOS:** WireGuard app → tunnel → Edit → *DNS Servers* → `10.10.0.1` → Save →
toggle off/on.
**Desktop (wg-quick):** in the tunnel's `[Interface]` add `DNS = 10.10.0.1`
and, because this is a non-systemd-resolved-specific option,
`resolvconf`/`openresolv` must be present (`wg-quick` uses it to point the
system resolver at the tunnel); then `wg-quick down <if> && wg-quick up <if>`.
There is no per-domain split — the whole machine uses it while the tunnel is
up.
Do not point a **cluster node** at this resolver: nodes and pods must keep
their own DNS (`CoreDNS` / `/etc/resolv.conf`) or kubelet and pod lookups will
break. This is for client devices only.
### 11.6 Rollback (do this first when DNS "breaks the internet")
On the device: WireGuard app → tunnel → Edit → clear the **DNS servers** field
→ Save → toggle the tunnel off/on. That restores the OS resolver immediately.
On the server: `sudo systemctl disable --now dnsmasq` stops the Pi's resolver
(don't — it also serves `.rpi.local`); to remove only the zone, delete
`/etc/dnsmasq.d/lab-internal.conf` and `/etc/dnsmasq-lab-internal.hosts` and
`systemctl restart dnsmasq`. To close the port again, remove the six `wg-dns`
ufw rules (`ufw status numbered`, then `ufw delete <n>`).
### 11.7 Verification log — 2026-10-27
Resolver: `dnsmasq` 2.91 on rpi, enabled at boot (`systemctl is-enabled dnsmasq`
= `enabled`), ufw `enabled`. Listeners (no `0.0.0.0`, no LAN address):
```
$ sudo ss -lntuH 'sport = :53'
udp 127.0.0.1:53 udp 10.10.0.1:53 udp 10.20.0.2:53 udp [::1]:53
tcp 127.0.0.1:53 tcp 10.10.0.1:53 tcp 10.20.0.2:53 tcp [::1]:53
$ sudo journalctl -u dnsmasq -n 4
using nameserver 100.100.100.100#53 # forwarded upstreams (tailscale MagicDNS)
using only locally-known addresses for lab.internal
read /etc/dnsmasq-lab-internal.hosts - 2 names
```
`10.10.0.1:8081`/`:8084` flap. `:53` does not: it is a host socket, not Envoy.
**Positive — from a WireGuard client (Legion, `10.20.0.5`, via the linode hub):**
```
$ dig +short grafana.lab.internal @10.10.0.1 -> 10.10.0.2
$ dig +short hubble.lab.internal @10.10.0.1 -> 10.10.0.2
$ dig +short grafana.lab.internal @10.20.0.2 -> 10.10.0.2
$ dig +tcp +short grafana.lab.internal @10.10.0.1 -> 10.10.0.2
$ dig +short example.com @10.10.0.1 -> 104.20.23.154 / 172.66.147.243 # forwarding
$ dig nosuch.lab.internal @10.10.0.1 -> status: NXDOMAIN # authoritative, not forwarded
```
From a mesh peer (`siriussec`, `10.10.0.2`): all three names `rcode 0`
(`grafana.lab.internal`, `hubble.lab.internal`, `example.com`). From the Pi's
own loopback: same, plus `nope.lab.internal` → `NXDOMAIN`.
**Negative — LAN and counters** (from Legion on `192.168.1.126`, same host that
resolved fine over the tunnel a second earlier):
```
$ dig +time=3 grafana.lab.internal @192.168.1.125 -> timed out, no servers could be reached
$ dig +tcp +time=3 grafana.lab.internal @192.168.1.125 -> timed out
$ sudo iptables -L ufw-user-input -n -v | grep dpt:53
2 120 ACCEPT tcp 10.20.0.0/24 dpt:53 # hub spokes (the phone's path)
3 188 ACCEPT udp 10.10.0.0/24 dpt:53 # mesh
7 602 ACCEPT udp 10.20.0.0/24 dpt:53
3 180 DROP tcp 0.0.0.0/0 dpt:53 # LAN / internet
1 89 DROP udp 0.0.0.0/0 dpt:53
```
**Regression:** `http://10.10.0.2:8081/` → 302 (Grafana login), `:8084/` → 200
(Hubble UI), public sites through the tunnel unchanged (no Cloudflare object
touched).
**Reboot survival:** `systemctl is-enabled dnsmasq` = `enabled`; the unit
`Requires=network-online.target` and has **no** `Requires=`/`After=` on any
`wg-quick@` template (which is `enabled` but currently `inactive` because `wg0`
was brought up by hand — a hard dependency would fail the boot). `bind-dynamic`
picks up `wg0`/`wg-remote` whenever they appear. Records and the bind list live
in `/etc/dnsmasq*`, not in `/run`; ufw rules are persistent.
## 12. Verification log — 2026-10-27 (the flap: rpi was a second, broken gateway node)
Symptom Lance saw: the internal dashboards "work / don't work" from his phone,
while they were rock-steady from a laptop. Nothing was flapping at 10.10.0.2 —
the flapping address was **10.10.0.1**.
**Root cause.** rpi carried `node-role.kubernetes.io/gateway=true` alongside
siriussec, so `cilium-envoy` ran there and bound `0.0.0.0:8080/8081/8084`. Its
Envoy completes TCP to a backend pod on siriussec but never finishes the
request (SYN-ACK back, no ACK on `reserved:ingress`), so every request on the Pi
hung and then failed. Fixed by removing the label: **one gateway node, one
serving address.**
**Premise corrected — the Pi's listener was not "bound but unresponsive".** A
4 s `curl` timeout made it look like a dead socket; the socket is fine and
answers. The exact shape of the failure is a **503 after 5.000 s**, which is the
upstream-connect timeout, not a stuck accept loop (`ss -lnt` Recv-Q 0, backlog
never filled):
```
# on rpi, before the fix
$ curl -s -o /dev/null -m 15 -w '%{http_code} %{time_total}\n' http://127.0.0.1:8081/
503 5.003515
$ curl -s -o /dev/null -m 15 -w '%{http_code} %{time_total}\n' http://127.0.0.1:8084/
503 5.003963
$ curl -s -o /dev/null -m 15 -w '%{http_code} %{time_total}\n' http://10.10.0.1:8081/
503 5.000658
```
**Envoy's own config (admin unix socket), pre-fix** — all three listeners are
identical in shape, which rules out a per-listener config fault:
```
$ sudo curl -s --unix-socket /var/run/cilium/envoy/sockets/admin.sock \
http://localhost/config_dump
LISTENER internal/cilium-gateway-hubble-ui/listener addr={'address': '0.0.0.0', 'port_value': 8084}
LISTENER gateway-system/cilium-gateway-public/listener addr={'address': '0.0.0.0', 'port_value': 8080}
LISTENER internal/cilium-gateway-internal/listener addr={'address': '0.0.0.0', 'port_value': 8081}
transparent=None use_original_dst=None
listener_filters=['envoy.filters.listener.tls_inspector', 'cilium.bpf_metadata']
FC match: {"transport_protocol": "raw_buffer"} # no per-address filter chains
```
Killed hypotheses: no `original_dst` / address-scoped filter chains (so the
destination IP is irrelevant — that is why `127.0.0.1` failed the same way), no
missing bind, no firewall. What differed was **which node the Envoy pod ran on**.
```
# the fix: exactly one node carries the label
$ kubectl label node rpi node-role.kubernetes.io/gateway-
node/rpi unlabeled
$ kubectl get nodes -l node-role.kubernetes.io/gateway=true -o name
node/siriussec
$ kubectl -n kube-system get pods -l k8s-app=cilium-envoy -o wide
cilium-envoy-xfkfq 1/1 Running 0 10.10.0.2 siriussec # the rpi pod is gone
```
`Gateway.status.addresses` still lists `10.10.0.1 10.10.0.2 10.10.0.5` (every
node InternalIP) and Cilium ignores `spec.addresses` (cilium#29060), so that
field is not a VIP and not a "try either IP" list. Also note the Pi's ufw accept
rules never showed a packet counter while requests to `10.10.0.1:8081` *were*
reaching Envoy (proved by the 503 body) — `ufw status` does not expose counters,
and "0 packets" there is not evidence the packet never arrived.
**Matrix after the fix** (`curl -m 6`, code + seconds):
| Vantage point | 10.10.0.1:8081 | 10.10.0.1:8084 | 10.10.0.2:8081 | 10.10.0.2:8084 |
|---|---|---|---|---|
| Legion over WG (10.20.0.5 → mesh) | 000 (6.00, ufw DROP) | 000 (6.00) | **302** (0.11) | **200** (0.11) |
| rpi itself, `10.10.0.1` | 000 (0.0002, no listener) | 000 (0.0002) | **302** (0.003) | **200** (0.002) |
| rpi itself, `127.0.0.1` | 000 (0.0002, no listener) | 000 (0.0002) | — | — |
| pod on siriussec (10.244.0.118) | 000 (0.0006) | 000 (0.0007) | **302** (0.001) | **200** (0.001) |
`sudo ss -lntH` on rpi: **0** sockets on 8081/8084 (was 4 + 4, reuseport).
**Firewall counters — the working path is provably accepted, not just "no
error"** (the accept rules now carry `counter`):
```
$ curl http://10.10.0.2:8081/ ; curl http://10.10.0.2:8084/ # from Legion, a pod, and locally on siriussec
$ sudo nft list table inet internal_gw # on siriussec
tcp dport { 8081, 8084 } iifname "lo" counter packets 48 bytes 3200 accept
tcp dport { 8081, 8084 } ip saddr { 10.10.0.0/24, 10.244.0.0/16 } counter packets 948 bytes 164449 accept
tcp dport { 8081, 8084 } counter packets 17 bytes 1020 drop # LAN attempts
```
**Flap detection** — `monitoring/controllers/home/gateway-probe.yaml`
(blackbox-exporter on siriussec + a `Probe` every 30 s + `PrometheusRule`
`InternalGatewayUnreachable` / `InternalGatewayProbeMissing`):
```
$ kubectl -n flux-system get kustomization monitoring -o jsonpath='{.status.lastAppliedRevision}'
master@sha1:48b2b6a...
$ kubectl -n monitoring get pods | grep blackbox
blackbox-exporter-78b95b789c-b4gl8 1/1 Running
$ # /api/v1/targets (Prometheus, port-forward)
probe/monitoring/internal-gateway http://10.10.0.2:8081/ up
probe/monitoring/internal-gateway http://10.10.0.2:8084/ up
probe_success{job="internal-gateway"} 1, 1
# it also caught a real flap while this card was being verified: the concurrent
# Grafana-persistence card recreated the pod and 8081 answered 503 for ~25 s.
# Negative proof of the detector: a third target pointed at the (dead)
# 10.10.0.1:8081 produced probe_success 0 and
# ALERTS{alertname="InternalGatewayUnreachable",alertstate="pending",
# instance="http://10.10.0.1:8081/"} = 1
# (state cleared when Flux re-applied the Probe from git before `for: 3m`
# elapsed, so `firing` was not observed end-to-end).
```
There is **no Alertmanager** in the stack, so this is visible in Prometheus
`/alerts` and Grafana → Alerting, not paged. Next step if a page is wanted: add
a contact point/receiver, not another probe.
The probe catches the **symptom**; `GatewayNodeCountNotOne`
(`count(kube_node_role{role="gateway"}) != 1`, 5 m) catches the **cause** —
kube-state-metrics exposes role labels as `kube_node_role`, so relabelling a
node is visible without a second scrape target. Both were proved by putting the
bug back on purpose:
```
$ kubectl label node rpi node-role.kubernetes.io/gateway=true --overwrite
node/rpi labeled
$ kubectl -n kube-system get pods -l k8s-app=cilium-envoy --no-headers
cilium-envoy-fwcqm Running rpi # the second Envoy is back
cilium-envoy-xfkfq Running siriussec
# the original fault, reproduced exactly, from rpi itself:
$ curl -m 15 -w '%{http_code} %{time_total}\n' http://10.10.0.1:8081/ -> 503 4.999340
$ curl -m 15 -w '%{http_code} %{time_total}\n' http://127.0.0.1:8081/ -> 503 5.001838
$ curl -m 6 -w '%{http_code} %{time_total}\n' http://10.10.0.2:8081/ -> 302 0.005733
# ~5 min later, the label alert fires (nothing paged, no user impact):
ALERTS{alertname="GatewayNodeCountNotOne",alertstate="firing"} = 1
$ kubectl label node rpi node-role.kubernetes.io/gateway-
node/rpi unlabeled
$ kubectl get nodes -l node-role.kubernetes.io/gateway=true -o name
node/siriussec
# and 10.10.0.1 is a closed port again (000 in 0.2 ms), 10.10.0.2 still 302/200
```
**Negatives re-proved after the change**
```
# LAN (from Legion, 192.168.1.0/24) — DROP on both nodes, both ports
192.168.1.179:8081 -> 000 (curl 28, 4.0 s) 192.168.1.179:8084 -> 000
192.168.1.125:8081 -> 000 (curl 28, 4.0 s) 192.168.1.125:8084 -> 000
# public: internal hostnames have no route on the public listener
curl -H 'Host: grafana.lab.internal' http://10.10.0.2:8080/ -> 404
curl -H 'Host: hubble.lab.internal' http://10.10.0.2:8080/ -> 404
# tunnel ingress = 9 entries, every service http://10.10.0.2:8080, no lab.internal
# public sites through the tunnel still 200 (from rpi):
# siriusdevops.com 200 forgejo.siriusdevops.com 200 piedmonthomesvc.com 200
# siriusgrowthsolutions.com 200
```
Commit `48b2b6a` (label removal is host state — `kubectl label node rpi
node-role.kubernetes.io/gateway-`; the manifests, the counter-augmented nft file
and this document are in git).