Skip to content

fix: set [pull,push] scope when helm push to a registry(use token auth) - v4 - #31211

Merged
TerryHowe merged 16 commits into
helm:mainfrom
kimsungmin1:main-fix-push-scope
Jul 3, 2026
Merged

fix: set [pull,push] scope when helm push to a registry(use token auth) - v4#31211
TerryHowe merged 16 commits into
helm:mainfrom
kimsungmin1:main-fix-push-scope

Conversation

@kimsungmin1

@kimsungmin1 kimsungmin1 commented Aug 28, 2025

Copy link
Copy Markdown
Contributor

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:

  • this PR contains user facing changes (the docs needed label should be applied if so)
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

@pull-request-size pull-request-size Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 28, 2025
Comment thread pkg/registry/utils_test.go Outdated
Comment thread pkg/registry/utils_test.go Outdated
Comment thread go.mod Outdated
@TerryHowe

TerryHowe commented Sep 6, 2025

Copy link
Copy Markdown
Contributor

I made some changes to the registry test that are causing conflicts

@kimsungmin1

Copy link
Copy Markdown
Contributor Author

I made some changes to the registry test that are causing conflicts
@TerryHowe
i resolved the conflict

@TerryHowe
TerryHowe requested a review from Copilot September 8, 2025 14:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 WithScopeHint function
  • 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.

Comment thread pkg/registry/client_scope_test.go Outdated
Comment thread pkg/registry/client_scope_test.go Outdated

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Generally looks good, just some comments from copilot.

Tests ran for me.

@kimsungmin1

Copy link
Copy Markdown
Contributor Author

Generally looks good, just some comments from copilot.

Tests ran for me.

@TerryHowe
i fixed the typo thank you

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm

@kimsungmin1

Copy link
Copy Markdown
Contributor Author

@mattfarina could you review this pr again?

@kimsungmin1

Copy link
Copy Markdown
Contributor Author

Is there any way I can get an approximate date when this PR can be merged?

@TerryHowe

Copy link
Copy Markdown
Contributor

We could still use this.

@kimsungmin1

Copy link
Copy Markdown
Contributor Author

conflict resolved

TerryHowe
TerryHowe previously approved these changes Oct 16, 2025

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm

sabre1041
sabre1041 previously approved these changes Nov 20, 2025

@sabre1041 sabre1041 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@TerryHowe

Copy link
Copy Markdown
Contributor

Closes: #31567

@TerryHowe TerryHowe added Has One Approval This PR has one approval. It still needs a second approval to be merged. Needs v3 backport Label PRs for v4/main, which are still applicable to v3 so need a separate backport PR labels Dec 1, 2025
@TerryHowe

Copy link
Copy Markdown
Contributor

Maybe if @gjenkins8 can get a chance to look at this

Comment thread pkg/registry/client_scope_test.go Outdated
kimsungmin1 and others added 7 commits July 2, 2026 21:34
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>
@kimsungmin1
kimsungmin1 force-pushed the main-fix-push-scope branch from 5c2997c to 4e9ca06 Compare July 2, 2026 12:49
@kimsungmin1

Copy link
Copy Markdown
Contributor Author

@kimsungmin1 this has two approvals from last year, but:

  1. most importantly, CI is failing
  2. also Copilot also made two good comments about avoiding deadlock

hello @scottrigby
i fixed 2 problems
can you run the workflows to check this PR?

- 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>
Copilot AI review requested due to automatic review settings July 2, 2026 12:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 5 comments.

Comment thread pkg/registry/registry_test.go Outdated
Comment on lines +150 to +155
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()
Comment on lines +61 to +66
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()
Comment on lines +107 to +112
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()
Comment thread pkg/registry/client.go
Comment on lines +933 to +940
// 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>
Copilot AI review requested due to automatic review settings July 3, 2026 12:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 1 comment.

Comment thread pkg/registry/client.go
Comment on lines +936 to +939
// 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)

@TerryHowe TerryHowe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm

@TerryHowe
TerryHowe merged commit 543b94d into helm:main Jul 3, 2026
6 checks passed
TerryHowe added a commit to TerryHowe/helm that referenced this pull request Jul 11, 2026
…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>
@scottrigby scottrigby added bug Categorizes issue or PR as related to a bug. needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. and removed Has One Approval This PR has one approval. It still needs a second approval to be merged. keep open labels Aug 12, 2026
@scottrigby scottrigby added this to the 4.2.4 milestone Aug 13, 2026
@scottrigby scottrigby added picked Indicates that a PR has been cherry-picked into the next release candidate. and removed needs-pick Indicates that a PR needs to be cherry-picked into the next release candidate. labels Aug 13, 2026
scottrigby added a commit that referenced this pull request Aug 13, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. Needs v3 backport Label PRs for v4/main, which are still applicable to v3 so need a separate backport PR picked Indicates that a PR has been cherry-picked into the next release candidate. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants