Skip to content

Fix 3.18.0 regression: registry login with scheme - #30887

Merged
scottrigby merged 1 commit into
helm:dev-v3from
scottrigby:v3-remove-registry-login-url
May 23, 2025
Merged

scottrigby merged 1 commit into
helm:dev-v3from
scottrigby:v3-remove-registry-login-url

Conversation

@scottrigby

@scottrigby scottrigby commented May 21, 2025 •

Copy link
Copy Markdown
Member

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:

  • 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

@scottrigby
scottrigby requested a review from sabre1041 May 21, 2025 00:39
@scottrigby scottrigby added bug Categorizes issue or PR as related to a bug. v3.x Issues and Pull Requests related to the major version v3 labels May 21, 2025
@pull-request-size pull-request-size Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label May 21, 2025
@TerryHowe

Copy link
Copy Markdown
Contributor

Thanks, looks good other than lint issue

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

@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

@scottrigby
scottrigby force-pushed the v3-remove-registry-login-url branch from 92f70ff to cf4c5c8 Compare May 21, 2025 06:47
@scottrigby

scottrigby commented May 21, 2025 •

Copy link
Copy Markdown
Member Author

URL parse considers both <protocol>: and <protocol>:// to be schemes. As a result, uniformly removing the scheme will result in undesirable results.

Ah, this is what was throwing the tests earlier when I initially added to [registry.Client.Login]. Nice sleuthing!

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.

Tests appear to pass with this type of logic

Yes! Added back with the stripping change and all is well! Ready for re-review

@scottrigby
scottrigby force-pushed the v3-remove-registry-login-url branch from cf4c5c8 to 5e3de74 Compare May 21, 2025 06:57

@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 Thanks @scottrigby this looks good!

Comment thread pkg/registry/client.go Outdated
// 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]

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.

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 ? :)

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.

Nevermind. Having // is not considered a valid scheme.

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.

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)

Comment thread pkg/registry/client.go Outdated
// 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]

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.

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)

Comment thread pkg/registry/client.go Outdated
Comment on lines +237 to +255
if strings.HasPrefix(host, "oci://") || strings.HasPrefix(host, "http://") || strings.HasPrefix(host, "https://") {
return strings.Split(host, "//")[1]
}

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 would recommend:

Suggested change
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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@gjenkins8 gjenkins8 May 21, 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.

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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I tested with 3.17.3 against https://ghcr.io and was able to login. No errors.

@gjenkins8 gjenkins8 May 21, 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.

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.

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.

#30897 maybe

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

warnings changed to debug statements per helm-dev meeting ✅

Comment thread pkg/registry/client.go Resolved
@gjenkins8 gjenkins8 added this to the 3.18.1 milestone May 21, 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

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]>
@scottrigby
scottrigby force-pushed the v3-remove-registry-login-url branch from 5bd14ad to c0f3ace Compare May 22, 2025 19:09
@pull-request-size pull-request-size Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 22, 2025
@scottrigby

scottrigby commented May 22, 2025 •

Copy link
Copy Markdown
Member Author

Combined with with @TerryHowe from #30897, added Co-authored-by commit trailer.
passes tests.
Ready for re-review

@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 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. Verified successfully

@benoittgt

Copy link
Copy Markdown
Contributor

Looks good. Very explicit and properly tested :)

@jessesimpson36

Copy link
Copy Markdown
Contributor

Looks good. Very explicit and properly tested :)

buuuuuuuut if you want MORE tests...
https://github.com/scottrigby/helm/pull/1/files

@scottrigby

Copy link
Copy Markdown
Member Author

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:

Looks good. Very explicit and properly tested :)

buuuuuuuut if you want MORE tests... https://github.com/scottrigby/helm/pull/1/files

@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:

@scottrigby
scottrigby merged commit e379625 into helm:dev-v3 May 23, 2025
@mattfarina mattfarina added the picked Indicates that a PR has been cherry-picked into the next release candidate. label May 27, 2025
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. picked Indicates that a PR has been cherry-picked into the next release candidate. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. v3.x Issues and Pull Requests related to the major version v3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants