cli/command/registry: fix "docker logout docker.io" leaving credentials behind - #7213
Open
c879873067877881111 wants to merge 2 commits into
Open
Conversation
…ls behind
"docker login docker.io" resolves the default registry to
registry.IndexServer ("https://index.docker.io/v1/") and stores the
credentials under that key. "docker logout docker.io" only treated an
empty server address as the default registry, so it looked for
"docker.io", "http://docker.io" and "https://docker.io" instead. None of
those exist, and fileStore.Erase returns nil for a key that is not
present, so every removal "succeeded": the credentials stayed in
config.json, "Removing login credentials for docker.io" was printed, and
the command exited 0.
Look for the full index address as well when logging out of the default
registry by its namespace ("docker.io") or index hostname
("index.docker.io"). The existing lookups are kept, so credentials stored
under a legacy key are still removed.
Add tests covering the login/logout round-trip; logout had no test
coverage.
Signed-off-by: c879873067877881111 <c879873067877881111@gmail.com>
Point at getAuthConfigKey in cli/config/configfile as the source of the "docker.io" / "index.docker.io" pairing, so the condition does not read as an ad-hoc choice. Signed-off-by: c879873067877881111 <c879873067877881111@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
- What I did
Fixed
docker logout docker.iosilently leaving the credentials inconfig.json. It printedRemoving login credentials for docker.io, returned no error and exited 0, but nothing was removed.docker.iois the name the docs use for Docker Hub, so this is the spelling a user is most likely to reach for.docker logoutwith no argument, anddocker logout https://index.docker.io/v1/, both work — only the namespace form is affected.- How I did it
runLoginresolves the default registry before storing:so
docker login docker.iostores underhttps://index.docker.io/v1/.runLogoutonly treats an empty server address as the default registry, so fordocker.ioit takes the!isDefaultRegistrybranch and buildsregsToLogoutasdocker.io,http://docker.io,https://docker.io. None of those keys exist, andfileStore.Erasereturnsnilfor a key that is not present:so every removal "succeeds",
errsstays empty, and the success message is printed.This patch appends
registry.IndexServertoregsToLogoutwhen logging out of the default registry by namespace or index hostname. The existing lookups are left in place, so credentials stored under a legacy key are still removed.- How to verify it
cli/command/registry/logout.gohad no test file at all. This PR adds one that drives the realrunLogin/runLogoutround-trip for the spellings a user can pass:$ go test ./cli/command/registry/ -run TestLogoutRemovesCredentialsStoredByLogin -vOn master exactly one subtest fails:
With the fix all five pass.
End to end, with a config file holding the entry
docker login docker.iowrites and no credential helper configured:The same sequence built from this branch leaves
.authsempty. In both cases the output and the exit status are identical, which is what makes this one easy to miss.- One thing I deliberately did not change
There is a second, larger reading of this asymmetry, and I would rather ask than guess.
runLogintreatsdocker.ioas the default registry for everything, including the OAuth device-code flow.runLogoutdoes not, soisDefaultRegistrystays false and this block is skipped:That means
docker logout docker.ioalso never reachesOAuthManager.Logout, so the refresh token is neither erased nor revoked with the tenant. Aligning the condition inrunLogoutwith the one inrunLoginwould fix both at once:I kept this PR to the narrow fix because that version also changes the address printed in the output message and drops the legacy
http:///https://lookups for this input. Happy to switch to it if you prefer the symmetry — the test above covers either shape.- Human readable description for the release notes