-
Notifications
You must be signed in to change notification settings - Fork 2.2k
configfile: normalize Docker Hub auth key aliases #7190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,10 +42,12 @@ const authConfigKey = "https://index.docker.io/v1/" | |
| // | ||
| // [registry.GetAuthConfigKey]: https://pkg.go.dev/github.com/docker/docker@v28.5.1+incompatible/registry#GetAuthConfigKey | ||
| func getAuthConfigKey(domainName string) string { | ||
| if domainName == "docker.io" || domainName == "index.docker.io" { | ||
| switch strings.TrimSpace(domainName) { | ||
| case "docker.io", "index.docker.io", "https://index.docker.io/v1", authConfigKey: | ||
| return authConfigKey | ||
| default: | ||
| return domainName | ||
| } | ||
| return domainName | ||
| } | ||
|
|
||
| // ConfigFile ~/.docker/config.json file info | ||
|
|
@@ -129,6 +131,7 @@ func (c *ConfigFile) LoadFromReader(configData io.Reader) error { | |
| return err | ||
| } | ||
| var err error | ||
| normalizedAuthConfigs := make(map[string]types.AuthConfig, len(c.AuthConfigs)) | ||
| for addr, ac := range c.AuthConfigs { | ||
| if ac.Auth != "" { | ||
| ac.Username, ac.Password, err = decodeAuth(ac.Auth) | ||
|
|
@@ -137,9 +140,10 @@ func (c *ConfigFile) LoadFromReader(configData io.Reader) error { | |
| } | ||
| } | ||
| ac.Auth = "" | ||
| ac.ServerAddress = addr | ||
| c.AuthConfigs[addr] = ac | ||
| ac.ServerAddress = getAuthConfigKey(addr) | ||
| normalizedAuthConfigs[getAuthConfigKey(addr)] = ac | ||
| } | ||
| c.AuthConfigs = normalizedAuthConfigs | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -370,10 +374,11 @@ func parseEnvConfig(v string) (map[string]types.AuthConfig, error) { | |
| if err != nil { | ||
| return nil, err | ||
| } | ||
| authConfigs[addr] = types.AuthConfig{ | ||
| normalizedAddr := getAuthConfigKey(addr) | ||
| authConfigs[normalizedAddr] = types.AuthConfig{ | ||
| Username: username, | ||
| Password: password, | ||
| ServerAddress: addr, | ||
| ServerAddress: normalizedAddr, | ||
| } | ||
|
Comment on lines
-373
to
382
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here; I don't think we have to account for someone setting a wrong env-var; if it doesn't resolve, they should fix their env-var to use the correct casing. |
||
| } | ||
| return authConfigs, nil | ||
|
|
@@ -387,7 +392,27 @@ var newNativeStore = func(configFile *ConfigFile, helperSuffix string) credentia | |
| // GetAuthConfig for a repository from the credential store | ||
| func (c *ConfigFile) GetAuthConfig(registryHostname string) (types.AuthConfig, error) { | ||
| acKey := getAuthConfigKey(registryHostname) | ||
| return c.GetCredentialsStore(acKey).Get(acKey) | ||
| store := c.GetCredentialsStore(acKey) | ||
| if authConfig, err := store.Get(acKey); err == nil && authConfig != (types.AuthConfig{}) { | ||
| return authConfig, nil | ||
| } | ||
|
|
||
| if registryHostname != "" && registryHostname != acKey { | ||
| if authConfig, err := store.Get(registryHostname); err == nil && authConfig != (types.AuthConfig{}) { | ||
| return authConfig, nil | ||
| } | ||
| } | ||
| if acKey == authConfigKey { | ||
| for _, candidate := range []string{"docker.io", "index.docker.io", "https://index.docker.io/v1"} { | ||
| if candidate == acKey || candidate == "" { | ||
| continue | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is all de-centralizing the logic again; I don't think that's good. The earlier implementation you had kept it central, and for the |
||
| } | ||
| if authConfig, err := store.Get(candidate); err == nil && authConfig != (types.AuthConfig{}) { | ||
| return authConfig, nil | ||
| } | ||
| } | ||
| } | ||
| return store.Get(acKey) | ||
| } | ||
|
|
||
| // getConfiguredCredentialStore returns the credential helper configured for the | ||
|
|
@@ -398,6 +423,13 @@ func getConfiguredCredentialStore(c *ConfigFile, registryHostname string) string | |
| if helper, exists := c.CredentialHelpers[registryHostname]; exists { | ||
| return helper | ||
| } | ||
| if registryHostname == authConfigKey { | ||
| for _, key := range []string{"docker.io", "index.docker.io", "https://index.docker.io/v1"} { | ||
| if helper, exists := c.CredentialHelpers[key]; exists { | ||
| return helper | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return c.CredentialsStore | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is now normalising something ... different? And only to lookup the defaults, but not to normalize the other cases? (i.e.,
getAuthConfigKey("REGISTRY.exAmPLe.COM")returnsREGISTRY.exAmPLe.COMas-is?