Skip to content

Commit d7bcf22

Browse files
authored
fix: retry using docker-credential helpers with trailing slash on the registry URL (#2728)
Currently using the docker-credential helpers might be broken to a missing slash on the registry address. Some registries might have a suffixed `/` or not. To be able to deal with both cases. We just try both approaches. `echo "https://index.docker.io/v1" | /usr/local/bin/docker-credential-osxkeychain get` vs `echo "https://index.docker.io/v1/" | /usr/local/bin/docker-credential-osxkeychain get ` I've tested this manually with the existing OSX test `TestGetAuthConfigForRepoOSX` (which is skipped by default). ``` go test -run TestGetAuthConfigForRepoOSX ./container-engine-lib/lib/backend_impls/docker/docker_manager/... -v === RUN TestGetAuthConfigForRepoOSX --- PASS: TestGetAuthConfigForRepoOSX (0.06s) ``` ## Description <!-- Describe this change, how it works, and the motivation behind it. --> ## REMINDER: Tag Reviewers, so they get notified to review ## Is this change user facing? YES/NO <!-- If yes, please add the "user facing" label to the PR --> <!-- If yes, don't forget to include docs changes where relevant --> ## References (if applicable) <!-- Add relevant Github Issues, Discord threads, or other helpful information. --> <!-- You can auto-close issues by putting "Fixes #XXXX" here. -->
1 parent 066e099 commit d7bcf22

File tree

1 file changed

+20
-0
lines changed
  • container-engine-lib/lib/backend_impls/docker/docker_manager

1 file changed

+20
-0
lines changed

container-engine-lib/lib/backend_impls/docker/docker_manager/docker_auth.go

+20
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,26 @@ func getCredentialsFromStore(credHelper string, registryURL string) (*registry.A
106106
// Prepare the helper command (docker-credential-<store>)
107107
credHelperCmd := "docker-credential-" + credHelper
108108

109+
// First try with the original URL
110+
auth, err := tryGetCredentialsWithURL(credHelperCmd, registryURL)
111+
if err == nil {
112+
return auth, nil
113+
}
114+
115+
// If the URL doesn't end with a slash, try again with a trailing slash
116+
if !strings.HasSuffix(registryURL, "/") {
117+
auth, retryErr := tryGetCredentialsWithURL(credHelperCmd, registryURL+"/")
118+
if retryErr == nil {
119+
return auth, nil
120+
}
121+
}
122+
123+
// If both attempts failed, return the original error
124+
return nil, err
125+
}
126+
127+
// tryGetCredentialsWithURL attempts to get credentials for a specific URL
128+
func tryGetCredentialsWithURL(credHelperCmd string, registryURL string) (*registry.AuthConfig, error) {
109129
// Execute the credential helper to get credentials for the registry
110130
cmd := exec.Command(credHelperCmd, "get")
111131
cmd.Stdin = strings.NewReader(registryURL)

0 commit comments

Comments
 (0)