diff --git a/pkg/cli/image/manifest/dockercredentials/auth_resolver.go b/pkg/cli/image/manifest/dockercredentials/auth_resolver.go index 6c583d2561..bec3493a59 100644 --- a/pkg/cli/image/manifest/dockercredentials/auth_resolver.go +++ b/pkg/cli/image/manifest/dockercredentials/auth_resolver.go @@ -50,12 +50,18 @@ func NewAuthResolver(authFilePath string) (*AuthResolver, error) { if err != nil { return nil, err } - if image.GetRegistryAuthConfigPreference() == image.DockerPreference { - // give priority to the docker config file $HOME/.docker/config.json - for registry, entry := range defaultClientDockerConfig() { - credentials[registry] = containertypes.DockerAuthConfig{ - Username: entry.Username, - Password: entry.Password, + if pref, warn := image.GetRegistryAuthConfigPreference(); pref == image.DockerPreference { + config := defaultClientDockerConfig() + if config != nil { + if len(warn) > 0 { + fmt.Fprint(os.Stderr, warn) + } + // give priority to the docker config file $HOME/.docker/config.json + for registry, entry := range config { + credentials[registry] = containertypes.DockerAuthConfig{ + Username: entry.Username, + Password: entry.Password, + } } } @@ -165,7 +171,7 @@ func defaultClientDockerConfig() credentialprovider.DockerConfig { if cfg, err := credentialprovider.ReadDockercfgFile(defaultPathsForLegacyCredentials()); err == nil { return cfg } - return credentialprovider.DockerConfig{} + return nil } // defaultPathsForCredentials returns the correct search directories for a docker config diff --git a/pkg/cli/registry/login/login.go b/pkg/cli/registry/login/login.go index 1c6fcf7914..f04e397710 100644 --- a/pkg/cli/registry/login/login.go +++ b/pkg/cli/registry/login/login.go @@ -242,7 +242,10 @@ func (o *LoginOptions) Complete(f kcmdutil.Factory, args []string) error { if len(o.ConfigFile) == 0 { if authFile := os.Getenv("REGISTRY_AUTH_FILE"); authFile != "" { o.ConfigFile = authFile - } else if image.GetRegistryAuthConfigPreference() == image.DockerPreference { + } else if pref, warn := image.GetRegistryAuthConfigPreference(); pref == image.DockerPreference { + if len(warn) > 0 { + fmt.Fprint(o.IOStreams.ErrOut, warn) + } home := homedir.HomeDir() o.ConfigFile = filepath.Join(home, ".docker", "config.json") } @@ -300,7 +303,7 @@ func (o *LoginOptions) Run() error { if o.ConfigFile == "-" { // TODO: deprecated, remove in 4.12 - fmt.Fprint(o.IOStreams.ErrOut, "Warning: support for stdout output is deprecated. The support will be removed in the future version.\n") + fmt.Fprint(o.IOStreams.ErrOut, "Warning: support for stdout output is deprecated. The support will be removed in the future version of oc.\n") authFilePath, err = createTmpAuthFile() if err != nil { return err @@ -341,7 +344,7 @@ func (o *LoginOptions) ensureEmptyAuthFileInitialized(configFile string) error { } if !os.IsNotExist(err) && fileInfo.Size() == 0 { // TODO: deprecated, remove in 4.12 - fmt.Fprint(o.IOStreams.ErrOut, "Warning: support for empty registry config files is deprecated. The support will be removed in the future version.\n") + fmt.Fprint(o.IOStreams.ErrOut, "Warning: support for empty registry config files is deprecated. The support will be removed in the future version of oc.\n") file, err := os.OpenFile(configFile, os.O_APPEND|os.O_WRONLY, 0600) if err != nil { return err diff --git a/pkg/helpers/image/helpers.go b/pkg/helpers/image/helpers.go index 04417f951a..f561727726 100644 --- a/pkg/helpers/image/helpers.go +++ b/pkg/helpers/image/helpers.go @@ -1,7 +1,6 @@ package image import ( - "fmt" "os" "strings" @@ -141,14 +140,15 @@ var ( PodmanPreference RegistryAuthConfigPreference = "podman" ) -func GetRegistryAuthConfigPreference() RegistryAuthConfigPreference { +func GetRegistryAuthConfigPreference() (RegistryAuthConfigPreference, string) { // TODO: docker default is deprecated and will be changed to podman in 4.12 result := DockerPreference // default to docker + warning := "" if authPreference := strings.ToLower(os.Getenv("REGISTRY_AUTH_PREFERENCE")); authPreference == string(DockerPreference) || authPreference == string(PodmanPreference) { result = RegistryAuthConfigPreference(authPreference) } else { // TODO: remove once deprecated in 4.12 - fmt.Fprintf(os.Stderr, "Warning: the default reading order of registry auth file will be changed from \"${HOME}/.docker/config.json\" to podman registry config locations in the future version. \"${HOME}/.docker/config.json\" is deprecated, but can still be used for storing credentials as a fallback. See https://github.com/containers/image/blob/main/docs/containers-auth.json.5.md for the order of podman registry config locations.\n") + warning = "Warning: the default reading order of registry auth file will be changed from \"${HOME}/.docker/config.json\" to podman registry config locations in the future version of oc. \"${HOME}/.docker/config.json\" is deprecated, but can still be used for storing credentials as a fallback. See https://github.com/containers/image/blob/main/docs/containers-auth.json.5.md for the order of podman registry config locations.\n" } - return result + return result, warning }