Repository navigation
Conversation
When the host Docker socket's GID is nonzero and unused in the container, the entrypoint changes the GID of the container's docker group with groupmod. That does not update the supplementary groups of processes that are already running, so they keep getting EACCES on the socket. With the dev container CLI this includes the wrapper shell that runs the entrypoint and then execs the image command (overrideCommand: false). Processes started later (docker exec, terminals) get fresh groups and are not affected, which is why tests that run in a new process do not catch it. Add an opt-in alwaysUseSocketProxy option (default false) that skips the groupmod branch and always uses the existing socat proxy, whose target socket is owned by the user and needs no group membership. Behavior is unchanged when the option is off. The proxy has a known limitation (devcontainers#483), so it stays opt-in. Add the socket_proxy_always scenario. It inspects the container's own command (not a fresh process) and runs docker with that process's group list. The same check fails with the default configuration.
@microsoft-github-policy-service agree |
There was a problem hiding this comment.
🟡 Changes recommended
The new scenario can pass even if the proxy-option condition is removed, so a deterministic unused, nonzero socket GID fixture is needed to verify the intended behavior.
2 open issues
What changed in this PR
Adds an opt-in alwaysUseSocketProxy option to avoid Docker socket permission failures in processes that retain their original supplementary groups. Default behavior remains unchanged.
Changes:
- Adds the boolean option and bumps the Feature version to 1.11.0.
- Routes enabled configurations through the existing
socatproxy and documents its limitations. - Adds a scenario checking proxy operation and Docker access with the container command’s group list.
| File | Description |
|---|---|
test/docker-outside-of-docker/socket_proxy_always.sh |
Checks proxy setup and socket access with startup groups. |
test/docker-outside-of-docker/scenarios.json |
Adds a scenario enabling the proxy option. |
src/docker-outside-of-docker/README.md |
Lists the new option and its default. |
src/docker-outside-of-docker/NOTES.md |
Explains stale-group permissions and the proxy limitation. |
src/docker-outside-of-docker/install.sh |
Bypasses groupmod when the option is enabled. |
src/docker-outside-of-docker/devcontainer-feature.json |
Declares the option and updates the version. |
Review effort: Balanced
| if [ "${ENABLE_NONROOT_DOCKER}" = "true" ] && [ "${SOURCE_SOCKET}" != "${TARGET_SOCKET}" ] && [ "${USERNAME}" != "root" ] && [ "${USERNAME}" != "0" ]; then | ||
| SOCKET_GID=\$(stat -c '%g' ${SOURCE_SOCKET}) | ||
| if [ "\${SOCKET_GID}" != "0" ] && [ "\${SOCKET_GID}" != "${DOCKER_GID}" ] && ! grep -E ".+:x:\${SOCKET_GID}" /etc/group; then | ||
| if [ "${ALWAYS_USE_SOCKET_PROXY}" != "true" ] && [ "\${SOCKET_GID}" != "0" ] && [ "\${SOCKET_GID}" != "${DOCKER_GID}" ] && ! grep -E ".+:x:\${SOCKET_GID}" /etc/group; then |
There was a problem hiding this comment.
Agreed, thanks. Fixed in cc68071.
socket_proxy_always now builds a fixture instead of depending on the host socket's GID: a socket owned by
an unused, nonzero GID (4242) that forwards to the real socket. The host socket is not touched. The script
runs a path-rewritten copy of the generated docker-init.sh against it. A fixture-socket-created check
makes the test fail with a clear message if the fixture socket does not appear.
- Option on: the proxy starts ("Enabling socket proxy" in the log), the
dockergroup's GID is unchanged,
the proxy socket is owned by the user, anddocker psworks through it. - Control, condition flipped to false: the same fixture takes the
groupmodpath (the group's GID becomes
4242) and the proxy does not start. This shows the fixture really would selectgroupmod.
I also checked that the scenario fails when the option's condition is removed from install.sh, including
with the older checks disabled, so the new checks catch it on their own.
One caveat: the test matches the literal [ "true" != "true" ] in the generated script to flip the
condition. If that line changes (for example #1749 rewrites the if), the
control-condition-present-in-generated-script check fails instead of passing silently, and the test needs
updating.
| } | ||
| ``` | ||
|
|
||
| > **Note:** `socat` can drop output from `docker run --interactive` when input arrives with pauses in it ([#483](https://github.com/devcontainers/features/issues/483)). This is why the proxy is opt-in. |
There was a problem hiding this comment.
Agreed, you are right that it is not about pauses in input. Fixed in cc68071.
The note now says that the Docker CLI closes its write side right after sending a request, that socat
then waits only 0.5 s before dropping the connection, and that this affects docker run and docker exec
with or without --interactive (with the sleep 5; date example). It also says the same applies when the
Feature falls back to the proxy on its own, so users can weigh it before enabling the option.
While in that section I also added one sentence saying the option has no effect when the remote user is
root, because root can use the socket directly and only a stub entrypoint is installed.
#1762 fixes the cause with socat -t 31536000 and removes this note, so the wording here only needs to be
correct until that lands.
… GID The scenario could pass without the option because a host socket with GID 0 or a GID already in the image selects the proxy anyway. Build a fixture socket owned by an unused GID, run a path-rewritten copy of the generated docker-init.sh against it, and assert that the option keeps the docker group's GID and starts the proxy. A control run with the condition flipped must take the groupmod path. Also describe delayed output after the client closes its write side in NOTES.md.


Summary
Adds an opt-in
alwaysUseSocketProxyoption (defaultfalse) that always uses the Feature'sexisting
socatproxy instead of changing the GID of the container'sdockergroup withgroupmod. Behavior is unchanged when the option is off. Version bump 1.10.1 -> 1.11.0.Problem
When the host socket's GID is nonzero and not used by any group in the container,
docker-init.shruns
groupmod --gid <socket gid> docker. That updates/etc/groupbut not the supplementarygroups of processes that are already running, so they keep getting
EACCESon the socket.The dev container CLI (checked in 0.90.0) starts the container as:
That wrapper shell starts before
groupmodand keeps its old groups, as does anything itexecs.Processes started later (
docker exec, terminals, lifecycle commands) get fresh groups and are notaffected. That is why tests that run in a new process do not catch this.
Observed here (host socket GID 997, container
dockergroup 999):999 1000docker psas a fresh process: worksdocker pswith exactly the wrapper's groups:permission denied while trying to connect to the docker API at unix:///var/run/docker.sockChange
devcontainer-feature.json: newalwaysUseSocketProxyboolean, version 1.11.0.install.sh: reads the option and adds it to the condition that selects thegroupmodbranch.With it set, the existing proxy branch runs. The proxy socket is owned by the user, so no group
membership is needed.
README.md/NOTES.md: option documented, including the docker-outside-of-docker: socat breaks interactive support #483 limitation (see below).socket_proxy_always(see below).Why opt-in
The default (auto) stays as it is: where
groupmodworks,/var/run/docker.sockis the host's ownsocket, with no extra process or hop. The proxy replaces it with a separate socket owned by the user
(mode 660), adds a long-lived
socatprocess, and has its own failure modes, so existing users shouldnot get it unless they ask. This option changes nothing for anyone who does not set it.
The proxy also has a known defect today:
socatdrops output that arrives after the client stopssending (#483; reproduced:
echo "sleep 2; uname; exit 2" | docker run -i ubuntu bashprints nothingthrough the proxy). That affects the existing fallback too, and it is fixed in the related PR below.
Related PR
#1762, "[docker-outside-of-docker] Fix socat proxy dropping delayed output" (fixes #483), is stacked on this
branch. The two address different problems and either is useful without the other. #1762 is stacked
because its regression test needs the proxy to be in use, and this option's scenario
(
socket_proxy_always) is the only deterministic way to do that. Until #1762 lands,NOTES.mdherementions #483; #1762 removes that note. Both bump the Feature version (1.11.0 here, 1.11.1 in #1762), so
expect a small rebase if one merges first.
Testing
devcontainer features test -f docker-outside-of-dockerlocally (arm64 host, Docker 29.9.2, CLI 0.90.0):all autogenerated tests and all scenarios pass except
docker_dash_compose_v1anddocker_dash_compose_v1_moby, which fail witherror: externally-managed-environment(pip) and failidentically on unmodified
main.New scenario
socket_proxy_always(mcr.microsoft.com/devcontainers/base:ubuntu-24.04,containerUser: vscode,alwaysUseSocketProxy: true). It has two parts.command (
/proc/<pid>/status) and runsdocker psthroughsudo setprivwith exactly those groups.It also checks that the socket is a real socket,
socatruns with the expected arguments, the log says"Enabling socket proxy", and a plain
docker psworks.groupmoddepends on the host (GID 0 or a GIDalready in the image picks the proxy anyway), so the script builds a fixture: a socket owned by an unused
GID (4242) that forwards to the real socket. The host socket is not touched. It runs a path-rewritten
copy of the generated
docker-init.shagainst it. With the option on, the proxy starts, thedockergroup's GID is unchanged, the proxy socket is owned by the user, and
docker psworks through it. Acontrol run with the condition flipped to false takes the
groupmodpath (the group's GID becomes 4242)and does not start the proxy.
I checked that the scenario fails when the option's condition is removed from
install.sh, including withthe checks from part 1 disabled, so part 2 catches it on its own. The test matches the literal
[ "true" != "true" ]in the generated script; a change to that line makes thecontrol-condition-present-in-generated-scriptcheck fail rather than pass silently.Not tested: other base images in
test-pr.yaml, x86_64 hosts, and an end-to-endoverrideCommand: false(Compose) container. The latter is expected to hit the issue from reading the CLI source.
Related
groupmodkeep stale groups and cannot use the socket #1760: the stale-groups problem this addresses, and the questions about the best fix.socatbreaks interactive support (open; fixed by the related PR above).DOCKER_GIDat runtime, usesgetent) and bumpsthe version to 1.10.2, so a rebase and a version change are possible.
related, but I did not verify the mechanism there.