From de6fa1659c231bcf46c74130b428801ee7eb5df6 Mon Sep 17 00:00:00 2001 From: bchanot Date: Fri, 9 Oct 2026 00:28:51 +0200 Subject: [PATCH] feat(install): rootless Docker offer disables the rootful daemon first docker.service + docker.socket disabled and /var/run/docker.sock removed before dockerd-rootless-setuptool.sh install, as the docs recommend; skipped when no rootful unit exists. --- .claude/memory/journal.md | 2 +- .claude/tasks/TODO.md | 2 +- README.md | 2 +- install.sh | 11 ++++++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index cf73e6c..01ce8d0 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -125,4 +125,4 @@ Done: choose_macos_shell default bash → zsh (Enter, no tty, unknown value). Fo Done: `gitconfig` template `[gitflow] autopush = @AUTOPUSH@` + fixed `core.hooksPath = ~/.claude/githooks`; install.sh `resolve_autopush` (existing ~/.gitconfig value via sed → `DOTFILES_GITFLOW_AUTOPUSH` strict, bad value aborts → prompt re-asks exact true/false, Enter = true → true), `render_gitconfig` fail-closed (non-boolean / leaked placeholder = nothing written). Found by challenge: install.sh:688 passed the repo bashrc TEMPLATE to deploy_gitconfig → every install wrote `name = @USER@`; fixed, identity passed directly. `shopt -u patsub_replacement` (bash ≥ 5.2 `&` in names). Oracle harness `.claude/tasks/contracts/check-autopush-render.sh` (12 cases, scratch HOMEs, zero `git config`: that command family is denied to the session). 3 challengers + 1 confirm, verifier ECARTS(1) → CONFORME, security PASS (MEDIUM noted: newline in IDENTITY_* env injects gitconfig lines, pre-existing for rc too). Code commit 9901ec5 on feature/gitconfig-autopush; merge on user signal. ## 2026-10-09 — rootless Docker offered at install -Done: `offer_docker_rootless()` (uidmap/dbus-user-session/slirp4netns/docker-ce-rootless-extras, `dockerd-rootless-setuptool.sh install` no --force, enable-linger, rootful daemon untouched), extras in install_docker list, bashrc-linux exports DOCKER_HOST only when the user socket exists (no PATH line: apt variant puts the tool in /usr/bin, not ~/bin). README step 16. Stub harness 4 cases + snippet with/without socket OK, shellcheck clean. Branch feature/docker-rootless, not merged. Machine state: rootless already set up by hand, rootful daemon still enabled, ~/.bashrc has a hardcoded uid 1000 DOCKER_HOST line (redeploy replaces it). +Done: `offer_docker_rootless()` (uidmap/dbus-user-session/slirp4netns/docker-ce-rootless-extras, `dockerd-rootless-setuptool.sh install` no --force, enable-linger, rootful daemon disabled first as the docs recommend, user asked for it), extras in install_docker list, bashrc-linux exports DOCKER_HOST only when the user socket exists (no PATH line: apt variant puts the tool in /usr/bin, not ~/bin). README step 16. Stub harness 4 cases + snippet with/without socket OK, shellcheck clean. Branch feature/docker-rootless, not merged. Machine state: rootless already set up by hand, rootful daemon still enabled, ~/.bashrc has a hardcoded uid 1000 DOCKER_HOST line (redeploy replaces it). diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 546e063..cf0a984 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -144,7 +144,7 @@ Branch: feature/gitconfig-autopush (off develop). Plan: .claude/tasks/plans/2026 Branch: feature/docker-rootless (off develop). Mirrors the manual setup done on this machine (docs.docker.com/engine/security/rootless, apt variant: setuptool lives in /usr/bin, not ~/bin). - [x] install.sh: `docker-ce-rootless-extras` in the install_docker package list -- [x] install.sh: offer_docker_rootless() — uidmap/dbus-user-session/slirp4netns + extras, setuptool install (no --force), enable-linger; rootful daemon left as is +- [x] install.sh: offer_docker_rootless() — uidmap/dbus-user-session/slirp4netns + extras, setuptool install (no --force), enable-linger; rootful daemon disabled first - [x] bash/bashrc-linux: DOCKER_HOST exported only when the rootless socket exists (no PATH line: /usr/bin already on PATH) - [x] README.md: table row, step 2 packages, packages list, new offer step - [x] shellcheck + bash -n; commit on the feature branch. No finish without explicit signal. diff --git a/README.md b/README.md index 258914e..d55837a 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ What it does: 13. On Linux, installs the **security baseline**, always, no prompt: **fail2ban** (+ `nftables`) with `etc/fail2ban/jail.d/local.conf` (sshd jail reading the journal, bans the offending IP on every port so the SSH port does not matter, 5 failures in 10 min → 1 h ban, loopback and private LAN ranges never banned); **unattended-upgrades** enabled through `etc/apt/apt.conf.d/20auto-upgrades`; and the **sshd drop-in** `etc/ssh/sshd_config.d/20-hardening.conf` (`PermitRootLogin no`, `MaxAuthTries 3`, `LoginGraceTime 20`), checked with `sshd -t` and removed again if sshd rejects it, then `reload ssh`. Authentication methods, port and user lists are left as they are. 14. On Linux, at the very end, **offers** (`[y/N]`, skipped when no terminal is attached) to move **`/tmp` to disk**: Ubuntu mounts `/tmp` as a RAM-backed tmpfs capped at 50% of RAM, which agent runs fill, halving the RAM and breaking every shell with "No space left on device". Accepting masks `tmp.mount` and installs `etc/tmpfiles.d/tmp.conf` (wipe at boot, 10-day purge). Effective at the next reboot. 15. On Linux, at the very end, **offers** to keep **SSH reachable under memory pressure**: installs the `ssh.service` drop-in (`OOMScoreAdjust=-1000`, `MemoryMin=256M`) and `earlyoom` with `etc/default/earlyoom` (kills the largest process, `node`/`java` first and never `sshd`, once free RAM and swap both drop under 10%). Restarting `ssh` keeps open sessions. Note: `MemoryMin` protects the sshd daemon only; login sessions live in `user.slice`, so no setting can reserve RAM for a future shell. earlyoom acting in time is the real protection. -16. On Linux, at the very end, **offers** to set up **rootless Docker**: installs `uidmap dbus-user-session slirp4netns docker-ce-rootless-extras`, runs `dockerd-rootless-setuptool.sh install` as you (the apt package puts it in `/usr/bin`, so no `PATH` line is needed, unlike the `~/bin` install from `get.docker.com/rootless`), then `loginctl enable-linger` so the user daemon starts at boot. The tool creates `~/.config/systemd/user/docker.service` and switches the CLI to the `rootless` context; the deployed bashrc exports `DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock` whenever that socket exists, for tools that ignore contexts. The rootful daemon is not touched: both coexist, but the tool refuses to run while `/var/run/docker.sock` is writable by your user (docker group), in which case disable it first (`sudo systemctl disable --now docker.service docker.socket`). Needs `/etc/subuid` and `/etc/subgid` entries for the user (Ubuntu adds them at user creation). +16. On Linux, at the very end, **offers** to set up **rootless Docker**: installs `uidmap dbus-user-session slirp4netns docker-ce-rootless-extras`, runs `dockerd-rootless-setuptool.sh install` as you (the apt package puts it in `/usr/bin`, so no `PATH` line is needed, unlike the `~/bin` install from `get.docker.com/rootless`), then `loginctl enable-linger` so the user daemon starts at boot. The tool creates `~/.config/systemd/user/docker.service` and switches the CLI to the `rootless` context; the deployed bashrc exports `DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock` whenever that socket exists, for tools that ignore contexts. The rootful daemon is disabled first (`systemctl disable --now docker.service docker.socket`, socket removed), as the docs recommend: `docker` then only talks to your user daemon. Needs `/etc/subuid` and `/etc/subgid` entries for the user (Ubuntu adds them at user creation). ### Packages installed (apt) diff --git a/install.sh b/install.sh index 28b544b..acf070c 100755 --- a/install.sh +++ b/install.sh @@ -173,8 +173,8 @@ offer_cloudpex() { # not needed (that line is for the ~/bin install from get.docker.com/rootless). The # setup tool writes ~/.config/systemd/user/docker.service, starts it and switches the # CLI to the "rootless" context; linger keeps the daemon up without a login session. -# The rootful daemon is left as it is: the two coexist (the tool only refuses when -# /var/run/docker.sock is writable by the user, i.e. docker group membership). +# The rootful daemon is disabled first, as the docs recommend: one daemon, and the +# tool refuses to run while /var/run/docker.sock is writable by the user anyway. # Idempotent: apt and the tool both skip what exists. Ubuntu-only (Docker apt repo). offer_docker_rootless() { confirm "Set up rootless Docker for $(id -un) (daemon runs as your user)?" || return 0 @@ -182,8 +182,13 @@ offer_docker_rootless() { echo "docker-ce-rootless-extras not installable (Docker apt repo missing?) — skipping" >&2 return 0 fi + if systemctl cat docker.service >/dev/null 2>&1; then + echo "Disabling the rootful Docker daemon (docker.service, docker.socket)" + sudo systemctl disable --now docker.service docker.socket + sudo rm -f /var/run/docker.sock + fi if ! dockerd-rootless-setuptool.sh install; then - echo "rootless Docker setup failed — see the tool's output above, rootful Docker unchanged" >&2 + echo "rootless Docker setup failed — see the tool's output above (rootful daemon is disabled)" >&2 return 0 fi sudo loginctl enable-linger "$(id -un)"