Skip to content

Lesson 8 of 14 · 14m

Shared Namespaces and Bad Mounts

--pid=host, --network=host, hostPath mounts, and writable /proc or cgroupfs each delete a specific wall, including the loopback-is-private assumption.

Host modes delete the boundary

Each namespace flag is a wall built by clone(2). Docker ships flags that build no wall at all: --pid=host, --network=host, --ipc=host. Kubernetes ships the same ones spelled hostPID, hostNetwork, hostIPC. Setting one does not weaken isolation; it means that namespace was never created — the container's /proc/<pid>/ns/* links have the host's inode numbers, provably, with readlink.

--pid=host hands the container the host's process table. /proc/<pid>/cmdline shows every command line on the node; /proc/<pid>/environ shows environment variables — the place databases URLs and API tokens live. Processes run as different users, but a root-in-container reading a same-user process's environ succeeds, and a lot of daemons run as root. Add CAP_SYS_PTRACE and it's attach-and-inject into arbitrary host processes. The legitimate uses are monitoring agents — node-exporter-style tools that genuinely need host procfs — and that legitimacy is why the flag survives.

--network=host merges the stacks. The container binds any port on any interface and reaches every service bound to loopback. It also changes sniffing scope: it sees the host's interfaces and, with NET_RAW — which the default capability set includes — can craft raw packets on the node's segment. And it was the precondition for CVE-2020-15257, the containerd-shim abstract-socket bug: the sockets lived in the host net namespace, so host-net containers could reach them without any mount at all.

--ipc=host shares SysV shared memory and message queues. Less glamorous, real anyway: a container reading host shm segments reads whatever processes put there.

The mounts that are doors

Bind mounts and hostPath are holes drilled on purpose — the question is which ones become doors:

  • -v /:/host or hostPath: "/". Full stop, the host filesystem is inside. This is the "why bother with exploits" configuration.
  • /proc mounted writable. /proc/sys/kernel/core_pattern accepts a |/path/to/script handler — the kernel runs that script as root when a process core-dumps. Write it, crash something trivial, collect host execution. A documented escape primitive that requires nothing but the mount.
  • /sys/fs/cgroup writable. The release_agent chain again — writable cgroupfs plus any task you can spawn and kill.
  • Kubelet credentials. hostPath onto /var/lib/kubelet/pki or the kubelet config leaks node identity: the kubelet's client certs authenticate to the API server as the node, and what a node identity can do escalates further — Siloscape demonstrated CSR-based privilege escalation on managed clusters.
  • mountPropagation: Bidirectional on a volume. Mounts created inside the container propagate to the host's tree — you can mount a tmpfs over a host path, or leave host-visible artifacts, by mounting into a bidirectional mount. Almost nothing needs it; it exists for CSI driver use cases, not applications.

The loopback trap, one more time

It bears repeating because it is the most exploited non-exploit: --network=host plus "the service only listens on localhost" equals no authentication. Prometheus exporters, Redis, Docker stats endpoints, local admin consoles — every loopback-bound service becomes reachable from every host-network container. Audits find this combination weekly. If the service requires "same machine" semantics, the correct primitive is a Unix socket with file permissions or mTLS, not a TCP port on 127.0.0.1.

What to actually do

Inventory by flag, not by vibes:

docker inspect --format '{{.HostConfig.PidMode}} {{.HostConfig.NetworkMode}} {{.HostConfig.IpcMode}}' <ctr>
kubectl get pods -o json | jq '.. | .hostPID?, .hostNetwork?, .hostIPC?, .hostPath?'

Every host mode is a wall that was never built; every hostPath is a hole someone drilled. For host-network monitoring agents, prefer the minimal shape — read-only procfs mount, dropped caps, no-write tmpfs — over the full stack. And treat "needed host networking" as a design smell worth one hard question: which specific thing does it reach that a sidecar or a real interface couldn't?

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.