fix: run every docker command through sudo when use_sudo is set - #485
Merged
Conversation
`use_sudo` reached exactly one command: the bare `docker` probe in `verify_dependencies`. Kitchen's `run_command` takes sudo as a call option rather than reading configuration, and `docker_command` never passed it, so every build, run, port, inspect, exec, cp, and rm still ran as the invoking user. That made the option useless for the case it exists for. On a host where the daemon socket needs root, `use_sudo: true` -- the answer the README gives for "permission denied while trying to connect to the Docker daemon socket" -- changed nothing: the probe succeeded under sudo and `kitchen create` then failed on the first real command. `docker_command` now adds the sudo options when `use_sudo` is set, and honours a `sudo_command` for hosts that use something other than `sudo -E`. The transport gains `use_sudo` and `sudo_command` too. It runs its own `docker exec` and `docker cp`, so setting them only on the driver would move the failure from create to converge rather than fixing it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
tas50
force-pushed
the
fix/use-sudo-docker-commands
branch
from
August 23, 2026 16:52
51617e3 to
8769189
Compare
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.
Reported behaviour:
use_sudo: truedoes not help on a host where the Docker daemon socket needs root -- the very case the README points at it for.The bug
use_sudoreached exactly one command: the baredockerprobe inverify_dependencies.Kitchen
'sShellOut#run_commandtreats sudo as a per-call option -- it reads:use_sudoout of the options hash it is handed and knows nothing aboutconfig.docker_commandbuilds its own command line and never passed it along, so everybuild,run,port,inspect,exec,cp, andrmstill ran as the invoking user.The result is the worst shape of failure: the probe succeeds under sudo, so the driver reports Docker is usable, and
kitchen createthen dies on the first command that actually touches the daemon.The transport is affected the same way and separately: it is its own plugin with its own config, and it runs
docker execanddocker cp. Fixing only the driver would have moved the failure from create to converge.The fix
docker_commandadds the sudo options whenuse_sudois set.sudo_commandis honoured, for hosts that use something other thansudo -E(doas, a wrapper script).Confirmation
Reproduced against Docker 29.7.2 (Docker Desktop 4.87.0, macOS/arm64) with Test Kitchen 4.1.1, using a
dockerwrapper onPATHthat refuses unless it was launched through sudo -- so a run can only succeed if every command went through it:Before:
After -- full
kitchen convergeagainst a realubuntu-24.04container:with 14 recorded sudo invocations (the probe plus 13 real docker commands) where there had been 1.
rake styleclean;rspec313 examples, 0 failures (6 new).