Open
Conversation
This was referenced Apr 3, 2026
There was a problem hiding this comment.
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.RWMutexwith*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.
7405960 to
97b8148
Compare
97b8148 to
56aa9cd
Compare
56aa9cd to
224448c
Compare
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>
224448c to
d846392
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #71
What
Migrate the npm registry handler from manual OIDC credential map, mutex, and direct hostname lookup to the shared
OIDCRegistrytype 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.
OIDCRegistrypreserves the full registry URL, fixing this.Key changes
oidcCredentials map[string]*oidc.OIDCCredential+sync.RWMutexwith*oidc.OIDCRegistryoidcRegistry.TryAuth()(handles both automatically)Register(cred, ["registry"], "npm registry")uses theregistryfield URL instead of hostname-only keyBehavior 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.TryAuthuses 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.ToLowerinstead of IDNA normalization. The oldTryAuthOIDCRequestWithPrefixusedhelpers.AreHostnamesEqual(IDNAToASCII), whileOIDCRegistry.TryAuthuses 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.