Skip to main content

More Info:

Do not generally admit containers which make use of hostPath volumes.

Risk Level

Low

Address

Security

Compliance Standards

  • CIS Kubernetes

Triage and Remediation

Remediation

Manual Steps

  1. List all workloads using hostPath volumes
    Run on: any machine with kubectl access
    Use this to identify which namespaces and pods currently depend on hostPath and why (logging, runtime, node access, etc.).
  2. Review each namespace’s existing admission controls
    Run on: any machine with kubectl access
    Determine which namespaces host user workloads and whether they already enforce Pod Security Standards or other policies that restrict hostPath.
  3. Decide namespace policy for hostPath usage
    For each namespace with user workloads:
    • Decide if hostPath should be:
      a) Fully disallowed,
      b) Allowed only for specific paths (e.g., /var/log, /var/run), or
      c) Temporarily allowed while refactoring workloads.
      Document required exceptions (namespaces, deployments, and exact host paths).
  4. Implement or tighten policy to restrict hostPath
    Run on: any machine with kubectl access
    Examples (adapt to your chosen mechanism; apply only where appropriate):
    • If using Pod Security admission labels:
    • If using Kyverno (example policy – edit namespace selector, allowed paths):
  5. Refactor or explicitly approve remaining hostPath users
    For each pod identified in step 1 in namespaces where hostPath should be minimized:
    • Prefer alternatives (emptyDir, PVC, projected volumes, CSI drivers) and update manifests:
    • Where hostPath is strictly necessary, ensure it is:
      • Limited to the minimal directory.
      • Read-only where possible.
      • Covered by an explicit, narrowly scoped policy exception.
  6. Verify policies and current workloads
    Run on: any machine with kubectl access
    • Confirm namespace labels / policy objects:
    • Re-run hostPath usage discovery to ensure only approved cases remain:
    • Optionally, perform a dry run of a pod using hostPath in a locked-down namespace to confirm it is rejected:

Using kubectl

1. List all namespaces to scope your review

Run on: any machine with kubectl access
You will review each namespace that runs user workloads (typically excluding kube-system, kube-public, kube-node-lease, and provider-specific system namespaces unless you intentionally run user apps there).

2. Check for pods using hostPath in each namespace

Run on: any machine with kubectl access
Indications of a problem:
  • Any pod in a user-workload namespace shows volume: ... hostPath: /some/path.
  • Especially concerning paths: /var/run, /var/run/docker.sock, /, /var/lib/kubelet, /etc, /var/lib/docker, or other sensitive host directories.
To drill into a specific namespace:

3. Identify which controllers define those pods

Use labels or ownerReferences to find the workload owning a pod that uses hostPath.Example (replace names as needed):
Look under .metadata.ownerReferences for kind (Deployment, DaemonSet, StatefulSet, Job, etc.), then inspect that controller:
Indications of a problem:
  • Any user-managed controller spec includes hostPath: under .spec.template.spec.volumes.

4. Check for PodSecurity or admission controls that restrict hostPath

4.1 Pod Security Admission (PSA) labels on namespaces
Look for labels like:
  • pod-security.kubernetes.io/enforce
  • pod-security.kubernetes.io/audit
  • pod-security.kubernetes.io/warn
Indications of a problem:
  • User-workload namespaces have no Pod Security labels, or:
  • They are set to profiles (baseline or privileged) that allow broad hostPath usage when your policy should be more restrictive (e.g., targeting restricted and specific allowed host paths).
4.2 PodSecurityPolicy (legacy, if still present)
In PSP definitions, inspect:
Indications of a problem:
  • volumes allows hostPath and:
    • .spec.allowedHostPaths is empty, or
    • pathPrefix: / or other very broad prefixes without readOnly: true where appropriate.
  • PSPs with broad hostPath allowances are bound to service accounts used in user-workload namespaces.
To see which service accounts use a PSP (RBAC binding example):

Search for hostPath in webhook configs and related CRDs/policies:
Indications of a problem:
  • No admission webhooks or policies mention hostPath while your security model expects centralized enforcement (e.g., Kyverno, OPA Gatekeeper) to restrict or forbid hostPath.
  • Policies exist but are in audit/warn mode only, not enforce for hostPath usage.

Examples (run only if the CRDs exist):Kyverno:
Gatekeeper (OPA):
Indications of a problem:
  • No constraints/policies reference hostPath at all.
  • Constraints exist but target only limited namespaces, leaving user-workload namespaces unprotected.

7. What you decide from the review (human judgement required)

Based on the above data, you must decide:
  • Which hostPath usages are strictly required for functionality and acceptable by policy.
  • Where you should:
    • Remove hostPath entirely,
    • Replace it with a safer volume type (e.g., emptyDir, PVC),
    • Or constrain it via namespace policies/Pod Security/admission controls to a small set of approved paths and workloads.
kubectl surfaces the current state; it does not decide or apply the correct restriction policy automatically.

Additional Reading: