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

Query parameters in raw bearer of an unauthorized response from the registry are overwritten #757

Closed
bryanchang15 opened this issue Aug 24, 2020 · 1 comment · Fixed by #758

Comments

@bryanchang15
Copy link

When the token authorization is used to authorized a registry, the query parameters in original realm field from an unauthorized response header are overwritten and leads to successive authorization failures.


E.g. the Bearer in a 401 response header that are returned by the registry is:

Www-Authenticate: Bearer realm="https://private.docker.io/artifacts-auth/docker/jwt?host=private.docker.io",service="docker"

It means that the authorization service is excepted to receive above host as a query parameter. But in our implementation, it won't get and would return errors.


I found that the root cause is the function refreshBasic() in the file pkg/v1/remote/transport/bearer.go, it overwrites (the correct behavior is appending, I think) the original RawQuery that is previously parsed from the realm:

func (bt *bearerTransport) refreshBasic() ([]byte, error) {
        u, err := url.Parse(bt.realm)
	if err != nil {
		return nil, err
	}
        // Now we have original query parameters in u.RawQuery, everything is ok, 
   
        ...

        // but unfortunately we overwrites it here
       u.RawQuery = url.Values{
		"scope":   bt.scopes,
		"service": []string{bt.service},
        }.Encode()

        ...
}

Hopefully my post can help to improve this repo.

@jonjohnsonjr
Copy link
Collaborator

Thanks for reporting this, I've landed a fix -- let me know if you're still having issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants