Skip to content

Unifies authorization for all outbound requests - #127

Merged
JamieMagee merged 6 commits into
dependabot:mainfrom
joniumGit:strip-auth
Jun 3, 2026
Merged

JamieMagee merged 6 commits into
dependabot:mainfrom
joniumGit:strip-auth

Conversation

@joniumGit

@joniumGit joniumGit commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

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.

@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

Copilot AI left a comment

Copy link
Copy Markdown

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 Outdated
Comment thread internal/helpers/helpers.go Outdated
Comment thread internal/helpers/helpers_test.go Outdated
Comment thread internal/helpers/helpers.go Outdated
Comment thread internal/helpers/helpers.go Outdated
Comment thread internal/helpers/helpers.go Outdated
@joniumGit
joniumGit requested review from brettfo and Copilot May 22, 2026 22:31

Copilot AI left a comment

Copy link
Copy Markdown

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 19 out of 19 changed files in this pull request and generated 4 comments.

Comment thread internal/helpers/helpers.go Outdated
Comment thread internal/helpers/helpers_test.go Outdated
Comment on lines +15 to +21
// ReplaceAuthorization replaces the authorization configured on req with the given key and value.
//
// Note: "Authorization"-header is always cleared to avoid multiple auth headers being set on the request.
func ReplaceAuthorization(req *http.Request, key string, value string) {
req.Header.Del("Authorization")
req.Header.Set(key, value)
}
Comment thread internal/helpers/helpers.go Outdated
@brettfo

brettfo commented May 22, 2026

Copy link
Copy Markdown
Contributor

My only remaining request is the naming suggestions from Copilot and the string concatenations instead of fmt.Sprintf where possible.

@joniumGit

Copy link
Copy Markdown
Contributor Author

My only remaining request is the naming suggestions from Copilot and the string concatenations instead of fmt.Sprintf where possible.

Removed the fmt use and fixed the GitHub typo

@joniumGit

Copy link
Copy Markdown
Contributor Author

@brettfo any more changes required?

@brettfo
brettfo dismissed their stale review May 27, 2026 20:29

addressed

@brettfo

brettfo commented May 27, 2026

Copy link
Copy Markdown
Contributor

@joniumGit Looks good from my end! I'll pass it around the team to see if they want anything.

@jakecoffman jakecoffman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

joniumGit added 6 commits June 3, 2026 10:26
- 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>
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>
Signed-off-by: joniumGit <52005121+joniumGit@users.noreply.github.com>
- Also fixes a GitHub naming typo

Signed-off-by: joniumGit <52005121+joniumGit@users.noreply.github.com>
@JamieMagee
JamieMagee merged commit 4bede52 into dependabot:main Jun 3, 2026
292 of 295 checks passed
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

5 participants