Skip to content

Migrate helm handler to OIDCRegistry#85

Open
kbukum1 wants to merge 1 commit intomainfrom
kamil/oidc-migrate-helm
Open

Migrate helm handler to OIDCRegistry#85
kbukum1 wants to merge 1 commit intomainfrom
kamil/oidc-migrate-helm

Conversation

@kbukum1
Copy link
Copy Markdown
Contributor

@kbukum1 kbukum1 commented Apr 3, 2026

What

Migrate the Helm registry handler from manual OIDC credential map + mutex to the shared OIDCRegistry type introduced in #78.

Why

Part of the phased migration to fix OIDC credential collisions when multiple registries share a host (#87).

Helm already stored the raw registry value as the OIDC key, so this is a pure structural refactor with no behavior change. Single-file diff, no test changes.

Behavior changes

  • Credential selection is now deterministic. The old code iterated over a Go map (map[string]*OIDCCredential), so with multiple OIDC credentials on the same host, which one matched was nondeterministic. OIDCRegistry.TryAuth uses longest path-prefix matching, ensuring the most specific credential always wins. This is the core fix for OIDC credential collision when multiple registries share a host #87.

  • Host matching uses strings.ToLower instead of IDNA normalization. The old TryAuthOIDCRequestWithPrefix used helpers.AreHostnamesEqual (IDNA ToASCII), while OIDCRegistry.TryAuth uses lowercase comparison. This is acceptable because all real OIDC registries (Azure DevOps, JFrog, AWS CodeArtifact, Cloudsmith) use ASCII hostnames — no package registry uses internationalized domain names.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors the Helm registry handler to use the shared oidc.OIDCRegistry (introduced in #78) instead of maintaining its own OIDC credential map + mutex, to align with the collision-free OIDC credential storage approach.

Changes:

  • Replace per-handler OIDC credential storage (map + sync.RWMutex) with *oidc.OIDCRegistry.
  • Register Helm OIDC credentials via OIDCRegistry.Register(...) during handler construction.
  • Authenticate requests via OIDCRegistry.TryAuth(...) instead of TryAuthOIDCRequestWithPrefix(...).

@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-helm branch from 74c2bcc to cb1d91e Compare April 3, 2026 04:21
@kbukum1 kbukum1 marked this pull request as ready for review April 3, 2026 04:21
@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-helm branch from cb1d91e to 8a474ff Compare April 3, 2026 05:17
@kbukum1 kbukum1 requested a review from Copilot April 3, 2026 05:34
Copy link
Copy Markdown

Copilot AI left a comment

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 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines +43 to +44
// OIDC credentials are not used as static credentials.
if oidcCred, _, _ := handler.oidcRegistry.Register(cred, []string{"registry"}, "helm registry"); oidcCred != nil {
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

OIDCRegistry.Register returns (cred, key, registered) but this code only checks oidcCred != nil and ignores whether the credential was actually registered (e.g., missing/invalid registry/host). That can silently drop an OIDC-configured credential with no warning and make misconfigurations harder to diagnose. Consider switching the condition to use the registered boolean (and optionally log when oidcCred != nil but registered == false).

Suggested change
// OIDC credentials are not used as static credentials.
if oidcCred, _, _ := handler.oidcRegistry.Register(cred, []string{"registry"}, "helm registry"); oidcCred != nil {
// OIDC credentials are not used as static credentials once successfully registered.
if _, _, registered := handler.oidcRegistry.Register(cred, []string{"registry"}, "helm registry"); registered {

Copilot uses AI. Check for mistakes.
Base automatically changed from kamil/oidc-registry-generalized to main April 4, 2026 00:12
Replace manual OIDC credential map and mutex with the shared
OIDCRegistry type. Helm already used the raw registry value as
the key, so this is a pure structural refactor with no behavior
change.
@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-helm branch from 8a474ff to 978b092 Compare April 4, 2026 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants