What is a Privileged Container?

A privileged container is a special type of Linux container, often used in Kubernetes, that is granted nearly all the capabilities of the host system's root user, effectively removing the isolation boundaries that containers are designed to enforce. This makes it a critical security risk, as a compromised privileged container can interact directly with the host kernel and its devices, significantly increasing the blast radius of any breach. Pwned Labs teaches escape from a container to its host node in its Kubernetes Attack and Defense bootcamp, which leads to the KRTP certification.

privileged_container-1

Understanding Privileged Containers

A privileged container is a container that runs with elevated access to the host operating system, bypassing nearly all security and isolation mechanisms that normally keep containers sandboxed. In Docker, this is the --privileged flag passed to docker run. In Kubernetes, it is the privileged: true setting in a Pod's securityContext. In Docker Compose, it is the privileged: true key in the service definition. The underlying mechanism is identical across all runtimes, it is the Linux kernel's isolation that gets disabled.

In a standard container setup, processes are restricted by namespaces and control groups. They often still run as root inside the container, because the default user within a container is root unless the image or the run command sets another user. This isolation is the fundamental security model of containerization. When you introduce the privileged flag, you are telling the kernel to essentially bypass these restrictions for that specific container. It is a powerful but dangerous escape hatch reserved for specific administrative tasks. The Pwned Labs Kubernetes Attack and Defense bootcamp starts in minikube and takes students with no prior Kubernetes experience through to root on a node.

How Container Isolation Works Under the Hood

Before diving into the risks, let's quickly review the core security mechanisms that make standard containers safe. This matters for understanding what a privileged container breaks.

Namespaces

The primary tool for container isolation in Linux is Namespaces. Namespaces partition global system resources, making it appear to a container that it has its own dedicated view of the system. Key namespaces include:

  • PID Namespace: Gives the container its own set of process IDs, so it can't see most processes on the host.
  • Mount Namespace: Provides a private file system view, preventing the container from accessing the host's file system structure.
  • Network Namespace: Gives the container its own network stack and IP address.
  • User Namespace: Provides UID/GID mapping so a container's UID 0 (root) maps to a non-privileged UID on the host, adding an additional layer of isolation. However, this does not restrict Linux capabilities within the container's namespace.

Control Groups (cgroups)

Control Groups (cgroups) manage and limit the resources (CPU, memory, disk I/O, network) a container can consume. While cgroups primarily prevent Denial of Service (DoS) attacks, they also contribute to the overall resilience of the host.

Capabilities

Linux Capabilities break up the monolithic power of the traditional root user into smaller, distinct units. A standard container typically runs with a heavily reduced set of capabilities. For instance, it might have CAP_NET_BIND_SERVICE (to bind to ports below 1024) but not CAP_SYS_ADMIN (the capability often referred to as "god mode"). The Pwned Labs Kubernetes Attack and Defense bootcamp teaches Kubernetes as a set of attackable trust boundaries, and these kernel mechanisms form the boundary between a container and its host.

What Changes When a Container is Run in Privileged Mode

Whether you run docker run --privileged myimage or set privileged: true in a Kubernetes Pod spec, the effect on the Linux kernel is the same, the isolation mechanisms described above are largely deactivated for that container.

Capability Grant

The most immediate change is that the container is granted a full set of Linux capabilities (permitted, effective, and bounding sets), including highly privileged capabilities like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_SYS_PTRACE, and others that a normal container does not have. It can now perform operations that are normally strictly forbidden.

Namespace Manipulation

While the container still exists within its own namespaces, the elevated capabilities (particularly CAP_SYS_ADMIN) allow the container to manipulate and escape those namespace restrictions. Crucially, a privileged container can:

  • Access Host Devices: It can directly access, modify, or interact with physical and virtual devices on the host system. This includes mounting host devices like /dev/sda1 or accessing network interfaces.
  • Mount Host File Systems: A privileged container can mount the entire host file system (the root directory, /) inside the container. Once mounted, the container can read, write, and modify any file on the host.

Practical Example of Extended Host Access

Consider a standard container that tries to reach the host machine's root disk:

$ ls /dev/sda1
ls: cannot access '/dev/sda1': No such file or directory

This fails because by default a container is not allowed to access any devices, so the host's disks never appear in its /dev, and it lacks the CAP_SYS_ADMIN capability needed to mount one.

In contrast, a privileged container, whether launched via docker run --privileged or deployed as a Kubernetes Pod, can easily breach this boundary. Once granted, a compromised process inside the container could execute a command sequence like this:

# Inside the privileged container
$ mkdir /host
$ mount /dev/sda1 /host       # Mounts the root partition of the host
$ chroot /host /bin/bash       # Changes the container root to the host root
$ cat /etc/shadow              # Accesses the host password hashes

This is a direct container escape and a complete compromise of the underlying host, demonstrating why privileged containers represent such a severe container security risk regardless of the runtime or orchestrator. Escaping the container to the host node is one of the listed learning outcomes of the Pwned Labs Kubernetes Attack and Defense bootcamp.

Real-World Examples Where Privileged Containers Are Used

Despite the inherent security risks, there are legitimate use cases for privileged containers across both standalone Docker environments and Kubernetes clusters. These typically involve tasks that require deep interaction with the host kernel or hardware.

Use Case

Description

Security Implication

System DaemonSets

Tools like network plugins (CNI) or storage provisioners (CSI) that need to configure networking interfaces or manage disk volumes on the host node.

Necessary for cluster function, but must be treated as system critical infrastructure.

Security Scanning/Auditing

Containers that run security tools that need to inspect host processes, file systems, or kernel configurations for anomalies.

Requires host visibility that only privileged mode can provide, but the container itself becomes a high-value target.

Monitoring and Observability

Node exporters (like Prometheus Node Exporter) or logging agents (like Fluentd) that need access to host metrics, /proc, or device driver data.

Required for full monitoring, often limited to read-only privileged access where possible.

Container-in-Container (DIND)

Running Docker or another container runtime inside a container, often for testing or CI/CD pipelines.

Requires the ability to manage system services and interfaces, making it inherently risky for production.

The Pwned Labs Exploit Kubernetes Overly Permissive RBAC lab shows why each of these exceptions deserves scrutiny: a pod scheduled with host mounts, host namespaces or a privileged security context can turn a namespace-scoped permission into root on the node.

Why Privileged Containers Are Considered a Major Security Risk

The primary reason privileged containers are deemed a major container security risk is simple: they destroy the security boundary between the workload and the infrastructure.

Compromise Leads to Node Takeover

If an attacker successfully exploits a vulnerability within a privileged container (e.g., in the application code, a vulnerable library, or a configuration mistake), they gain immediate and complete root access to the entire host machine. This is now a node compromise, not just a container compromise. In a Kubernetes cluster, a compromised node can be leveraged to compromise the entire cluster control plane.

Lateral Movement Facilitation

Once an attacker has root on the host, they can:

  1. Read Sensitive Files: Access cloud provider metadata, host credentials, or kubelet configuration files that might contain secrets for accessing the Kubernetes API.
  2. Inspect All Traffic: Install network sniffers or modify firewall rules, exposing all network communication from other pods and containers on that same node.
  3. Launch Containers: Use the host's container runtime (Docker or containerd) to launch malicious containers for persistence.

This rapid privilege escalation is the core security concern. The Pwned Labs Kubernetes Attack and Defense bootcamp spends two of its four sessions on what comes next in managed clusters, showing how node identity on EKS, GKE and AKS leads into the cloud account behind the cluster.

Common Attack Scenarios, Including Container Escape Risks

The risks posed by a privileged container are often realized through sophisticated container escape techniques, which are made trivial when the container is running in the least secure mode.

Host File System Hijacking

This is the most straightforward escape. As shown in the previous example, a privileged container can mount the host's root file system. An attacker can use this access to:

  • Modify Host Binaries: Overwrite critical system files like /usr/bin/bash with a backdoor script.
  • Inject SSH Keys: Add their public key to the host's /root/.ssh/authorized_keys, gaining permanent, credentialed remote access.
  • Disable Security Tools: Stop or remove host-based security agents.

Device Manipulation and Kernel Interaction

Since the container can access host devices, an attacker can engage in direct kernel exploitation.

  • If the host mounts a disk device like /dev/sdb into the privileged container, the container can format or corrupt that entire disk, causing massive data loss or system failure.
  • The attacker can load malicious kernel modules directly onto the host operating system, effectively establishing deep and invisible persistence.

Abusing Capabilities

While a standard container only has a limited set of capabilities, the privileged container has them all. An attacker can immediately abuse high privilege capabilities like:

  • CAP_SYS_ADMIN: Allows mounting file systems, creating devices, and performing kernel-level administrative tasks.
  • CAP_NET_ADMIN: Allows the attacker to configure network interfaces, modify routing tables, and set up man-in-the-middle attacks on the host.

These are the primary attack paths for container escape. The Pwned Labs Escalate from Prototype Pollution to EKS Takeover lab includes breaking out of a container running on containerd as one step in a chain from a web application flaw to cluster takeover.

Real-World Attacks Targeting Privileged Containers

Privileged container abuse is not theoretical. Documented attack campaigns and CVEs show how attackers target container isolation in production environments, and how a privileged container widens the impact when that isolation fails.

CVE-2022-0185: Linux Kernel Container Escape

In January 2022, researchers disclosed CVE-2022-0185, a heap-based buffer overflow in the Linux kernel's filesystem context handling. The vulnerability allowed an attacker inside a container with CAP_SYS_ADMIN (granted by default to privileged containers) to trigger a kernel memory corruption and escape to the host. The exploit was straightforward: any privileged container on an unpatched node was immediately vulnerable to full node takeover, with no additional misconfiguration required.

TeamTNT and Hildegard: Cryptojacking in Kubernetes Clusters

The TeamTNT threat group has repeatedly targeted misconfigured Kubernetes clusters. Their Hildegard campaign (2021) gained initial access through a kubelet that allowed anonymous access, used the kubelet API to run commands inside existing containers, launched cryptojacking, and searched the hosts and the cloud metadata services for credentials. Unit 42 did not observe a privilege escalation attempt, but the malware dropped BOtB, a tool that Unit 42 notes can escape from privileged containers. The Pwned Labs Kubernetes Attack and Defense bootcamp draws on tradecraft seen in TeamTNT campaigns, which worm across exposed Kubernetes clusters and steal cloud credentials from compromised nodes.

Azurescape: Cross-Tenant Container Escape

In 2021, Palo Alto's Unit 42 disclosed Azurescape, which it described as the first cross-account container takeover in the public cloud. The researchers escaped their own container in Azure Container Instances through an outdated version of runC that was vulnerable to known breakout bugs such as CVE-2019-5736, then acquired a privileged Kubernetes service account token and used it to take over the multitenant cluster and other customers' containers. The research demonstrated that in multi-tenant environments, a single container escape can have a blast radius far beyond the originating cluster.

Leaky Vessels: runc and BuildKit Container Escapes (2024)

In January 2024, Snyk disclosed four "Leaky Vessels" vulnerabilities (CVE-2024-21626, CVE-2024-23651, CVE-2024-23652, CVE-2024-23653) affecting runc and Docker BuildKit. CVE-2024-21626 allowed container escape through a leaked file descriptor that could be set as the container's working directory. While these vulnerabilities affected containers regardless of privilege level, privileged containers amplified the impact significantly: an attacker escaping from a privileged container immediately had full root capabilities on the host, whereas escape from a standard container still left the attacker constrained by reduced capabilities and read-only filesystem restrictions.

Detection and Monitoring Strategies

Detecting the presence of privileged containers and monitoring their behavior is critical for effective container security risks mitigation.

Configuration Detection

The easiest detection is at the infrastructure level. Security teams should scan the cluster configuration files regularly.

  • Pod/Deployment YAML Scanning: Look for the line privileged: true in the securityContext section of any Pod, Deployment, or DaemonSet definition.
  • Admission Controllers: Use Kubernetes Admission Controllers (like Gatekeeper or Kyverno) to define a policy that blocks the deployment of any new Pods with privileged: true. Teams requiring exceptions must use exception labels or obtain explicit approval.

Runtime Monitoring

Once a privileged container is running, standard runtime monitoring should focus on host-level indicators of compromise.

  • Process Monitoring: Monitor for suspicious process activity originating from the container's PID namespace that interacts with the host. For example, a process inside the container using mount, modprobe, or chroot.
  • File Access Auditing: Use tools (like Falco or host based intrusion detection systems) to monitor access to sensitive host files such as /etc/shadow, /root/.ssh/, or /var/lib/kubelet/.
  • Network Activity: Flag any unexpected outgoing connections from the privileged container, as this could indicate exfiltration of host data.

Pwned Labs teaches Kubernetes audit log analysis and cloud-native detections in the purple team capstone session of its Kubernetes Attack and Defense bootcamp.

Best Practices to Avoid or Securely Manage Privileged Containers

To avoid the pitfalls of privileged container security risks while still allowing necessary administrative tasks, organizations must adhere to strict Kubernetes security best practices.

Always Prefer Specific Capabilities

Instead of granting blanket privileged mode, identify the exact Linux Capabilities the container needs and grant only those capabilities.

For example, if a container only needs to modify network routes, grant it only CAP_NET_ADMIN and nothing else. This is the principle of least privilege in action.

Anti-Pattern

Recommended Best Practice

privileged: true

Use capabilities: add: [NET_ADMIN] (Kubernetes manifests omit the CAP_ prefix)

Running as root user (UID 0)

Use runAsNonRoot: true or runAsUser: 1000

Mounting /dev host directory

Mount specific devices like /dev/null if needed, not the entire /dev

Use Security Contexts and PSPs (or Successors)

Enforce security policies across the cluster. Use a Pod Security Standard, enforced through Pod Security Admission, that restricts or prevents the use of privileged containers entirely in production namespaces. Pod Security Policy was removed in Kubernetes v1.25, so it is no longer an option on current clusters. Apply the Restricted standard to all application workloads.

Read Only Root Filesystems

Ensure that the privileged container, if absolutely necessary, is running with a read only root file system. This prevents an attacker from writing malicious binaries inside the container image itself, limiting post-exploitation persistence.

Tightly Scope and Review DaemonSets

Privileged containers are often found in DaemonSets. Treat every DaemonSet with the same scrutiny as host kernel modules.

  • Isolate DaemonSets: Run them in their own dedicated namespace (e.g., kube-system or monitoring).
  • Regular Audits: Regularly review the code and configuration of these system level tools to ensure no excessive privileges have been added.

Apply Seccomp and AppArmor Profiles

Use Linux kernel security modules like Seccomp and AppArmor.

  • Seccomp (Secure Computing Mode): Use a custom Seccomp profile to restrict the system calls a container can make. This reduces the attack surface by blocking dangerous syscalls like mount, bpf, or module loading. It does not cover a privileged container in Kubernetes, because a seccomp profile cannot be applied to a container with privileged: true, and privileged containers always run as Unconfined.

Pwned Labs teaches this kind of enforcement in its Secure Kubernetes using OPA Gatekeeper lab, which uses Rego policies to require read-only root filesystems and to block privilege escalation, host networking and hostPath volumes.

Related Labs

Pwned Labs runs these Kubernetes scenarios as hands-on labs. All four are Premium.

  • Exploit Kubernetes Overly Permissive RBAC (Premium, Intermediate): start from compromised credentials, use permissive role bindings to move laterally, and escalate to root on the underlying node.
  • Escalate from Prototype Pollution to EKS Takeover (Premium, Intermediate): turn a Node.js prototype pollution flaw into code execution in a pod, break out of a container running on containerd, and take over an Amazon EKS cluster.
  • Escalate from SSJI to EKS (Premium, Beginner): chain server-side JavaScript injection into a Kubernetes pod, cross a namespace boundary through misconfigured RBAC, and abuse the cluster's IAM integration to reach AWS data.
  • Secure Kubernetes using OPA Gatekeeper (Premium, Intermediate): write Rego policies that require read-only root filesystems and block privilege escalation, host networking and hostPath volumes.

Frequently Asked Questions

Why are privileged containers dangerous?

A privileged container is dangerous because it breaks the fundamental isolation boundary between the container and the host system. If the container is compromised, whether running in Docker or Kubernetes, an attacker gains root access to the entire underlying host, leading to severe container escape. In Kubernetes, this can escalate to cluster-wide compromise through the kubelet and API server. Pwned Labs teaches this path, from a container to its host node and on into the cloud account, in its Kubernetes Attack and Defense bootcamp.

What is the difference between running a container as root and running it in privileged mode?

Running a container as root (UID 0) means the application inside the container has administrative rights within the container's isolated namespaces. Running a container in privileged container mode means the container's root user is granted almost all of the host kernel's capabilities, allowing it to bypass namespace isolation and access host devices.

How can I check if a Pod is running in privileged mode?

You can check a Pod's configuration by inspecting its YAML definition. Look inside the spec.containers.securityContext section for the flag privileged: true. Security scanning tools should automate this check as part of your overall Kubernetes security best practices. Pwned Labs teaches admission policies that reject risky pod settings before they run in its Secure Kubernetes using OPA Gatekeeper lab.

Is there any alternative to using a privileged container?

Yes, in almost all cases, there is an alternative. Instead of using blanket privileged mode, you should use the principle of least privilege by granting only the minimum necessary Linux Capabilities (e.g., CAP_NET_ADMIN) and by mounting only specific host paths or devices, rather than the entire host system.

Does running a privileged container increase the risk of a container escape attack?

Absolutely. A privileged container makes a container escape attack trivial. An attacker does not need to find a kernel vulnerability to break out; they simply need to use the already existing host capabilities, such as mounting the host file system or manipulating host devices, which is much easier to exploit.

Learn this hands-on

Privileged containers are one of the first things an attacker looks for once inside a cluster. The Pwned Labs Kubernetes Attack and Defense Bootcamp, Professional Edition (KRTP) covers workload escape and the wider Kubernetes attack surface in live clusters, starting in minikube and moving through EKS, GKE and AKS, and is assessed with a fully hands-on exam.

About Pwned Labs

Pwned Labs is a hands-on cloud and AI offensive security training platform. It runs real-world attack labs and bootcamps for AWS, Azure, GCP, Kubernetes and AI systems, including the ACRTP, MCRTP, GCRTP, KRTP and AISRTP certifications. Free labs are at pwnedlabs.io/explore.

Learn this hands-on in a bootcamp

 


Train, certify, prove it


Our bootcamps combine expert-led instruction with real cloud environments. Complete the training, pass the exam, and earn an industry-recognized certification.



MCRTE_-1

What practitioners say.

Caleb Havens

Red Team Operator & Social Engineer, NetSPI


"I’ve attended two training sessions delivered by Pwned Labs: one focused on Microsoft cloud environments and the other on AWS. Both sessions delivered highly relevant content in a clear, approachable manner and were paired with an excellent hands-on lab environment that reinforced key concepts and skills for attacking and defending cloud infrastructures. The training was immediately applicable to real-world work, including Red Team Operations, Social Engineering engagements, Purple Team exercises, and Cloud Penetration Tests. The techniques and insights gained continue to be referenced regularly and have proven invaluable in live operations, helping our customers identify vulnerabilities and strengthen their cloud defenses."

Sebas Guerrero

Senior Security Consultant, Bishop Fox


"The AWS, Azure, and GCP bootcamps helped me get up to speed quickly on how real cloud environments are built and where they tend to break from a security standpoint. They were perfectly structured, with real-world examples that gave me rapid insight into how things can go wrong and how to prevent those issues from happening in practice. I’m now able to run cloud pentests more confidently and quickly spot meaningful vulnerabilities in customers’ cloud infrastructure.
”

Dani Schoeffmann

Security Consultant, Pen Test Partners


"I found the Pwned Labs bootcamps well structured and strongly focused on practical application, with clear background on how and why cloud services behave the way they do and how common attack paths become possible. The team demonstrates both sides by walking through attacks and the corresponding defenses, backed by hands-on labs that build confidence using built-in and third-party tools to identify and block threats. The red-team labs are hands-on and challenge-driven, with clear walkthroughs that explain each step and the underlying logic. I’ve seen several of these techniques in real engagements, and the bootcamp helped me develop a repeatable methodology for cloud breach assessments and deliver more tailored mitigation recommendations."

Matt Pardo

Senior Application Security Engineer, Fortune 500 company


"I’ve worked in security for more than 15 years, and every step up came from taking courses and putting the lessons into practice. I’ve attended many trainings over the years, and Pwned Labs’ bootcamps and labs are among the best I’ve experienced. When you factor in how affordable they are, they easily sit at the top of my list. As a highly technical person, I get the most value from structured, hands-on education where theory is immediately reinforced through labs. Having lifetime access to recordings, materials, and training environments means you can repeat the practice as often as needed, which is invaluable. If you’re interested in getting into cloud security, sign up for Pwned Labs.
”

Steven Mai

Senior Penetration Tester, Centene


“Although my background was mainly web and network penetration testing, the ACRTP and MCRTP bootcamps gave me a solid foundation in AWS and Azure offensive security. I’m now able to take part in cloud penetration testing engagements and have more informed security discussions with my team.
”

 

Got any Questions? Get in touch