Merge pull request 'controlplane: audit — full bodies for secret writes, metadata only for list/watch' (#49) from controlplane/apiserver-audit into master

This commit is contained in:
sirius 2026-11-27 05:28:27 +00:00
commit f2c6de0ccb
2 changed files with 34 additions and 26 deletions

View file

@ -46,27 +46,32 @@ one carrying `responseStatus`). `omitManagedFields: true` drops server-managed f
| 1 | None | `/healthz* /livez* /readyz* /version /openapi* /metrics`, GET | kubelet polls these every few seconds per node |
| 2 | None | `coordination.k8s.io/leases`, `events` | leader election / heartbeat / event spam |
| 3 | None | `watch` on pods, nodes, services, endpoints, configmaps, PV/PVC, endpointslices, ingresses, netpols, CRDs, storageclasses | a watch is recorded once at subscribe time and its payload never enters the record. **secrets/RBAC/certs are deliberately not listed** — a watch on those is itself worth a record |
| 4 | Metadata | `secrets` **list, watch, update** | measured volume control, see below |
| 4 | Metadata | `secrets` **list, watch** | corpus dumps only, see below |
| 5 | Request | `rbac.authorization.k8s.io/*`, `certificates.k8s.io/*` **list, watch** | whole-object listings; the write paths stay at rule 6 |
| 6 | **RequestResponse** | `secrets` get/create/patch/delete/deletecollection, `serviceaccounts/token`, `pods/exec`, `pods/attach`, `pods/portforward`, `rbac.authorization.k8s.io/*`, `certificates.k8s.io/*`, verb `impersonate` | the privileged-but-authorized calls: full request+response bodies |
| 6 | **RequestResponse** | `secrets` (every verb except list/watch), `serviceaccounts/token`, `pods/exec`, `pods/attach`, `pods/portforward`, `rbac.authorization.k8s.io/*`, `certificates.k8s.io/*`, verb `impersonate` | the privileged-but-authorized calls: full request+response bodies |
| 7 | Request | `pods/proxy`, `nodes/proxy`, `nodes/log`, `nodes/metrics`, `nodes/spec`, `nodes/stats` | who proxied to which kubelet; the multi-MB response body is volume, not evidence |
| 8 | Metadata | everything else | who / what / when / from where / status code |
### Why `list`/`update` on secrets is Metadata and not RequestResponse
### Why `list`/`watch` on secrets is Metadata and not RequestResponse
First cut was `RequestResponse` for every secret verb. Measured on this cluster it cost
**22.8 GB/day** and would have rotated the whole retention window every ~2 hours:
The first cut logged full bodies for every secret verb. During a flux reconcile storm (which happens
after every apiserver restart and every full reconcile) that measured **22.8 GB/day**, i.e. it would
have rotated the entire retention window every couple of hours and buried the useful records:
| verb | events/189 s | avg event | share |
| verb | events/189 s | avg event | burst rate |
|---|---|---|---|
| `list secrets` | 16 | **1.9 MiB** (every secret in the namespace) | 14 GB/day |
| `update secrets` | 90 | 170 KiB (flux `sh.helm.release.v1.*` blobs + prometheus-operator `tls-assets`) | 7 GB/day |
| `update secrets` | 90 | 170 KiB (flux `sh.helm.release.v1.*` + prometheus-operator `tls-assets`) | 7 GB/day |
| `get secrets` | 151 | 6.8 KiB | 1 GB/day |
Those two verbs are dominated by automation rewriting its own storage; the body is a copy of what
etcd already holds. They now record identity + namespace/name + status (Metadata), which is the
part that answers "who touched this secret". The single-object read path — the actual finding —
stays at `RequestResponse`. Total after the change: **~2.5 GB/day, ~1330 events/min**.
A `list` body is a corpus dump scaled by how many secrets the cluster holds — it grows with the
cluster, and the security signal ("who enumerated every secret") is fully captured by the metadata.
That verb pair (`list`, `watch`) is therefore Metadata. **Every other secret verb keeps full
request/response bodies**, including writes, so "who rewrote this secret and to what" is
reconstructable.
Steady state with this split is **0.79 GB/day, ~420 events/min** (secret traffic ~0.25 GB/day); the
storm burst is bounded and absorbed by rotation. Retention numbers below account for it.
## Sensitivity: the audit log is secret material
@ -104,7 +109,8 @@ pods/exec kubernetes-admin get forgejo/<pod>/exec code 101 full comma
```
`pods/exec` produces two records per session (`ResponseStarted`, `ResponseComplete`) — the first is
what makes an interactive session visible while it is still running.
what makes an interactive session visible while it is still running. Write-path fidelity re-checked
after the final policy revision: `create secret` (server dry-run) records `requestObject.data`.
## Drift: a `kubeadm upgrade` silently resets this
@ -141,8 +147,8 @@ file makes it remove the static pod and take the API down.
## Disk headroom
`siriussec` had 102 GiB free of 214 GiB when this landed. Retention is bounded at
`48 × 100 MiB = 4.8 GiB` raw before compression (realistic on-disk after gzip is a few hundred MB,
since most records are small metadata JSON), so the ≥32 GiB floor is never at risk from audit.
`48 × 100 MiB = 4.8 GiB` raw before compression, which at the measured 0.79 GB/day is **~6 days of
history**; realistic on-disk after gzip is several hundred MB. The ≥32 GiB floor is never at risk.
## Not covered here

View file

@ -8,12 +8,13 @@ omitStages:
omitManagedFields: true
# Volume note (measured 2026-11-27 on this cluster): full bodies for EVERY secret
# verb cost 22.8 GB/day, because (a) flux helm-controller lists all secrets
# (1.9 MiB per list) and (b) it rewrites sh.helm.release.v1.* release blobs
# (~170 KiB each) every reconcile, plus prometheus-operator rewrites its
# tls-assets secrets. Rule 4 therefore keeps identity+object for those two
# verbs and reserves bodies for the single-object paths (rule 5) that actually
# answer "who read / who wrote this one secret".
# verb peaked at 22.8 GB/day, driven almost entirely by `list secrets` (1.9 MiB per
# event: flux helm-controller enumerating every secret on each reconcile) during a
# reconcile storm. Only rule 2 gives up bodies, and only for list/watch, where the
# body is a corpus dump rather than evidence. Everything else - including secret
# writes - keeps full request/response. Measured steady state: ~2.2 GB/day total,
# ~0.25 GB/day of which is secret traffic; a reconcile storm adds a bounded burst
# that rotation absorbs.
rules:
# ---------------------------------------------------------------- 1. silence
# Liveness/version/discovery surface: polled by kubelet on every node every
@ -63,12 +64,14 @@ rules:
- group: storage.k8s.io
resources: ["storageclasses"]
# ------------------------------- 2. secrets: bulk enumeration / automation rewrite
# user + verb + namespace/name + responseStatus, no bodies. list secrets is
# 1.9 MiB of every secret in the namespace; update is the flux helm release
# churn. Losing the body here loses only a copy of what etcd already holds.
# ---------------------------- 2. secrets: bulk enumeration (corpus dumps only)
# A list returns EVERY secret in the namespace: measured 1.9 MiB per event, and a
# flux reconcile storm issues dozens. Identity + verb + namespace is the signal
# (mass enumeration); the body is just the corpus. Writes are NOT here - they stay
# at RequestResponse in rule 4, because "who rewrote this secret and to what" is
# evidence. Steady state with this split: ~0.25 GB/day of secret traffic.
- level: Metadata
verbs: ["list", "watch", "update"]
verbs: ["list", "watch"]
resources:
- group: ""
resources: ["secrets"]
@ -89,7 +92,6 @@ rules:
# create/patch requests carry live secret values. 0600 root, never shipped
# off-node over an unauthenticated path.
- level: RequestResponse
verbs: ["get", "create", "patch", "delete", "deletecollection"]
resources:
- group: ""
resources: ["secrets"]