Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't filter out registries to logout from with config file contents #2583

Merged
merged 1 commit into from
Jun 17, 2020

Conversation

simonferquel
Copy link
Contributor

@simonferquel simonferquel commented Jun 15, 2020

supersedes / closes

closes #1917
closes #2346
fixes #204

- What I did
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.

- How I did it
Change the logic to call the credential helper for each candidate entry, and comparing the number of returned errors to the number of tries.

- How to verify it

  • docker login (with a credential helper)
  • remove the authInfo from ~/.docker/config.json
  • ensure private pull / push operations still work
  • docker logout
  • ensure private pull / push operations fail

- Description for the changelog

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

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>
@simonferquel simonferquel force-pushed the logout-config-out-of-sync2 branch from 2c04ba0 to 6248f2f Compare June 15, 2020 12:29
@codecov-commenter
Copy link

Codecov Report

Merging #2583 into master will increase coverage by 0.01%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #2583      +/-   ##
==========================================
+ Coverage   58.04%   58.05%   +0.01%     
==========================================
  Files         295      295              
  Lines       21166    21162       -4     
==========================================
  Hits        12285    12285              
+ Misses       7979     7975       -4     
  Partials      902      902              

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

overall looks good; left one comment/question

}

// if at least one removal succeeded, report success. Otherwise report errors
if len(errs) == len(regsToLogout) {
Copy link
Member

Choose a reason for hiding this comment

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

Should we check if len(errs) > 0 or len(regsToLogout) > 0 as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

regsToLogout cannot be empty (it is initialized with one value, and we append other candidates in it if it is not the default registry)

@thaJeztah
Copy link
Member

I see another PR also added some tests; #2346. Haven't looked closely, but could you check if those tests would be useful to have?

if !loggedIn {
fmt.Fprintf(dockerCli.Out(), "Not logged in to %s\n", hostnameAddress)
return nil
regsToLogout = append(regsToLogout, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress)
Copy link
Member

Choose a reason for hiding this comment

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

Actually, given that we duplicate hostnameAddress and perform a logout three times for each registry, I'm wondering if we should make regsToLogout a map[string][]string, so that we (at most) generate a single error per registry

Suggested change
regsToLogout = append(regsToLogout, hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress)
regsToLogout[hostnameAddress] = []string{hostnameAddress, "http://"+hostnameAddress, "https://"+hostnameAddress}

wdyt? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, we logout from a single registry here. It is just that we generate a list of candidates so that docker logout toto tries to logout from both toto, http://toto and https://toto. So there will always be only one entry in this map.
I wonder though if we could only print the first error...

Copy link
Member

Choose a reason for hiding this comment

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

Ah, yes, had my wires crossed, and thinking we're logging out from all registries. Perhaps it's ok for now, considering this a "these are the URLs we tried to logout from, and this is why they failed".

Only thing I'm wondering is if we produce an error if "no entry was found"; if so, and if we would be able to detect that cause, we (IMO) should ignore those, and treat it as an idempotent action.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The "plaintext" credstore implementation is already idempotent, and the wincred helper as well. I am not sure about the mac one, and 3rd parties. But I agree we should document the intended behavior should be idempotent (now that the CLI code is)

@simonferquel
Copy link
Contributor Author

I see another PR also added some tests; #2346. Haven't looked closely, but could you check if those tests would be useful to have?

Hmm, the thing is those tests do not really apply there I think, as it changes the errors reported here (and especially, as a side effect, logout is idempotent - at least for creds helper that don't report an error when loging out from a not logged-in registry)

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@silvin-lubecki PTAL

Copy link
Contributor

@silvin-lubecki silvin-lubecki left a comment

Choose a reason for hiding this comment

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

LGTM, but I think this is the third time we modify this part of the code, we should definitely have some tests on this part.

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.

docker does not gracefully logout for non-default registry
4 participants