Skip to content

Unifies authorization for all outbound requests#127

Open
joniumGit wants to merge 4 commits into
dependabot:mainfrom
joniumGit:strip-auth
Open

Unifies authorization for all outbound requests#127
joniumGit wants to merge 4 commits into
dependabot:mainfrom
joniumGit:strip-auth

Conversation

@joniumGit
Copy link
Copy Markdown
Contributor

@joniumGit joniumGit commented May 21, 2026

This PR is co-authored by Copilot

  • 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

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

  • I have run the complete test suite to ensure all tests and linters pass.
  • I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
  • I have written clear and descriptive commit messages.
  • I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
  • I have ensured that the code is well-documented and easy to understand.

- 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>
@joniumGit joniumGit requested a review from a team as a code owner May 21, 2026 21:14
Copilot AI review requested due to automatic review settings May 21, 2026 21:14
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

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/RawAuth plus helpers.SetAuthorization to standardize auth header formatting and clearing.
  • Updated OIDC and multiple package/registry handlers to use helpers.SetAuthorization instead of SetBasicAuth / 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 thread internal/helpers/helpers.go
Comment thread internal/helpers/helpers.go Outdated
Comment thread internal/helpers/helpers_test.go Outdated
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 {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not too familiar on how to cleanly do optional arguments in golang. Would appreciate feedback.

joniumGit added 3 commits May 22, 2026 00:55
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>
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.

OIDC Authentication fails with checked-in config files present

2 participants