Skip to content

Migrate cargo handler to OIDCRegistry#79

Merged
kbukum1 merged 2 commits intomainfrom
kamil/oidc-migrate-cargo
Apr 6, 2026
Merged

Migrate cargo handler to OIDCRegistry#79
kbukum1 merged 2 commits intomainfrom
kamil/oidc-migrate-cargo

Conversation

@kbukum1
Copy link
Copy Markdown
Contributor

@kbukum1 kbukum1 commented Apr 2, 2026

What

Migrate the cargo 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). Cargo already used full URL keys, so this is a pure structural refactor with no behavior change.

What changes

  • Replace oidcCredentials map[string]*oidc.OIDCCredential + sync.RWMutex with *oidc.OIDCRegistry
  • Constructor uses oidcRegistry.Register() instead of manual CreateOIDCCredential + map insertion
  • HandleRequest uses oidcRegistry.TryAuth() instead of TryAuthOIDCRequestWithPrefix()
  • OIDC registration is guarded with if url != "" to preserve the original URL-scoped behavior and prevent host-only fallback from widening auth scope

All existing tests pass unchanged.

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

Migrates the Cargo registry handler’s OIDC credential storage and request authentication from a per-handler map+mutex to the shared oidc.OIDCRegistry (added in #78), to avoid credential collisions and centralize OIDC handling.

Changes:

  • Replace map[string]*oidc.OIDCCredential + sync.RWMutex with *oidc.OIDCRegistry in the Cargo handler.
  • Use oidcRegistry.Register(...) during handler construction instead of manual CreateOIDCCredential + map insertion.
  • Use oidcRegistry.TryAuth(req, ctx) during request handling instead of TryAuthOIDCRequestWithPrefix(...).

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 no new comments.

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 no new comments.

@kbukum1 kbukum1 marked this pull request as ready for review April 3, 2026 04:10
@kbukum1 kbukum1 requested a review from Copilot April 3, 2026 04:37
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 no new comments.

@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-cargo branch 2 times, most recently from 7c3a59f to 6da585c Compare April 3, 2026 05:19
@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 no new comments.

Base automatically changed from kamil/oidc-registry-generalized to main April 4, 2026 00:12
@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-cargo branch 3 times, most recently from 1c7023e to 6dffe7b Compare April 5, 2026 21:45
@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-cargo branch from 6dffe7b to 064a3f9 Compare April 6, 2026 17:51
Copy link
Copy Markdown
Contributor

@AbhishekBhaskar AbhishekBhaskar left a comment

Choose a reason for hiding this comment

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

LGTM

@kbukum1 kbukum1 merged commit 20de734 into main Apr 6, 2026
6 of 8 checks passed
@kbukum1 kbukum1 deleted the kamil/oidc-migrate-cargo branch April 6, 2026 19:28
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.

3 participants