Skip to content

fix(k8s): replace privileged DinD with rootless DinD - #2044

Merged
ericksoa merged 4 commits into
mainfrom
fix/rootless-dind-k8s
Apr 18, 2026
Merged

ericksoa merged 4 commits into
mainfrom
fix/rootless-dind-k8s

Conversation

@ericksoa

@ericksoa ericksoa commented Apr 17, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Replaces the privileged DinD sidecar in k8s/nemoclaw-k8s.yaml with rootless Docker-in-Docker (docker:24-dind-rootless), eliminating trivial host escape via nsenter
  • Updates all volume mount paths, socket paths, daemon config paths, and env vars for rootless operation
  • Adds rootlesskit env vars (DOCKERD_ROOTLESS_ROOTLESSKIT_NET=host, --propagation=rslave) to ensure k3s networking and mount propagation work inside the pod

Security changes

Before After
privileged: true privileged: false, UID 1000, runAsNonRoot: true
All capabilities Drop ALL, add SETUID/SETGID/SETFCAP/NET_ADMIN/NET_RAW
No seccomp Pod-level RuntimeDefault; dind Unconfined (rootlesskit requires it)
No fsGroup fsGroup: 1000 for emptyDir volume ownership

Known limitations of rootless DinD

  • overlay2 requires kernel 5.11+ (older nodes fall back to fuse-overlayfs)
  • No --net=host for inner containers
  • No privileged port binding (< 1024) inside DinD — NemoClaw uses only ports >= 1024

Test plan

  • Trigger nightly E2E suite on this branch (all jobs)
  • Verify pod starts and all containers reach Running
  • Verify host escape PoC fails: kubectl exec -it nemoclaw -c dind -- nsenter --target 1 --mount --uts --ipc --net --pid -- bash → "Operation not permitted"
  • Verify Docker connectivity from workspace: kubectl exec -it nemoclaw -c workspace -- docker info
  • Verify NemoClaw installer completes end-to-end
  • Verify inference routing through socat proxy

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Switched to rootless Docker deployment for improved security isolation, running containers as non-root with tighter capability controls and relocated Docker socket/state to user-specific locations to preserve workflows.
  • Bug Fixes
    • Improved runtime detection used during onboarding to more reliably determine local Docker status.

The DinD sidecar ran with securityContext.privileged: true, granting
full host kernel access and enabling trivial container escape via
nsenter.  Switch to rootless Docker-in-Docker to eliminate that
attack surface while preserving the nested k3s sandbox architecture.

Changes:
- Image: docker:24-dind → docker:24-dind-rootless
- Security context: privileged: true replaced with non-root UID 1000,
  drop-all capabilities, selective add (SETUID, SETGID, SETFCAP,
  NET_ADMIN, NET_RAW), Unconfined seccomp for rootlesskit user-ns setup
- Remove command override — let the rootless entrypoint handle
  dockerd-rootless.sh / rootlesskit startup
- Volume paths updated for rootless user home:
  /var/lib/docker       → /home/rootless/.local/share/docker
  /var/run              → /run/user/1000
  /etc/docker           → /home/rootless/.config/docker
- Workspace DOCKER_HOST updated to rootless socket path
- Workspace drops unused docker-config mount
- Init container writes daemon.json to rootless config path
- Pod-level: add fsGroup: 1000, RuntimeDefault seccomp baseline
- Rootlesskit env vars: DOCKERD_ROOTLESS_ROOTLESSKIT_NET=host (use
  pod network, not isolated slirp4netns) and --propagation=rslave
  (mount propagation for k3s volume mounts)

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 17, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 6fd71ab4-a03d-481d-875f-4ac0cd11002b

📥 Commits

Reviewing files that changed from the base of the PR and between 06faf5a and 95c9c37.

📒 Files selected for processing (1)
  • src/lib/onboard.ts

📝 Walkthrough

Walkthrough

Replaced privileged Docker-in-Docker with rootless DinD in the Kubernetes Pod manifest and adjusted securityContext, mounts, env vars, and sockets; plus a small robustness fix in verifyGatewayContainerRunning() coercing command output to string before trimming.

Changes

Cohort / File(s) Summary
Rootless DinD Migration
k8s/nemoclaw-k8s.yaml
Replaced docker:24-dind with docker:24-dind-rootless; added pod-level securityContext (fsGroup: 1000), set containers to run as non-root (runAsUser: 1000, runAsNonRoot: true), removed privileged, dropped capabilities then added SETUID, SETGID, SETFCAP, NET_ADMIN, NET_RAW; set seccomp to Unconfined; introduced rootlesskit env vars and moved Docker data/socket/config paths to /home/rootless and /run/user/1000; updated workspace DOCKER_HOST and adjusted init-docker-config output path and volume mounts.
Stdout Coercion Fix
src/lib/onboard.ts
In verifyGatewayContainerRunning(), coerced result.stdout with .toString() before .trim() and comparison to "true" to handle non-string stdout values more robustly while retaining existing return behavior.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I nibble bytes and tweak the sod,

rootless DinD—no longer god.
A gentle .toString() trims the fray,
sockets moved where rabbits play.
Hop, secure, and ship away!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically summarizes the main change: replacing privileged Docker-in-Docker with rootless Docker-in-Docker in Kubernetes manifests, which is the primary focus of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rootless-dind-k8s

Comment @coderabbitai help to get the list of available commands and usage tips.

@ericksoa ericksoa self-assigned this Apr 17, 2026
verifyGatewayContainerRunning() called .trim() directly on
result.stdout, but spawnSync returns a Buffer (not a string) when
no encoding option is passed.  Buffer is truthy so the || "" fallback
never fires, and Buffer has no .trim() method — causing a TypeError
on every re-onboard that hits an existing gateway container.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
ericksoa added a commit that referenced this pull request Apr 18, 2026
Squashed PR #2044 as base for socket proxy work.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
ericksoa and others added 2 commits April 18, 2026 05:41
Take main's String() wrapper over PR's .toString() since both
fix the same stdout coercion and main's landed first.
@ericksoa
ericksoa merged commit 4e6508d into main Apr 18, 2026
12 checks passed
@wscurran wscurran added the bug-fix PR fixes a bug or regression label Jun 8, 2026
@cv
cv deleted the fix/rootless-dind-k8s branch June 28, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix PR fixes a bug or regression

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants