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 all non-system pods using hostPath (any machine with kubectl access):
  2. For each non-compliant pod, identify its managing controller (any machine with kubectl access). Replace NAMESPACE and OWNER_NAME as needed:
    If .ownerReferences is empty, you must edit the Pod manifest source in your own deployment process; do not edit live pods directly as they are not persistent.
  3. Export the controller manifest that creates the offending pods (any machine with kubectl access). Use the kind/name from ownerReferences, for example:
    • Deployment:
    • StatefulSet:
    • DaemonSet:
  4. Edit the exported manifest locally to remove hostPath volumes and use safer alternatives (local file edit on your workstation):
    • In spec.template.spec.volumes[], delete any entries that contain hostPath:.
    • Update corresponding spec.template.spec.containers[].volumeMounts[] to either:
      • Remove the mount completely, or
      • Point to a replacement volume, such as:
    Save the file.
  5. Apply the updated controller manifest so new pods are created without hostPath (any machine with kubectl access):
    Then, force recreation of existing pods that were using hostPath:
  6. Verification (any machine with kubectl access): rerun the audit and confirm all remaining rows show is_compliant=true and none have hostPaths=:
On any machine with kubectl access:
  1. Identify Pods using hostPath (and their controllers)
  1. For each affected workload, edit the owning object (Deployment, StatefulSet, DaemonSet, etc.) to remove hostPath and use a safer volume type such as emptyDir or a PersistentVolumeClaim.
Example: replace a hostPath volume with emptyDir in a Deployment.
Edit /tmp/deploy-no-hostpath.yaml:
  • In .spec.template.spec.volumes[], remove entries like:
  • Replace with:
  • Ensure containers’ volumeMounts still reference name: data only (no change usually needed).
Apply the updated manifest:
  1. For standalone Pods not managed by a controller, recreate them from a manifest without hostPath:
Edit /tmp/pod-no-hostpath.yaml:
  • Remove metadata.uid, metadata.resourceVersion, metadata.creationTimestamp, metadata.ownerReferences, status fields.
  • In .spec.volumes[], delete hostPath volumes and replace with emptyDir or a PVC-backed volume, for example:
Delete and recreate the Pod:
  1. Verification (same machine with kubectl access)