Safeguard
Security Guides•

Is it safe to mount hostPath volumes in Kubernetes pods?

Usually not. Kubernetes documents many security risks with hostPath volumes, and the Baseline standard forbids them. Safer options and a rule to enforce.

Safeguard Security Team
3 min read

Usually not. The Kubernetes documentation warns that hostPath volumes present many security risks and should be avoided if possible. They can expose kubelet credentials or the container runtime socket, which can be used for container escape. The Baseline Pod Security Standard forbids them. If you must use one, restrict the path and mount it read only.

What hostPath is

A hostPath volume mounts a file or directory from the node's filesystem into a pod. The documentation calls it a powerful escape hatch that most pods do not need.

Why it is risky

The documentation lists several reasons:

  • Access to the host filesystem can expose privileged system credentials, such as the kubelet's, or privileged APIs, such as the container runtime socket.
  • Those can then be used to escape the container or attack other parts of the cluster.
  • Restricting paths through admission only works if you also require read only mounts. A read write mount of any host path by an untrusted pod may let its containers subvert the restriction.
  • Pods built from the same template can behave differently on different nodes, because the files on each node differ.

Safer options

NeedPrefer
Persistent storage on a nodeA local PersistentVolume, as the docs suggest
Scratch spaceAn ephemeral volume type
Config filesConfigMap or Secret volumes
Node log shipping or monitoring agentshostPath, read only, narrow path, in a restricted namespace

The Restricted standard allows only a defined list of volume types, including configMap, csi, downwardAPI, emptyDir, ephemeral, persistentVolumeClaim, projected and secret. hostPath is not on that list.

If you really need it

  1. Mount a specific directory, never the root or a runtime socket path.
  2. Set readOnly: true on the mount.
  3. Set the optional type field, for example Directory or Socket, so the mount is checked before use.
  4. Put these workloads in a namespace with its own, narrower policy, and review who can create pods there.
  5. Log and alert on new pods that use hostPath.

Enforcing it

The Pod Security Admission controller does this at the Baseline level. A custom admission policy can also reject it. Adapted from the pattern the Kubernetes docs show for another volume type, a CEL expression looks like this:

!has(object.spec.volumes) || !object.spec.volumes.exists(v, has(v.hostPath))

Try it in audit mode first. See rolling out admission policy with warn and audit first.

Quick check

Is a read only hostPath mount safe?

Safer, but not safe. The docs say to take care whether mounts are read only or read write, because host files can still expose credentials or sockets.

What does the Baseline standard say?

HostPath volumes must be forbidden. The allowed value is undefined.

Safeguard runs policies and gates on pull requests, so a failed rule can hold a merge, and its dependency and SBOM scanning covers the packages your infrastructure code pulls in. You can try a free scan at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.