highCWE-269OWASP A05:2021

Kubernetes Privileged Container

Your Kubernetes pod runs with securityContext.privileged: true, giving the container full access to the host kernel and effectively bypassing container isolation.

How It Works

A privileged container runs with almost the same access as a process running directly on the host. It can access all host devices, modify kernel parameters, and escape the container to access the underlying node. If an attacker compromises a privileged container (via a vulnerability in your app), they can escape to the host and compromise the entire Kubernetes node and potentially the whole cluster.

Vulnerable Code
# BAD: pod spec with privileged container
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: app
    image: myapp:latest
    securityContext:
      privileged: true  # full host access — almost never necessary
Secure Code
# GOOD: minimal security context, no privilege escalation
apiVersion: v1
kind: Pod
spec:
  containers:
  - name: app
    image: myapp:latest
    securityContext:
      privileged: false
      allowPrivilegeEscalation: false
      runAsNonRoot: true
      runAsUser: 1000
      readOnlyRootFilesystem: true

Real-World Example

Container escape vulnerabilities (CVE-2019-5736 runc, CVE-2022-0185 Linux kernel) are significantly more exploitable when containers are privileged. In 2022, attackers who compromised a privileged container in a Kubernetes cluster were able to escape to the node within minutes, then pivot to access secrets from other pods via the node's kubelet.

How to Prevent It

  • Never set privileged: true unless you have a specific, documented reason (e.g., certain CNI plugins, DaemonSets for node monitoring)
  • Set allowPrivilegeEscalation: false and runAsNonRoot: true as defaults for all containers
  • Use Pod Security Admission (PSA) to enforce baseline or restricted policies cluster-wide
  • Set readOnlyRootFilesystem: true to prevent attackers from writing tools to the container filesystem
  • Use tools like kube-bench to audit your cluster against CIS Kubernetes Benchmark

Affected Technologies

Node.jsPython

Data Hogo detects this vulnerability automatically.

Scan Your Repo Free

Related Vulnerabilities