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

Support updating registry credentials scoped to namespaces/repos #1288

Merged
merged 1 commit into from
Jul 16, 2021

Conversation

saschagrunert
Copy link
Member

@saschagrunert saschagrunert commented Jul 1, 2021

We now error on login if repositories or repository namespaces are used
for other credential helpers than the AuthenticationFileHelper. On
logout we ignore them and debug log a warning that nothing has been
modified.

The functions SetCredentials (for login) as well as
RemoveAuthentication (for logout) already feature support for path
based registries for the AuthenticationFileHelper. This patch adds
unit tests to ensure that the support will not break in the future.

Refers to #1276

@saschagrunert
Copy link
Member Author

I was checking the functionality during my follow-up mentioned in #1278 (review). Looks like we're mostly set in c/image, whereas c/common would require some slight adaption to make login/logout work correctly.

@rhatdan
Copy link
Member

rhatdan commented Jul 1, 2021

LGTM

@mtrmac
Copy link
Collaborator

mtrmac commented Jul 1, 2021

The functions SetCredentials (for login) as well as
RemoveAuthentication (for logout) already feature support for path
based registries. This patch adds unit tests to ensure that the support
will not break in the future.

That’s not good, because the functions blindly send such values to credential helpers, which may work very badly (see https://issues.redhat.com/browse/RUN-1246?focusedCommentId=16344129&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-16344129 ).

Also, if we are not adding new functions, the documentation of SetCredentials/RemoveAuthentication should be expanded to document that new input is allowed (well, some new input; do we want to allow tagged/digested references?).

WRT credential helpers, for now it would be consistent to just refuse to write namespaced credentials to them (and RemoveAuthentication then needs to account for that by not failing if trying to remove something that we would never add/look up). Eventually we might need to either propose fixes to the helpers, or maintain a list of known good/bad helpers…

@saschagrunert
Copy link
Member Author

@mtrmac would it be better to normalize the input registry for every credentials helper other than AuthenticationFileHelper or test the input registry for being namespaced and fail in that case if the helper is not the AuthenticationFileHelper?

@mtrmac
Copy link
Collaborator

mtrmac commented Jul 1, 2021

If the user requests to record a login for quay.io/foo and later for quay.io/bar, it wouldn’t do to store both to quay.io.

IIRC from a quick skim, we already ~silently continue if a helper refuses data; so I think we can continue to do that and just refuse to even try with non-AuthenticationFileHelper helpers.

Non-blocking? It might be useful to provide a typed error for such a case, or at least to special-case the multiErr handling here, so that the * login commands can report a meaningful “namespaced credentials are not supported with credential helpers” error.

@saschagrunert saschagrunert force-pushed the login-logout-tests branch 2 times, most recently from a12697b to ecdb320 Compare July 1, 2021 14:31
@saschagrunert
Copy link
Member Author

Added a new error type ErrNamespacedRegistry if the registry is namespaced and a non auth.json credentials helper is being used.

@TomSweeneyRedHat
Copy link
Member

@saschagrunert looks like you need a rebase here.

@saschagrunert
Copy link
Member Author

The branch is not on the latest master but I don't see any conflicts :)

@saschagrunert saschagrunert changed the title Add test cases for path based registry login and logout Error on namespaced registries for credential helpers Jul 2, 2021
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.

I have troubles understanding the meaning of "namespaced registry". It mostly relates to using the "namespaced" adjective (all registries have namespaces) but also c/image usually uses "repo[sitory]" rather than "namespace".

I am also a bit worried of the implications of the new error. Can we be certain that registry+repo/path is not supported for creds helpers? I tried looking in the (scarse) docs (https://pkg.go.dev/github.com/docker/[email protected]/credentials#Credentials) but could not find much info on what a "ServerURL" is.

@mtrmac
Copy link
Collaborator

mtrmac commented Jul 2, 2021

I have troubles understanding the meaning of "namespaced registry". It mostly relates to using the "namespaced" adjective (all registries have namespaces) but also c/image usually uses "repo[sitory]" rather than "namespace".

Yeah the key is not a “registry”, so a “namespaces registry” is not ideal. We should think of a name and use it consistently throughout.

  • host[:port] = registry
  • host[:port]/[ns1/…/nsX/]name = repository
  • host[:port]/[ns1/…]/nsX (meant as a parent of …/nsX/name) = namespace; sometimes namespaces might also include leaf repositories (?)
  • any of the above = ???

containers-registries.conf(5) just define a similar syntax (but with leading wildcards) for the prefix field, and then talks about “like the prefix field”.

containers-policy.json(5) talks about “scopes” (but in a more generic transport-dependent way).

I don’t have a good suggestion. “Credentials scope”? “Credential [storage] key”? Both are pretty bad.


I am also a bit worried of the implications of the new error. Can we be certain that registry+repo/path is not supported for creds helpers? I tried looking in the (scarse) docs (https://pkg.go.dev/github.com/docker/[email protected]/credentials#Credentials) but could not find much info on what a "ServerURL" is.

See the various helper implementations in that repo:

  • osxkeychain parses the serverURL into protocol://host:port/path, and stores all of that (but not possible URL query/fragment parts)
  • pass and secretservice seemingly treat serverURL as an opaque byte sequence with no parsing/normalization
  • wincred does approximate matching where basically only the hostname must match.

For now this is already ~decided by #1278 , which does not call helpers for any non-registry keys, and this just does the same thing on the write path; if we don’t look for per-repo credentials in helpers, it doesn’t make much sense to report success on storing the credentials in those helpers. Though we can certainly revisit, and now before a release would be the best time :)

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.

To be explicit, I’m treating this PR as a full “add support for editing namespaced credentials” feature addition. If that’s a bad assumption, please correct me.

pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config_test.go Outdated Show resolved Hide resolved
pkg/docker/config/config_test.go Outdated Show resolved Hide resolved
pkg/docker/config/config_test.go Outdated Show resolved Hide resolved
pkg/docker/config/config_test.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
@saschagrunert
Copy link
Member Author

saschagrunert commented Jul 5, 2021

Alright, just a few points are left open, mostly about the term "namespaced" and "registry". How about:

  • changing "registry" to "key", mentioning in the docs that it should be a "registry" for any credentials helper than the auth file, which supports full "repositories"
  • chaning the ErrNamespacedRegistry to ErrRepositoryPath or ErrUnsupportedRepository, …

@saschagrunert saschagrunert force-pushed the login-logout-tests branch 3 times, most recently from 33a364e to e1a9b66 Compare July 5, 2021 08:22
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.

So that it isn’t forgotten, we will need a solution for namespaces-only logins, maybe containers/common#659 (comment) .

pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
@mtrmac
Copy link
Collaborator

mtrmac commented Jul 9, 2021

Alright, just a few points are left open, mostly about the term "namespaced" and "registry". How about:

  • changing "registry" to "key",

*shrug* works for me. @vrothberg ?

mentioning in the docs that it should be a "registry" for any credentials helper than the auth file, which supports full "repositories"

repositories and repository namespaces

  • chaning the ErrNamespacedRegistry to ErrRepositoryPath or ErrUnsupportedRepository, …

If nothing is checking for that value (as is currently the case), maybe we can just not provide an API and this specific instance goes away (OTOH naming still affects most of the PR throughout anyway).

@vrothberg
Copy link
Member

SGTM

@mtrmac mtrmac changed the title Error on namespaced registries for credential helpers Support updating registry credentials scoped to namespaces/repos Jul 10, 2021
@saschagrunert saschagrunert force-pushed the login-logout-tests branch 5 times, most recently from d41f449 to 0e01664 Compare July 12, 2021 08:40
@saschagrunert
Copy link
Member Author

Implemented the review suggestions, PTAL @mtrmac @vrothberg

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.

So that it isn’t forgotten, we will need a solution for namespaces-only logins, maybe containers/common#659 (comment) .

docs/containers-auth.json.5.md Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Show resolved Hide resolved
pkg/docker/config/config.go Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
pkg/docker/config/config.go Outdated Show resolved Hide resolved
@saschagrunert
Copy link
Member Author

@mtrmac thank you for the review! I addressed your requested changes, PTAL again.

@TomSweeneyRedHat
Copy link
Member

Couple small nits and you need to rebase @saschagrunert

We now error on login if repositories or repository namespaces are used
for other credential helpers than the `AuthenticationFileHelper`. On
logout we ignore them and debug log a warning that nothing has been
modified.

The functions `SetCredentials` (for login) as well as
`RemoveAuthentication` (for logout) already feature support for path
based registries for the `AuthenticationFileHelper`. This patch adds
unit tests to ensure that the support will not break in the future.

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

Rebased and addressed @TomSweeneyRedHat's comments.

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.

LGTM. Thanks!

Are you planning to work on containers/common#659 (comment) as well, to make everything fit together?

return nameParts[0]
}

// stripScheme striped the http|https scheme from the provided URL.
func stripScheme(url string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

(Non-blocking: This can be inlined back into its only caller.)

@TomSweeneyRedHat
Copy link
Member

LGTM
The skopeo test failed, looks like a flake trying to setup a connection to a registry.

@rhatdan rhatdan merged commit d695b98 into containers:main Jul 16, 2021
@saschagrunert
Copy link
Member Author

LGTM. Thanks!

Are you planning to work on containers/common#659 (comment) as well, to make everything fit together?

Yes, I’ll continue working on it next week. :)

@saschagrunert saschagrunert deleted the login-logout-tests branch July 16, 2021 17:53
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.

5 participants