Repository navigation
Fix 3.18.0 regression: registry login with scheme - #30887
Conversation
|
Thanks, looks good other than lint issue |
sabre1041
left a comment
There was a problem hiding this comment.
@scottrigby Not in favor of this approach as it URL parse considers both <protocol>: and <protocol>:// to be schemes. As a result, uniformly removing the scheme will result in undesirable results. Also, would recommend that the logic be lower down in the call to capture additional use cases where the action package is not used.
Proposed enhancement would be to include the logic in the login method of the client.go in the registry package and align closer to the prior functionality. Something along the lines of the following:
func stripScheme(host string) string {
if strings.HasPrefix(host, "oci://") || strings.HasPrefix(host, "http://") || strings.HasPrefix(host, "https://") {
return strings.Split(host, "//")[1]
}
return host
}
Tests appear to pass with this type of logic
92f70ff to
cf4c5c8
Compare
Ah, this is what was throwing the tests earlier when I initially added to [registry.Client.Login]. Nice sleuthing!
Yes! Added back with the stripping change and all is well! Ready for re-review |
cf4c5c8 to
5e3de74
Compare
sabre1041
left a comment
There was a problem hiding this comment.
LGTM Thanks @scottrigby this looks good!
| // TODO: document that Helm 4 `registry login` does accept full URLs | ||
| func stripScheme(host string) string { | ||
| if strings.HasPrefix(host, "oci://") || strings.HasPrefix(host, "http://") || strings.HasPrefix(host, "https://") { | ||
| return strings.Split(host, "//")[1] |
There was a problem hiding this comment.
Maybe it will be even safier to specify :// ? I think oci://ghcr.io//my-account is a valid one but would only return ghcr.io ? :)
There was a problem hiding this comment.
Nevermind. Having // is not considered a valid scheme.
There was a problem hiding this comment.
using strings.Split is making me feel uneasy too. What if the user has passed an (invalid) registry:
ghcr.io//my-account
They would get a confusing (perhaps failed) login to ghcr.io. Furthermore, we might actually support registry paths in the future, where this logic becomes a footgun.
But I think we can easily tidy this (made suggestion below)
| // TODO: document that Helm 4 `registry login` does accept full URLs | ||
| func stripScheme(host string) string { | ||
| if strings.HasPrefix(host, "oci://") || strings.HasPrefix(host, "http://") || strings.HasPrefix(host, "https://") { | ||
| return strings.Split(host, "//")[1] |
There was a problem hiding this comment.
using strings.Split is making me feel uneasy too. What if the user has passed an (invalid) registry:
ghcr.io//my-account
They would get a confusing (perhaps failed) login to ghcr.io. Furthermore, we might actually support registry paths in the future, where this logic becomes a footgun.
But I think we can easily tidy this (made suggestion below)
| if strings.HasPrefix(host, "oci://") || strings.HasPrefix(host, "http://") || strings.HasPrefix(host, "https://") { | ||
| return strings.Split(host, "//")[1] | ||
| } |
There was a problem hiding this comment.
I would recommend:
| if strings.HasPrefix(host, "oci://") || strings.HasPrefix(host, "http://") || strings.HasPrefix(host, "https://") { | |
| return strings.Split(host, "//")[1] | |
| } | |
| for _, s := range []string{"oci://", "http://", "https://"} { | |
| if strings.HasPrefix(host, s) { | |
| fmt.Printf(os.stderr, "WARNING: Invalid registry passed: registries must NOT be prefixed with a URL scheme. Use %q instead", host[len(s):len(host) - 1]) | |
| return strings.TrimPrefix(host, s) | |
| } | |
| } |
Printing (to stderr) here is awkward. But we don't have a better facility in Helm 3 I think?
There was a problem hiding this comment.
Why would we issue a warning? In Helm v3.17.3 using a scheme works and does not present a warning. There are no issues with it. It should not be invalid to have a scheme on it. That would be a breaking change.
There was a problem hiding this comment.
It is wrong to present a scheme. That is an existing bug in Helm. And it doesn't fully work:
echo foo | ./bin/helm-3.17 registry login -u user --password-stdin http://ghcr.io/repo/
Error: Get "https://ghcr.io/v2/": net/http: TLS handshake timeout
Note here that http:// was converted to https://. Also that the URL path is dropped.
The intent of the warning was to inform users that they are using an unsupported behavior. So while this "worked" in previous versions of Helm, that was really unintentional. I think if we had realized, we would have also introduced this warning. That said, we could put this warning into a new PR (since this PR strictly is targeting patching to the original behavior)
There was a problem hiding this comment.
I tested with 3.17.3 against https://ghcr.io and was able to login. No errors.
There was a problem hiding this comment.
My example isn't expected to work (it uses dummy creds to illustrate):
echo foo | ./bin/helm-3.17 registry login -u user --password-stdin http://ghcr.io/repo/
Error: Get "https://ghcr.io/v2/": net/http: TLS handshake timeout
You will find (with Helm 3.17, etc), helm registry login -u .. -p .. http://ghcr.io/repo/ will log you into ghcr.io via https only.
There was a problem hiding this comment.
warnings changed to debug statements per helm-dev meeting ✅
TerryHowe
left a comment
There was a problem hiding this comment.
/lgtm
Tried some tests in the playground
Helm 3.18.0 released an upgrade of ORAS from v1 to v2. ORAS v2 correctly does not accept http/https scheme for registry login, while ORAS v1 previously did. Even if v1 should not have, we want to preserve backwards compatibility for Helm 3 users who pass the scheme. This will be removed in Helm 4, where registry login will not accept http/https scheme. Co-authored-by: Andrew Block <[email protected]> Co-authored-by: Terry Howe <[email protected]> Signed-off-by: Scott Rigby <[email protected]>
5bd14ad to
c0f3ace
Compare
|
Combined with with @TerryHowe from #30897, added Co-authored-by commit trailer. |
sabre1041
left a comment
There was a problem hiding this comment.
LGTM. Verified successfully
|
Looks good. Very explicit and properly tested :) |
buuuuuuuut if you want MORE tests... |
|
Thanks everyone, I'm going to merge this PR now as-is in the interest of getting the regression fix out to users ASAP 🚀 And also:
@jessesimpson36 excellent that you found a way to test the mock registry with different domain patterns 👏 Talking with other maintainers including @sabre1041 we should incorporate your testing approach into the efforts in this HIP: |
fixes #30873
What this PR does / why we need it:
Helm 3.18.0 released an upgrade of ORAS from v1 to v2.
ORAS v2 correctly does not accept http/https scheme for registry login, while ORAS v1 previously did. Even if v1 should not have, we want to preserve backwards compatibility for Helm 3 users who pass the scheme.
This will be removed in Helm 4, where registry login will not accept http/https scheme.
Special notes for your reviewer:
edit: @sabre1041 tracked down that here is where the URL scheme gets stripped in older Helm versions: https://github.com/moby/moby/blob/v25.0.6/registry/config.go#L203-L205
If applicable:
docs neededlabel should be applied if so)