From 1ff65e517aeb34010ebd805ba6ad15e9aa5c7a23 Mon Sep 17 00:00:00 2001 From: Robert Zastrau Date: Tue, 4 Jun 2019 17:21:03 +0200 Subject: [PATCH 1/3] REMOVE MULTIPLE CREDENTIAL ERASES When starting to erase docker credentials on logout, the slice "regsToTry" is initialised with the given server address. Afterwards the server address is normalized and the possible, different formats are being built for the actual credential erase. If the given server address is already normalized, it would be checked twice, issuing when checking the second time. This bug is fixed here. Signed-off-by: Robert Zastrau --- cli/command/registry/logout.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/command/registry/logout.go b/cli/command/registry/logout.go index ac84139f7efc..4b5f495dc25a 100644 --- a/cli/command/registry/logout.go +++ b/cli/command/registry/logout.go @@ -42,7 +42,7 @@ func runLogout(dockerCli command.Cli, serverAddress string) error { loggedIn bool regsToLogout []string hostnameAddress = serverAddress - regsToTry = []string{serverAddress} + regsToTry []string ) if !isDefaultRegistry { hostnameAddress = registry.ConvertToHostname(serverAddress) From 1bba6b45ee62f7fc52ac2c4370da36fbdfb7d378 Mon Sep 17 00:00:00 2001 From: Robert Zastrau Date: Thu, 6 Jun 2019 22:27:01 +0200 Subject: [PATCH 2/3] REMOVE MULTIPLE CREDENTIAL ERASES Fix problem that no logout is performed, when dealing with the default registry. Also shortened the whole func to avoid appending to a second slice. This also saves a second for loop, because auth credentials can be removed as they are found. Not sure how the errors shall be handled in here. Signed-off-by: Robert Zastrau --- cli/command/registry/logout.go | 37 +++++++++++++++++----------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/cli/command/registry/logout.go b/cli/command/registry/logout.go index 4b5f495dc25a..6a281b2c7669 100644 --- a/cli/command/registry/logout.go +++ b/cli/command/registry/logout.go @@ -31,24 +31,25 @@ func NewLogoutCommand(dockerCli command.Cli) *cobra.Command { func runLogout(dockerCli command.Cli, serverAddress string) error { ctx := context.Background() - var isDefaultRegistry bool - - if serverAddress == "" { - serverAddress = command.ElectAuthServer(ctx, dockerCli) - isDefaultRegistry = true - } var ( - loggedIn bool - regsToLogout []string hostnameAddress = serverAddress - regsToTry []string + loggedIn bool // is set later, when checking for credentials + regsToTry []string // is set based on the type of registry ) - if !isDefaultRegistry { + + // differentiate between default und private registry + if serverAddress == "" { + // if no server address given, handle case for default registry + serverAddress = command.ElectAuthServer(ctx, dockerCli) + regsToTry = []string{serverAddress} + } else { + // if server address given, handle case for private registry hostnameAddress = registry.ConvertToHostname(serverAddress) + // the tries below are kept for backward compatibility where a user could have // saved the registry in one of the following format. - regsToTry = append(regsToTry, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress) + regsToTry = []string{hostnameAddress, "http://" + hostnameAddress, "https://" + hostnameAddress} } // check if we're logged in based on the records in the config file @@ -56,7 +57,12 @@ func runLogout(dockerCli command.Cli, serverAddress string) error { for _, s := range regsToTry { if _, ok := dockerCli.ConfigFile().AuthConfigs[s]; ok { loggedIn = true - regsToLogout = append(regsToLogout, s) + + // remove credentials, for found auth config + fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress) + if err := dockerCli.ConfigFile().GetCredentialsStore(s).Erase(s); err != nil { + fmt.Fprintf(dockerCli.Err(), "WARNING: could not erase credentials: %v\n", err) + } } } @@ -65,12 +71,5 @@ func runLogout(dockerCli command.Cli, serverAddress string) error { return nil } - fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress) - for _, r := range regsToLogout { - if err := dockerCli.ConfigFile().GetCredentialsStore(r).Erase(r); err != nil { - fmt.Fprintf(dockerCli.Err(), "WARNING: could not erase credentials: %v\n", err) - } - } - return nil } From a48577ea9b694a44f4da79b3558a8578e0d9b5ed Mon Sep 17 00:00:00 2001 From: Robert Zastrau Date: Thu, 6 Jun 2019 22:32:56 +0200 Subject: [PATCH 3/3] REMOVE MULTIPLE CREDENTIAL ERASES Fix problem with hostname address. If default registry is handled, the hostname address would be empty and error logs would not be clear to the user. Signed-off-by: Robert Zastrau --- cli/command/registry/logout.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cli/command/registry/logout.go b/cli/command/registry/logout.go index 6a281b2c7669..30d0cc9e50f5 100644 --- a/cli/command/registry/logout.go +++ b/cli/command/registry/logout.go @@ -33,9 +33,8 @@ func runLogout(dockerCli command.Cli, serverAddress string) error { ctx := context.Background() var ( - hostnameAddress = serverAddress - loggedIn bool // is set later, when checking for credentials - regsToTry []string // is set based on the type of registry + loggedIn bool // is set later, when checking for credentials + regsToTry []string // is set based on the type of registry ) // differentiate between default und private registry @@ -45,7 +44,7 @@ func runLogout(dockerCli command.Cli, serverAddress string) error { regsToTry = []string{serverAddress} } else { // if server address given, handle case for private registry - hostnameAddress = registry.ConvertToHostname(serverAddress) + hostnameAddress := registry.ConvertToHostname(serverAddress) // the tries below are kept for backward compatibility where a user could have // saved the registry in one of the following format. @@ -59,7 +58,7 @@ func runLogout(dockerCli command.Cli, serverAddress string) error { loggedIn = true // remove credentials, for found auth config - fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", hostnameAddress) + fmt.Fprintf(dockerCli.Out(), "Removing login credentials for %s\n", serverAddress) if err := dockerCli.ConfigFile().GetCredentialsStore(s).Erase(s); err != nil { fmt.Fprintf(dockerCli.Err(), "WARNING: could not erase credentials: %v\n", err) } @@ -67,7 +66,7 @@ func runLogout(dockerCli command.Cli, serverAddress string) error { } if !loggedIn { - fmt.Fprintf(dockerCli.Out(), "Not logged in to %s\n", hostnameAddress) + fmt.Fprintf(dockerCli.Out(), "Not logged in to %s\n", serverAddress) return nil }