@@ -20,6 +20,34 @@ import (
2020 "github.com/sirupsen/logrus"
2121)
2222
23+ // authConfigKey is the key used to store credentials for Docker Hub. It is
24+ // a copy of [registry.IndexServer].
25+ //
26+ // [registry.IndexServer]: https://pkg.go.dev/github.com/docker/docker@v28.5.1+incompatible/registry#IndexServer
27+ const authConfigKey = "https://index.docker.io/v1/"
28+
29+ // getAuthConfigKey returns the canonical key used to look up stored
30+ // registry credentials for the given registry domain.
31+ //
32+ // For the official Docker Hub registry ("docker.io"), credentials are stored
33+ // under the historical full index address ("https://index.docker.io/v1/").
34+ //
35+ // For all other registries, the input is domainName to already be a normalized
36+ // hostname (optionally including ":port") and is returned unchanged.
37+ //
38+ // This function performs key normalization only; it does not validate or parse
39+ // the input.
40+ //
41+ // It is similar to [registry.GetAuthConfigKey] in the daemon.
42+ //
43+ // [registry.GetAuthConfigKey]: https://pkg.go.dev/github.com/docker/docker@v28.5.1+incompatible/registry#GetAuthConfigKey
44+ func getAuthConfigKey (domainName string ) string {
45+ if domainName == "docker.io" || domainName == "index.docker.io" {
46+ return authConfigKey
47+ }
48+ return domainName
49+ }
50+
2351// ConfigFile ~/.docker/config.json file info
2452type ConfigFile struct {
2553 AuthConfigs map [string ]types.AuthConfig `json:"auths"`
@@ -293,7 +321,7 @@ func decodeAuth(authStr string) (string, string, error) {
293321func (configFile * ConfigFile ) GetCredentialsStore (registryHostname string ) credentials.Store {
294322 store := credentials .NewFileStore (configFile )
295323
296- if helper := getConfiguredCredentialStore (configFile , registryHostname ); helper != "" {
324+ if helper := getConfiguredCredentialStore (configFile , getAuthConfigKey ( registryHostname ) ); helper != "" {
297325 store = newNativeStore (configFile , helper )
298326 }
299327
@@ -358,7 +386,8 @@ var newNativeStore = func(configFile *ConfigFile, helperSuffix string) credentia
358386
359387// GetAuthConfig for a repository from the credential store
360388func (configFile * ConfigFile ) GetAuthConfig (registryHostname string ) (types.AuthConfig , error ) {
361- return configFile .GetCredentialsStore (registryHostname ).Get (registryHostname )
389+ acKey := getAuthConfigKey (registryHostname )
390+ return configFile .GetCredentialsStore (acKey ).Get (acKey )
362391}
363392
364393// getConfiguredCredentialStore returns the credential helper configured for the
0 commit comments