How do you design the Kubernetes audit policy so it is useful without being enormous?
IntermediateProductionKubernetes Security Posture
Answer
Log metadata for most things, request bodies for sensitive writes, and nothing for noisy read-only traffic.
apiVersion: audit.k8s.io/v1
kind: Policy
omitStages: ["RequestReceived"]
rules:
- level: None
users: ["system:kube-proxy"]
verbs: ["watch"]
- level: Metadata
resources: [{group: "", resources: ["secrets", "configmaps"]}]
- level: RequestResponse
verbs: ["create", "update", "patch", "delete"]
resources: [{group: "rbac.authorization.k8s.io"}]
- level: Request
verbs: ["create"]
resources: [{group: "", resources: ["pods/exec", "pods/attach", "pods/portforward"]}]
- level: Metadata
Never log Secrets at Request level, or the audit log becomes a secret store. On EKS the policy is fixed by AWS, so focus on shipping and alerting.
More on Kubernetes Security Posture
What is your security baseline for a new production EKS cluster?IntermediateDraw the layered security controls for workloads on Kubernetes.BeginnerHow do you assign Pod Security Admission levels across namespaces in production?BeginnerKyverno, OPA Gatekeeper or ValidatingAdmissionPolicy: how do you choose?IntermediateShow a ValidatingAdmissionPolicy that blocks containers without resource limits.AdvancedHow do you roll out default-deny NetworkPolicies in a running production cluster?Intermediate