Repository navigation
Honour CONTAINER_CONNECTION in PodmanClient.from_env() - #673
Closed
rjmcgee53192 wants to merge 2 commits into
Closed
rjmcgee53192 wants to merge 2 commits into
rjmcgee53192 wants to merge 2 commits into
Conversation
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, when no explicit CONTAINER_HOST/DOCKER_HOST URL is set, from_env() resolves CONTAINER_CONNECTION through PodmanConfig.services (the same path as PodmanClient(connection=...)), and raises a clear ValueError for unknown connection names instead of silently using the wrong host. Fixes containers#654 Signed-off-by: rjmcgee53192 <[email protected]>
Contributor
|
Thanks for picking this up. Two things I noticed while testing this branch:
Smaller, possibly follow-up: the CLI also honours |
Matches the podman CLI, which checks CONTAINER_CONNECTION before CONTAINER_HOST. An explicit CONTAINER_HOST URL no longer silently wins, so podman-py and the CLI always resolve to the same host. Also notes the dependency on PR containers#656 for identity-less connections. Signed-off-by: rjmcgee53192 <[email protected]>
Contributor
Author
|
Thanks for the detailed review. Both points addressed: |
Honny1
requested changes
Oct 20, 2026
Honny1
left a comment
Member
There was a problem hiding this comment.
Code changes seem good. PPlease squashyour commits and properly sign them to satisfy DCO. Also check contribution guidelines and LLM policy.
This was referenced Oct 21, 2026
Contributor
Author
This branch was previously deployed
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.
Honour CONTAINER_CONNECTION in PodmanClient.from_env()
Fixes #654
Problem
from_env()readCONTAINER_HOST/DOCKER_HOSTbut ignoredCONTAINER_CONNECTION,which the
podmanCLI honours. The failure was silent: withCONTAINER_CONNECTIONpointing at a remote host,
from_env()connected to the local socket and returnedentirely plausible data from the wrong machine.
Fix
When no explicit
CONTAINER_HOST/DOCKER_HOSTURL is set,from_env()now resolvesCONTAINER_CONNECTIONthroughPodmanConfig.services— the same path asPodmanClient(connection=...)— so the named connection's URL (and identity) isapplied. When both are set,
CONTAINER_CONNECTIONtakes precedence, matching thepodmanCLI (setupRemoteConnectionchecksCONTAINER_CONNECTIONbeforeCONTAINER_HOST). An unknown connection name raises a clearValueErrorinstead ofsilently 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 identitytest_from_env_container_connection_takes_precedence: named connection wins over an explicit URLtest_from_env_unknown_connection: unknown name raisesValueErrortest_from_env_no_connection_env: no env vars keeps the local-socket fallback unchangedResults:
python3 -m unittest podman.tests.unit.test_podmanclient: 11/11 passtest_utilsimport error(it shells out to a
podmanbinary that isn't installed here; fails identicallywithout this change)
ruff check+ruff format --check: cleanmypy podman/client.py: cleanpylint: 10.00/10podman/client.py: 98% (merge bar is 85%)Notes
by ServiceConnection.identity raises TypeError when a connection has no identity #652 / PR fix: make service connection identity optional #656; this change routes through the same
PodmanClient(connection=...)path, so it picks that fix up automatically.linked PR and no maintainer assignment, so I went ahead — happy to coordinate
if they are already working on it.
CONTAINER_CONNECTIONvalue without an identity raisesTypeErrorfromServiceConnection.identity; merged together with fix: make service connection identity optional #656 it resolves to the right socket.