docs(gateway): record the access-log fields, measured volume and rotation window

Live numbers from a 19.6-minute window after enabling F7: 641 B/line, 9.54
lines/s, 528 MB/day raw (274 MB/day at the 5-day average), 1.008 lines per
request. kubelet's default 10Mi x 5 gives 28.6 min per file / ~2.4 h total at
the measured rate (50 MiB hard cap = 0.023% of the 213.5 GiB root); Loki stores
the same traffic at 12.6x compression (42 MB/day, ~340 MB for 192 h), so the
kubelet default is kept.

Also records the wedge that made the first apply look inert: the operator's
gateway controller had failed to init during an earlier apiserver restart, so
GatewayClassConfig changes produced nothing until the operator was restarted.
This commit is contained in:
Lance Walters 2026-11-27 01:56:21 -05:00
commit f03f171b34

View file

@ -0,0 +1,138 @@
# Gateway access logging (cilium-envoy)
Source of truth for the HTTP access log the Cilium Gateway class emits. Closes finding F7 of the
2026-11-27 cluster netsec audit: before this, `cilium-envoy` wrote **no request-level record**, so the
design's application-layer detection (traversal / `union select` / `%00` / `.env`/`.git` probes,
high-rate 401-403 per client, scanner user agents) had no input stream.
## What is configured, and where it lives
| Object | File |
|---|---|
| `CiliumGatewayClassConfig kube-system/cilium` | `infrastructure/networking/gateway/gatewayclass-config.yaml` |
| `GatewayClass cilium` (+ `spec.parametersRef`) | `infrastructure/networking/gateway/gatewayclass.yaml` |
Cilium 1.20 reads `spec.telemetry.accessLogs` from the config referenced by
`GatewayClass.spec.parametersRef`. The cilium Helm chart creates the GatewayClass but has **no values
knob for `parametersRef`**, so the object is declared in Git with the chart's spec plus the reference;
Flux (`kustomization infrastructure`) owns both. Access logging therefore applies to **every** Gateway
on the `cilium` class: `gateway-system/public` and the internal `internal/*` Gateways.
Cilium renders the config into each Gateway listener's HTTP connection manager as an
`envoy.access_loggers.stdout` access log (`StdoutAccessLog`), i.e. one JSON line per request on the
`cilium-envoy` container's stdout. Nothing is applied by hand; `cilium upgrade` / `helm upgrade` must
not be used.
## Fields
`gateway, start_time, method, path, protocol, response_code, response_flags, duration_ms,
bytes_received, bytes_sent, authority, client_ip, x_forwarded_for, peer, user_agent, cf_ray,
upstream_host`
- `client_ip` = `CF-Connecting-IP`. Envoy is hostNetwork, so the **raw peer is cloudflared on the Pi**
(`10.10.0.1`) for public traffic and the WG client address for internal traffic — `peer` and
`x_forwarded_for` are kept so a missing/forged `CF-Connecting-IP` is visible rather than trusted.
Internal/WG requests have `client_ip: null` and a real `peer`.
- `authority` is the Host (which public hostname / which `10.10.0.2:<port>`).
- `path` is `X-ENVOY-ORIGINAL-PATH?:PATH`, so a rewrite does not hide the requested path.
**Not logged, by construction** (the JSON map is an allowlist, not a filter): no request/response
bodies and no header dumps, so `Authorization`, `Cookie` and `Set-Cookie` never reach disk. Envoy
application log level stays `info` — no debug/trace logging.
## Where the lines land
1. `/var/log/pods/kube-system_cilium-envoy-<suffix>_<uid>/cilium-envoy/*.log` (kubelet container log).
2. Loki automatically: the `logging` Alloy DaemonSet tails `/var/log/pods/*/*/*.log*`, so the stream
appears as `{namespace="kube-system", container="cilium-envoy", job="kube/pods", node="siriussec"}`
with the store's 192 h retention. No extra Alloy/Loki configuration was needed.
Only **siriussec** runs envoy (`node-role.kubernetes.io/gateway=true` is a single node), so there is
exactly one container log — the "3 nodes" framing in the finding does not apply.
## Measured volume and retention (2026-11-27)
Window `06:35:26Z → 06:55:04Z`, 1,178 s, live public traffic:
| Measure | Value |
|---|---|
| access lines | 11,240 |
| bytes written | 7,205,793 |
| per line | 641 B |
| line rate | 9.54/s |
| write rate | 6.1 KB/s |
| **projected** | **528 MB/day raw (504 MiB)** |
| 5-day request average (envoy `downstream_rq_total` 2,059,146 / 417,181 s = 4.94/s) | 274 MB/day |
| lines per request (594 s sub-window: +5,534 lines vs +5,492 requests) | 1.008 |
Composition: 93.5 % `forgejo.siriusdevops.com` (about half of those are 303 login redirects to
crawlers, because the registry/UI is login-only), 4.2 % hubble UI, 1.2 % the sites, 1.1 % bare-IP
internal ports.
**kubelet default rotation (10 MiB x 5 per container):** 10 MiB at 6.1 KB/s = **28.6 min per file**,
so the 5-file budget (50 MiB) holds **≈2.4 h** of access log at the measured rate (≈4.6 h at the 5-day
average). Hard disk cost is capped at 50 MiB — 0.023 % of siriussec's 213.5 GiB root (99 GiB free;
`/var/log/pods` is 66 MB total today). Not minutes-long, so the default is kept: Loki is the archive.
If a longer *file* window is ever wanted, `containerLogMaxSize: 50Mi` + `containerLogMaxFiles: 5`
(250 MiB/container, ≈7 h) in `/var/lib/kubelet/config.yaml` is the change — it is node-wide and needs
a kubelet restart, and at ~35 containers that is a worst case of ~8.6 GiB of logs inside 99 GiB free.
Loki cost: `gzip -6` of the captured window shrinks 8.1 MB → 0.64 MB (**12.6x**), so 528 MB/day raw is
≈42 MB/day stored, ≈340 MB for the full 192 h inside the 8 GiB `logging/loki-data` PVC.
## Verify
```bash
# config accepted and bound
kubectl -n kube-system get ciliumgatewayclassconfig cilium # ACCEPTED True
kubectl get gatewayclass cilium -o jsonpath='{.spec.parametersRef}'
# the listener really carries the access log (host, because the container has no curl)
sudo curl -s --unix-socket /var/run/cilium/envoy/sockets/admin.sock \
http://localhost/config_dump | grep -o 'envoy.access_loggers.stdout' | head -1
# drive one request through the tunnel and read the line
curl -s -o /dev/null "https://siriusdevops.com/?probe=$(date +%s)"
sudo tail -1 /var/log/pods/kube-system_cilium-envoy-*/cilium-envoy/*.log
```
A request that matches a Cloudflare cache HIT never reaches the origin and therefore produces no line —
add a query string when proving logging.
Rotation happens at 10 MiB; when the container log rotates, `kubectl logs` and the glob above still
cover the previous files (`*.log.1`, ...).
## Parse
```bash
# one line -> flat record; client_ip is the real client for tunnelled traffic
sudo grep -h '"authority"' /var/log/pods/kube-system_cilium-envoy-*/cilium-envoy/*.log \
| sed 's/^.* stdout F //' \
| jq -c 'select(.gateway=="gateway-system/public")
| {ts:.start_time, host:.authority, method, path, code:.response_code,
client:(.client_ip//.peer), ua:.user_agent, ray:.cf_ray,
flags:.response_flags, ms:(.duration_ms|tonumber)}'
```
Example (client redacted to /24), real line from the proof request:
```json
{"authority":"siriusdevops.com","bytes_received":0,"bytes_sent":30179,"cf_ray":"a60f1bb759b3d96c-ATL",
"client_ip":"137.118.156.0","duration_ms":1,"gateway":"gateway-system/public","method":"GET",
"path":"/?f7probe=1795761278","peer":"10.10.0.1","protocol":"HTTP/1.1","response_code":200,
"response_flags":"-","start_time":"2026-11-27T06:34:38.642Z","upstream_host":"10.244.0.60:80",
"user_agent":"curl/8.23.0","x_forwarded_for":"137.118.156.0,10.10.0.1"}
```
## Operational notes
- **The change is an xDS push, not a restart.** `cilium-envoy` was not restarted and no listener was
rebound; the pod kept its original age/restart count through the change.
- **Nothing happens if the cilium-operator's gateway controller is not running.** It is the component
that reads `parametersRef` and rewrites the Gateway listeners. On 2026-11-27 it had failed to
initialise during an apiserver restart (`Required GatewayAPI resources are not found` — transient
RBAC lookup failure at 05:24Z) and stayed wedged, so a GatewayClassConfig change applied cleanly in
Git but produced no access log until `kubectl -n kube-system rollout restart deploy/cilium-operator`.
Always confirm `kubectl -n kube-system logs deploy/cilium-operator | grep Reconciling Gateway`.
- Rollback: revert the commit (or delete the `parametersRef`); the operator drops the access log on
the next Gateway reconcile. Nothing else in the chain depends on it.