Merge pull request 'audit(policy): drop bodies for secret reads, keep them for writes' (#60) from t_d1275a3a-secret-read-metadata into master

This commit is contained in:
sirius 2026-11-27 05:49:32 +00:00
commit 9f07d3330c
2 changed files with 60 additions and 33 deletions

View file

@ -46,13 +46,13 @@ 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 | | 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 | | 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 | | 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` **get, list, watch** | reads: a corpus dump (`list`) or one live credential (`get`); objectRef is the whole signal, see below |
| 5 | Request | `rbac.authorization.k8s.io/*`, `certificates.k8s.io/*` **list, watch** | whole-object listings; the write paths stay at rule 6 | | 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` **create/update/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. For secrets this is the **write** path only — the body is the tampering evidence |
| 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 | | 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 | | 8 | Metadata | everything else | who / what / when / from where / status code |
### Why `list`/`watch` on secrets is Metadata and not RequestResponse ### Why secret reads are Metadata and secret writes are not
The first cut logged full bodies for every secret verb. During a flux reconcile storm (which happens 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 after every apiserver restart and every full reconcile) that measured **22.8 GB/day**, i.e. it would
@ -66,19 +66,37 @@ have rotated the entire retention window every couple of hours and buried the us
A `list` body is a corpus dump scaled by how many secrets the cluster holds — it grows with the 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. 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 That verb pair (`list`, `watch`) was therefore the first to go Metadata.
request/response bodies**, including writes, so "who rewrote this secret and to what" is
reconstructable. `get` was the second half of the same problem, and it was not a volume issue. Measured on the live log
2026-11-27: of **3,527** secret events, **1,606** were `get` and **2,574** carried `.data` in
`responseObject` — the audit log was a second plaintext copy of every secret that had been read
(`kubernetes-admin`, `kustomize-controller`, `source-controller`, `sirius-growth:portal`, …). That copy
is root-only on the control-plane node, so reading it produces **no audit event**, which inverts the
purpose of the log. A `get` is fully described by `objectRef` + `user` + `sourceIPs` + `responseStatus`.
Secret **writes** are the opposite case and keep full `request`/`response` bodies: an attacker filling
a secret with their own SSH key or rewriting a `dockerconfigjson` is exactly the record you want, and a
write body is evidence rather than a credential that was already in the cluster. Verbs are enumerated
(`create/update/patch/delete/deletecollection`) so an unrecognised verb falls through to Metadata
instead of silently acquiring a body.
Steady state with this split is **0.79 GB/day, ~420 events/min** (secret traffic ~0.25 GB/day); the 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. storm burst is bounded and absorbed by rotation. Retention numbers below account for it.
## Sensitivity: the audit log is secret material ## Sensitivity: the audit log still holds secret material
At `RequestResponse`, a `get secret` audit event contains the secret's `data` in `responseObject`. Secret **reads** are Metadata since 2026-11-27, so a `get`/`list`/`watch` record carries no `data`.
`/var/log/kubernetes/audit/` is therefore `0700 root` and the log `0600 root`, on the control-plane Secret **writes** still do: at `RequestResponse` a `create`/`update`/`patch` record carries the object in
node only. Treat any future log shipper as a **secrets pipeline**: no unauthenticated sink, no `requestObject` (and the server's answer in `responseObject`). `/var/log/kubernetes/audit/` therefore
plaintext off-node copy, and its own encryption/retention story. Nothing ships this log today. stays `0700 root` with the log `0600 root`, on the control-plane node only.
Files written **before** that date also held every secret that had been *read*; they were deleted as part
of the change rather than left to age out (see "Purge" below). Treat any log shipper that touches this
path as a **secrets pipeline**: no unauthenticated sink, no plaintext off-node copy, and its own
encryption/retention story. The Loki/Alloy stack in `infrastructure/logging/` does **not** mount this
directory today (`/var/log/pods` + `/var/log/journal` only) — keep it that way unless the pipeline has an
encryption story.
## Verify it is live ## Verify it is live

View file

@ -7,14 +7,20 @@ omitStages:
# server-managed noise, never evidence # server-managed noise, never evidence
omitManagedFields: true omitManagedFields: true
# Volume note (measured 2026-11-27 on this cluster): full bodies for EVERY secret # 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 # 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 # 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 # reconcile storm.
# 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, # Read/write split: secret READS (get/list/watch) are Metadata - the body is a
# ~0.25 GB/day of which is secret traffic; a reconcile storm adds a bounded burst # credential and objectRef already answers who/which/from where. Secret WRITES
# that rotation absorbs. # (create/update/patch/delete) keep full request/response - the body there is the
# evidence (an attacker planting their own key), not a credential to protect.
# Measured before the split: 2,574 of 3,527 secret events carried `.data` in
# responseObject, i.e. the log was a second copy of every secret that had been read.
# Everything else - pods/exec, tokenreviews, RBAC writes, proxies - is unchanged.
# 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: rules:
# ---------------------------------------------------------------- 1. silence # ---------------------------------------------------------------- 1. silence
# Liveness/version/discovery surface: polled by kubelet on every node every # Liveness/version/discovery surface: polled by kubelet on every node every
@ -64,14 +70,26 @@ rules:
- group: storage.k8s.io - group: storage.k8s.io
resources: ["storageclasses"] resources: ["storageclasses"]
# ---------------------------- 2. secrets: bulk enumeration (corpus dumps only) # ---------------------- 4a. secrets: READS (corpus + single object) = Metadata
# A list returns EVERY secret in the namespace: measured 1.9 MiB per event, and a # `list` returns EVERY secret in the namespace (measured 1.9 MiB per event, dozens
# flux reconcile storm issues dozens. Identity + verb + namespace is the signal # per flux reconcile storm); `get` returns one object whose responseObject.data is
# (mass enumeration); the body is just the corpus. Writes are NOT here - they stay # the live credential. Neither body is evidence: objectRef + user + sourceIPs +
# at RequestResponse in rule 4, because "who rewrote this secret and to what" is # responseStatus fully answers "who read which secret, when, and did it succeed".
# evidence. Steady state with this split: ~0.25 GB/day of secret traffic. # Keeping the body writes a second plaintext copy of every secret into a root-only
# file that no audit event covers (root can read the log without touching the API).
- level: Metadata - level: Metadata
verbs: ["list", "watch"] verbs: ["get", "list", "watch"]
resources:
- group: ""
resources: ["secrets"]
# -------------------- 4b. secrets: WRITES = full request/response bodies
# The tampering verbs. Here the body IS the evidence: who planted which key, who
# rewrote the forgejo-pull dockerconfigjson, who deleted the SOPS age key secret.
# Verbs are enumerated so an unknown future verb falls through to Metadata (rule 6)
# rather than silently acquiring a body.
- level: RequestResponse
verbs: ["create", "update", "patch", "delete", "deletecollection"]
resources: resources:
- group: "" - group: ""
resources: ["secrets"] resources: ["secrets"]
@ -87,15 +105,6 @@ rules:
- group: certificates.k8s.io - group: certificates.k8s.io
resources: ["*"] resources: ["*"]
# --------------------- 4. secrets: single-object read/write, full bodies
# THIS FILE IS SECRET MATERIAL from here on: get/read responses and
# create/patch requests carry live secret values. 0600 root, never shipped
# off-node over an unauthenticated path.
- level: RequestResponse
resources:
- group: ""
resources: ["secrets"]
# -------------------------------- 5. everything privileged-but-authorized # -------------------------------- 5. everything privileged-but-authorized
- level: RequestResponse - level: RequestResponse
resources: resources: