Container security is a discipline that hardens container images, runtime environments, and orchestration configurations to eliminate attack surfaces across every stage of the software delivery pipeline.
The CIS Docker Benchmark and CIS Kubernetes Benchmark frame the control surface across both runtimes, and the joint CISA/NSA Kubernetes Hardening Guide identifies misconfiguration as the dominant root cause of production cluster compromise. Five layers carry the controls that matter: supply chain (image signing, software bill of materials attestation, admission gating), runtime (Pod Security Standards, seccomp, AppArmor), network (Kubernetes NetworkPolicy, service mesh mTLS), workload identity, and secrets management. Skipping any one layer leaves a class of attack untreated regardless of how well the others are tuned.
Why Container Security Fails at Runtime
Container security fails at runtime because containers concentrate the attack surface that traditional VMs spread across separate hosts. Three vectors carry most production incidents: image provenance (what packages and binaries the image actually contains), runtime privilege (what syscalls, capabilities, and host paths the container can reach), and orchestration misconfiguration (what the cluster permits by default). The CISA/NSA Kubernetes Hardening Guide names misconfiguration as the dominant root cause across the deployments its authors have triaged, and the pattern holds in commercial incident-response data as well.
Defenders who treat container hardening as image scanning alone miss the orchestration layer entirely. A scanned image still runs as root if the pod spec says so. A signed image still mounts the host Docker socket if no admission control blocks it. The five-layer model below is what runtime protection actually requires in production:
- Supply chain. Image signing, SBOM generation, and admission-time signature verification gate what reaches the cluster.
- Runtime. Pod Security Standards, seccomp profiles, AppArmor, and dropped Linux capabilities bound what a running container can do.
- Network. Kubernetes NetworkPolicy and service mesh mTLS replace the default pod-to-pod allow with explicit least-privilege flows.
- Identity. Federated workload identity removes static cloud credentials from images and environment variables.
- Secrets. External secret stores and namespace-scoped role-based access control (RBAC) keep sensitive material out of etcd and out of default service accounts.
The data-layer controls that complement workload hardening at the secrets and storage boundary are covered in Difference Between Encryption and Tokenization. The cloud-posture layer that detects misconfigured Kubernetes control planes from outside the cluster sits in Best CSPM Tools for AWS.
Supply-Chain Hardening: Image Signing and SBOM Attestation
Container security at the supply-chain layer rests on two artifacts: a cryptographic signature that proves an image came from a trusted build system, and a software bill of materials (SBOM) that enumerates every package and dependency baked into that image. Image signing with Cosign (Sigstore) attaches a signature to the OCI artifact in the registry, indexed to the image digest rather than the mutable tag. The SBOM, emitted in SPDX or CycloneDX format, lets the security team triage a fresh CVE against every running image in minutes instead of rescanning the registry. The two artifacts together close the supply-chain gap that OWASP and the OWASP Docker Security Cheat Sheet identify as the most common entry point for compromised dependencies.

- Build the image from a trusted minimal base. CIS Docker Benchmark control 4.1 requires a verified base image; control 4.2 forbids unnecessary packages. Distroless or Alpine bases shrink the attack surface to the application binary plus its direct runtime.
- Generate an SBOM during the build. Syft, Trivy, or the docker buildx attest flag emit an SPDX or CycloneDX document and attach it to the image as an OCI referrer.
- Sign the image with Cosign. The CI system signs the image digest using a keyless OIDC identity or a stored key, and pushes the signature to the same registry path.
- Verify on admission. The cluster admission controller checks the signature against the trusted issuer before allowing the pod to schedule.
- Re-evaluate the SBOM on each new CVE. The SBOM inventory is queried against vulnerability feeds, and affected images are rebuilt and resigned rather than patched in place.
Signature attestation alone does not block runtime exploits. It gates the supply-chain entry point, and admission gating is the enforcement mechanism that turns the gate into a wall. Without verification at scheduling time, a developer with kubectl access can still pull an unsigned image directly into the cluster.
Admission Controllers as the Signing Enforcement Gate
The pattern most production clusters land on is OPA Gatekeeper or Kyverno running as a validating webhook. The policy is stored in version control alongside the application manifests, which means policy violations surface in CI before merge, not at runtime. A pod spec that references an unsigned image digest, or an image from a registry not on the allow list, is rejected before the kubelet ever sees it. This policy-as-code pattern is what supply-chain security looks like once it is operational rather than aspirational, and it is the control NIST SP 800-53 r5 SA-10 (developer configuration management) maps to at the cluster boundary.
Runtime Hardening: Pod Security Standards, Seccomp, and AppArmor
Container hardening at the runtime layer is enforced by three Linux mechanisms working together: Pod Security Standards (PSS), seccomp filters, and AppArmor profiles. PSS defines three enforcement levels (Privileged, Baseline, Restricted), and the Restricted profile is the CIS Kubernetes Benchmark recommended baseline for production workloads. PSS replaced PodSecurityPolicy (PSP) in Kubernetes 1.25 and is enforced natively through the Pod Security admission webhook without a separate controller. Operators migrating off PSP cannot rely on a shim; the API was removed, and any pod spec that sets runAsRoot, hostNetwork, or hostPID has to be audited against the Restricted profile before the upgrade.
The syscall-filter layer, configured per pod, blocks the kernel calls a container process can issue. The RuntimeDefault profile blocks 44 high-risk syscalls and is the CIS Kubernetes Benchmark v1.8 Level 1 control; the Localhost profile lets operators define a custom allowlist down to the exact calls the application requires. AppArmor enforces mandatory access control at the Linux security module layer, restricting filesystem paths, network operations, and capability use independently of the syscall filter. The three controls overlap deliberately: a kernel-call escape that targets an unfiltered path is still bounded by the AppArmor profile, and both sit underneath the PSS-defined pod boundary. Runtime protection at this depth is what the CISA/NSA Kubernetes Hardening Guide treats as table stakes for any cluster handling regulated workloads.
| Control | What it bounds | Enforcement point | CIS Benchmark mapping |
|---|---|---|---|
| Pod Security Standards | Pod-spec privilege (root, host namespaces, volume types) | Kubernetes API server admission | CIS Kubernetes 5.2 (Restricted profile baseline) |
| seccomp | Linux syscalls available to the container process | Kernel syscall filter via container runtime | CIS Kubernetes 5.7.2 (RuntimeDefault required) |
| AppArmor | Filesystem paths, network ops, capability use | Linux Security Module on the node | CIS Kubernetes 5.7.3 (profile loaded per workload) |
Dropping Linux Capabilities
Containers inherit a default capability set that includes NET_RAW, SYS_CHROOT, and others that are rarely needed and frequently exploited. The CIS Docker Benchmark recommends dropping all capabilities and adding back only those the process requires. In a Kubernetes pod spec the pattern is securityContext.capabilities.drop set to ALL and capabilities.add set to the minimum list, for example NET_BIND_SERVICE for a web server that needs to bind port 80. The least-privilege capability set, combined with a Restricted PSS profile and a RuntimeDefault profile, removes most of the privilege-escalation paths attackers rely on after an initial code-execution foothold.
Network Isolation: Kubernetes NetworkPolicy and Service Mesh mTLS
Kubernetes network policy is the layer-3 and layer-4 enforcement primitive that turns the default pod-to-pod allow into an explicit allow-list, and it is the first piece of Kubernetes hardening most clusters get wrong. Without a NetworkPolicy resource in place, every pod can reach every other pod on any port, which means a single compromised workload has unrestricted lateral reach across the namespace. A default-deny-all network policy combined with explicit ingress and egress selectors implements the least-privilege model at the pod boundary. The selectors use pod labels and namespace labels rather than IPs, so the policy follows the workload through reschedules and rollouts.
NetworkPolicy enforcement requires a CNI plugin that supports it (Calico, Cilium, Weave); not every CNI implements the policy spec. Service mesh mTLS (Istio, Linkerd) sits one layer up: it enforces mutual certificate authentication between workload identity pairs at layer 7, so a pod cannot impersonate another pod even if it bypasses layer-3 controls via a compromised CNI. The mTLS layer depends on the TLS certificate infrastructure covered in Role of TLS/SSL in Data Protection, and the architectural microsegmentation model the network policy implements at the pod boundary is treated at the network design level in Implement Zero Trust Network Architecture.
- Default-deny ingress and egress per namespace. A baseline NetworkPolicy in every workload namespace that selects all pods and permits no traffic, so subsequent policies are additive.
- Explicit allow for DNS egress. A second policy that permits UDP port 53 to kube-dns; without this, every pod loses name resolution and breaks silently.
- Tier-to-tier allow rules with pod and namespace selectors. Web tier to API tier on the API port only, API tier to database tier on the database port only, no other inter-tier traffic.
- Egress allow-list to external services. Egress rules that name the specific external destinations workloads need (cloud APIs, payment processors), with everything else denied at the cluster boundary.
Workload Identity and Secrets Management
Container security at the identity layer fails most often because static cloud credentials end up baked into container images or environment variables. AWS access keys in a Dockerfile, GCP service-account JSON files mounted as a secret volume, and Azure client secrets in a ConfigMap are the three patterns that show up in nearly every credential-leak postmortem. Federated bindings replace them: IRSA (IAM Roles for Service Accounts) on EKS, GKE federation, and the Azure equivalent each bind a Kubernetes service account to a cloud IAM role through OIDC token exchange. The pod receives a short-lived token signed by the cluster OIDC issuer, the cloud IAM service exchanges it for a session credential, and the credential expires within an hour. No long-lived secret ever sits at rest on the node.
Kubernetes Secrets are base64-encoded by default, which is encoding rather than encryption; the prerequisite for any production secrets posture is etcd encryption at rest. The External Secrets Operator (ESO) extends that baseline by syncing material from HashiCorp Vault, AWS Secrets Manager, or GCP Secret Manager into Kubernetes Secrets without storing the source value in etcd permanently. RBAC closes the loop: the CIS Kubernetes Benchmark requires namespace-scoped service accounts with only the minimum secret access each workload needs, because many distributions ship default service accounts with cluster-wide secret read permission. The supply-chain security work and the secrets posture are complementary; the SaaS-layer credential and SSPM controls that sit above the workload identity boundary are covered in How To Secure SaaS Applications At Scale, and CSPM detection for misconfigured RBAC and exposed secrets on AWS sits in Best CSPM Tools for AWS.
- Static cloud keys in container images
- Replace with federated bindings: IRSA on EKS, GKE OIDC federation, or the Azure equivalent. The pod receives a short-lived OIDC token rather than a long-lived secret.
- Mounted .env files with secrets in plaintext
- Replace with External Secrets Operator that syncs from Vault or a cloud secret manager and rotates the in-cluster Secret on a schedule.
- Default service account with cluster-wide secret read
- Replace with namespace-scoped service accounts and least-privilege RBAC roles that grant only the secrets the workload requires; disable automountServiceAccountToken on pods that make no API calls.
- Secrets stored in unencrypted etcd
- Enable etcd encryption at rest with a KMS provider, audit the encryption-config manifest, and rotate the data-encryption key on a documented cadence.
CIS Benchmark Hardening Checklist: Docker and Kubernetes
Docker hardening and Kubernetes hardening converge in the CIS Benchmark control families, which synthesize the five-layer model into an actionable checklist with explicit IDs. Prioritize Level 1 controls first; they are automated and low-disruption. Level 2 controls require tuning and are appropriate once Level 1 is fully enforced. The benchmarks are the implementation baseline; NIST SP 800-53 Rev 5 controls SA-10, CM-7, SC-7, and IA-9 map to the same hardening surface, and the MITRE ATT&CK Containers Matrix names the specific techniques each control mitigates (T1610 Deploy Container, T1611 Escape to Host, T1552.007 Container API).
- CIS Docker 2.x (daemon). Restrict the Docker daemon to a non-root user where supported, enable user namespace remapping, and disable inter-container communication on bridges that do not need it.
- CIS Docker 4.1 and 4.2 (image). Use trusted minimal base images and avoid installing unnecessary packages; the smaller the image, the smaller the attack surface.
- CIS Docker 5.x (runtime). Drop all Linux capabilities by default and add only what each container needs; mount the filesystem read-only where the workload tolerates it.
- CIS Kubernetes 1.x (API server). Disable anonymous auth, require TLS on every endpoint, and enable audit logging that ships off-cluster.
- CIS Kubernetes 2.x (etcd). Enforce client and peer TLS, encrypt secrets at rest, and restrict etcd access to the API server identity.
- CIS Kubernetes 4.x (kubelet). Disable read-only port 10255, require client certificate auth, and rotate kubelet certificates automatically.
- CIS Kubernetes 5.2 (PSS) and 5.7 (kernel filters). Enforce the Restricted profile on production namespaces; require RuntimeDefault and a loaded AppArmor profile per workload.
- CIS Kubernetes 5.3 (network policy) and 5.1 (RBAC). Default-deny network policy in every workload namespace; namespace-scoped service accounts with least-privilege RBAC bindings and no cluster-admin grants outside the platform team.
Further reading
- Difference Between Encryption and Tokenization (hub guide on the data-layer controls that complement workload hardening at the secrets and storage boundary)
- Implement Zero Trust Network Architecture (architectural microsegmentation model that Kubernetes NetworkPolicy implements at the pod boundary)
- Role of TLS/SSL in Data Protection (TLS certificate infrastructure that underpins service mesh mTLS between workloads)
- How To Secure SaaS Applications At Scale (SaaS-layer credential management that complements the container workload identity boundary)
- Best CSPM Tools for AWS (cloud posture detection layer for misconfigured Kubernetes control planes and exposed RBAC)
- Building a SOC Team: Roles and Tools (security operations center tooling that monitors container runtime anomalies and Kubernetes audit logs)
- Cloud Security vs On-Prem Security (deployment model comparison that determines whether container orchestration runs on managed Kubernetes or self-hosted)
Frequently Asked Questions
Does Kubernetes have a security model that replaces the deprecated PodSecurityPolicy?
Pod Security Standards replaced PodSecurityPolicy (PSP) in Kubernetes 1.25 and are enforced natively through the Pod Security admission webhook without requiring a separate controller. PSS defines three levels: Privileged (no restrictions), Baseline (prevents known privilege escalations), and Restricted (CIS Benchmark-aligned, blocks root containers and requires a kernel syscall filter). Clusters still running PSP on Kubernetes 1.25+ silently lose enforcement; the PSP API was removed, not replaced by a shim. Migrating to PSS requires auditing pod specs against the Restricted profile and patching any spec that sets runAsRoot, hostNetwork, or hostPID.
Can image signing prevent supply-chain attacks without admission control enforcing the policy?
Signature attestation alone does not block a supply-chain attack if no policy verifies the signature at scheduling time. Signing creates a cryptographic record stored alongside the image digest in the registry; it does not modify the container runtime or block pod scheduling. Without an OPA Gatekeeper or Kyverno rule that rejects unsigned image references, a developer or a compromised CI system can schedule an unsigned image directly using kubectl or the Kubernetes API. The full control requires both the signing step in the build pipeline and the cluster policy, deployed together to close the attack surface.
What is the minimum role-based access control configuration that satisfies the CIS Kubernetes Benchmark for production workloads?
The CIS Kubernetes Benchmark v1.8 minimum RBAC configuration requires dedicated service accounts per workload (no use of the default service account), namespace-scoped roles instead of cluster-level ClusterRoles wherever the workload does not need cluster-wide access, and explicit denial of secret list and watch verbs for service accounts that only need secret get. The benchmark also requires disabling automountServiceAccountToken on pods that make no API server calls, and auditing ClusterRoleBindings with cluster-admin to verify that no non-administrator subjects are bound.









