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

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

zregvart
Copy link

What this PR does / why we need it:

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

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 documentation
  • 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 Aug 16, 2023
@sabre1041 sabre1041 self-assigned this Aug 17, 2023
pkg/registry/client.go Outdated Show resolved Hide resolved
pkg/registry/client.go Outdated Show resolved Hide resolved
pkg/registry/client.go Outdated Show resolved Hide resolved
pkg/registry/client.go Outdated Show resolved Hide resolved
pkg/registry/client.go Outdated Show resolved Hide resolved
pkg/registry/client.go Outdated Show resolved Hide resolved
pkg/registry/client.go Outdated Show resolved Hide resolved
pkg/registry/client.go Outdated Show resolved Hide resolved
pkg/registry/client.go Outdated Show resolved Hide resolved
Copy link

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM but I am not a maintainer.

@joejulian joejulian added the oci Related to Helm OCI feature label Aug 22, 2023
pkg/registry/client.go Outdated Show resolved Hide resolved
@zregvart
Copy link
Author

Thank you @Wwwsylvia for excellent comments and suggestions.
@sabre1041 this has gotten an review and suggestions from two ORAS contributors, can you have a look now?

@sabre1041
Copy link
Contributor

Spent some time testing out the integration of the new ORAS v2 library. Below are the results

Test Result Comment
Push Chart with Registry
Pull + show values from Registry
Push Chart with Registry with self signed certificates
Pull + show values from Registry with self signed certificates
Push Chart with Registry with plain http
Pull + show values from Registry with plain http
Login to registry
Logoff from registry
Login to registry with self signed certificates
Logoff from registry with self signed certificates
Login to registry with plain http Fails. No option exists in Helm to explicitly specify plain http. Existing functionality automatically falls back to plain HTTP and succeeds

The migration looks good, but there does need to be additional work into the one validation failure scenario as described above in addition to the now conflicting go.mod file

@zregvart
Copy link
Author

@sabre1041 how would you like to handle the plain HTTP issue? With a if localhost assume --plain-http? Or should I add a --plain-http flag to helm, the helm push and helm pull already have it.

@sabre1041
Copy link
Contributor

@zregvart Personally, I would like to have feature parity with --plain-http in the login subcommand so that it aligns with the rest of capabilities surronding communicating

@zregvart
Copy link
Author

@sabre1041 added support --plain-http to helm login the diff is here.

Copy link
Contributor

@sabre1041 sabre1041 left a comment

Choose a reason for hiding this comment

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

LGTM

@sabre1041
Copy link
Contributor

@zregvart This looks good. Can you resolve the conflict and we should be in good shape

@Wwwsylvia
Copy link

Hi @zregvart @sabre1041, FYI, oras-go v2.3.0 is just out, would you like to update the go mod in this PR?

@sabre1041
Copy link
Contributor

Hi @zregvart @sabre1041, FYI, oras-go v2.3.0 is just out, would you like to update the go mod in this PR?

@zregvart if you want to update, I can retest again

@banjoh
Copy link

banjoh commented Dec 15, 2023

Spent some time testing out the integration of the new ORAS v2 library. Below are the results

Test Result Comment
Push Chart with Registry ✅
Pull + show values from Registry ✅
Push Chart with Registry with self signed certificates ✅
Pull + show values from Registry with self signed certificates ✅
Push Chart with Registry with plain http ✅
Pull + show values from Registry with plain http ✅
Login to registry ✅
Logoff from registry ✅
Login to registry with self signed certificates ✅
Logoff from registry with self signed certificates ✅
Login to registry with plain http ❌ Fails. No option exists in Helm to explicitly specify plain http. Existing functionality automatically falls back to plain HTTP and succeeds
The migration looks good, but there does need to be additional work into the one validation failure scenario as described above in addition to the now conflicting go.mod file

I ran these tests as well and they seem to pass. One test that is missing is the mTLS use case. I configured zot to enforce mTLS and managed to push and pull charts. I'm however not convinced that zot is enforcing mTLS fully cause I also managed to push charts without a client cert passed using --cert-file flag. Omitting this flag ought to fail tests. I'll try with another registry

@banjoh
Copy link

banjoh commented Dec 19, 2023

I managed to run an mTLS test using this setup of nginx + zot. This PR changes work as expected. helm successfully gets authenticated using a client cert and pushes the chart to the registry

helm push ../playground/my-chart-1.0.0.tgz oci://127.0.0.1 --ca-file ca.crt --cert-file client.crt --key-file client.key
Pushed: 127.0.0.1/my-chart:1.0.0
Digest: sha256:e0cdbbf0ddd269b74abf748fba3e6ae80b7e5fe6d5c9285ad31c239bbd354b0a

Strangely enough, the current version of helm cli did not work as I expected it to. I might be missing something here though. By looking at the output, it seems to be defaulting to insecure connections even if certs have been provided. It might just be the PR fixed an existing issue.

helm push ../playground/my-chart-1.0.0.tgz oci://127.0.0.1 --ca-file ca.crt --cert-file client.crt --key-file client.key
Error: failed to do request: Head "http://127.0.0.1/v2/my-chart/blobs/sha256:0160276299adc66a534585cacf1af08d1dd3ac9c4eb6aa20d82af81deb40e67e": dial tcp 127.0.0.1:80: connect: connection refused

helm version
version.BuildInfo{Version:"v3.13.3", GitCommit:"c8b948945e52abba22ff885446a1486cb5fd3474", GitTreeState:"clean", GoVersion:"go1.21.5"}

@zregvart
Copy link
Author

zregvart commented Jan 2, 2024

I is unclear to me what the expectation here is, i.e. could a release of Helm v4 be made with this or should the backward compatibility be maintained without exceptions. I think communicating the expectations would make this work a lot easier.

I've made a judgement call and restored the backward compatibility in a62313e, now the ClientOptResolver function panics on
invocation and the LoginOption function accepts the loginOperation and does not return error. The loginOperation struct was still modified, it is and it's members are unexported and I consider this not to be braking backward compatibility.

@chrisgacsal
Copy link

@zregvart Thank you for keeping this PR up-to-date! 🙏🏻

}
func ClientOptResolver(_ remotes.Resolver) ClientOption {
return func(c *Client) {
c.err = errDeprecatedRemote
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 a breaking change and requires a Helm major version change. It's about taking functions and making them non-functional with an error.

Copy link
Author

Choose a reason for hiding this comment

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

As previously noted support for containerd was removed from oras-go and there are no plans to reintroduce it. See oras-project/oras-go#64 (comment) for details.

I have yet to see any suggestions on how to get this addressed, no plans on the next major version of Helm either. Please do share any insights that you are privy to.

Frankly I do not see a way forward with this and will limit my effort going forward. Anyone is welcome to pick this up and continue the work.

Choose a reason for hiding this comment

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

For the records, this client option:

  1. was recently added in 3.13.0 (under 6 months ago, and only two weeks before this PR was opened)
  2. was added without any real testing
  3. was in beta / RC1 for less than 10 days (3.13.0-rc.1 is identical to 3.13.0)
  4. was implemented by the same person that opened the issue
  5. has what seems like 1 known use across all of github's public codebases, barring matches that seem to be forks or vendored modules
  6. has alternative solutions to what the original issue was asking for -- albeit yes, breaking

In terms of breaking changes, I think this is very manageable and the benefits of moving to oras v2 outweigh the costs of delaying this PR until the theoretical helm v4 release. I'm fairly sure that VMware team members @antgamdia or @alemorcuq would be okay with managing this change, as they are the source of this API in helm and still seem to be the only people affected.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @zevisert, thanks for the analysis on the current usage of this ClientOptResolver we added.
To give you all some context, we required this resolver to be configurable for use cases in Kubeapps (see vmware-tanzu/kubeapps#4194). However... due to different business reasons, we never get the bandwidth to actually make the changes on our side). We will probably bypass the Helm usage and will interact directly with ORAS, I guess.

I have checked with @alemorcuq and I think they can safely remove the usage of this option. In fact, I have just opened vmware-labs/distribution-tooling-for-helm#55 for doing so.
Both ClientOptPlainHTTP and ClientOptHTTPClient options cover their needs without the need of setting the resolver manually.

So, my (personal) two cents here: despite it being a breaking change, migrating to an up-to-date and maintained ORAS version and removing some CVEs is worthfile enough.

Choose a reason for hiding this comment

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

Great analysis @zevisert! Just FYI https://github.com/d2iq-labs/csi-driver-trusted-ca is not maintained so does not need to be considered in any discussion.

I'm also very supportive of getting this change in.

Copy link

Choose a reason for hiding this comment

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

Hey @mattfarina, I understand if you're busy with other things, but we'd appreciate if you could come back here reconsider this sometime soon :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to add one more thing to the discussion: This is the only remaining reference to containerd v1.x in Helm. Removing this API allows the entire containerd dependency to be dropped. This would allow Helm and the upcoming containerd 1.8 API to be used in the same Go module, avoiding ambiguous import errors (e.g. github.com/containerd/containerd v1.7.16 vs. github.com/containerd/containerd/api v1.8.0-rc.0).

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`.

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.

Fixes helm#11821

Signed-off-by: Zoran Regvart <zoran@regvart.com>
This restores the `ClientOptResolver` function which now panics on
invocation and previous signature of the `LoginOption` function.

Signed-off-by: Zoran Regvart <zoran@regvart.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
oci Related to Helm OCI feature refactor size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Switch to oras.land/oras-go/v2