Skip to main content

Kyverno Blocks docker.sock, Misses containerd.sock

Critical severityKubernetes About 20 minutes to fix

Overview

A hostPath denylist written for Docker-era clusters checks for /var/run/docker.sock by exact string but never learned the containerd or CRI-O equivalents, so migrating the runtime silently reopens the same node-root escape the policy was written to close.

At a glance

Symptom
A pod requests a hostPath mount at /run/containerd/containerd.sock or /var/run/crio/crio.sock after a CRI migration, evading the outdated policy.
Likely cause
A hostPath denylist policy matches only the literal string /var/run/docker.sock and ignores containerd or CRI-O socket paths.
Impact
Direct containerd or CRI-O API access lets an attacker spawn a new container with host namespaces and root filesystem access, compromising the node and its scheduled workloads.
Verification signal
Re-run the detection test and a controlled negative-path test.
Safe correction
Replace literal socket path denylists with regex-based ValidatingAdmissionPolicy or Kyverno rules covering all known CRI socket variants, and restrict socket mounts to dedicated node DaemonSets.
Rollback or recovery
Restore the exported configuration if the new control blocks required production traffic, then narrow the policy before redeployment.

The Trap

Denylisting runtime-socket hostPath mounts by their literal path string, rather than by regex or by capability class, in Kyverno, OPA Gatekeeper, or PodSecurity Admission exemptions.

The Default State

Most published Kyverno and Gatekeeper policy packs for blocking dangerous hostPath mounts were written when Docker was the default CRI and contain a hard-coded string match against /var/run/docker.sock. When a cluster migrates to containerd or CRI-O (as most clusters running Kubernetes 1.24+ have, following dockershim removal), the actual runtime socket moves to /run/containerd/containerd.sock or /var/run/crio/crio.sock.

Nobody updates the policy, because the CI pipeline that validated it against docker.sock still passes. The denylist author assumed the socket path is the threat; the socket path is just one instance of it.

The Blast Radius

A pod that requests a hostPath volume at /run/containerd/containerd.sock is admitted cleanly because the string never matches the policy’s blocked-paths array. Inside the container, a containerd gRPC client (or a statically compiled ctr binary) talks to that socket directly, bypassing Docker entirely.

From there an attacker calls the containerd Containers and Tasks services to create and start a new container with host PID, host network, and a bind mount of the node’s root filesystem — no privileged: true flag required, because the exploit runs through the runtime API, not through kernel capabilities the pod spec declares.

PodSecurity Admission does not inspect hostPath target strings at all: its baseline and restricted levels forbid every hostPath volume, so the gap is in namespaces running at the privileged level or exempted, and most clusters exempt kube-system or CI namespaces anyway.

Once the runtime socket is reachable, the attacker owns the node: kubelet client certs, every Secret volume mounted into pods scheduled there, and lateral movement into the API server using the kubelet’s node credentials and any service account tokens mounted on that node.

The Lead Mechanic Fix

Replace literal path matching with a Kyverno validate rule whose deny condition applies regex_match() to each spec.volumes[].hostPath.path (Kyverno patterns support only * and ? wildcards, not regex), using ^/(var/)?run/(docker|containerd|crio|dockershim)(/.*)?\.sock$; note that mounting a parent directory such as /run or /run/containerd exposes the socket just as well, so better still, deny all hostPath volumes outside an explicit allowlist enforced via a ValidatingAdmissionPolicy CEL expression that checks every volume’s hostPath.path against a maintained regex constant, not a per-runtime string list.

Mount CRI sockets only inside node-level DaemonSets running under a dedicated ServiceAccount with no API server RBAC beyond what the CNI or CSI driver needs, isolate that DaemonSet in its own namespace (it needs the privileged PodSecurity level, since baseline and restricted forbid hostPath), and keep every other namespace at baseline or restricted with no exemption.

Audit existing clusters with kubectl get pods -A -o json | jq for any hostPath.path containing ‘.sock’ to find current exposure before writing the rule.

3

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.

Control to implement

Replace literal socket path denylists with regex-based ValidatingAdmissionPolicy or Kyverno rules covering all known CRI socket variants, and restrict socket mounts to dedicated node DaemonSets.

Validate the vendor-specific syntax in official documentation before applying it.

4

Verify, 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.

The KBY Brief

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.

After remediation

Further reading stays below the corrective workflow and is selected by platform, category and shared technical keywords.

More from KBY that goes with this config trap.

Discover more

Connected KBY resources

Lexicon Definitions