Skip to content

Honour CONTAINER_CONNECTION in PodmanClient.from_env() - #682

Merged
Honny1 merged 1 commit into
containers:mainfrom
rjmcgee53192:contrib/fix-654-squashed
Oct 26, 2026
Merged

Honny1 merged 1 commit into
containers:mainfrom
rjmcgee53192:contrib/fix-654-squashed

Conversation

@rjmcgee53192

Copy link
Copy Markdown
Contributor

Supersedes #673 — this is the same change, squashed into a single commit with a proper sign-off, per @Honny1's review on #673. The two commits there were authored under one identity and signed off under another, so the DCO check failed; this branch has one commit, signed off by its author. Closing #673 in favor of this PR.

Honour CONTAINER_CONNECTION in PodmanClient.from_env()

Fixes #654

Problem

from_env() read CONTAINER_HOST/DOCKER_HOST but ignored CONTAINER_CONNECTION, which the podman CLI honours. The failure was silent: with CONTAINER_CONNECTION pointing at a remote host, from_env() connected to the local socket and returned entirely plausible data from the wrong machine.

Fix

When no explicit CONTAINER_HOST/DOCKER_HOST URL is set, from_env() now resolves CONTAINER_CONNECTION through PodmanConfig.services — the same path as PodmanClient(connection=...) — so the named connection's URL (and identity) is applied. When both are set, CONTAINER_CONNECTION takes precedence, matching the podman CLI (setupRemoteConnection checks CONTAINER_CONNECTION before CONTAINER_HOST). An unknown connection name raises a clear ValueError instead of silently falling back to the local socket. The docstring now documents CONTAINER_CONNECTION.

Tests

Added 4 regression tests in podman/tests/unit/test_podmanclient.py:

  • test_from_env_container_connection: named connection resolves to its URL and identity
  • test_from_env_container_connection_takes_precedence: named connection wins over an explicit URL
  • test_from_env_unknown_connection: unknown name raises ValueError
  • test_from_env_no_connection_env: no env vars keeps the local-socket fallback unchanged

Results:

  • python3 -m unittest podman.tests.unit.test_podmanclient: 11/11 pass
  • Full unit suite: 255 tests pass, except a pre-existing test_utils import error (it shells out to a podman binary that isn't installed here; fails identically without this change)
  • ruff check + ruff format --check: clean
  • mypy podman/client.py: clean
  • pylint: 10.00/10
  • Coverage on podman/client.py: 98% (merge bar is 85%)

Notes

from_env() read CONTAINER_HOST/DOCKER_HOST but ignored CONTAINER_CONNECTION, which the podman CLI honours. The failure was silent: it connected to the local socket and returned plausible data from the wrong machine.

Now from_env() resolves CONTAINER_CONNECTION through PodmanConfig.services (the same path as PodmanClient(connection=...)), raises a clear ValueError for unknown connection names instead of silently using the wrong host, and CONTAINER_CONNECTION takes precedence over CONTAINER_HOST, matching the CLI. Four regression tests cover the named-connection, precedence, unknown-name, and no-env cases.

Fixes containers#654

Signed-off-by: Ryan McGee <[email protected]>

@Honny1 Honny1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Honny1

Honny1 commented Oct 22, 2026

Copy link
Copy Markdown
Member

Depends on: #656

@TomSweeneyRedHat

Copy link
Copy Markdown
Member

LGTM
after #656 merges, which should happen soon @Honny1

@Honny1
Honny1 merged commit 241b3d5 into containers:main Oct 26, 2026
23 checks passed

This branch was previously deployed

1 inactive deployment
build — 82d66660 Deployed Oct 22, 2026 by rjmcgee53192 via Test Build Python distribution 📦 #315
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

from_env() ignores CONTAINER_CONNECTION and silently uses the local socket

3 participants