Repository navigation
feat(auth): accept instance authenticators on Cargo endpoints - #61
Conversation
87aa0b6 to
7875c0b
Compare
| class CargoAuthMixin: | ||
| """Authenticate the Cargo token first, then the deployment's configured authenticators. | ||
|
|
||
| Cargo endpoints must not shadow ``DEFAULT_AUTHENTICATION_CLASSES``: hardcoding only |
There was a problem hiding this comment.
Avoid double-backticks please. And please disclose AI use in accordance with our AI policy https://github.com/pulp/pulp-docs/blob/main/pulpproject.org/help/more/governance/ai_policy.md
|
Apologies for taking some time to getting around to review these. It has been a busy couple of weeks |
| "dl": self.base_download_url, | ||
| "api": self.base_api_url, | ||
| "auth-required": False, | ||
| "auth-required": bool(self.distribution.content_guard_id), |
There was a problem hiding this comment.
Is this a general change, or do you specifically have in mind a use case for mixing content guards with cargo download?
There was a problem hiding this comment.
Hey, I am super busy at the moment, a colleague will be helping on the fixes you asked for.
About the change itself, I added to pulp core the equivalent of https://crates.io/docs/trusted-publishing, it allows CIs to get time and context bound privileges, this helps fight against Arrakis wildlife by ensuring CIs job don't use hardcoded tokens and have limited privileges.
Porting this feature here would duplicate code, so I looked at how other part of pulp (like docker for instance) handle delegating privileges managent to pulp core and replicated it here.
I hope it answers your question :)
Baptiste
There was a problem hiding this comment.
It still feels like two separate things are being conflated, maybe I'm missing something.
auth-required refers to needing to pass cargo auth credentials alongside requests (all API requests + downloads). Content guards are specifically about protecting downloads.
Note that in CargoDownloadApiView, the API is protected but it's just returning a redirect to the content app, which is not really protected in the same way currently. The download API will enforce and prevent a redirect from being returned, but the content app is not actually receiving any protection (I think?) from the content guard.
So it's a bit of a weird scenario where the content guard isn't actually protecting the content, but rather the API?
I might be misunderstanding. If not maybe that's still OK as a partial step forwards, but I want to call it out as a potential gap.
There was a problem hiding this comment.
That might be slightly overstated as the content app would still have some protection via the guard, but I think regardless we're over-promising given that the mere existence of a content guard (rather than some specific type e.g. RBAC) can't really guarantee the protections implied here.
Is there a particular need to use the content guard existence specifically as a mechanism here, as opposed to making it a setting on the distribution/repository? Seems like you could just decouple the two completely and have a setting to control auth-required e.g. cargo_auth_required while letting the content guard remain it's own thing.
Alternatively maybe we could be selective about what content guard types to accept. But that seems more complicated tbh.
|
Review from Codex, acting on behalf of @dralley. The endpoint-authentication part looks sound: prepend CargoTokenAuthentication, then retain the deployment default authentication classes. That preserves I have a blocker on deriving The new test only checks the JSON flag, so it cannot establish the advertised behavior. Please split or restrict this part until it has an end-to-end Minor wording point: crates.io trusted publishing exchanges an OIDC assertion for a short-lived publishing token; it is not raw OIDC authentication automatically performed by Cargo against an alternate registry. Pulp workload identity can be a supported case only when Cargo is configured to send the header form that authenticator expects (for example, |
|
@pkriko See new comments |
|
@dralley Thank you for the review. I check your comments. Regarding of what and why we did it's just that we inspired from https://crates.io/docs/trusted-publishing as Baptiste said. Our main need is private registries: CI jobs using Workload Identity should be able to publish and fetch crates, and neither the crates nor the index should be readable anonymously. I guess that I can create a new PR to reject anonymous reads of the index when the flag |
Sure |
The Cargo me, publish, yank and download views now try the Cargo token first, then the instance's default authentication classes, so clients can use the credentials the deployment is configured for (e.g. HTTP Basic) as well as `cargo login` tokens. Token scope checks only apply when the request is authenticated with a Cargo token. Add a cargo_auth_required boolean on the Rust distribution and use it for auth-required in the index config. The setting only controls whether Cargo sends its credential on index and download requests; it does not restrict access by itself. Assisted By: Claude Opus 5.5 Co-authored-by: baptiste <BaptisteCentreon@users.noreply.github.com>
2863e0a to
700667a
Compare
|
see #71 |
Today the Cargo views (/me, publish, download/yank) hardcode authentication_classes = [CargoTokenAuthentication].
This overrides DEFAULT_AUTHENTICATION_CLASSES. So the endpoints only accept crg_ tokens. Every other credential the deployment supports (Basic, session, SSO, OIDC) gets rejected.
Authorization is not the problem: the views already call request.user.has_perm(...), which works for any user. Only authentication blocks them.
The fix
This PR replaces the hardcoded list with a small mixin. It keeps CargoTokenAuthentication first, then adds the instance's configured authenticators. So cargo login keeps working, and any other configured credential also reaches the Cargo endpoints. Nothing ties the plugin to a specific authenticator.
It also sets the index config.json auth-required flag from the distribution's content guard. A guarded distribution now tells cargo to send its credentials on the index and downloads, not only on publish.
Tests
I added functional tests. They check that Basic auth reaches /me, and that auth-required follows the content guard.