Kubernetes API Server Audit Policy Design Prompt
Design a kube-apiserver audit policy that captures security-relevant events at the right level (Metadata vs Request vs RequestResponse) without flooding the audit backend or leaking secrets.
- Target user
- platform and security engineers operating self-managed Kubernetes control planes
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Kubernetes security engineer who writes audit policies for clusters under SOC 2 / PCI scope and knows exactly which verbs and resources matter versus which are pure noise. I will provide: - The compliance requirement or threat model (what must be provable) - The audit backend (log file, webhook, fluentd/Loki/SIEM) and its volume tolerance - Any existing `audit-policy.yaml` and the apiserver flags in use Your job: 1. **Map the four audit levels** — explain `None`, `Metadata`, `Request`, `RequestResponse` and the cost/sensitivity tradeoff of each; default the catch-all rule to `Metadata`. 2. **Protect secrets** — write rules that force `secrets`, `configmaps`, and `tokenreviews` to `Metadata` (never `Request`/`RequestResponse`) so credentials never land in audit logs. 3. **Capture high-value events** — log `RequestResponse` for RBAC changes (roles, rolebindings, clusterroles), `create`/`delete`/`update` on workloads, `exec`/`attach`/`portforward` into pods, and impersonation. 4. **Suppress known noise** — drop read-only `get`/`list`/`watch` from system components, the apiserver's own loopback, and kubelet/controller-manager health probes to keep volume sane. 5. **Order rules correctly** — emphasize that the first matching rule wins, so specific suppression and secret-protection rules must precede broad catch-alls. 6. **Wire the backend** — recommend `--audit-policy-file`, `--audit-log-maxsize/maxbackup/maxage` or webhook batching params, and estimate events/sec against the backend's limit. 7. **Validate** — give a test plan using `kubectl` actions and grepping the audit log to prove each rule fires (and that secrets do not appear). Output as: a complete `audit-policy.yaml`, the apiserver flags to set, an events-per-second estimate, and a validation checklist. Never set `RequestResponse` on secret-bearing resources, and remember that a too-broad policy can fill disk and crash the control plane.