Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Bug 2073113: do not report docker conf deprecation warning when the d…
…ocker is not available
  • Loading branch information
atiratree committed Apr 8, 2022
commit 15eda52a809b03ecb93b5c8a0d3e52f59d015dbc
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
5 changes: 4 additions & 1 deletion 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
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. \"${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
}