Interview Prep/DevSecOps/Kubernetes admission control and Pod Security

Pods pass admission, but someone exec'd in with `kubectl debug` and an ephemeral container that runs privileged

AdvancedTroubleshootingKubernetes admission control and Pod Security
Answer

Likely causes → Policies check containers and initContainers only; ephemeral containers are added via the pods/ephemeralcontainers subresource, which the webhook does not match.

Diagnose →

kubectl get pod api-7d9 -o jsonpath='{.spec.ephemeralContainers}' | jq
kubectl get clusterpolicy -o yaml | grep -n ephemeral

Fix → Extend policies to ephemeralContainers and include the subresource in rule matches (Kyverno pod-security policies cover it; Gatekeeper needs pods/ephemeralcontainers operations). PSA already evaluates ephemeral containers.

Prevent → RBAC: restrict pods/ephemeralcontainers and pods/exec to on-call roles with audit logging.

All DevSecOps questions Roadmap: Policy as code

More on Kubernetes admission control and Pod Security