feat: add TLS certificate support for Docker contexts#3728
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Itx-Psycho0 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @Itx-Psycho0. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3728 +/- ##
==========================================
+ Coverage 56.95% 57.07% +0.12%
==========================================
Files 181 181
Lines 21116 21202 +86
==========================================
+ Hits 12026 12101 +75
- Misses 7866 7874 +8
- Partials 1224 1227 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Extends Docker context detection (from knative#3684) to support TLS certificates stored in Docker contexts. This enables secure connections to remote Docker daemons configured via Docker contexts. Changes: - Extended getDockerContextHost() to getDockerContextConfig() which returns both host and TLS configuration - Added DockerContextConfig struct to hold host and TLS settings - Modified newHttpClient() to check Docker context first, then fall back to environment variables - Added newHttpClientFromContext() to create HTTP client from context config - Load TLS certificates directly from context (no temp files or env vars) - Added comprehensive test with mock TLS daemon Benefits: - Remote Docker setups work automatically with TLS - Consistent with Docker CLI behavior - No manual environment variables needed - Proper TLS support for secure connections - Clean implementation without temp files Fixes knative#3719
5ecc50a to
1af6e75
Compare
|
/ok-to-test |
Review: feat: add TLS certificate support for Docker contextsBranch: OverallThe approach of building the TLS config in-memory via Significant1. Wrong fallback TLS path
// Docker stores context TLS files in contexts/meta/<sha256-hash>/
hash := sha256.Sum256([]byte(contexts[0].Name))
tlsPath = filepath.Join(dockerConfigDir, "contexts", "meta", fmt.Sprintf("%x", hash))Docker stores TLS files under The test masks this because it always sets 2. Precedence inversion: context TLS overrides explicit env vars
func newHttpClient() *http.Client {
// First, try to get TLS config from Docker context
if contextConfig := getDockerContextConfig(); contextConfig != nil && len(contextConfig.TLSCert) > 0 && len(contextConfig.TLSKey) > 0 {
return newHttpClientFromContext(contextConfig)
}
// Fall back to environment variables
tlsVerifyStr, tlsVerifyChanged := os.LookupEnv("DOCKER_TLS_VERIFY")
...Context is checked before 3. Context TLS applied even when
|
|
Thanks for the detailed review @matejvasek! I see the issues, let me fix them:
Working on the fixes now! |
Fixes based on @matejvasek's review: Significant fixes: 1. Fixed TLS path: use contexts/tls/<hash>/ not contexts/meta/<hash>/ 2. Fixed precedence: env vars (DOCKER_TLS_VERIFY) now override context 3. Context TLS only applies when host came from context detection 4. Cache context config to avoid calling 'docker context inspect' twice Minor improvements: 5. Unexported dockerContextConfig (internal-only struct) 6. Removed redundant DOCKER_CONFIG passthrough (auto-inherited) 7. Added error logging for malformed certificates The implementation now correctly: - Checks DOCKER_TLS_VERIFY env var first - Only uses context TLS when env vars are not set - Only applies context TLS when host came from context - Calls docker CLI once instead of twice - Logs warnings for cert loading failures
Review: feat: add TLS certificate support for Docker contextsBranch: OverallGood iteration. The core approach — building TLS config in-memory via What was fixed
Remaining issues1.
|
|
Also please add test for the previous TLS functionality using the envvars too. |
Description
Extends Docker context detection (from #3684) to support TLS certificates stored in Docker contexts. This enables secure connections to remote Docker daemons configured via Docker contexts.
Fixes #3719
Changes
Extended
getDockerContextHost()togetDockerContextConfig()which returns both host and TLS configurationAdded
DockerContextConfigstruct to hold host and TLS settingsLoad TLS certificates from context's
tls/directoryWrite certificates to temp directory and configure via environment variables
Reuse existing TLS functionality via
newHttpClient()Added comprehensive test with mock TLS daemon
Benefits
Remote Docker setups work automatically with TLS
Consistent with Docker CLI behavior - if
dockercommands work,funccommands workNo manual environment variables needed
Proper TLS support for secure connections
Testing
Added
TestNewClient_DockerContextTLSwith mock TLS-enabled daemonAll existing Docker tests pass
make checkpassesRelated
PR fix: detect Docker host from context when DOCKER_HOST is not set #3684 - Initial Docker context detection implementation (merged)