diff --git a/internal/reg_client.go b/internal/reg_client.go index d50cf76..100f298 100644 --- a/internal/reg_client.go +++ b/internal/reg_client.go @@ -31,7 +31,7 @@ type RegistryClient struct { func ResolveAuthConfig(ctx context.Context, index *registrytypes.IndexInfo) registrytypes.AuthConfig { cfg := config.LoadDefaultConfigFile(os.Stderr) - a, _ := cfg.GetAuthConfig(index.Name) + a, _ := cfg.GetAuthConfig(registry.GetAuthConfigKey(index)) return registrytypes.AuthConfig(a) } diff --git a/pkg/compose/auth.go b/pkg/compose/auth.go index 721dffb..27ed9c2 100644 --- a/pkg/compose/auth.go +++ b/pkg/compose/auth.go @@ -2,9 +2,19 @@ package compose import ( "fmt" + "net/http" + "github.com/containerd/containerd/remotes/docker" "github.com/docker/cli/cli/config/configfile" - "net/http" +) + +const ( + DefaultDockerRegistryHost = "registry-1.docker.io" + DefaultDockerIndexHost = "https://index.docker.io/v1/" +) + +type ( + authCredsFunc func(string) (string, string, error) ) func NewRegistryAuthorizer(cfg *configfile.ConfigFile, client *http.Client) docker.Authorizer { @@ -14,12 +24,13 @@ func NewRegistryAuthorizer(cfg *configfile.ConfigFile, client *http.Client) dock ) } -type ( - authCredsFunc func(string) (string, string, error) -) - func getAuthCreds(cfg *configfile.ConfigFile) authCredsFunc { return func(host string) (string, string, error) { + // containerd code translates "docker.io" into "registry-1.docker.io" + if host == DefaultDockerRegistryHost { + // but docker cli uses "https://index.docker.io/v1/" as the key to store auth config + host = DefaultDockerIndexHost + } creds, err := cfg.GetAllCredentials() if err != nil { return "", "", err