fix: set [pull,push] scope when helm push to a registry(use token auth) - v4 - #31211
Conversation
|
I made some changes to the registry test that are causing conflicts |
|
There was a problem hiding this comment.
Pull Request Overview
This PR addresses an issue with OCI registry authentication scopes in Helm v4 when pushing charts to registries that use token authentication. The fix ensures that Helm requests the appropriate [pull,push] scope during push operations instead of making separate [pull] and [pull,push] requests.
- Adds proper scope hinting for push operations using
WithScopeHintfunction - Introduces comprehensive test coverage for registry scope validation
- Updates existing test infrastructure to support token authentication testing
Reviewed Changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/registry/client.go | Adds WithScopeHint function and integrates scope hinting into push operations |
| pkg/registry/utils_test.go | Extends test setup to support token authentication configuration |
| pkg/registry/client_scope_test.go | New test suite specifically for validating registry authentication scopes |
| pkg/registry/client_tls_test.go | Updates setup call to include auth parameter |
| pkg/registry/client_insecure_tls_test.go | Updates setup call to include auth parameter |
| pkg/registry/client_http_test.go | Updates setup call to include auth parameter |
| go.mod | Adds dependency for JWT token handling |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
TerryHowe
left a comment
There was a problem hiding this comment.
Generally looks good, just some comments from copilot.
Tests ran for me.
@TerryHowe |
|
@mattfarina could you review this pr again? |
|
Is there any way I can get an approximate date when this PR can be merged? |
|
We could still use this. |
daa7019 to
6d3278c
Compare
|
conflict resolved |
|
Closes: #31567 |
|
Maybe if @gjenkins8 can get a chance to look at this |
a7f6b08 to
2dc1ee9
Compare
Signed-off-by: kimsm28 <sm28.kim@samsung.com>
…erver listener management - Change DockerRegistryHost to use 127.0.0.1 for HTTP tests and helm-test-registry for TLS tests to match certificate hostname - Add defer ln.Close() to prevent resource leak in token auth server setup - Restore requestURL variable and assertion in test body instead of handler to avoid potential race condition Signed-off-by: kimsm28 <sm28.kim@samsung.com>
- Change 'bellow' to 'below' (spelling correction in multiple places) - Change 'WithScopeHint' to 'withScopeHint' to match actual function name Signed-off-by: kimsm28 <sm28.kim@samsung.com>
…sertions - Fix data race by using channel instead of shared variable for requestURL - Make assertions more robust by parsing URL and checking query parameters instead of exact string matching Signed-off-by: kimsm28 <sm28.kim@samsung.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Terry Howe <terrylhowe@gmail.com>
The scope test configured a TLS registry while advertising an http token
realm. oras refuses to send credentials to an http token realm when the
registry itself was contacted over https, so the auth server was never
reached and the test timed out ("timeout waiting for auth request").
Use a plain-http registry so the registry and token-realm schemes match;
the scope carried in the token request is what this test verifies, and
that is independent of TLS.
Also make the auth handler's channel send non-blocking so that a client
retry can never block the handler and stall the push/pull flow, which
addresses the review comment about a potential deadlock.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: kimsm28 <sm28.kim@samsung.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: kimsm28 <sm28.kim@samsung.com>
5c2997c to
4e9ca06
Compare
hello @scottrigby |
- Use (*net.ListenConfig).Listen with the test context instead of net.Listen (noctx). - Use suite.NoError instead of suite.Nil for the error check (testifylint). - Drop the unnecessary leading blank lines in the scope test funcs (whitespace). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: kimsm28 <sm28.kim@samsung.com>
| ln, err := lnCfg.Listen(suite.T().Context(), "tcp", "127.0.0.1:0") | ||
| suite.NoError(err, "no error finding free port for test auth server") | ||
| defer ln.Close() | ||
|
|
||
| //set test auth server host | ||
| suite.AuthServerHost = ln.Addr().String() |
| listener, err := lnCfg.Listen(suite.T().Context(), "tcp", suite.AuthServerHost) | ||
| suite.NoError(err, "no error creating server listener") | ||
|
|
||
| ts := httptest.NewUnstartedServer(handler) | ||
| ts.Listener = listener | ||
| ts.Start() |
| listener, err := lnCfg.Listen(suite.T().Context(), "tcp", suite.AuthServerHost) | ||
| suite.NoError(err, "no error creating server listener") | ||
|
|
||
| ts := httptest.NewUnstartedServer(handler) | ||
| ts.Listener = listener | ||
| ts.Start() |
| // add actions when request a registry authentication token(jwt) | ||
| // example1. when we want to pull 'testrepo/local-subchart' we can send below url, and 'pull' is the action | ||
| // auth?scope=repository%3Atestrepo%2Flocal-subchart%3Apull&service=testservice | ||
| // example2. when we want to push 'testrepo/local-subchart' we can send below url, and 'pull%2Cpush' are the actions | ||
| // auth?scope=repository%3Atestrepo%2Flocal-subchart%3Apull%2Cpush&service=testservice | ||
| // we can set the actions like below | ||
| // example) ctx = withScopeHint(ctx, repository, auth.ActionPush, auth.ActionPull) | ||
| func withScopeHint(ctx context.Context, repo *remote.Repository, actions ...string) context.Context { |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: kimsungmin1 <142377392+kimsungmin1@users.noreply.github.com>
| // example2. when we want to push 'testrepo/local-subchart' we can send below url, and 'pull%2Cpush' are the actions | ||
| // auth?scope=repository%3Atestrepo%2Flocal-subchart%3Apull%2Cpush&service=testservice | ||
| // we can set the actions like below | ||
| // example) ctx = withScopeHint(ctx, repository, auth.ActionPush, auth.ActionPull) |
…istry When pushing a chart to an OCI registry that uses token auth, the auth client first requested a [pull]-only scope token, which fails for a repository path that does not yet exist, making it hard to mint a valid token. Hint the [pull,push] scope up front so a single valid token request is made. Ports the fix from helm#31211 to the oras-go v3 code path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Terry Howe <terrylhowe@gmail.com>
This one-line fix is already in main, from #31862. but that PR relies on other refactor PRs, and all are too broad to apply to the patch release branch. Signed-off-by: Scott Rigby <scott@r6by.com>
What this PR does / why we need it:
this pr is same content with #31129
helm v4 also have same problem
make proper scope [pull,push] when helm push a chart to a registry(use token auth)
Special notes for your reviewer:
this pr is about issue #31117 helm make [pull] scope request when push a chart to a registry
so it's hard to give a proper token (becuase helm want a pull permission for a new object(repository path is not exists yet))
old version helm(~3.17)
helm make multiscope [pull],[pull,push] request when push to a registry
https://auth.ociregistry.io/token?scope=repository:myrepo:pull&scope=repository:myrepo:pull,push&service=oci.registry.io"
latest version helm(3.18)
helm make scope [pull] request first
https://auth.ociregistry.io/token?scope=repository:myrepo:pull&service=oci.registry.io"
and then make scope [pull, push] request
https://auth.ociregistry.io/token?scope=repository:myrepo:pull,push&service=oci.registry.io"
this pr version
helm make [pull,push] scope request
https://auth.ociregistry.io/token?scope=repository:myrepo:pull,push&service=oci.registry.io"
i checked actions in my forked repository
please check v3 pr again #31129
If applicable:
docs neededlabel should be applied if so)