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
HighAddress
SecurityCompliance Standards
- Cloudanix Best Practice
Triage and Remediation
- Remediation
Remediation
Manual Steps
Manual Steps
-
On any machine with kubectl access, list all pods using hostPath volumes (excluding system namespaces) and note which are controlled by higher-level resources (Deployment/DaemonSet/StatefulSet/Job/etc.):
-
For each offending pod that is controlled by a workload resource (e.g., Deployment), edit the controller manifest and remove/replace the
hostPathvolumes. Example for a Deployment:In the editor:- Under
spec.template.spec.volumes, delete any entries containinghostPath:or replace them withemptyDir: {}or a PersistentVolume/PVC reference as appropriate. - Under
spec.template.spec.containers[].volumeMounts, remove the correspondingname:entries or adjust them to point to the new volume type. Save and exit; Kubernetes will roll out new pods without hostPath.
- Under
-
For pods created directly (no controller) using hostPath, export, modify, and reapply their manifests:
Edit
/tmp/pod-with-hostpath.yaml:- Remove the entire
metadata:block fieldsresourceVersion,uid,selfLink,creationTimestamp,status, and anyownerReferences. - Under
spec.volumes, remove or replace any entries containinghostPath:withemptyDir: {}or a PV/PVC. - Update
spec.containers[].volumeMountsto remove or point away from those volume names.
- Remove the entire
-
For workloads that legitimately need node storage, create and use PersistentVolumes and PersistentVolumeClaims instead of hostPath (on any machine with kubectl access). Example (adapt for your case) to create a PVC and reference it from the workload:
Then in the controller manifest (
kubectl -n NAMESPACE edit deployment CONTROLLER_NAME), use: -
For any third-party or GKE-managed add-ons that appear to use hostPath, review their documentation and only modify them if they are not required or if the vendor provides a hostPath-free configuration. If you must keep a hostPath-based add-on, document the risk and namespace, labels, and pod names for risk acceptance:
-
Verification (on any machine with kubectl access): rerun the audit command and confirm there are no lines with
is_compliant=falseand nohostPaths=fields:The cluster is compliant when the output is eitheris_compliant=trueonly, or all listed pods showis_compliant=trueand nohostPaths=.
Using kubectl
Using kubectl
On any machine with kubectl access:For each non‑compliant line, note:Edit Apply the updated manifest:Repeat the same pattern for other controller types as applicable:Edit
- Identify offending pods and their owners
ns=<namespace>owner=<Kind>/<namespace>/<name>/...if present; otherwise treat it as a standalone Pod.
- Edit the controller manifest to remove
hostPath
/tmp/deploy-no-hostpath.yaml:- In
spec.template.spec.volumes, delete any entries withhostPath:. - In
spec.template.spec.containers[].volumeMounts, remove mounts that referenced thosehostPathvolumes. - If needed, add a safer volume type, for example:
- ReplicaSet:
kubectl -n NAMESPACE get rs NAME -o yaml > /tmp/rs-no-hostpath.yaml - StatefulSet:
kubectl -n NAMESPACE get sts NAME -o yaml > /tmp/sts-no-hostpath.yaml - DaemonSet:
kubectl -n NAMESPACE get ds NAME -o yaml > /tmp/ds-no-hostpath.yaml - Job/CronJob:
kubectl -n NAMESPACE get job|cronjob NAME -o yaml > /tmp/job-no-hostpath.yaml
hostPath volumes and corresponding mounts, replace with emptyDir, PersistentVolumeClaims, or projected volumes, and:- For standalone Pods (no controller)
hostPath:/tmp/pod-no-hostpath.yaml to:- Remove
hostPathentries underspec.volumes. - Remove corresponding
volumeMounts. - Optionally add safer volume types as above.
- Verification
is_compliant=true only, or that no lines show hostPaths=:Automation
Automation

