Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions pkg/cli/image/manifest/dockercredentials/auth_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}

Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions pkg/cli/registry/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/helpers/image/helpers.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package image

import (
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -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
}