Skip to content

fix(k8s): make Docker-in-Docker actually work — userns-rootful dockerd, proven-on-cluster spec, Helm CA - #900

Open
ulbi wants to merge 1 commit into
jonwiggins:mainfrom
ulbi:work
Open

ulbi wants to merge 1 commit into
jonwiggins:mainfrom
ulbi:work

Conversation

@ulbi

@ulbi ulbi commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Problem

The shipped Docker-in-Docker (dockerInDocker on a repo) never gets dockerd up on kernels/containerds that restrict nested user namespaces. Measured failure chain on such a cluster (each step isolated in dockerd/runc logs before its fix):

  1. fuse-overlayfs + SYS_CHROOT only → failed to create NAT chain DOCKER: iptables … Permission denied (you must be root)
    • NET_ADMIN → Enabling IP forwarding failed: open /proc/sys/net/ipv4/ip_forward: read-only file system
  2. rootless ({"rootless": true} requires the RootlessKit API socket, which never exists here)
  3. with writable procfs bound in → overlay2: failed to mount overlay: invalid argument inside the user namespace; vfs alone → runc dies at mkdir /sys/fs/cgroup/docker: read-only file system
  4. {"rootless": true} + vfs needs the RootlessKit /v1/info handshake (moby v29 panics without it) — so a stub serves it
  5. then pulls die at x509: certificate signed by unknown authority on TLS-inspecting networks
  6. then runc dies at unable to apply caps — Docker's default caps (NET_RAW, SETPCAP, AUDIT_WRITE, FSETID…) were missing

What this changes

  • Pod spec (dind-pod.ts): uid 0 inside a pod user namespace (hostUsers: false, runAsUser: 0), the Docker-default capability set plus SYS_ADMIN/SYS_PTRACE, seccomp/AppArmor Unconfined, tmpfs /var/lib/docker + /var/run, its own /proc/sys, vfs, rootless cgroupDriver — all in one shared DIND_POD_FIELDS, used by both bare-pod and StatefulSet paths.
  • Entrypoint (dind-entrypoint.sh): installs a CA bundle before dockerd starts; fails loudly instead of silently continuing without Docker.
  • RootlessKit stub (fakerk.py): moby v29 requires a full /v1/info (networkDriver: host, portDriver: implicit) or clients see EOF; serves only that, nothing else.
  • Helm (values.yaml + templates): new dockerInDocker.caCert renders <release>-dind-ca, sets OPTIO_DIND_CA_CONFIGMAP on the API, repo pods mount it at /etc/optio-ca; empty value = no ConfigMap, no volume, no-op.

Evidence

Full-cluster E2E (hostUsers:false pod, no host Docker involved): dockerd up under vfs+rootless stub, then from GHCR:

Unable to find image 'hello-world:latest' locally … Digest: sha256:a46257e06c82ad85242d0d38077d0a52d9896389ca60a1a59d3463db586e5fa4
hello-from-dind

(hostCA installed from the ConfigMap path; probe log ends DOCKERD-READY → pull digest → container output.)

Tests

All written first:

  • helm-unittest suites (helm/optio/tests/dind-ca-*_test.yaml): ConfigMap renders with cert / not at all when empty; env set / absent (4 tests)
  • Vitest (dind-pod.spec.test.ts, repo-pool-service.dind.test.ts, others): hardened spec asserted on both create paths; CA volume added only when env set (both bare pod + StatefulSet)
  • Shell test (images/dind-entrypoint.ca.test.sh): cert installed with bundle present; silent no-op without
  • Affected suites green (102/102 in the DinD-related files)

@ulbi
ulbi force-pushed the work branch 2 times, most recently from 856b31e to ef681ec Compare December 3, 2026 19:06
… spec, Helm-provisioned CA

Upstream's rootless DinD (fuse-overlayfs, SYS_CHROOT only) never starts
dockerd on kernels/containerd that restrict nested user namespaces: iptables
denied, /proc/sys read-only, overlay invalid in the user namespace, runc
rejected on cgroups. The spec now matches what E2E proved works on a
restrictive cluster: uid 0 in a pod user namespace, Docker's default
capability set plus SYS_ADMIN/SYS_PTRACE, Unconfined seccomp/AppArmor,
writable /proc/sys (own procfs bind via the dind.optio.io/procfs-bind
annotation), vfs storage, rootless cgroupDriver=none and a RootlessKit API
stub (images/fakerk.py) for moby v29's network driver handshake. The
preStop hook stops the run's containers and dockerd so pods don't stick
Terminating.

Behind TLS-inspecting networks the registry pull dies at x509: the chart now
takes dockerInDocker.caCert, renders it as <release>-dind-ca and points the
API at it (OPTIO_DIND_CA_CONFIGMAP); repo pods mount it at /etc/optio-ca and
the dind entrypoint installs it before dockerd starts. Without the value,
nothing renders and no volume is added.

Tests first at every layer: helm-unittest suites for ConfigMap + env (set
and empty), Vitest for the CA wiring on both bare-pod and StatefulSet paths
and the hardened DIND_POD_FIELDS, a shell test for the entrypoint's CA
install/no-op. Cluster E2E ran against debian:12-slim with only this spec:
dockerd up under vfs+rootless stub, hello-world pulled from GHCR and run.

Co-Authored-By: Claude Code <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant