Skip to content
Threat Feed
medium advisory

Kubernetes Privilege Escalation via HostPID Namespace

Attackers can leverage misconfigured pods with hostPID enabled to gain visibility into host-level processes, facilitating container escape and privilege escalation to root on the underlying host node.

The Kubernetes hostPID namespace configuration allows a pod to share the process ID space with the underlying host node. While this capability is sometimes utilized for legitimate diagnostic or monitoring tasks, it introduces a significant security risk when unauthorized or compromised pods are deployed with this flag. By gaining access to host processes, an attacker can enumerate running services, identify sensitive configuration files, or inject code into host processes. When this misconfiguration is combined with privileged container status or capabilities like ptrace, it enables an attacker to escape the container environment, enter the host init system (PID 1), and escalate privileges to root on the node. This threat vector is critical in multi-tenant or shared-responsibility cluster environments where workload isolation is paramount. Defenders must monitor Kubernetes API audit logs for the creation or modification of pods that include the 'hostPID: true' specification.

Attack Chain

  1. Attacker gains initial access to the Kubernetes cluster via compromised service account credentials or a vulnerable web application.
  2. Attacker prepares a malicious container image designed for host process interaction.
  3. Attacker uses the Kubernetes API to create or patch a pod specification, setting 'hostPID' to true.
  4. The Kubernetes scheduler successfully deploys the malicious pod on a worker node.
  5. Attacker executes a shell within the container to gain access to the host's PID namespace.
  6. Attacker leverages ptrace or other process manipulation techniques to interact with host-level processes (PID 1).
  7. Attacker executes malicious commands as root on the host node, effectively escaping the container boundary.

Impact

Successful exploitation results in full host node compromise, allowing the attacker to access sensitive host files, modify system configurations, pivot to other nodes in the cluster, or exfiltrate data from all containers running on the affected node.

Recommendation

Prioritize auditing cluster configurations and implementing admission control policies to restrict the use of the hostPID namespace to only verified, necessary system workloads.

  • Deploy the provided detection rule to monitor for unauthorized pods using hostPID.
  • Audit Kubernetes API audit logs (logs-kubernetes.audit_logs-*) for any pod creation or update events where hostPID is enabled.
  • Implement Kubernetes Pod Security Admission (PSA) policies to prevent the deployment of pods with hostPID enabled in production namespaces.
  • Review and prune high-privilege service account permissions to prevent unauthorized pod creation.

Immediate actions

Deploy the Sigma detection rule to monitor for HostPID pod deployments

Detection Engineering 48h

Threat Hunt

Search for existing pods with hostPID: true in the environment

T1611 high high confidence hunt now

Data: Kubernetes configuration metadata

Mitigations

Implement Pod Security Admission to restrict HostPID usage

short_term IT Operations

HostPID privilege escalation

Detection coverage 1

Detect Kubernetes Pod Created With HostPID

medium

Detects creation or modification of pods with hostPID set to true, which can facilitate container escape and host-level privilege escalation.

sigma tactics: execution, privilege_escalation techniques: T1610, T1611 sources: webserver

Detection queries are available on the platform. Get full rules →