Skip to content
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

Add Repository Bearer Authentication #4483

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

valentijnscholten
Copy link
Contributor

@valentijnscholten valentijnscholten commented Dec 20, 2024

Description

Add Bearer authentication support for repositories.

Addressed Issue

Some repositories require authentication with a Bearer token, for example https://packages.shopware.com and other (private) packagist.com repositories.

Additional Details

FrontEnd PR will be done as soon as API PR is agreed.

Checklist

  • I have read and understand the contributing guidelines
  • This PR fixes a defect, and I have provided tests to verify that the fix is effective
  • This PR implements an enhancement, and I have provided tests to verify that it works as intended
  • This PR introduces changes to the database model, and I have added corresponding update logic
  • This PR introduces new or alters existing behavior, and I have updated the documentation accordingly

@valentijnscholten
Copy link
Contributor Author

@nscure I didn't go the full monty to add another Enum to configure authentication type, but just implemented an if statement where a Bearer token gets priority over Basic auth. I could go even simpler and just instruct users to use the Password field for the bearer token and avoid having to add an extra column and remove the bearerToken field from the PR. Let me know what you think.

Copy link

codacy-production bot commented Dec 20, 2024

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%) 100.00% (target: 70.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (72e582c) 23013 18283 79.45%
Head commit (80198f8) 23015 (+2) 18285 (+2) 79.45% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#4483) 3 3 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Codacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more

@valentijnscholten valentijnscholten marked this pull request as ready for review December 23, 2024 22:23
Copy link
Member

@nscuro nscuro left a comment

Choose a reason for hiding this comment

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

I could go even simpler and just instruct users to use the Password field for the bearer token and avoid having to add an extra column and remove the bearerToken field from the PR.

That would be best for now IMO. I don't think having a column for each credential type makes a lot of sense. If we get more variety of credentials (e.g. API keys, certificates, OIDC) we'll need to re-think this anyway.

Copy link
Member

Choose a reason for hiding this comment

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

New columns are added automatically by DataNucleus, a manual migration is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohhh you're making me feel all nice and warm about DataNucleus all of a sudden.

@valentijnscholten
Copy link
Contributor Author

@nscuro changed the PR to do just that: send a Bearer token if username is null but password is populated.
There was test case for that scenario that expected a Basic Auth style header, but I don't think that's a valid scenario, basic auth with null username?

@valentijnscholten
Copy link
Contributor Author

valentijnscholten commented Jan 4, 2025

@AbdelHajou I can see a NuGetMetaAnalyzerTest that is asserting that a Basic Auth header is sent when the username is null but the password is present. Is this a valid use case for NuGet repositories?

https://github.com/DependencyTrack/dependency-track/blob/master/src/test/java/org/dependencytrack/tasks/repositories/NugetMetaAnalyzerTest.java#L164

Could only find documentation on how to authenticate but not what types/styles of authentication are supported: https://learn.microsoft.com/en-us/nuget/consume-packages/consuming-packages-authenticated-feeds

I don't think it is valid: https://stackoverflow.com/questions/49580896/http-authentication-without-username

EDIT: I have updated the test case to test for Bearer token instead of Basic Auth when username is null.

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.

2 participants