Skip to main content

More Info:

Containers sharing the host PID namespace can view and interact with all processes on the node. Their admission should be restricted via Pod Security Admission policies.

Risk Level

High

Address

Security

Compliance Standards

  • CIS AKS

Triage and Remediation

Remediation

Manual Steps

  1. Identify pods using hostPID across all namespaces
    Run on: any machine with kubectl access
    Save the list and, for each pod found, inspect who runs it and why:
  2. Decide which workloads (if any) truly require hostPID
    For each pod with hostPID: true, review its purpose with the owning team (e.g., node monitoring/diagnostics agents may have a requirement; most app workloads do not).
    • If hostPID is not strictly required, plan to remove it from the pod spec.
    • If it is required, note the namespace, pod name, and service account for later RBAC tightening:
  3. Harden namespaces with Pod Security Admission labels
    Decide which namespaces must be strictly protected (no hostPID allowed) and which, if any, can host exceptional workloads.
    • To enforce restricted (disallowing hostPID) on a namespace:
    • To enable baseline warnings cluster-wide (helps detect issues without blocking):
    Avoid placing hostPID-dependent workloads into restricted namespaces.
  4. Tighten RBAC for namespaces that legitimately use hostPID
    For any namespace that truly needs hostPID, ensure only a dedicated service account can create such pods:
    • Identify who can create pods now:
    • Based on this output, reduce create/update permissions on pods so that only the specific service account(s) used by the approved hostPID workloads retain that ability.
  5. Refactor or remove non-essential hostPID usage
    For pods where hostPID is not required, update their manifests or Helm charts to remove hostPID: true from .spec and re-deploy. Use your normal deployment mechanism (kubectl apply, GitOps, or Helm) and ensure that application behavior remains correct without host PID access.
  6. Verify the policy and current state
    Run on: any machine with kubectl access
    • Confirm no remaining hostPID pods except in approved namespaces:
    • Confirm Pod Security Admission labels are set as intended:
    • Optionally, attempt to create a test pod with hostPID: true in a restricted namespace and ensure it is rejected.

Using kubectl

1. List pods that request hostPID: true

Run on: any machine with kubectl access.
Problem indication:
  • Any line of output means that pod is running with hostPID: true and must be manually reviewed to confirm if this is strictly necessary.
For more detail on those pods:

2. Inspect a specific pod’s spec

For each pod identified above:
Problem indication:
  • spec.hostPID: true without a clear, documented operational need.
  • Pods using default service accounts or broadly scoped service accounts when hostPID: true is set.

3. Check Pod Security Admission labels on namespaces

List PSA labels for all namespaces:
Problem indication:
  • Namespaces lacking pod-security.kubernetes.io/enforce=restricted where hostPID should generally be disallowed.
  • Sensitive or multi-tenant namespaces with ENFORCE unset or set to privileged/baseline.
  • Namespaces allowing hostPID but not clearly segregated for that purpose.
To inspect labels for a single namespace:

4. Review RBAC for namespaces that legitimately need hostPID

First, list service accounts in a namespace that is allowed to use hostPID:
Then list rolebindings and clusterrolebindings referencing those service accounts:
Problem indication:
  • Service accounts used by hostPID pods are bound to roles that are overly broad or reused widely across other workloads.
  • No clear, dedicated service account for hostPID workloads (e.g., using default service account).
Problem indicators in the script output:
  • Any non-system namespace (or any namespace you do not explicitly trust for privileged workloads) that:
    • Lacks ENFORCE=restricted, and/or
    • Contains pods listed with HOSTPID=true.
  • Service accounts shown in the hostPID list that are also used widely by non-privileged pods.