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

Normalize auth key before calling SetAuthentication #11430

Merged
merged 1 commit into from
Sep 9, 2021

Conversation

saschagrunert
Copy link
Member

@saschagrunert saschagrunert commented Sep 3, 2021

Recent changes in c/image caused the SetAuthentication API to be more
restrictive in terms of validating the key (server) input. To ensure
that manually modified or entries in ~/.docker/config.json still work,
we now strip the leading http[s]:// prefix.

Fixes #11235

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 3, 2021
@rhatdan
Copy link
Member

rhatdan commented Sep 3, 2021

Shouldn't this be in containers/common/pkg/auth, then Buildah and other tools like Skopeo and CRI-O could use it.

@vrothberg
Copy link
Member

Shouldn't this be in containers/common/pkg/auth, then Buildah and other tools like Skopeo and CRI-O could use it.

I don't think so, it's used for the REST API.

pkg/auth/auth.go Outdated Show resolved Hide resolved
Copy link
Member

@vrothberg vrothberg left a comment

Choose a reason for hiding this comment

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

LGTM

golint isn't happy at the moment. @mtrmac PTAL

Copy link
Collaborator

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

[NO TESTS NEEDED]

???

We have user reports and reproducers. Why not turn that into a “we didn’t think about it before, and we need to record this case for the future” unit test?

pkg/auth/auth.go Outdated
// the resulting registry.
func stripHTTPSPrefix(server string) string {
stripped := strings.TrimPrefix(server, "http://")
return strings.TrimPrefix(stripped, "https://")
Copy link
Collaborator

Choose a reason for hiding this comment

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

This turns the proverbial https://index.docker.io/v1/ into index.docker.io/v1/, a repo-namespaced value (and an invalid one at that.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added normalization cases for docker registries as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is still so different from https://github.com/containers/image/blob/4fcb52359b759a276a760fb28c939c357b3aea48/pkg/docker/config/config.go#L732 . Why?

http{,s}://-prefixed entries are not namespaced; but it is supposed to be possible to have a docker.io/vendor namespaced entry.

@mtrmac
Copy link
Collaborator

mtrmac commented Sep 3, 2021

We have user reports and reproducers. Why not turn that into a “we didn’t think about it before, and we need to record this case for the future” unit test?

It could even be interesting to have a test that provides a file directly to c/image/docker/config (via AuthFilePath), and data via this code path, and ensures that the lookups return the same data.

Recent changes in c/image caused the `SetAuthentication` API to be more
restrictive in terms of validating the `key` (`server`) input. To ensure
that manually modified or entries in `~/.docker/config.json` still work,
we now strip the leading `http[s]://` prefix.

Fixes containers#11235

Signed-off-by: Sascha Grunert <[email protected]>
@saschagrunert
Copy link
Member Author

[NO TESTS NEEDED]

???

We have user reports and reproducers. Why not turn that into a “we didn’t think about it before, and we need to record this case for the future” unit test?

Sure, I added unit tests around the covered use cases.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 9, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: saschagrunert

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@rhatdan
Copy link
Member

rhatdan commented Sep 9, 2021

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2021
@openshift-merge-robot openshift-merge-robot merged commit e73574a into containers:main Sep 9, 2021
@saschagrunert saschagrunert deleted the normalize-key branch September 9, 2021 11:43
name: "normalize https:// prefix",
server: "http://my-registry.local/username",
shouldErr: false,
expectedContains: `"my-registry.local/username":`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

name: "normalize docker registry with https prefix",
server: "http://index.docker.io/v1/",
shouldErr: false,
expectedContains: `"index.docker.io":`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I’d expect the key to be docker.io here, although ultimately it works.

name: "normalize docker registry without https prefix",
server: "docker.io/v2/",
shouldErr: false,
expectedContains: `"docker.io":`,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be docker.io/v2, or rejected as invalid due to the trailing slash. (it never matches in actual files).

@mtrmac
Copy link
Collaborator

mtrmac commented Sep 11, 2021

containers/image#1373 could help with this problem by making GetAllCredentials return normalized auth keys (in particular, docker.io for the old https://index.docker.io/v1/ key values), which AFAICS changes what clients send over the remote API.

But the server should still be doing its own normalization, at the very least to support older clients, incl. possibly (?) projectatomic/docker .

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker APIv2 build endpoint bug with X-Registry-Config
5 participants