Container Security
Container security protects containerized workloads: the code inside each image, the kernel isolation around it, and the credentials the orchestrator hands it.
Also known as container runtime security, Kubernetes security, K8s security, Docker security, CWPP, CNAPP, cloud workload protection
Container security is the practice of protecting containerized workloads across three layers: the code and dependencies inside each image, the kernel isolation that separates a container from its host and neighbors, and the identity and secrets an orchestrator such as Kubernetes hands each container. Most real container compromises arrive through the code inside the image, not through the kernel.
That ordering is our position, and it runs against how the category is usually sold. Container security tooling has spent a decade hardening the wall between a container and its host. The supply chain attacks of 2026 did not climb that wall. A compromised dependency ran as the workload and took the credentials the workload had been given.
What is container security?
#Container security covers everything that can make a containerized workload do something its owner did not intend: a malicious or vulnerable package in the image, a tampered base image, a container that can break out to its host, and an orchestrator that grants a container more access than it needs.
A container is not a small virtual machine. It is an ordinary Linux process that the kernel runs with a restricted view of the system. Namespaces give it its own process IDs, network stack, mount table, and hostname. Control groups (cgroups) cap its CPU and memory. Linux capabilities split root's powers into pieces it can be denied, seccomp filters which system calls it may make, and AppArmor or SELinux confine which files it may touch. The image supplies a filesystem. Containers on a node share that node's kernel, unless a sandboxed runtime such as gVisor or Kata Containers puts its own kernel layer in between.
A virtual machine draws the line lower. It runs its own kernel on a hypervisor, so a guest kernel bug compromises the guest, not the host. That is why "can this container escape?" and "can this VM escape?" have different answers, and why most of the field's attention has gone to the first question. Our Docker page covers how images are built and layered. This page covers what happens when they run.
Container isolation holds only as long as the shared kernel and its configuration hold. There are four classic ways out:
- A privileged container.
--privilegedorprivileged: truehands the container nearly all capabilities and host devices. - A mounted container runtime socket. Access to
/var/run/docker.sockis root on the host. The strutil-core gem, published to RubyGems on November 1, 2026, used the Docker socket to launch a privileged Alpine container that edited/etc/sudoers.d. - Host mounts and host namespaces. A
hostPathvolume orhostPID: trueputs host files or processes inside the container's view. - A kernel vulnerability. Any exploitable bug in a system call the container is allowed to make.
Three defaults make the last two worse than most teams assume. Without a user namespace, UID 0 inside a container is UID 0 on the host, with only capabilities and seccomp standing between it and the node. User namespaces became generally available in Kubernetes v1.36 on April 23, 2026, and they are still opt-in through hostUsers: false. Kubernetes also does not filter system calls by default. Its seccomp documentation puts it plainly: unless the kubelet runs with --seccomp-default, "the default is Unconfined." And the Restricted Pod Security Standard, the strictest built-in policy, requires a seccomp profile, non-root users, and dropping all capabilities, but says nothing about service account tokens.
How do attackers compromise containers in practice?
#Attackers compromise containers in practice by getting their code into the image and letting it run with the container's own permissions. No escape is needed, because the valuable things are already inside: environment variables, mounted secrets, the pod's Kubernetes identity, and a network path to the cloud metadata service.
The LiteLLM compromise on October 21, 2026 shows the pattern end to end. LiteLLM 1.107.0 shipped to PyPI and to container images on GitHub Container Registry. The malicious image build ran from 10:51 to 11:06 UTC, and by about 13:14 UTC the floating tags latest, main-latest, and main-stable all resolved to the same image index as v1.107.0. Deployments that tracked a floating tag received the payload without choosing the new version. The payload was a .pth file, so it ran on every Python startup, whether or not the application imported LiteLLM. It collected non-empty environment variables, other processes' environments, container-mounted secrets, AWS instance and task credentials, Google Cloud service account tokens, and Azure instance metadata.
The Mini Shai-Hulud worm went further inside Kubernetes. Our analysis of the TanStack compromise in May 2026 found the payload reading the pod's service account files and chaining them:
/var/run/secrets/kubernetes.io/serviceaccount/token
/var/run/secrets/kubernetes.io/serviceaccount/ca.crt
/var/run/secrets/kubernetes.io/serviceaccount/namespace
http://169.254.169.254/latest/api/token (IMDSv2 session token, PUT)
http://169.254.169.254/latest/meta-data/iam/security-credentials/
http://169.254.170.2 (ECS task metadata)
*.svc.cluster.local:8200 and 127.0.0.1:8200 (HashiCorp Vault)The chain is short: steal the Kubernetes service account token, use it to authenticate to Vault, and read every secret Vault will release to that identity. The token grants whatever RBAC rights the pod's service account holds, which in a misconfigured cluster can mean cluster-admin. Requesting an IMDSv2 session token first means the theft works on instances that have disabled IMDSv1.
The figure shows the six paths a compromised dependency used without leaving its container. Inside the pod: (1) environment variables such as AWS_*, DATABASE_URL, and VAULT_TOKEN; (2) mounted files, including the service account token under /var/run/secrets/ and .env files; (3) the pod's own identity against the Kubernetes API, at whatever RBAC rights it holds. On the node: (4) the metadata services at 169.254.169.254 for EC2 and 169.254.170.2 for ECS task credentials. Beyond the node: (5) cluster services such as Vault at *.svc.cluster.local:8200, authenticated with the stolen token; and (6) the outbound network the credentials leave on. None of the six crosses the kernel isolation boundary drawn at the top.
The same holds for the strongest isolation available. Firecracker, the microVM monitor AWS built for Lambda and Fargate, gives each workload its own guest kernel, and its specification promises at most 125 ms to boot and at most 5 MiB of overhead. Yet Lambda passes the function's execution role credentials to the code as AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN environment variables. A malicious dependency inside a microVM reads them as easily as one inside a container. This is the job of an infostealer, and isolation was never designed to stop it.
What are container security best practices?
#The container security best practices that matter most remove credentials from the workload's reach and keep malicious code out of the image; kernel hardening comes second. Every control below is worth having, and each one stops a different thing:
| Control | Stops escape to the host | Stops in-container credential theft | Cost and limits |
|---|---|---|---|
| Non-root user, drop ALL capabilities, no privilege escalation | Partly | No | Cheap; some images assume root |
| seccomp RuntimeDefault | Partly: shrinks kernel attack surface | No | Cheap; Kubernetes does not apply it by default |
| User namespaces (hostUsers: false) | Yes, for root-to-host escalation | No | Kubernetes 1.36+, recent kernels; incompatible with host namespaces |
| gVisor, Kata Containers, Firecracker | Strongest | No | Startup and syscall overhead; more to operate |
| automountServiceAccountToken: false | No | Yes, for the Kubernetes API token | Free for workloads that never call the Kubernetes API |
| Block or limit node metadata access | No | Yes, for node and instance credentials | IMDSv2 hop limit 1 blocks bridge-networked containers only |
| Default-deny egress NetworkPolicy | No | Limits exfiltration and Vault reachability | Needs a CNI that enforces it; allowlists drift |
| Pin images by digest | No | Prevents silent swaps like LiteLLM's floating tags | You own the update cadence |
| Block malicious packages before the build | No | Yes, by keeping the payload out | Must run at install time, not after deploy |
Verdict: start at the bottom half. Turn off token automounting for every pod that does not talk to the Kubernetes API, give workloads short-lived, audience-bound credentials through workload identity instead of node roles, deny egress by default, and pin images by digest. Then add the isolation controls in the top half, which matter for multi-tenant clusters and for limiting what an attacker does after the theft. The reverse order leaves credentials in reach of exactly the attacks we keep seeing.
Here is a pod spec that applies the cheap controls. User namespaces in it require Kubernetes 1.36 or later, where the feature is generally available:
apiVersion: v1
kind: Pod
metadata:
name: api
spec:
hostUsers: false # user namespace: root in the pod is not root on the node
automountServiceAccountToken: false # no API token unless the app calls the Kubernetes API
securityContext:
runAsNonRoot: true
runAsUser: 10001
seccompProfile:
type: RuntimeDefault # the Kubernetes default is Unconfined
containers:
- name: api
image: registry.example.com/api:1.4.2
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]In production, replace the tag with the digest your pipeline tested, image@sha256:…, so a retagged image cannot change what runs. For pods that do need the Kubernetes API, Kubernetes mounts a projected token that the kubelet refreshes once it is older than 80% of its lifetime. That shortens the window a stolen token is useful, but it does nothing to stop the theft. Apply least privilege to the service account's RBAC role, because that role is what the attacker inherits.
On AWS, the metadata service needs its own decision. AWS documents that "in a container environment, a hop limit of 1 can cause issues", because the token response cannot travel the extra network hop to a bridge-networked container. That same property is a control: an IMDSv2 hop limit of 1 keeps bridge-networked containers away from the node's role. It does not cover everything: Latacora's testing found ECS tasks in awsvpc and host networking modes could still reach the node's metadata with a hop limit of 1. Pair it with per-workload identities and keep node roles minimal.
Image scanning, CWPP, and CNAPP
#Image scanning reads the operating system and language packages in an image and matches them against known vulnerabilities. It is necessary and late. A malicious package does not get a CVE, so a scanner that only matches versions against advisories passes it. Scanning a built image also happens after the package already ran during the build, where install scripts and .pth hooks fire on the build machine with its credentials. Even security tools ship through this path: the compromised Trivy Docker images in March 2026 pushed tags 0.69.5 and 0.69.6 with no matching GitHub release, and latest pointed at the bad image.
The check that changes outcomes runs at install time. A package firewall inspects each dependency as the package manager fetches it and blocks known malicious packages before they reach the image. Socket Firewall now ships inside Docker Hardened Images for Node.js, Python, and Rust, where npm, pnpm, yarn, pip, uv, and cargo are aliased to run through it during builds.
Two market labels absorb much of this work. A cloud workload protection platform (CWPP) secures running workloads, containers, VMs, and serverless functions, typically with runtime detection and vulnerability scanning. A cloud-native application protection platform (CNAPP) bundles CWPP with cloud posture management and pipeline checks. Both are categories of tools, not controls, and neither replaces checking what goes into the image.
Microservices multiply identities, not just containers
#Microservices and serverless architectures make the credential problem larger. Each service is a separate workload with its own service account, its own secrets, and its own egress, so a cluster of 200 services holds 200 sets of credentials, and a compromised package harvests the set of every service that imports it. Secret management that issues short-lived, narrowly scoped credentials per workload shrinks each harvest; a shared secret mounted everywhere turns one compromised service into all of them.
Container security spent its first decade asking whether code inside a container could reach the host. The more useful question for a supply chain attack is what the container could reach on day one, before anything escaped. For most production workloads, the honest answer is the cloud account.
