Skip to content

Fix login logout when engine is down and credential helper is in use - #1789

Merged
thaJeztah merged 2 commits into
docker:masterfrom
djs55:fix-login-logout
Mar 29, 2019
Merged

thaJeztah merged 2 commits into
docker:masterfrom
djs55:fix-login-logout

Conversation

@djs55

@djs55 djs55 commented Mar 29, 2019

Copy link
Copy Markdown
Contributor

- What I did

Fixed docker login and docker logout when the engine is not running and when using a credential helper.

- How I did it

The logic in ElectAuthServer accidentally combined together checking the error from the engine with the state of the debug flag when deciding which value to return.

- How to verify it

I used Docker Desktop on Mac with the docker-credential-osxkeychain enabled (which is the default). I shutdown the app. Without this patch I ran:

$ docker logout
Not logged in to

-- note the missing server URL

$ docker --debug logout
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
Not logged in to https://index.docker.io/v1/

-- note the server URL is present

This shows that the --debug flag is changing the actual behaviour of the program.

I ran docker login and observed an error from the credential helper

Error saving credentials: error storing credentials - err: no credentials server URL, out: `no credentials server URL`

When I rebuilt the CLI with this PR docker login and docker logout operated as expected.

I separated this PR into 2 patches:

  1. the actual bugfix
  2. a small refactoring which I think makes ElectAuthServer easier to read but which is optional

- Description for the changelog
Fix docker login and docker logout when the engine is not running and a credential helper is in use.

- A picture of a cute animal (not mandatory but encouraged)

39df0ec8dab014008eb217865bc4635b

djs55 added 2 commits March 28, 2019 21:04
Previously if the Docker engine was not running the behaviour of
commands would vary depending on whether the --debug flag was provided.

For example, consider `docker logout`:

    $ docker logout
    Not logged in to

-- note the missing server URL

    $ docker --debug logout
    Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
    Not logged in to https://index.docker.io/v1/

-- note the server URL is present

This patch makes only the debug printing conditional on the `--debug` flag,
not the return value.

Signed-off-by: David Scott <dave.scott@docker.com>
Instead of using an `if else if else`, switch to a sequence of independent
`if` blocks containing a `return`.

Instead of defining a return variable and updating it in the `if` blocks
and returning at the end, make each `if` block return the desired value
independenly.

Signed-off-by: David Scott <dave.scott@docker.com>
@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #1789 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1789      +/-   ##
==========================================
+ Coverage   56.26%   56.26%   +<.01%     
==========================================
  Files         308      308              
  Lines       21293    21295       +2     
==========================================
+ Hits        11980    11982       +2     
  Misses       8439     8439              
  Partials      874      874

1 similar comment
@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #1789 into master will increase coverage by <.01%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1789      +/-   ##
==========================================
+ Coverage   56.26%   56.26%   +<.01%     
==========================================
  Files         308      308              
  Lines       21293    21295       +2     
==========================================
+ Hits        11980    11982       +2     
  Misses       8439     8439              
  Partials      874      874

Comment thread cli/command/registry.go
fmt.Fprintf(cli.Err(), "Warning: Empty registry endpoint from daemon. Using system default: %s\n", serverAddress)
} else {
serverAddress = info.IndexServerAddress
info, err := cli.Client().Info(ctx)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use /_ping for this? (/info is a bit heavy just to know if the engine is up and running)

Comment thread cli/command/registry.go
}
return registry.IndexServer
}
if info.IndexServerAddress == "" {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, never mind, I see we need this information 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread cli/command/registry.go
return registry.IndexServer
}
if info.IndexServerAddress == "" {
if debug.IsEnabled() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely need a real log policy here: we should write something like log.Warning(...) and let the debug flag change only the output level, not spreading it everywhere. But of course that's another issue.

@silvin-lubecki silvin-lubecki left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread cli/command/registry.go
@@ -28,16 +28,22 @@ func ElectAuthServer(ctx context.Context, cli Cli) string {
// used. This is essential in cross-platforms environment, where for
// example a Linux client might be interacting with a Windows daemon, hence

@thaJeztah thaJeztah Mar 29, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was added in moby/moby#19891 at a time where a temporary/special Windows registry was set up: moby/moby#18019 https://github.com/moby/moby/blob/960710bd810e70b7c06b77b956c7bf8cdfeb15f8/registry/config_windows.go#L9-L19

Which was removed in moby/moby#21100

Actually thinking if that handling is now just dead code and no longer needed

@thaJeztah thaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I'll have a look at removing the handling of "special" URLs for windows; guess this could be removed altogether

@thaJeztah
thaJeztah merged commit 2236568 into docker:master Mar 29, 2019
@GordonTheTurtle GordonTheTurtle added this to the 19.03.0 milestone Mar 29, 2019
@djs55

djs55 commented Mar 29, 2019

Copy link
Copy Markdown
Contributor Author

Thanks for the very quick response (and merge)!

@djs55
djs55 deleted the fix-login-logout branch March 29, 2019 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants