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

fix/Add hostname check in registry URL on login #5055

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kttyt
Copy link

@kttyt kttyt commented May 3, 2024

- What I did: To address the issue related to potential credential leakage when specifying a registry URL without a hostname, I added validation checks for the registry URL's validity and the presence of a hostname when passing the registry address in the CLI.

- How I did it: As fixing the bug on the server side seemed unfeasible due to the data formation for client-side authentication, which results in passing an empty hostname string and attempting login to the default address with private credentials, I incorporated corresponding checks into the code.

- How to verify it: You can verify it by using the command docker login http:///path, which should output the following message: "Server address must include a hostname: ''".

- Description for the changelog:

Added validation checks for the registry URL's validity and the presence of a hostname when passing the registry address in the CLI to prevent potential credential leakage. [GitHub issue #47795](https://github.com/moby/moby/issues/47795)

- Link to the relevant code snippet in Moby: Moby Code - registry/service.go#L55

fixes: moby/moby#47795

@kttyt kttyt marked this pull request as ready for review May 3, 2024 20:50
Signed-off-by: Vlad Cherkasov <vpcherk@gmail.com>
@kttyt kttyt force-pushed the fix/47795--check-hostname-in-registry-url branch from e78f0a3 to 47e373f Compare May 5, 2024 16:11
Comment on lines +102 to +110
if opts.serverAddress != "" {
u, err := url.Parse(opts.serverAddress)
if err != nil {
return errors.Errorf("Invalid server address: %s", opts.serverAddress)
}
if u.Host == "" {
return errors.Errorf("Server address must include a hostname: %s", opts.serverAddress)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Not sure this change is correct; the expected argument is the hostname[:port] of the registry (so only a hostname, and optionally a port). I think the fact it accepts a scheme may be an accidental side-effect of how it's handled further on, but this change likely will break "correct" cases, e.g. docker login docker.io or docker login example.com:5000.

That said; there's definitely ambiguity in some of these areas, so we need to better define these.

Copy link
Author

Choose a reason for hiding this comment

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

net/url, in accordance with RFC3986, accepts and processes all variations of URLs, including those with or without a scheme and hostname. However, in our case, the hostname is mandatory since it is the only component used for login in the subsequent code. The issue is not the presence of a scheme; the problem lies in the fact that even '/host' is considered a valid URL not related to 'defaultRegistry'. As a result, at the stage indicated in https://github.com/docker/cli/blob/master/cli/command/registry.go#L66, the program follows the wrong path

@kttyt kttyt marked this pull request as draft May 6, 2024 11:00
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 this pull request may close these issues.

Docker send credentials to docker.io when registry URL doesn't contain a host but has a scheme and a path
2 participants