-
Notifications
You must be signed in to change notification settings - Fork 16
use hostname/path rather than just path to key OIDCCredential map #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
32b961d
266a999
82543b7
634a992
bdcb53f
5a15dbb
e53500e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| package handlers | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "net/http" | ||
| "strings" | ||
| "sync" | ||
|
|
@@ -46,18 +45,20 @@ func NewNPMRegistryHandler(creds config.Credentials) *NPMRegistryHandler { | |
|
|
||
| oidcCredential, _ := oidc.CreateOIDCCredential(cred) | ||
| if oidcCredential != nil { | ||
| host := cred.Host() | ||
| if host == "" && registry != "" { | ||
| regURL, err := helpers.ParseURLLax(registry) | ||
| if err == nil { | ||
| host = regURL.Hostname() | ||
| maybeUrl := cred.GetString("host") | ||
| if maybeUrl == "" { | ||
| maybeUrl = cred.GetString("url") | ||
| if maybeUrl == "" { | ||
| maybeUrl = registry | ||
| } | ||
| } | ||
| if host != "" { | ||
| handler.oidcCredentials[host] = oidcCredential | ||
| logging.RequestLogf(nil, "registered %s OIDC credentials for npm registry: %s", oidcCredential.Provider(), host) | ||
| parsedUrl, err := helpers.ParseURLLax(maybeUrl) | ||
| if err == nil { | ||
| handler.oidcCredentials[parsedUrl.String()] = oidcCredential | ||
| logging.RequestLogf(nil, "registered %s OIDC credentials for npm registry: %s", oidcCredential.Provider(), parsedUrl.String()) | ||
| continue | ||
| } | ||
| continue | ||
| logging.RequestLogf(nil, "failed to register OIDC credential for npm registry: %s", registry) | ||
| } | ||
|
|
||
| npmCred := npmRegistryCredentials{ | ||
|
|
@@ -86,20 +87,10 @@ func (h *NPMRegistryHandler) HandleRequest(req *http.Request, ctx *goproxy.Proxy | |
| } | ||
|
|
||
| // Try OIDC credentials first | ||
| h.mutex.RLock() | ||
| oidcCred, hasOIDC := h.oidcCredentials[reqHost] | ||
| h.mutex.RUnlock() | ||
| authed := oidc.TryAuthOIDCRequestWithPrefix(&h.mutex, h.oidcCredentials, req, ctx) | ||
|
|
||
| if hasOIDC { | ||
| token, err := oidc.GetOrRefreshOIDCToken(oidcCred, req.Context()) | ||
| if err != nil { | ||
| logging.RequestLogf(ctx, "* failed to get token via OIDC for %s: %v", reqHost, err) | ||
| // Fall through to try static credentials | ||
| } else { | ||
| logging.RequestLogf(ctx, "* authenticating npm registry request with OIDC token (host: %s)", reqHost) | ||
| req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token)) | ||
| return req, nil | ||
| } | ||
| if authed { | ||
| return req, nil | ||
|
Comment on lines
89
to
+93
|
||
| } | ||
|
|
||
| // Fall back to static credentials | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OIDC credential registration no longer considers the credential's
hostfield (orcred.Host()), onlyurl/registry. This is a behavior change from the previous implementation and will break OIDC for npm registries configured viahostonly. Consider falling back tocred.Host()(and/orcred.GetString("host")) whenurlandregistryare empty, while still preferring the full URL+path when available.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now trying host, url, registry (in that order). but not using the .Host() method as it just returns the hostname part if a url is specified