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. On any machine with kubectl access, list all non-system pods using hostPath and identify owners (Deployments, DaemonSets, etc.):
  2. For each affected pod, get the full manifest of its controller (example for a Deployment; run on any machine with kubectl access):
    For other controllers, change deploy to statefulset, daemonset, job, or cronjob as appropriate.
  3. Edit the saved manifest to remove hostPath volumes and references (any machine with kubectl access):
    • Open the file:
    • Under spec.template.spec.volumes, delete any entries containing hostPath:, including the path field.
    • Under spec.template.spec.containers[].volumeMounts, delete mounts that reference the removed volume names.
    • Optionally add safer replacements such as emptyDir: {} or PVC-backed volumes according to your application’s storage requirements.
  4. Apply the updated manifest (any machine with kubectl access):
    Confirm old pods are being replaced and new pods are running:
  5. For any stand-alone Pod objects (no controller ownerReference), edit them in place to remove hostPath (any machine with kubectl access):
  6. Verify no non-system pods use hostPath (any machine with kubectl access):
    Compliance is achieved when the output is exactly:
    is_compliant=true
On any machine with kubectl access:
  1. Identify the offending pod and workload
Find the namespace and pod reported in the finding, then see what owns it:
  • If ownerReferences is empty: it’s a naked Pod; you will edit/recreate the Pod.
  • If it shows a controller (Deployment, StatefulSet, DaemonSet, etc.): you will edit that controller, not the pod.
  1. Export the current spec
For a naked Pod (no controller):
For a controller (example: Deployment; adjust kind/name as needed):
  1. Edit the manifest to remove hostPath
Open the saved YAML file and in the pod template:
  • Under spec.volumes, delete any entries that contain hostPath:.
  • Under each container’s volumeMounts, delete mounts that refer to those deleted volumes.
Example of what to remove:
And its mount:
If storage is still needed, replace with one of:
  • emptyDir:
  • A PersistentVolumeClaim (assuming it already exists):
Then mount app-data instead of the hostPath volume in volumeMounts.
  1. Apply the updated manifest
For a naked Pod, delete and recreate (Pods cannot be updated in place):
For a controller (example: Deployment):
Kubernetes will roll out new pods without the hostPath volumes.
  1. Verification
On any machine with kubectl access, rerun: