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
| Need | Prefer |
|---|---|
| Persistent storage on a node | A local PersistentVolume, as the docs suggest |
| Scratch space | An ephemeral volume type |
| Config files | ConfigMap or Secret volumes |
| Node log shipping or monitoring agents | hostPath, 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
- Mount a specific directory, never the root or a runtime socket path.
- Set
readOnly: trueon the mount. - Set the optional type field, for example Directory or Socket, so the mount is checked before use.
- Put these workloads in a namespace with its own, narrower policy, and review who can create pods there.
- 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.