homek8s/infrastructure/controlplane/audit/audit-policy.yaml
Lance Walters 2c7eab2b0b controlplane: audit — full bodies for secret writes, metadata only for list/watch
Measured on the live cluster: the 22.8 GB/day burst was driven by `list secrets`
(1.9 MiB per event — every secret in the namespace) and by helm-controller
rewriting its release blobs. Only list/watch give up their bodies now, so
"who rewrote this secret, and to what" stays reconstructable; steady state is
0.79 GB/day / ~420 events/min, i.e. ~6 days inside 48 x 100 MiB.

Re-verified after the change: create secret (server dry-run) records
requestObject.data; get/patch behave the same.
2026-11-27 00:28:24 -05:00

129 lines
4.9 KiB
YAML

apiVersion: audit.k8s.io/v1
kind: Policy
# One record per request instead of two (RequestReceived + ResponseComplete).
# The completion record carries responseStatus and is the forensic one.
omitStages:
- RequestReceived
# server-managed noise, never evidence
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.
rules:
# ---------------------------------------------------------------- 1. silence
# Liveness/version/discovery surface: polled by kubelet on every node every
# few seconds and carries no identity information.
- level: None
verbs: ["get"]
nonResourceURLs:
- /healthz
- /healthz/*
- /livez
- /livez/*
- /readyz
- /readyz/*
- /version
- /version/*
- /openapi/v2
- /openapi/v3
- /openapi/v3/*
- /metrics
# Leader election / heartbeat / event spam.
- level: None
resources:
- group: coordination.k8s.io
resources: ["leases"]
- group: ""
resources: ["events"]
- group: events.k8s.io
resources: ["events"]
# Informer watch subscriptions on high-volume, non-secret resources: recorded
# once at subscribe time and the payload never enters the record. secrets,
# RBAC and certificate objects are deliberately NOT here - a watch on those is
# itself worth a record (rules 4/6 keep it, minus the body).
- level: None
verbs: ["watch"]
resources:
- group: ""
resources: ["pods", "nodes", "services", "endpoints", "configmaps",
"persistentvolumes", "persistentvolumeclaims"]
- group: discovery.k8s.io
resources: ["endpointslices"]
- group: networking.k8s.io
resources: ["ingresses", "networkpolicies"]
- group: apiextensions.k8s.io
resources: ["customresourcedefinitions"]
- 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.
- level: Metadata
verbs: ["list", "watch"]
resources:
- group: ""
resources: ["secrets"]
# ------------------- 3. RBAC / certs enumeration: identity + request, no response
# list/watch of roles & bindings returns whole objects; the write paths are what
# matter and rule 6 keeps those at RequestResponse.
- level: Request
verbs: ["list", "watch"]
resources:
- group: rbac.authorization.k8s.io
resources: ["*"]
- group: certificates.k8s.io
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
- level: RequestResponse
resources:
- group: ""
resources:
- serviceaccounts/token
- pods/exec
- pods/attach
- pods/portforward
# every verb + subresource: create/update/patch/bind/escalate of a
# ClusterRoleBinding is a cluster takeover, not a config change
- group: rbac.authorization.k8s.io
resources: ["*"]
# CSR approval signs new client certs against the cluster CA
- group: certificates.k8s.io
resources: ["*"]
# acting as another identity
- level: RequestResponse
verbs: ["impersonate"]
# Metadata + request body only: kubelet/API proxies can return multi-MB bodies
# (metrics, pprof, logs) and the response is the volume, not the evidence.
- level: Request
resources:
- group: ""
resources: ["pods/proxy", "nodes/proxy", "nodes/log", "nodes/metrics",
"nodes/spec", "nodes/stats"]
# ------------------------------------------------------------------ 6. default
# who / what / when / from where / status code - no bodies.
- level: Metadata