fix(login): accept equivalent registry hosts in auth creds callback - #5128
Open
xianyuwu wants to merge 1 commit into
Open
fix(login): accept equivalent registry hosts in auth creds callback#5128xianyuwu wants to merge 1 commit into
xianyuwu wants to merge 1 commit into
Conversation
Parse() appends the standard HTTPS port to the registry address, but the containerd authorizer calls the credentials callback with the request URL host, which omits the default port (or uses the registry-1.docker.io alias for Docker Hub). The strict equality check then fails and login aborts. Replace the strict equality check with an equivalence check that accepts the same hostname with the default port omitted, and the Docker Hub index.docker.io/registry-1.docker.io alias pair. Callback hosts with an explicit non-standard port must still match exactly. Fixes containerd#3992 Refs containerd#3245 Signed-off-by: rainwu <xianyuwu@foxmail.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.
PR Title
fix(login): accept equivalent registry hosts in auth creds callback
PR Body
Summary
nerdctl loginfails against registries served on the default HTTPS port (443)with:
docker loginworks fine against the same registry.Fixes #3992
Refs #3245
Root cause
In
pkg/cmd/login/login.go, the credentials callback passed to the containerdauthorizer used a strict string equality check:
However, the two sides of the comparison are built differently:
hostcomes fromdockerconfigresolver.Parse(), which appends thestandard HTTPS port explicitly when the user did not specify one
(
registryurl.go), sohostisharbor.example.io:443.acArgis passed by containerd'sdockerAuthorizer.AddResponses()aslast.Request.URL.Host, i.e. the host of the actual request, which isharbor.example.io— without the default port.The same fragility produces #3245: logging in to
docker.ioresolves toindex.docker.io:443, while the actual registry endpoint calling back isregistry-1.docker.io.Fix
Replace the strict equality check with an equivalence check
(
isEquivalentRegistryHost) that additionally accepts:did not explicitly configure a non-default port.
index.docker.io(the addressdocker.ioresolves to)and
registry-1.docker.io(the actual registry endpoint).Callback hosts carrying an explicit non-standard port still must match
exactly, so credentials are never served to a different endpoint.
This mirrors the equivalence rules already encoded in
RegistryURL.AllIdentifiers()for credential lookup.Test plan
Added
pkg/cmd/login/login_test.gowith table-driven cases covering:registry-1.docker.iowith/without port against adocker.iologin —reproduces Login to docker.io failed. (
expected acArg to be "docker.io", got "registry-1.docker.io") #3245:8443) — not silently dropped or matchedThe failing scenarios from both issues were reproduced against a private Harbor
registry served on port 443 (
nerdctl login --insecure-registry); the unittest cases above encode exactly those mismatches.