diff --git a/docs/internal-wireguard-services.md b/docs/internal-wireguard-services.md index 1c79f50..81de75b 100644 --- a/docs/internal-wireguard-services.md +++ b/docs/internal-wireguard-services.md @@ -23,12 +23,14 @@ Related: [[Home-Lab-Kubernetes-Cluster]], `docs/cluster-overview.md`, Cilium's Gateway implementation runs **one hostNetwork Envoy per gateway node** (`cilium-envoy` DaemonSet, node selector `node-role.kubernetes.io/gateway=true` -— currently `rpi` 10.10.0.1 and `siriussec` 10.10.0.2) and binds **every** +— **`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.125:8081`, - `192.168.1.179:8081` and the public interface the moment it is Programmed. +- 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:/`** — no `/etc/hosts` @@ -59,13 +61,14 @@ 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` | -| ufw rules (inserted above the LAN catch-all) | rpi host | same policy for `:8081`+`:8084` | -| `infrastructure/networking/internal/host-firewall/` | repo | the two host artifacts + install/verify instructions | +| `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 | -Both firewalls must be in place: Envoy listens on **both** gateway nodes, so -leaving either node's port open leaks the service to the LAN from that node's -address (and the other node answers 503, which still proves a listener exists). +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 @@ -79,11 +82,20 @@ address (and the other node answers 503, which still proves a listener exists). 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. +**`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 @@ -220,10 +232,21 @@ curl -sS -o /dev/null -w '%{http_code}\n' -H 'Host: forgejo.siriusdevops.com' ht 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`). -- Envoy on both nodes answers for the listener. If a request to - `10.10.0.1:8081` hangs for ~5 s and returns 503 while `10.10.0.2:8081` is - instant, that is the co-location fault (backend not on that node), not a - firewall or routing problem. +- **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) diff --git a/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft b/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft index e03cb00..9f51db6 100644 --- a/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft +++ b/infrastructure/networking/internal/host-firewall/siriussec-internal-gw.nft @@ -22,11 +22,11 @@ table inet internal_gw { type filter hook input priority filter; policy accept; # local process / kubelet probes - tcp dport { 8081, 8084 } iifname "lo" accept + tcp dport { 8081, 8084 } 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 } ip saddr { 10.10.0.0/24, 10.244.0.0/16 } accept + tcp dport { 8081, 8084 } ip saddr { 10.10.0.0/24, 10.244.0.0/16 } counter accept # everything else: LAN, tailscale, public tcp dport { 8081, 8084 } counter drop diff --git a/monitoring/controllers/home/gateway-probe.yaml b/monitoring/controllers/home/gateway-probe.yaml new file mode 100644 index 0000000..b89c70f --- /dev/null +++ b/monitoring/controllers/home/gateway-probe.yaml @@ -0,0 +1,161 @@ +# Internal-gateway liveness probe (WireGuard-only services). +# +# Why this exists: the internal listeners (8081 Grafana, 8084 Hubble UI) are +# served by the Cilium hostNetwork Envoy on the node(s) carrying +# `node-role.kubernetes.io/gateway=true`. Before 2026-10-27 that label was on +# both rpi and siriussec, and the Pi's Envoy could complete TCP to a backend +# pod on siriussec but never finish the request: every request to +# 10.10.0.1:8081/8084 hung for 5 s and then returned 503, even from the Pi's +# own 127.0.0.1. Clients that tried "either IP" therefore saw the dashboards +# flap. The label now lives on siriussec only, and this probe makes a +# regression (label re-added, listener gone, Envoy wedged, firewall rule +# dropped) visible in Prometheus/Grafana instead of on Lance's phone. +# +# Prober: blackbox-exporter, pinned to siriussec (same node as the Gateway, so +# the probe crosses the pod network over the WireGuard mesh rather than +# loopback). Nothing here is public: the prober talks to the node IP over the +# mesh and the host firewall in `infrastructure/networking/internal` is what +# restricts the listeners themselves. +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: blackbox-exporter + namespace: monitoring +data: + blackbox.yml: | + modules: + # Grafana answers / with a 302 to /login, Hubble UI answers 200. + http_2xx_or_3xx: + prober: http + timeout: 5s + http: + valid_status_codes: [200, 301, 302, 303, 307, 308] + preferred_ip_protocol: ip4 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: blackbox-exporter + namespace: monitoring + labels: + app.kubernetes.io/name: blackbox-exporter +spec: + replicas: 1 + selector: + matchLabels: + app.kubernetes.io/name: blackbox-exporter + template: + metadata: + labels: + app.kubernetes.io/name: blackbox-exporter + spec: + nodeSelector: + kubernetes.io/hostname: siriussec + containers: + - name: blackbox-exporter + image: prom/blackbox-exporter:v0.25.0 + args: + - --config.file=/etc/blackbox_exporter/blackbox.yml + ports: + - name: http + containerPort: 9115 + readinessProbe: + httpGet: + path: /-/healthy + port: http + initialDelaySeconds: 5 + resources: + requests: + cpu: 10m + memory: 32Mi + limits: + cpu: 100m + memory: 64Mi + volumeMounts: + - name: config + mountPath: /etc/blackbox_exporter + volumes: + - name: config + configMap: + name: blackbox-exporter +--- +apiVersion: v1 +kind: Service +metadata: + name: blackbox-exporter + namespace: monitoring + labels: + app.kubernetes.io/name: blackbox-exporter +spec: + selector: + app.kubernetes.io/name: blackbox-exporter + ports: + - name: http + port: 9115 + targetPort: http +--- +# Only 10.10.0.2 is a serving internal-gateway 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`, so the status list is NOT a "try either IP" guide. +apiVersion: monitoring.coreos.com/v1 +kind: Probe +metadata: + name: internal-gateway + namespace: monitoring + labels: + release: kube-prometheus-stack +spec: + jobName: internal-gateway + interval: 30s + module: http_2xx_or_3xx + prober: + url: blackbox-exporter.monitoring.svc:9115 + path: /probe + targets: + staticConfig: + static: + - http://10.10.0.2:8081/ + - http://10.10.0.2:8084/ + labels: + exposure: wireguard-internal +--- +apiVersion: monitoring.coreos.com/v1 +kind: PrometheusRule +metadata: + name: internal-gateway + namespace: monitoring + labels: + release: kube-prometheus-stack +spec: + groups: + - name: internal-gateway + rules: + - alert: InternalGatewayUnreachable + expr: probe_success{job="internal-gateway"} == 0 + for: 3m + labels: + severity: warning + annotations: + summary: >- + Internal gateway listener {{ $labels.instance }} is not answering + (probe_success 0 for 3m) + description: >- + Grafana (8081) / Hubble UI (8084) are served by cilium-envoy on + siriussec only. Check that rpi has NOT re-acquired + node-role.kubernetes.io/gateway=true, that cilium-envoy is Running + on siriussec, that the internal_gw nft table accepts 10.10.0.0/24 + and 10.244.0.0/16, and that the route/service behind the listener + exists. + - alert: InternalGatewayProbeMissing + expr: absent(probe_success{job="internal-gateway"}) + for: 10m + labels: + severity: warning + annotations: + summary: The internal-gateway blackbox probe has disappeared from Prometheus + description: >- + Either the Probe object / blackbox-exporter pod is gone or the + operator is not selecting it (label release=kube-prometheus-stack). + The dashboards are then unmonitored, not necessarily broken. diff --git a/monitoring/controllers/home/kustomization.yaml b/monitoring/controllers/home/kustomization.yaml index a18bc33..8426887 100644 --- a/monitoring/controllers/home/kustomization.yaml +++ b/monitoring/controllers/home/kustomization.yaml @@ -6,6 +6,7 @@ resources: - repository.yaml - release.yaml - httproute.yaml + - gateway-probe.yaml configMapGenerator: - name: kube-prometheus-stack-values files: