hostPath readOnly Split Leaves docker.sock Writable
Overview
A hostPath volume has no readOnly field of its own, only path and type, and even a read-only volumeMount does not stop a process connecting to /var/run/docker.sock. Admission policies need to deny the socket path itself rather than trust readOnly settings.
At a glance
- Symptom
- An admission policy validates only the volume-level readOnly flag, admitting a pod whose volumeMount grants writable access to /var/run/docker.sock.
- Likely cause
- hostPath.readOnly set to true while the corresponding volumeMounts.readOnly is left unset or false.
- Impact
- Writable docker.sock access lets a container spawn a privileged sibling container with the host root filesystem mounted, compromising every workload on that node.
- Verification signal
- Re-run the detection test and a controlled negative-path test.
- Safe correction
- Validate both readOnly fields together in admission policy, block hostPath sockets outright, and enforce PodSecurity restricted profile cluster-wide.
- Rollback or recovery
- Restore the exported configuration if the new control blocks required production traffic, then narrow the policy before redeployment.
The Trap
The hostPath readOnly field split. A hostPath volume has only path and type; the only readOnly setting that applies is spec.containers[].volumeMounts[].readOnly. A manifest that sets spec.volumes[].hostPath.readOnly is rejected by kubectl’s default strict field validation, or, where validation is relaxed, the field is silently dropped. And even a read-only volumeMount does not stop a process connecting to a Unix socket.
The Default State
Kyverno and OPA Gatekeeper rules written to block docker.sock access can key on hostPath.readOnly, which reads intuitively as “is this path writable” but does not exist, so a rule that denies only when it is false never fires. Engineers writing manifests, and the policies auditing them, treat it as the single source of truth.
The volumeMount’s own readOnly key defaults to false when omitted, and a policy that never checks it will pass a pod straight through even when the volume-level flag says true.
The Blast Radius
A pod ships with hostPath.readOnly: true against /var/run/docker.sock, passes a Kyverno ClusterPolicy that denies only when that field is false, and gets admitted. The volumeMount omits readOnly, defaulting to writable, though readOnly: true would not help: connecting to the socket is all the Docker API needs.
Any process inside that container can now issue Docker Engine API calls over the socket: create a privileged container with the host filesystem bind-mounted at /, chroot into it, and read node-level kubelet credentials, kubeconfig files and any secrets cached in memory.
The compromise reaches every workload scheduled on that node, and the admission log shows a clean pass, so incident responders start by ruling out the exact control that failed.
The Lead Mechanic Fix
Stop relying on readOnly for sockets and deny the host path itself. In Kyverno:
validate:
message: "Use of the Docker Unix socket is not allowed."
pattern:
spec:
=(volumes):
- =(hostPath):
path: "!/var/run/docker.sock"
Add matching rules for /var/run/containerd/containerd.sock, /var/run/crio/crio.sock and their /run equivalents, since a read-only mount of any runtime socket still gives full API access. Enforce PodSecurity admission at the restricted profile cluster-wide via AdmissionConfiguration, which disallows hostPath volumes entirely rather than trusting per-field flags, and remove the exception namespace once workloads migrate to a CSI-backed runtime socket proxy with scoped RBAC instead of a raw Docker Engine bind mount.
Related reading
Apply the safer control
Before you change production
Confirm the affected scope, export the current configuration, and test the replacement control in a non-production environment first.
Fix commands and configuration
validate:
message: "Use of the Docker Unix socket is not allowed."
pattern:
spec:
=(volumes):
- =(hostPath):
path: "!/var/run/docker.sock"/var/run/containerd/containerd.sock/var/run/crio/crio.sockVerify, roll back or escalate
Verify
Re-run the detection test and a controlled negative-path test. Confirm the unsafe behaviour is blocked while approved traffic still succeeds.
Rollback
Restore the exported configuration if the new control blocks required production traffic, then narrow the policy before redeployment.
Escalate
Escalate when the blast radius is uncertain, the control cannot be tested safely, or remediation requires an outage or security exception.
Fixed? Get the next one before it hits you: The KBY Brief
Practical fixes for the systems you run, by email about twice a week. Unsubscribe at any time.
About this page
Credited to
Dates
Published
Last updated
Corrections
No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.
Was this useful?
Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.
Found this useful? Follow KBY for more like it.

