Skip to content

Migrate npm handler to OIDCRegistry#91

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

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

Conversation

@kbukum1
Copy link
Copy Markdown
Contributor

@kbukum1 kbukum1 commented Apr 3, 2026

Fixes #71

What

Migrate the npm registry handler from manual OIDC credential map, mutex, and direct hostname lookup 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).

npm previously stored OIDC credentials keyed by hostname only via a direct map lookup. Two npm registries on the same host with different paths would collide — the second silently overwrote the first. OIDCRegistry preserves the full registry URL, fixing this.

Key changes

  • Replace oidcCredentials map[string]*oidc.OIDCCredential + sync.RWMutex with *oidc.OIDCRegistry
  • Replace 20-line inline OIDC token exchange + Cloudsmith special case with oidcRegistry.TryAuth() (handles both automatically)
  • Register(cred, ["registry"], "npm registry") uses the registry field URL instead of hostname-only key
  • Net -32 lines

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 npm registry request handler to use the shared oidc.OIDCRegistry so OIDC credentials can be stored and matched collision-free (host bucket + longest path-prefix match), aligning npm with the registry-wide OIDC refactor introduced in #78.

Changes:

  • Replaces the handler-local map[string]*oidc.OIDCCredential + sync.RWMutex with *oidc.OIDCRegistry.
  • Replaces inline OIDC token acquisition + Cloudsmith header special-casing with oidcRegistry.TryAuth(req, ctx).
  • Updates OIDC credential registration to go through oidcRegistry.Register(...) during handler construction.

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 2 out of 2 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:37
@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-npm branch from 97b8148 to 56aa9cd Compare April 3, 2026 05:18
@kbukum1 kbukum1 requested a review from Copilot April 3, 2026 05:33
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 2 out of 2 changed files in this pull request and generated no new comments.

@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-npm branch from 56aa9cd to 224448c Compare April 3, 2026 19:07
Base automatically changed from kamil/oidc-registry-generalized to main April 4, 2026 00:12
Replace manual OIDC credential map, mutex, and direct hostname
lookup with the shared OIDCRegistry type. npm previously stored
OIDC credentials keyed by hostname only, which caused collisions
when multiple npm registries shared a host. OIDCRegistry preserves
the full registry URL, fixing this.

The Cloudsmith-specific X-Api-Key handling is now provided by
OIDCRegistry.TryAuth() automatically.

Co-authored-by: James Garratt <572389+microblag@users.noreply.github.com>
@kbukum1 kbukum1 force-pushed the kamil/oidc-migrate-npm branch from 224448c to d846392 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