Skip to content

chore(oci): migrate to ORAS Golang library v2 - #13382

Merged
scottrigby merged 1 commit into
helm:mainfrom
TerryHowe:orasv2
Feb 3, 2025
Merged

scottrigby merged 1 commit into
helm:mainfrom
TerryHowe:orasv2

Conversation

@TerryHowe

@TerryHowe TerryHowe commented Oct 8, 2024 •

Copy link
Copy Markdown
Contributor

What this PR does / why we need it:

I could not create a PR on Zoran's #12310 so this combines the two with:

  • rebased
  • fixed broken tests
  • diffs from Zoran's e88e515

Updates from oras.land/oras-go to oras.land/oras-go/v2. The main user facing change is that the --plain-http parameter is now required even when accessing OCI registries running on localhost.

Fixes #11821
Closes #12310

Special notes for your reviewer:

I'm new to this codebase and some tests needed to be adjusted to match the new dependency, please look over the test changes to see if there are any issues with those.

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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Oct 8, 2024
@TerryHowe TerryHowe changed the title Orasv2 chore(oci): migrate to ORAS Golang library v2 Oct 8, 2024
@TerryHowe
TerryHowe force-pushed the orasv2 branch 2 times, most recently from 3d9ac74 to 2efec5c Compare October 8, 2024 19:49
@robertsirc

Copy link
Copy Markdown
Member

Two of the commits are Unverified.

@TerryHowe

Copy link
Copy Markdown
Contributor Author

Two of the commits are Unverified.

Hmm, since I cant do a PR on Zoran's repo, I'll probably have to merge main instead of rebase.

@TerryHowe

Copy link
Copy Markdown
Contributor Author

Two of the commits are Unverified.

Hmm, since I cant do a PR on Zoran's repo, I'll probably have to merge main instead of rebase.

Fixed

@Happylinzy

Copy link
Copy Markdown

Hi. Any update in merging this pr?

@Happylinzy Happylinzy left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@gjenkins8 gjenkins8 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have managed to get to a partial review. I would like to finish full review next few days.

The sticking point for this PR is still going to be the breaking change. ie. this comment: #13382 (comment)

We might just be better targeting Helm v4 and moving forward?

func (suite *InsecureTLSRegistryClientTestSuite) Test_4_Logout() {
err := suite.RegistryClient.Logout("this-host-aint-real:5000")
suite.NotNil(err, "error logging out of registry that has no entry")
if err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is redundant / suite.NotNil(err) will validate that err is not nil?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Alright, I was confused too, but the comment is actually correct.

On the mac the docker credential backend produces and error for credential not found, but it is silently ignored by other credential providers.

func (suite *TLSRegistryClientTestSuite) Test_4_Logout() {
err := suite.RegistryClient.Logout("this-host-aint-real:5000")
suite.NotNil(err, "error logging out of registry that has no entry")
if err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same as above

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On the mac the docker credential backend produces and error for credential not found, but it is silently ignored by other credential providers. I don't think v1 oras-go supported using the native key store, so this change needs to happen. I'm not sure of a more graceful way to handle this.

Comment thread pkg/registry/client_test.go Resolved
Comment thread cmd/helm/dependency_build.go Resolved
Comment thread cmd/helm/dependency_update.go Resolved
registry.LoginOptBasicAuth(username, password),
registry.LoginOptInsecure(a.insecure),
registry.LoginOptTLSClientConfig(a.certFile, a.keyFile, a.caFile))
registry.LoginOptTLSClientConfig(a.certFile, a.keyFile, a.caFile),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will LoginOptPlainText work with LoginOptTLSClientConfig and LoginOptInsecure?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't see anything in the underlying code that would validate those options. It looks like to me that if you specified plainHTTP, it is going to ignore any TLS options which makes sense.

I don't think there is any mutually exclusive check on insecure/TLS as well.

If PlainHTTP is an issue, I'd almost sooner remove the flag from this PR and throw it in another PR. It is a new feature in this PR.

Comment thread pkg/registry/client.go
}
func ClientOptResolver(_ remotes.Resolver) ClientOption {
return func(c *Client) {
c.err = errDeprecatedRemote

@gjenkins8 gjenkins8 Nov 11, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I honestly think, converting the previous build time breakage to a runtime error (in the name of maintaining API compatibility) is a much worse idea.

That said, aside from deferring this PR to Helm v4, I'm not sure how to solve this otherwise. The choices are API or functional breakage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

More discussion on this from Zoran's PR https://github.com/helm/helm/pull/12310/files#r1499833508 I don't love it either, but I'm not seeing a better solution

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bad for a few, but great for many.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

For Helm 4, we should just remove ClientOptResolver I think

For a Helm 3 backport, what would be the alternative for users? Can we document in a function doc comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I create #13593 to track the removing this from v4, but figured I'd leave this here for now in case we backport this change.

gjenkins8
gjenkins8 previously approved these changes Dec 20, 2024
@gjenkins8

Copy link
Copy Markdown
Member

Upgrading here is good for Helm 4. Backport to Helm 3 I think we should (continue to) think hard about https://github.com/helm/helm/pull/13382/files#r1836977600

gjenkins8
gjenkins8 previously approved these changes Dec 21, 2024
@gjenkins8 gjenkins8 added the Has One Approval This PR has one approval. It still needs a second approval to be merged. label Dec 21, 2024
@gjenkins8
gjenkins8 requested a review from sabre1041 December 28, 2024 18:04
@TerryHowe
TerryHowe force-pushed the orasv2 branch 2 times, most recently from b7d77b0 to 1dff544 Compare January 2, 2025 19:46
@TerryHowe

Copy link
Copy Markdown
Contributor Author

Rebased the changes from the digest PR.

gjenkins8
gjenkins8 previously approved these changes Jan 16, 2025
Comment thread pkg/registry/client.go Outdated
authorizer *auth.Client
registryAuthorizer RemoteClient
credentialsStore credentials.Store
resolver func(ref registry.Reference) (remotes.Resolver, error)

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.

If I'm not mistaken, this never gets assigned and will probably cause a nil pointer dereference in Client.Resolve on line 837:

helm/pkg/registry/client.go

Lines 827 to 844 in 6505d41

func (c *Client) Resolve(ref string) (*ocispec.Descriptor, error) {
ctx := context.Background()
parsedRef, err := newReference(ref)
if err != nil {
return nil, err
}
if parsedRef.Registry == "" {
return nil, nil
}
remotesResolver, err := c.resolver(parsedRef.orasReference)
if err != nil {
return nil, err
}
_, desc, err := remotesResolver.Resolve(ctx, ref)
return &desc, err
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@twz123 It appears to be set in NewClient() on lines 147 or 150, depending on dockerStore status.

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.

@scottrigby I wasn't talking about credentialsStore in line 80, but about resolver in line 81. This is not directly obvious from how GitHub displays this comment. Sorry, I should have been clearer.

Still pretty sure that resolver never gets assigned and will produce a nil pointer dereference in the aforementioned code block.

@scottrigby scottrigby Jan 31, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@twz123 that makes more sense. Not needed for Helm 4, but to continue attempting a reasonable backwards compatibility for Helm 3 (re this thread #13382 (comment)), we'd need to keep resolver in the struct. For that, out of curiosity, what would you recommend?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed resolver in the latest changes. It is no longer needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

resolver was private, so I don't think we need to keep it in the struct, but the latest changes keeps ClientOptResolver with a deprecated message.

@scottrigby scottrigby added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 30, 2025

@scottrigby scottrigby left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@TerryHowe this is all looking good IMO. Just a few things:

  1. needs a rebase again
  2. can you please verify my reply to this question #13382 (comment)
  3. Since the starting point from this was #12310—and you're a good community player by noting that and linking to a diff— would you mind also please adding @zregvart's co-author commit trailer to your commit message? Like this:
Co-authored-by: Zoran Regvart <[email protected]>

Signed-off-by: Terry Howe <[email protected]>
Co-authored-by: Zoran Regvart <[email protected]>
@TerryHowe

Copy link
Copy Markdown
Contributor Author

@scottrigby

  1. rebase done
  2. I'll respond to question chore(oci): migrate to ORAS Golang library v2 #13382 (comment)
  3. Thanks for this suggestion, Zoran added as co-author

@TerryHowe

Copy link
Copy Markdown
Contributor Author

One more thing with this change, --plain-http is now required to communicate with a registry that only supports http. From a security perspective, this is the way it should work.

If/When this gets merged to Helm 3, we should probably fallback to http with a warning message.

@scottrigby scottrigby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm!

@scottrigby
scottrigby merged commit 6254b98 into helm:main Feb 3, 2025
@scottrigby scottrigby added Needs v3 backport Label PRs for v4/main, which are still applicable to v3 so need a separate backport PR and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. Has One Approval This PR has one approval. It still needs a second approval to be merged. labels Feb 3, 2025
@scottrigby

Copy link
Copy Markdown
Member

kudos to your perseverance @TerryHowe

let's see if we can find a way to get a backport PR backwards-compatible for Helm 3. This PR is very close already.

@scottrigby scottrigby added v3 port complete For completed v2->v3 ports and removed Needs v3 backport Label PRs for v4/main, which are still applicable to v3 so need a separate backport PR labels Jul 1, 2025
@TerryHowe
TerryHowe deleted the orasv2 branch September 7, 2025 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. v3 port complete For completed v2->v3 ports

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch to oras.land/oras-go/v2

6 participants