Conversation
A context endpoint created with `docker context create --docker host=tcp://...,ca=ca.pem` (CA only) or `skip-tls-verify=true` (no TLS files) uses TLS in the Docker CLI. Context._load_certs only built a TLSConfig when ca, cert and key were all present, so these contexts got no TLS config and from_env()/from_context() talked plain HTTP to the TLS port. Build the docker endpoint's TLSConfig when it has any TLS material or skip-tls-verify is set, pass the client cert only when both cert and key exist, and treat a missing SkipTLSVerify as false like the CLI. TLSMaterial no longer assumes a client cert. Assisted-By: Claude Signed-off-by: breken-ai <312387581+breken-ai@users.noreply.github.com>
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.
What's wrong
Context._load_certsbuilds aTLSConfigonly when an endpoint hasca,certandkey. The Docker CLI turns TLS on for a context endpoint when it has any TLS material, or whenskip-tls-verifyis set. The client cert is optional. So two common contexts load in docker-py without TLS:docker --context caonly versionspeaks TLS.DOCKER_CONTEXT=caonly python -c 'import docker; docker.from_env().ping()'sends plain HTTP to the TLS port and fails. Sincefrom_env()now falls back to the current context (#3401, 7.2.0), this also hitsdocker.from_env().Reproduction on
main: a local HTTPS server with a self-signed cert, and both contexts created with the Docker CLI 27.5:On this branch:
A related crash:
Context.TLSMaterial(used byinspect()/str(ctx)) unpackedtls.certunconditionally. A TLS config without a client cert would raise aTypeErrorthere.Fix
dockerendpoint, build theTLSConfigwhen any ofca/cert/keyexists orSkipTLSVerifyis true. Passclient_certonly when both cert and key exist.verifystays as it was:Trueunless skip-tls-verify is set. Other endpoints keep the old all-three rule.SkipTLSVerifynow meansfalse, which is the CLI's zero value. Before, it defaulted totrue. That default only mattered for contexts with full certs, where it quietly turned verification off. With the first change it would also have turned TLS on for such endpoints.TLSMateriallists only the files that exist.Tests
LoadContextTLSTestintests/unit/context_test.py. Each test writes a context in the CLI's on-disk layout under a temporaryDOCKER_CONFIG. The CA-only and skip-tls-verify tests fail onmain(assert None is not None) and pass here. The full-mTLS and plain-TCP cases are controls and pass on both.pytest tests/unit: 618 passed, run with an isolatedHOME. Two existing tests read the developer's own~/.dockerconfig and fail the same way onmain.ruff check docker testsis clean.This was found and fixed with help from an AI coding assistant (Claude). I checked the change and ran the end-to-end reproduction above. The commit is signed off and carries an
Assisted-By:trailer.