Skip to content

Commit 26b412e

Browse files
authored
Merge pull request #5258 from thaJeztah/cleanup_unencrypted_warning
login: slightly cleanup warning about unencrypted store
2 parents 07baebe + fcefe44 commit 26b412e

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

cli/command/registry/login.go

+13-22
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ import (
1818
"github.com/spf13/cobra"
1919
)
2020

21-
const unencryptedWarning = `WARNING! Your password will be stored unencrypted in %s.
21+
// unencryptedWarning warns the user when using an insecure credential storage.
22+
// After a deprecation period, user will get prompted if stdin and stderr are a terminal.
23+
// Otherwise, we'll assume they want it (sadly), because people may have been scripting
24+
// insecure logins and we don't want to break them. Maybe they'll see the warning in their
25+
// logs and fix things.
26+
const unencryptedWarning = `
27+
WARNING! Your credentials are stored unencrypted in '%s'.
2228
Configure a credential helper to remove this warning. See
23-
https://docs.docker.com/engine/reference/commandline/login/#credential-stores
29+
https://docs.docker.com/go/credential-store/
2430
`
2531

2632
type loginOptions struct {
@@ -60,17 +66,6 @@ func NewLoginCommand(dockerCli command.Cli) *cobra.Command {
6066
return cmd
6167
}
6268

63-
// displayUnencryptedWarning warns the user when using an insecure credential storage.
64-
// After a deprecation period, user will get prompted if stdin and stderr are a terminal.
65-
// Otherwise, we'll assume they want it (sadly), because people may have been scripting
66-
// insecure logins and we don't want to break them. Maybe they'll see the warning in their
67-
// logs and fix things.
68-
func displayUnencryptedWarning(dockerCli command.Streams, filename string) error {
69-
_, err := fmt.Fprintln(dockerCli.Err(), fmt.Sprintf(unencryptedWarning, filename))
70-
71-
return err
72-
}
73-
7469
type isFileStore interface {
7570
IsFileStore() bool
7671
GetFilename() string
@@ -143,19 +138,15 @@ func runLogin(ctx context.Context, dockerCli command.Cli, opts loginOptions) err
143138

144139
creds := dockerCli.ConfigFile().GetCredentialsStore(serverAddress)
145140

146-
store, isDefault := creds.(isFileStore)
147-
// Display a warning if we're storing the users password (not a token)
148-
if isDefault && authConfig.Password != "" {
149-
err = displayUnencryptedWarning(dockerCli, store.GetFilename())
150-
if err != nil {
151-
return err
152-
}
153-
}
154-
155141
if err := creds.Store(configtypes.AuthConfig(authConfig)); err != nil {
156142
return errors.Errorf("Error saving credentials: %v", err)
157143
}
158144

145+
if store, isDefault := creds.(isFileStore); isDefault && authConfig.Password != "" {
146+
// Display a warning if we're storing the users password (not a token)
147+
_, _ = fmt.Fprintln(dockerCli.Err(), fmt.Sprintf(unencryptedWarning, store.GetFilename()))
148+
}
149+
159150
if response.Status != "" {
160151
fmt.Fprintln(dockerCli.Out(), response.Status)
161152
}

0 commit comments

Comments
 (0)