Hardening Kubernetes Pods Against Privilege Escalation and Container Escapes
Scenario Prompt:
“A security audit reveals that several developer deployments run as root, mount the host Docker socket, and lack securityContext restrictions. You are tasked with establishing an enterprise Pod Security Standard. What controls do you implement?”
Substantive Technical Concepts to Hit:
Pod Security Standards (Restricted Profile)
Enforce the Kubernetes Restricted profile: runAsNonRoot: true, allowPrivilegeEscalation: false, readOnlyRootFilesystem: true, and drop all Linux capabilities.
Eliminating Docker Socket Mounts
Mounting /var/run/docker.sock allows root-equivalent host access. Replace it with unprivileged user-space build tools like Kaniko or Buildah for in-cluster builds.
Automated Policy Enforcement via Admission Webhooks
Deploy Kyverno or OPA Gatekeeper to validate and reject any pod specification submitted to the API server that violates the securityContext baseline.
Seccomp & AppArmor Profiles
Enable the RuntimeDefault seccomp profile to restrict the set of Linux system calls available to containers by default.
- Can we enforce policies in audit/warning mode first before moving to hard blocking mode in production?
- Do any legacy workloads genuinely require writing to local disk (which can be mitigated via emptyDir memory mounts)?
- Are developers currently relying on root access inside development clusters?