Skip to main content

More Info:

Verifies no pod mounts a hostPath volume. hostPath exposes the node filesystem to the pod and can be used to escape to the host.

Risk Level

High

Address

Security

Compliance Standards

  • Cloudanix Best Practice

Triage and Remediation

Remediation

Manual Steps

  1. Identify pods using hostPath volumes
    Run on: any machine with kubectl access
  2. Export the owning workload manifest(s)
    For each non‑compliant pod line, note the owner= field (e.g., Deployment/ns/name/uid). Then export that owner resource. Examples:
    Run on: any machine with kubectl access
  3. Edit manifests to remove hostPath volumes and use safer alternatives
    Run on: any machine with kubectl access (local file edits)
    Open each exported YAML file and in the spec.template.spec.volumes (or spec.volumes for standalone pods), remove entries that define hostPath. Example before/after:
    Before:
    Replace with an approved alternative, such as emptyDir or a persistentVolumeClaim (if appropriate for the application): emptyDir example:
    PVC example (requires an existing PVC or one you create separately):
    Ensure matching volumeMounts refer to the updated volume name and that any dependency on the host filesystem is addressed functionally (e.g., by moving data to PV-backed storage).
  4. Apply the updated manifests
    Run on: any machine with kubectl access
    The workloads will be recreated/rolled out with the new volume configuration; expect pod restarts as part of this change.
  5. Confirm there are no remaining hostPath volumes in non‑system namespaces
    Run on: any machine with kubectl access
    Compliance is achieved when the output is either a single line is_compliant=true or no lines contain is_compliant=false.
On any machine with kubectl access:
  1. Identify noncompliant Pods (and their controllers)
  1. For each violating controller (Deployment, DaemonSet, StatefulSet, Job, etc.), edit the manifest to remove hostPath volumes and replace them with emptyDir, a PersistentVolumeClaim, or another non-hostPath type.
Example: patch a Deployment to replace a hostPath with emptyDir (adjust names, namespace, volume names as needed):
If you use manifests in Git or files, update them and apply declaratively:
  1. For standalone Pods (no controller ownerReference), recreate them without hostPath:
a. Export, edit, and save as a manifest:
Edit /absolute/path/to/example-pod.yaml:
  • Remove any hostPath: blocks under spec.volumes.
  • Adjust containers’ volumeMounts to use the new volume types.
b. Delete and recreate the Pod:
  1. Verification (same command as audit)