Unifies authorization for all outbound requests#127
Open
joniumGit wants to merge 4 commits into
Open
Conversation
- Clears any existing Authorization or overlapping headers - Adds a unified helper for setting auth - Unifies behavior in all supported registries - Leaves dependabot and github api handlers untouched Signed-off-by: joniumGit <52005121+joniumGit@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR centralizes how outbound requests are authenticated by introducing helper functions to build/set Authorization-like headers, and updates all handlers to use the new helper to ensure any client-provided auth is replaced consistently.
Changes:
- Added
helpers.BasicAuth/BearerAuth/TokenAuth/RawAuthplushelpers.SetAuthorizationto standardize auth header formatting and clearing. - Updated OIDC and multiple package/registry handlers to use
helpers.SetAuthorizationinstead ofSetBasicAuth/Header.Set(...). - Added unit tests covering the new auth helpers and header replacement behavior.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| internal/oidc/oidc_registry.go | Switches OIDC request auth setting to centralized helper functions. |
| internal/helpers/helpers.go | Introduces typed auth builders and SetAuthorization helper that clears/replaces headers. |
| internal/helpers/helpers_test.go | Adds tests verifying auth formatting and header replacement semantics. |
| internal/handlers/terraform_registry.go | Uses helper-based Bearer auth setting. |
| internal/handlers/rubygems_server.go | Uses helper-based Basic auth setting. |
| internal/handlers/python_index.go | Uses helper-based Basic auth setting. |
| internal/handlers/pub_repository.go | Uses helper-based Bearer auth setting. |
| internal/handlers/nuget_feed.go | Uses helper-based Basic/Bearer auth setting (including Azure DevOps special case). |
| internal/handlers/npm_registry.go | Uses helper-based Basic/Bearer auth setting. |
| internal/handlers/maven_repository.go | Uses helper-based Basic auth setting. |
| internal/handlers/hex_repository.go | Uses helper-based raw Authorization value setting. |
| internal/handlers/hex_organization.go | Uses helper-based raw Authorization value setting. |
| internal/handlers/helm_registry.go | Uses helper-based Basic auth setting. |
| internal/handlers/goproxy_server_handler.go | Uses helper-based Basic auth setting. |
| internal/handlers/git_server.go | Uses helper-based Basic auth setting for primary and retry requests. |
| internal/handlers/docker_registry.go | Uses helper-based Basic auth setting (ECR flow). |
| internal/handlers/composer.go | Uses helper-based Bearer/Basic auth setting. |
| internal/handlers/cargo_registry.go | Uses helper-based raw Authorization value setting. |
| internal/handlers/azdo_api.go | Uses helper-based Basic auth setting. |
Comment on lines
+23
to
+27
| // BasicAuth returns an authorization for "Basic <base64(username:password)>". | ||
| func BasicAuth(username, password string) authorization { | ||
| encoded := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", username, password))) | ||
| return authorization{fmt.Sprintf("Basic %s", encoded)} | ||
| } |
Comment on lines
+47
to
+49
| func SetAuthorization(req *http.Request, auth authorization, key ...string) { | ||
| h := "Authorization" | ||
| if len(key) > 0 { |
Contributor
Author
There was a problem hiding this comment.
I am not too familiar on how to cleanly do optional arguments in golang. Would appreciate feedback.
Signed-off-by: joniumGit <52005121+joniumGit@users.noreply.github.com>
Signed-off-by: joniumGit <52005121+joniumGit@users.noreply.github.com>
Signed-off-by: joniumGit <52005121+joniumGit@users.noreply.github.com>
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.
This PR is co-authored by Copilot
What are you trying to accomplish?
Fix #126
Anything you want to highlight for special attention from reviewers?
Please sanity check this implementation
How will you know you've accomplished your goal?
I need review to be sure, I am just going by the code and am not sure how to test this locally end-2-end.
Checklist