6 Layers of Kubernetes Container Hardening That Matter

Kubernetes container hardening comes down to six deliberate settings: run every workload as non-root, block privilege escalation, drop unused Linux capabilities, apply the runtime seccomp profile, mount the root filesystem read-only, and enforce the whole set with Pod Security Admission labels. None of that is guaranteed out of the box. The Pod Security Standards profiles are cumulative and range from highly permissive to highly restrictive, and a namespace with no security label simply accepts whatever the pod spec asks for. The checklist below applies the same way on EKS, GKE and AKS.
Root by default is the problem
The starting posture is weaker than most teams assume: container processes run as the Linux root user by default, and privileged pods inherit every root capability on the host. The container runtime hands an ordinary container a fixed set of Linux capabilities — CAP_CHOWN, CAP_NET_BIND_SERVICE, CAP_SETUID and roughly a dozen more — which is already enough for an attacker who reaches a shell to escalate privileges or read sensitive information bound to the host, including Secrets and ConfigMaps. A privileged container is worse still, because it disables most of the isolation between the pod and its node. The first hardening decision is therefore not which tool to buy, but which of these defaults each workload genuinely needs.
What the standards enforce
Kubernetes ships the answer inside the API. The Pod Security Standards define three policy levels: Privileged, Baseline and Restricted. Baseline blocks the well-known privilege-escalation paths — hostNetwork, hostPID, hostIPC, hostPath volumes, privileged containers and unconfined seccomp — while still allowing the default pod configuration. The biggest jump is the top level: the Restricted profile requires every workload to run as a non-root user and to set allowPrivilegeEscalation to false, while also limiting which volume types pods may declare. That last level targets security-critical applications and lower-trust tenants, and it trades some compatibility for a much smaller attack surface.
Enforcement comes from Pod Security Admission, which reads namespace labels. Labels that are set once and never audited tend to drift, though — new namespaces ship unlabeled and catch-alls creep back in. For a field-tested review routine, read 3 Pod Security Admission gaps that leave pods unchecked before you trust the labels alone.
Six-layer hardening checklist
Work through the layers in order; each one removes a distinct escape route from the container.
- Non-root execution: set
runAsNonRoot: truein the pod securityContext, and give the image a non-root USER. - No privilege escalation: set
allowPrivilegeEscalation: falseon every container. Mind the trap: when allowPrivilegeEscalation is left undefined, the value defaults to true, so the omission itself is the vulnerability. - Minimal capabilities: drop all Linux capabilities, then re-add only the ones the binary needs, such as NET_BIND_SERVICE for ports below 1024.
- Seccomp: set
seccompProfile.type: RuntimeDefaultto filter system calls with the runtime profile. - Read-only filesystem: set
readOnlyRootFilesystem: trueand mount an emptyDir for the paths the app legitimately writes to. - Enforcement label: apply
pod-security.kubernetes.io/enforce: restrictedto the namespace so the settings stop being per-pod goodwill.
| Layer | Manifest key | What it removes |
|---|---|---|
| Non-root execution | runAsNonRoot: true | Root access inside and outside the container namespace |
| Privilege escalation | allowPrivilegeEscalation: false | setuid and setgid escape paths |
| Capabilities | capabilities.drop: ALL | Unused kernel privileges such as CAP_SYS_ADMIN |
| Seccomp | seccompProfile.type: RuntimeDefault | Unfiltered system calls against the host kernel |
| Filesystem | readOnlyRootFilesystem: true | Binary replacement by a compromised process |
| Admission | enforce: restricted label | Unreviewed unsafe specs reaching the cluster |
Rolling out enforcement safely
Pod Security Admission runs in three modes. In warn mode, violations only trigger a user-facing warning; in audit mode they add an annotation to the audit event; in enforce mode the pod is rejected outright. Use them as a sequence: label namespaces with warn and audit first, review a week of warnings from CI and developers, then flip to enforce. Expect one operational surprise: when a Deployment violates the enforced level, the Deployment object applies successfully while its pods are silently rejected — inspect the ReplicaSet conditions with kubectl before assuming the rollout is healthy. External guidance points the same direction: NIST SP 800-190, the Application Container Security Guide published in September 2017, frames container security as a set of concerns that each need their own countermeasures rather than a property you buy with the platform.
Hardened pods also change what an attacker can reach after a foothold. Pair this checklist with a periodic review of traffic rules — the method in 5 steps to audit Kubernetes NetworkPolicies in production closes the network side of the same door.
Trade-offs and edge cases
The layers are not free. Legacy images that assume root will crash under runAsNonRoot until the Dockerfile is fixed, and applications that write logs or temp files to the root filesystem need an explicit emptyDir mount before the read-only layer can ship. On AWS Fargate, capabilities can only be dropped, never added back, so capability-hungry sidecars need a different home. Windows containers are the clearest exception: readOnlyRootFilesystem cannot be set to true there because Windows requires write access to the registry and system processes inside the container. System workloads such as CNIs, storage drivers and logging agents legitimately need privileged access and belong in namespaces pinned to the Privileged level, not forced into Restricted. Finally, pod hardening complements but never replaces image supply-chain checks and secrets management — a non-root container running a tampered image is still compromised.