diff --git a/docs/kube-apiserver-audit-logging.md b/docs/kube-apiserver-audit-logging.md index becdb33..cddc258 100644 --- a/docs/kube-apiserver-audit-logging.md +++ b/docs/kube-apiserver-audit-logging.md @@ -46,32 +46,27 @@ 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** | corpus dumps only, see below | +| 4 | Metadata | `secrets` **list, watch, update** | measured volume control, 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` (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 | +| 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 | | 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`/`watch` on secrets is Metadata and not RequestResponse +### Why `list`/`update` on secrets is Metadata and not RequestResponse -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: +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: -| verb | events/189 s | avg event | burst rate | +| verb | events/189 s | avg event | share | |---|---|---|---| | `list secrets` | 16 | **1.9 MiB** (every secret in the namespace) | 14 GB/day | -| `update secrets` | 90 | 170 KiB (flux `sh.helm.release.v1.*` + prometheus-operator `tls-assets`) | 7 GB/day | +| `update secrets` | 90 | 170 KiB (flux `sh.helm.release.v1.*` blobs + prometheus-operator `tls-assets`) | 7 GB/day | | `get secrets` | 151 | 6.8 KiB | 1 GB/day | -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. +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**. ## Sensitivity: the audit log is secret material @@ -109,8 +104,7 @@ pods/exec kubernetes-admin get forgejo//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. Write-path fidelity re-checked -after the final policy revision: `create secret` (server dry-run) records `requestObject.data`. +what makes an interactive session visible while it is still running. ## Drift: a `kubeadm upgrade` silently resets this @@ -147,8 +141,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, 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. +`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. ## Not covered here diff --git a/infrastructure/controlplane/audit/audit-policy.yaml b/infrastructure/controlplane/audit/audit-policy.yaml index ccb0329..aea8e77 100644 --- a/infrastructure/controlplane/audit/audit-policy.yaml +++ b/infrastructure/controlplane/audit/audit-policy.yaml @@ -8,13 +8,12 @@ omitStages: omitManagedFields: true # Volume note (measured 2026-11-27 on this cluster): full bodies for EVERY 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. +# 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". rules: # ---------------------------------------------------------------- 1. silence # Liveness/version/discovery surface: polled by kubelet on every node every @@ -64,14 +63,12 @@ rules: - group: storage.k8s.io resources: ["storageclasses"] - # ---------------------------- 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. + # ------------------------------- 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. - level: Metadata - verbs: ["list", "watch"] + verbs: ["list", "watch", "update"] resources: - group: "" resources: ["secrets"] @@ -92,6 +89,7 @@ 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"]