Audit Mode — log policy violations without blocking.
1apiVersion: v12kind: Namespace3metadata:4 name: production5 labels:6 pod-security.kubernetes.io/audit: restricted7 pod-security.kubernetes.io/audit-version: latest8 pod-security.kubernetes.io/enforce: baseline9 pod-security.kubernetes.io/enforce-version: latest10 pod-security.kubernetes.io/warn: restricted11 pod-security.kubernetes.io/warn-version: latest12---13# Non-compliant Pod (will be logged but allowed)14apiVersion: v115kind: Pod16metadata:17 name: audit-pod18 namespace: production19spec:20 containers:21 - name: app22 image: nginx:latest23 # Missing restricted security context
1# Check audit configuration2kubectl get namespace production -o yaml | grep pod-security34# View audit events5kubectl get events --field-selector reason=FailedCreate --sort-by=.lastTimestamp67# Check audit annotations8kubectl get pod audit-pod -o jsonpath='{.metadata.annotations}' | jq910# View warnings11kubectl apply -f audit-pod.yaml 2>&1 | grep Warning1213# Check audit logs14kubectl get events -n production --sort-by=.lastTimestamp | grep -i "audit\|warn"1516# Verify audit policy17kubectl get namespace production -o json | jq '.metadata.labels | to_entries[] | select(.key | contains("audit"))'
Audit Behavior:
Use cases: