Skip to content

Replace host Docker socket bind with rootless docker-in-docker#77

Open
YuseiIto wants to merge 1 commit into
mainfrom
claude/dazzling-brown-ac2k7j
Open

Replace host Docker socket bind with rootless docker-in-docker#77
YuseiIto wants to merge 1 commit into
mainfrom
claude/dazzling-brown-ac2k7j

Conversation

@YuseiIto

@YuseiIto YuseiIto commented Jun 13, 2026

Copy link
Copy Markdown
Owner

背景

  • devcontainerでは、/var/run/docker.sock を bind マウントしていた
  • これは、コンテナ内プロセスがホストの Docker デーモンをフル制御できることを意味し、--privileged コンテナ起動やホスト FS マウント経由で 実質ホスト root へ昇格可能な典型的エスカレーション経路。

対応: rootless docker-in-docker

ホスト socket の共有をやめ、コンテナの user namespace 内で動く rootless Docker デーモンに置き換える。これでホスト root への経路を断ちつつ Docker は引き続き利用可能。

  • mitamae/cookbooks/docker/default.rb: Debian/Ubuntu 分岐に docker-ce-rootless-extras と rootless 前提パッケージ(uidmap, fuse-overlayfs, slirp4netns, dbus-user-session)を追加。
  • .devcontainer/start-rootless-docker.sh: per-user runtime socket 上で dockerd-rootless.sh を起動。rootless ツール不在時は no-op で コンテナ起動をブロックしない
  • .devcontainer/devcontainer.json: host socket マウントを削除し、DOCKER_HOST を rootless socket に向け、UID を固定、postStartCommand で起動スクリプトを実行。
  • ~/.ssh の readonly bind マウントはレビュー通り維持。

CI への影響

test.yaml の devcontainer ジョブは prebuild イメージ bamboo-latest(rootless extras 未導入)を pull するため、起動スクリプトは dockerd-rootless.sh 不在を検知してスキップ → 起動は成功。本 PR が main にマージされ build.yaml でイメージが再ビルドされると、以降の devcontainer セッションで rootless デーモンが実際に有効化される。

確認

  • rubocop: 100 files inspected, no offenses
  • shellcheck (新規スクリプト): pass

https://claude.ai/code/session_01AA3kErMVaeCYEX81JNdwXx


Generated by Claude Code

Bind-mounting /var/run/docker.sock gave the dev container full control of
the host Docker daemon, which is effectively host root (it can start a
privileged container or mount the host filesystem). A container compromise
therefore escalated straight to the host.

Remove the host socket mount and run a rootless Docker daemon inside the
container instead, so Docker stays available without the host-root path:

- docker cookbook installs docker-ce-rootless-extras and the rootless
  prerequisites (uidmap, fuse-overlayfs, slirp4netns, dbus-user-session)
  on Debian/Ubuntu.
- .devcontainer/start-rootless-docker.sh starts dockerd-rootless.sh on the
  per-user runtime socket; it no-ops when the rootless tooling is absent so
  it never blocks container startup.
- devcontainer.json drops the socket mount, points DOCKER_HOST at the
  rootless socket, pins the user UID, and runs the start script via
  postStartCommand.
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.

2 participants