Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 936779c

Browse files
simonferquelthaJeztah
authored andcommitted
Don't filter out registries to logout from with config file contents
Previously, if a registry AuthInfo was not present in the CLI config file, docker logout could not be used to ask the credential helper to forget about it. It causes problem for people working with multiple alternative config files, and it causes problems for cases like Docker Desktop w/ WSL 2, as it uses the same win32 credential helper as the Windows CLI, but a different config file, leading to bugs where I cannot logout from a registry from wsl2 if I logged in from Windows and vice-versa. Signed-off-by: Simon Ferquel <simon.ferquel@docker.com> (cherry picked from commit 6248f2fb6fa6c6035d7b94193a70b44ffd9b3c9e) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 5a12f90b4cbf675f3b7d3c0a216ce5eee911e88a Component: cli
1 parent 2fbdc02 commit 936779c

1 file changed

Lines changed: 12 additions & 19 deletions

File tree

components/cli/cli/command/registry/logout.go

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,36 +39,29 @@ func runLogout(dockerCli command.Cli, serverAddress string) error {
3939
}
4040

4141
var (
42-
loggedIn bool
43-
regsToLogout []string
42+
regsToLogout = []string{serverAddress}
4443
hostnameAddress = serverAddress
45-
regsToTry = []string{serverAddress}
4644
)
4745
if !isDefaultRegistry {
4846
hostnameAddress = registry.ConvertToHostname(serverAddress)
4947
// the tries below are kept for backward compatibility where a user could have
5048
// saved the registry in one of the following format.
51-
regsToTry = append(regsToTry, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress)
52-
}
53-
54-
// check if we're logged in based on the records in the config file
55-
// which means it couldn't have user/pass cause they may be in the creds store
56-
for _, s := range regsToTry {
57-
if _, ok := dockerCli.ConfigFile().AuthConfigs[s]; ok {
58-
loggedIn = true
59-
regsToLogout = append(regsToLogout, s)
60-
}
61-
}
62-
63-
if !loggedIn {
64-
fmt.Fprintf(dockerCli.Out(), "Not logged in to %s\n", hostnameAddress)
65-
return nil
49+
regsToLogout = append(regsToLogout, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress)
6650
}
6751

6852
fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress)
53+
errs := make(map[string]error)
6954
for _, r := range regsToLogout {
7055
if err := dockerCli.ConfigFile().GetCredentialsStore(r).Erase(r); err != nil {
71-
fmt.Fprintf(dockerCli.Err(), "WARNING: could not erase credentials: %v\n", err)
56+
errs[r] = err
57+
}
58+
}
59+
60+
// if at least one removal succeeded, report success. Otherwise report errors
61+
if len(errs) == len(regsToLogout) {
62+
fmt.Fprintln(dockerCli.Err(), "WARNING: could not erase credentials:")
63+
for k, v := range errs {
64+
fmt.Fprintf(dockerCli.Err(), "%s: %s\n", k, v)
7265
}
7366
}
7467

0 commit comments

Comments
 (0)