Skip to content

feat(docker): container commands find a Podman engine before Docker's default socket, and rootless sandboxes run as the host user #1117

Closed

Description

@dan-petty

Problem

Lines cited at dcafadf. At 132ecc5, ai/mcp/server.py:1317 is at :1340; the other cited lines have not moved. Paths are under src/devops_cli/ unless they start with tests/ or docs/. Paths marked docker-py are in the locked docker 7.2.0 (pyproject.toml:24). Paths marked Podman are at tag v6.1.3 of containers/podman, and compat/ there is short for pkg/api/handlers/compat/. Paths marked podman-py are in the podman 5.8.0 sdist on PyPI. The go-containerregistry path is at tag v0.22.1.

devops-cli reaches a container engine only through docker-py. DockerEngineService.client() builds its client with docker.from_env() (docker/engine.py:248-264), and the dashboard builds its own the same way (ui/data_providers.py:217-221). Everything else goes through get_engine(): commands/docker.py, docker/sandbox.py (and devops test through it, commands/test_cmd.py:374), sandbox/engine.py and sandbox/metrics.py:242-245. None of it knows Podman:

  • With DOCKER_HOST unset and no Docker CLI context, the client dials /var/run/docker.sock. On a host that runs only rootless Podman, such as the maintainer's workstation, every container command and sandbox fails until the user exports DOCKER_HOST by hand.
  • Podman's endpoint variables are ignored: CONTAINER_HOST and CONTAINER_CONNECTION (Podman docs/source/markdown/podman.1.md:215-236 and :272-278, cmd/podman/root.go:220-262). No code looks for Podman's sockets either: $XDG_RUNTIME_DIR/podman/podman.sock for rootless and /run/podman/podman.sock for rootful (Podman docs/source/markdown/podman-system-service.1.md:60-61).
  • The knowledge base says the SDK "connects seamlessly to Podman's Docker-compatible socket" (ai/knowledge_base/devops_cli/libraries/docker.md:30), but nothing finds that socket.
  • DEFAULT_CONTAINER_ENGINE = "docker" (config/defaults.py:713) and BIN_DOCKER (config/commands.py:26, re-exported at config/__init__.py:13 and :489) are never read.

Podman's Docker-compatible API serves almost every call devops-cli makes (read from the Podman handlers):

  • It serves:
    • ping;
    • container get, list, create, start, stop, remove, exec, logs, wait and stats;
    • networks, with Docker-shaped attrs including Internal;
    • image list, build, push and export;
    • df, info and version.
  • The sandbox create kwargs are all mapped: network name, Tmpfs, SecurityOpt (no-new-privileges:true) and NanoCPUs (Podman pkg/api/handlers/compat/containers_create.go:395-410, :471, :497-502). They come from sandbox/engine.py:221-255, docker/sandbox.py:265-276 and SandboxPolicy.to_docker_security_kwargs (sandbox/models.py:380-389).
  • A build reports the image ID in the form docker-py's images.build reads: a Successfully built <id> stream line (Podman compat/images_build.go:909, docker-py models/images.py:305-311).
  • A push without an X-Registry-Auth header uses the service's own auth file (Podman pkg/auth/auth.go:30-61, compat/images_push.go:82-95), so podman login covers devops docker push.
  • Podman advertises compat API 1.44 (Podman version/version.go:42-45), one below docker-py's default of 1.45. docker-py asks the server for its version on connect (docker-py api/client.py:203-207).

Gaps on Podman and other rootless engines:

  • Rootless engines get the wrong sandbox user.
    • --rootless, the default, sends user=f"{uid}:{gid}" (sandbox/engine.py:80-84, docker/sandbox.py:260-264). Under rootful Docker that is the host user.
    • Under rootless Podman or rootless Docker, container UID 1000 maps to a subordinate host UID, so the sandbox cannot write its rw workspace.
    • Podman's keep-id cannot be sent: docker-py refuses any userns_mode other than "host" before the request (docker-py types/containers.py:551-556).
    • The subordinate UID is also what keeps a rootless sandbox out of the user's 0700 runtime directory today, where the user's engine socket and session bus live. Mapping the sandbox to the host user removes that barrier, so fix(security): a sandbox workspace can never expose the container engine socket or the user's runtime directory and its session bus #1115's workspace check must be in place first.
  • CPU percentages are wrong on Podman.
    • container_stats asks for stream=False (docker/engine.py:341). Podman fills the CPU baseline only when streaming (Podman compat/containers_stats.go:62-67), so _cpu_percentage (docker/engine.py:52-65) divides lifetime totals.
    • The first streamed frame (docker/engine.py:356-363) covers almost no time on Podman and has no baseline on Docker.
  • The build cache is Docker-only.
    • devops docker cache reads BuildCache from df (docker/engine.py:522-525), and Podman always returns it empty (Podman compat/system.go:113).
    • --prune calls prune_builds (docker/engine.py:530). Podman has no /build/prune route, only /build (Podman pkg/api/server/register_images.go:781), so the call fails with a 404.
  • Child processes and the devcontainer bypass the chosen endpoint.
    • _wait_for_docker_daemon needs a docker binary and runs docker info (commands/devcontainer.py:935-946).
    • dive <image> (security/dive.py:89-91) uses dive's default Docker source. That source reads DOCKER_HOST or /var/run/docker.sock, not the endpoint the engine chose.
    • Child processes do not get XDG_RUNTIME_DIR (allowlist at core/process.py:27-77), and rootless podman login stores its credentials under that directory. When no Docker config.json is found, cosign's keychain looks there (go-containerregistry pkg/authn/keychain.go:109-137), so devops docker sign and verify miss those credentials. REGISTRY_AUTH_FILE is dropped by the *AUTH* deny pattern (core/process.py:92).

Out of scope. The first three end in a one-line error that says what to set or run:

Acceptance criteria

  • Endpoint table, parametrised and offline.
    • Test setup:
      • CONTAINER_HOST, CONTAINER_CONNECTION, DOCKER_HOST, DOCKER_CONTEXT, DOCKER_TLS_VERIFY and DOCKER_CERT_PATH are unset.
      • DOCKER_CONFIG, HOME and XDG_RUNTIME_DIR point under tmp_path, and so do the rootful socket path and the /run/user base (both patched).
      • Socket stand-ins are empty files.
      • docker.DockerClient is patched.
      • Only TEST-NET and loopback literals are used.
    • With nothing set and no files, the client gets http+unix:///var/run/docker.sock, as in fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108.
    • A rootless Podman file gives http+unix://<tmp>/podman/podman.sock. With XDG_RUNTIME_DIR unset, the patched /run/user/<uid> path is used.
    • The rootful file alone is used when os.access allows read and write, and skipped otherwise.
    • With both Podman files present, the rootless one wins.
    • CONTAINER_HOST=unix:///<tmp>/custom.sock beats DOCKER_HOST and both files.
    • DOCKER_HOST, DOCKER_CONTEXT and a non-default currentContext each beat the Podman files. currentContext: default does not.
    • DOCKER_CONTEXT naming a context that does not exist is a configuration error, and no client is built.
    • CONTAINER_CONNECTION=dev, with or without CONTAINER_HOST, is a configuration error that names CONTAINER_HOST, and no client is built.
    • CONTAINER_HOST=ssh://[email protected]:22/run/user/1000/podman/podman.sock gives a one-line error. No client is built and no ssh process starts.
    • CONTAINER_HOST=TCP://192.0.2.1:2375 is refused by fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108's check, as the same value in DOCKER_HOST is.
    • Every endpoint error exits 1 with one line that names the source: CONTAINER_HOST, DOCKER_HOST, the context name or the socket path.
    • When Docker's default context was chosen and the dial fails, that line also says to set CONTAINER_HOST or DOCKER_HOST, or to run systemctl --user enable --now podman.socket.
    • Only one endpoint is ever dialled. A failure on the chosen endpoint is reported; no other endpoint is tried.
  • Contract rows. fix(docker): the Docker endpoint check covers the endpoint the SDK dials, including contexts and the TUI, and pushes accept registry ports #1108's parse_host contract test gains two rows:
    • unix:///run/user/1000/podman/podman.sock → http+unix:///run/user/1000/podman/podman.sock;
    • the ssh URI above raises DockerException.
  • Engine facts.
    • The engine reports its kind: Podman when version()["Components"] has a component named Podman Engine (Podman compat/version.go:35-36), Docker otherwise.
    • It reports rootless when info()["SecurityOptions"] contains name=rootless (Podman compat/info.go:197-198; rootless Docker reports the same).
    • Each fact is fetched once per engine instance.
    • Tests use minimal version and info fixtures with the fields the Podman handlers set and the fields Docker sets.
  • The sandbox workspace check follows the new sources. fix(security): a sandbox workspace can never expose the container engine socket or the user's runtime directory and its session bus #1115's check takes the engine socket from the resolve step, so it covers the sources this item adds. With CONTAINER_HOST=unix://<d>/custom.sock under tmp_path, a workspace of <d> is refused. With only the rootful Podman file present (its path patched under tmp_path), a workspace that holds it is refused.
  • User mapping.
    • With a rootless engine (mocked info()), both sandbox paths send user="0:0". With a rootful engine, both send uid:gid as today. rootless=False (--root on devops docker sandbox and devops test) sends no user on either path.
    • A dry run does not connect to the engine. It shows uid:gid as today, with a note that a rootless engine runs the sandbox as container root, which is the host user.
    • Apart from user, the create kwargs for Podman and Docker are identical, pinned by a test, so there is one dialect.
  • Stats.
    • container_stats reads the second frame of a streamed sample and closes the stream.
    • stream_container_stats drops the first frame.
    • A two-frame fixture whose first frame has empty precpu_stats yields the CPU percentage of the second frame.
  • Build cache. On a Podman engine, devops docker cache exits 1 with or without --prune, prints the message from the key questions and makes no prune_builds call. Docker behaviour is unchanged.
  • Child processes and the devcontainer.
    • _wait_for_docker_daemon polls get_engine().ping() and needs no docker binary.
    • When the engine's endpoint did not come from DOCKER_HOST, dive runs with DOCKER_HOST set to that endpoint as its source gave it. A test asserts the env passed to run_subprocess.
    • The cosign calls in devops docker sign and verify pass extra_allowed_env={"XDG_RUNTIME_DIR"}, and a test asserts the env passed to run_subprocess.
    • XDG_RUNTIME_DIR is not added to DEFAULT_ALLOWED_ENV_VARS:
      • D-Bus clients fall back to $XDG_RUNTIME_DIR/bus when DBUS_SESSION_BUS_ADDRESS is unset (tests/conftest.py:308);
      • the session bus reaches gnome-keyring;
      • devops-cli passes the bus only per call (commands/devcontainer.py:1452, :1522).
  • Docs and release.
    • docs/cheatsheets/docker.md gives:
      • the endpoint order;
      • how to start Podman's user socket (systemctl --user enable --now podman.socket);
      • the out-of-scope limits.
    • docs/commands/docker.md is generated from help text and is not edited by hand. It is regenerated with devops docs generate, and the docs check passes.
    • The knowledge base page docker.md says devops-cli looks for Podman's socket before Docker's default.
    • DEFAULT_CONTAINER_ENGINE and BIN_DOCKER are deleted.
    • A changelog.d fragment describes the endpoint order and the rootless user mapping.
    • Tests are offline and never build a real DockerClient, since connecting asks the server for its version. The new tests take well under 1 s together, and uv run devops ci passes.
  • Pending a person: on a host running rootless Podman with podman.socket enabled and no DOCKER_HOST, run each of these and record the results in the task file:
    • devops docker images, build, push (after podman login), stats, prune, cache, analyze-layers, sign and verify;
    • a devops docker sandbox that writes to an rw workspace (the files must be owned by the host user);
    • devops sandbox deploy --network sandbox_namespace;
    • the dashboard's Docker panel.
  • Pending a person: on that host, record the delegated cgroup controllers (cat /sys/fs/cgroup/user.slice/user-$(id -u).slice/user@$(id -u).service/cgroup.controllers), and whether the sandbox's memory, CPU and PID limits take effect.
  • Pending a person: capture /version, /info and two stats frames from that service. Confirm the test fixtures carry the same fields. Host-specific values are removed before anything is committed.
  • Pending a person: on that host, confirm that devops docker sandbox --workspace "$XDG_RUNTIME_DIR" -- true is still refused by fix(security): a sandbox workspace can never expose the container engine socket or the user's runtime directory and its session bus #1115's check once the sandbox runs as the host user.

Key questions

Strategic alignment

Update 2026-10-08: refinement

No code reads CONTAINER_HOST. #1115 landed: feeding configured_host() (docker/engine.py:233-262) covers the workspace check, and /run and $XDG_RUNTIME_DIR are already refused (sandbox/engine.py:156-161). #1108 lands first. Mapping to the host user also exposes the SSH agent's 0700 directory, so #1384 (v0.2.30) lands first too.

  • The person-run check expects a workspace holding the SSH_AUTH_SOCK directory to be refused.

Activity

  1. added
    type/feature
    scope/security
    scope/cli
    priority/p2-medium
    on Oct 3, 2026
  2. dan-petty commented on Oct 8, 2026

    @dan-petty
    OwnerAuthor

    Linked: #698. Both plan DockerEngineService.security_options(); whichever lands first adds it, and the other reuses it. Found by the 2026-10-08 backlog review.

  3. added this to the v0.2.34 milestone on Oct 10, 2026
  4. dan-petty-bot commented on Oct 10, 2026

    @dan-petty-bot
    Collaborator

    Moved to v0.2.34: v0.2.34 started with fewer than its 16 items and was topped up to 16 from Ready items, critical fixes and P0 features first. (devops roadmap reprioritize)

  5. dan-petty commented on Oct 11, 2026

    @dan-petty
    OwnerAuthor

    Merged

  6. added a commit that references this issue on Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p2-mediumscope/cliscope/securitytype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions