Skip to content

Commit ccd5bd8

Browse files
committed
registry: warn of DOCKER_AUTH_CONFIG usage in login and logout
Signed-off-by: Alano Terblanche <[email protected]>
1 parent dec07e6 commit ccd5bd8

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

cli/command/registry/login.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ func runLogin(ctx context.Context, dockerCLI command.Cli, opts loginOptions) err
110110
if err := verifyLoginOptions(dockerCLI, &opts); err != nil {
111111
return err
112112
}
113+
114+
maybePrintEnvAuthWarning(dockerCLI)
115+
113116
var (
114117
serverAddress string
115118
msg string

cli/command/registry/logout.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func NewLogoutCommand(dockerCli command.Cli) *cobra.Command {
3636
}
3737

3838
func runLogout(ctx context.Context, dockerCLI command.Cli, serverAddress string) error {
39+
maybePrintEnvAuthWarning(dockerCLI)
40+
3941
var isDefaultRegistry bool
4042

4143
if serverAddress == "" {

cli/command/registry/warning.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package registry
2+
3+
import (
4+
"os"
5+
6+
"github.com/docker/cli/cli/command"
7+
"github.com/docker/cli/cli/config/configfile"
8+
"github.com/docker/cli/internal/tui"
9+
)
10+
11+
// maybePrintEnvAuthWarning if the `DOCKER_AUTH_CONFIG` environment variable is
12+
// set this function will output a warning to stdErr
13+
func maybePrintEnvAuthWarning(out command.Streams) {
14+
if os.Getenv(configfile.DockerEnvConfigKey) != "" {
15+
tui.NewOutput(out.Err()).
16+
PrintWarning("%[1]s is set and takes precedence.\nUnset %[1]s to restore the CLI auth behaviour.\n", configfile.DockerEnvConfigKey)
17+
}
18+
}

0 commit comments

Comments
 (0)