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. List all non-system pods that mount hostPath volumes (run on any machine with kubectl access):
  2. For each non-compliant pod, identify the owning object (Deployment/StatefulSet/DaemonSet/Job, etc.) from the owner= field, then export its manifest (example for a Deployment; run on any machine with kubectl access):
  3. Edit the saved manifest to remove hostPath volumes and use compliant alternatives (run on any machine with kubectl access):
    • In spec.template.spec.volumes, delete each entry that contains hostPath:.
    • Add replacement volumes such as:
      • emptyDir: {} for ephemeral storage, or
      • a persistentVolumeClaim: that references a suitable PVC, or
      • a projected/secret/configMap volume as appropriate.
    • Update spec.template.spec.containers[*].volumeMounts to reference the new volume names and paths instead of the removed hostPath volumes. Save the file when done.
  4. Apply the updated manifest and let Kubernetes recreate pods without hostPath (run on any machine with kubectl access):
  5. For any standalone Pods (no controller owner) that use hostPath, delete and recreate them from corrected manifests that do not define hostPath volumes (run on any machine with kubectl access):
  6. Verify no remaining non-exempt pods use hostPath volumes (run on any machine with kubectl access):
    The cluster is compliant when the command outputs only is_compliant=true.
On any machine with kubectl access:
  1. Identify noncompliant pods (excluding AKS control namespaces):
  1. For each offending pod, edit the owning workload (Deployment, StatefulSet, DaemonSet, Job, etc.) to remove hostPath volumes and use compliant alternatives.
Example: replace a hostPath with emptyDir in a Deployment.a. Fetch the existing Deployment manifest:
b. In my-app-deploy.yaml, find and change:
to, for example, an emptyDir:
Or to a PersistentVolumeClaim you have created:
c. Apply the updated manifest:
  1. For standalone Pods defined by manifests, edit the Pod YAML similarly: remove each hostPath under .spec.volumes[] and replace with emptyDir, a PVC, or another non-hostPath volume type, then re-create the Pod:
  1. Verification (on any machine with kubectl access):