A host-path mount maps a directory or file from the host into a container (Docker -v /host/path:/in/container, Kubernetes hostPath volume). It is useful for sharing data, but mounting a sensitive path lets a compromised container read host secrets or write to host-controlled locations and escape to the node. Mounting /, /etc, /var/run/docker.sock, or a writable system directory effectively breaks isolation. Prefer named volumes and, in Kubernetes, block hostPath with policy.
What a host-path mount is
A host-path mount makes a path on the host appear inside the container. In Docker that is -v /host/dir:/container/dir; in Kubernetes it is a `hostPath` volume.
The mount is as powerful as the path it exposes and the permissions it grants. A read-only mount of a harmless data directory is fine. A mount of a sensitive or writable host location gives the container a foothold on the host itself.
The abuse and payload
A dangerous mount turns a container compromise into a host compromise:
- Mounting host root or
/etc: read/etc/shadow, SSH keys, or cloud credentials; with write access, add a root user or a cron job on the host. - Mounting a writable system path (for example a host
binor a kubelet directory): drop a binary the host will execute. - Mounting
/var/run/docker.sock: full daemon control (see the Docker socket). - Writing to
/host/etc/cron.d/to get root code execution on the node.
Documented techniques shown for defenders.
How to defend
- Avoid hostPath for application workloads. Use named volumes, CSI drivers, or cloud storage instead.
- Never mount sensitive host paths (
/,/etc,/var/run, system binaries) into containers. - Mount read-only when a mount is unavoidable, and scope it to the narrowest possible directory.
- In Kubernetes, block hostPath with Pod Security Standards and admission control (or allow-list specific safe paths).
- Scan manifests for hostPath volumes and risky
-vmounts.
References
- [1]Kubernetes docs: Volumes (hostPath)(Kubernetes)
- [2]NIST SP 800-190 Application Container Security Guide(NIST)
- [3]MITRE ATT&CK: Containers Matrix(MITRE)