From ccd5bd8d5754d8924905b05a67dc8ca11c280baf Mon Sep 17 00:00:00 2001 From: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> Date: Fri, 4 Jul 2025 14:05:11 +0200 Subject: [PATCH] registry: warn of DOCKER_AUTH_CONFIG usage in login and logout Signed-off-by: Alano Terblanche <18033717+Benehiko@users.noreply.github.com> --- cli/command/registry/login.go | 3 +++ cli/command/registry/logout.go | 2 ++ cli/command/registry/warning.go | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 cli/command/registry/warning.go diff --git a/cli/command/registry/login.go b/cli/command/registry/login.go index ce5e584859..3679e51edd 100644 --- a/cli/command/registry/login.go +++ b/cli/command/registry/login.go @@ -110,6 +110,9 @@ func runLogin(ctx context.Context, dockerCLI command.Cli, opts loginOptions) err if err := verifyLoginOptions(dockerCLI, &opts); err != nil { return err } + + maybePrintEnvAuthWarning(dockerCLI) + var ( serverAddress string msg string diff --git a/cli/command/registry/logout.go b/cli/command/registry/logout.go index 6dc75dc585..2af2cdad3f 100644 --- a/cli/command/registry/logout.go +++ b/cli/command/registry/logout.go @@ -36,6 +36,8 @@ func NewLogoutCommand(dockerCli command.Cli) *cobra.Command { } func runLogout(ctx context.Context, dockerCLI command.Cli, serverAddress string) error { + maybePrintEnvAuthWarning(dockerCLI) + var isDefaultRegistry bool if serverAddress == "" { diff --git a/cli/command/registry/warning.go b/cli/command/registry/warning.go new file mode 100644 index 0000000000..22a8c8655b --- /dev/null +++ b/cli/command/registry/warning.go @@ -0,0 +1,18 @@ +package registry + +import ( + "os" + + "github.com/docker/cli/cli/command" + "github.com/docker/cli/cli/config/configfile" + "github.com/docker/cli/internal/tui" +) + +// maybePrintEnvAuthWarning if the `DOCKER_AUTH_CONFIG` environment variable is +// set this function will output a warning to stdErr +func maybePrintEnvAuthWarning(out command.Streams) { + if os.Getenv(configfile.DockerEnvConfigKey) != "" { + tui.NewOutput(out.Err()). + PrintWarning("%[1]s is set and takes precedence.\nUnset %[1]s to restore the CLI auth behaviour.\n", configfile.DockerEnvConfigKey) + } +}