Repository navigation
feat(module): docker-rootless - rootless Docker for a dedicated non-root account - #423
Merged
Merged
Conversation
…oot account (#422) Archetype D module that installs, upgrades and removes rootless Docker for one dedicated account (DOCKER_ROOTLESS_USER, default 'rootless'): uidmap and docker-ce-rootless-extras (only removed again if this module installed them), subuid/subgid, linger, optional Delegate drop-in for user@UID.service, dockerd-rootless-setuptool, and a user docker.service drop-in that waits for docker.sock. Advisory AppArmor userns and NVIDIA CDI checks. remove reverses the whole sequence and refuses to delete a privileged or invoking account. Includes the bats spec (78 cases, all system commands mocked), regenerated module INDEX and a CHANGELOG entry.
…account When nvidia-ctk is present, run 'nvidia-ctk runtime configure --runtime=docker --config=<home>/.config/docker/daemon.json' as the target account and restart only the user docker.service, so --gpus all and --device nvidia.com/gpu=all work rootless. Skipped when the runtime is already registered (idempotent). User-level only: no rootful daemon, /etc/docker or nvidia-container-runtime config.toml changes. The file lives in the account home, so remove (userdel -r) discards it. Adds six bats cases (84 total).
… state dir Record the packages added by the apt run (installed-set diff before/after), so dependencies such as libsubid5 are removed on remove while packages that were already installed never are. remove also rmdirs the empty module state dir and its parent (only when empty). Five new bats cases (89 total).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
docker-rootlessmodule (archetype D, custom) that installs, upgrades and removes rootless Docker for one dedicated non-root account, GPU-ready. The existingdockermodule (rootful Engine) is untouched; the two coexist and are selected by socket:/var/run/docker.sock/run/user/<uid>/docker.sock(DOCKER_HOST=unix:///run/user/<uid>/docker.sock). Never usesudo dockerto select rootless.Parameters (environment variables):
DOCKER_ROOTLESS_USER- target account, defaultrootless.DOCKER_ROOTLESS_DELEGATE-true(default) installs theuser@<uid>.servicedrop-inDelegate=cpu cpuset io memory pids.Lifecycle
install(idempotent; a second run is a no-op):docker/sudo/admin, not the invoking account. Warn if the AppArmor unprivileged-userns restriction is active and no rootlesskit profile exists.uidmapanddocker-ce-rootless-extrasif missing, and record in a marker file (/var/lib/init_ubuntu/docker-rootless/<user>.pkgs) only the ones this module installed.loginctl enable-linger; Delegate drop-in plusdaemon-reload; startuser@<uid>.service.dockerd-rootless-setuptool.sh installas the account (withXDG_RUNTIME_DIR/DBUS_SESSION_BUS_ADDRESS).After=user@UID.servicealone is not enough becausedocker.sockappears later, so a userdocker.servicedrop-in setsRestart=on-failure,RestartSec=3and anExecStartPostthat waits (timeout 60) for%t/docker.sock. Units orderedAfter=docker.servicetherefore see the socket.systemctl --user enable --now docker.service.nvidia-ctkis present and the runtime is not yet registered, runnvidia-ctk runtime configure --runtime=docker --config=<home>/.config/docker/daemon.jsonas the account (user-level only), thensystemctl --user restart docker.service(the user daemon only). Idempotent: skipped when"nvidia"is already in that file. The module never touches/etc/docker, the rootful daemon, or/etc/nvidia-container-runtime/config.toml, and issues no restart of the rootful docker. Advisory warnings remain: warn ifnvidia-cdi-refreshis missing, or ifno-cgroups = trueis set (keep the default, false).upgrade:apt-get install --only-upgradefor both packages, re-apply the idempotent steps, try-restart the user docker service. Runsinstallif not installed.remove(reverse sequence): stopuser@UID.serviceanduser-runtime-dir@UID.service,loginctl disable-linger,userdel -r, clean/etc/subuidand/etc/subgid, remove the Delegate drop-in,daemon-reload, thenapt-get removeonly the packages recorded in the marker. Refuses to delete an account that is indocker/sudo/adminor is the invoking account. Safe to run twice.purge=removeplus dropping the module state dir.doctorchecks account privileges, linger, subuid/subgid,user@UID, the socket and AppArmor.is_outdatedusesapt list --upgradable.is_recommendedis always false (opt-in).Also: module INDEX regenerated, CHANGELOG entry under
[Unreleased].Testing
Run inside Docker via the repo's recipes:
just -f justfile.ci test-unit docker-rootless- 89 bats cases pass. Every system-changing command goes through a mockedsudothat also emulates the few file operations against a scratch root; nothing touches the host.just -f justfile.ci lint(ShellCheck, fish, hadolint) - pass.just -f justfile.ci test-unit(full unit suite, includes the module metadata and INDEX checks) - pass.just -f justfile.ci test-integration- 24 ok, 0 not ok on the latest run (an earlier run had one environment-related harness failure,chown: invalid group: lifecycle:lifecycle, in a TUI spec unrelated to this change).Real-host result
Run on one Ubuntu 26.04 host with one NVIDIA GPU and Docker 29.x, with live rootful workloads present:
install: rc=0; the account has only its own group (no docker, no sudo); linger enabled; userdocker.serviceactive;docker infoshows rootless, cgroup v2 and the nvidia runtime; the account'sdaemon.jsongot the nvidia runtime; delegation showscpuset cpu io memory pids.docker run --gpus alland--device nvidia.com/gpu=allboth show the GPU; the account cannot reach/var/run/docker.sock.installis a no-op (no apt, no configure, no restart; the user dockerd PID is unchanged).remove: rc=0; removes the account, subuid/subgid entries, the drop-in anduidmap. The rootful daemon (PID and start time), running containers,/etc/docker/daemon.jsonand/etc/nvidia-container-runtime/config.tomlwere byte-identical before and after.libsubid5(a dependency apt pulled in withuidmap) was not removed, and an empty/var/lib/init_ubuntu/docker-rootlessremained. Install now records exactly the packages added by the apt run (installed-set diff, so new dependencies are included and pre-existing packages never are), andremovermdirs the empty state dir and its parent only when empty. These two fixes are covered by bats only; they have not been re-run on the host.NOT tested
upgrade.Open points for review:
docker.service(ExecStartPost), not a consumer unit; a consumer that cannot order afterdocker.servicecan still add its ownExecStartPrewait.Closes #422