Skip to content

feat(auth): accept instance authenticators on Cargo endpoints - #61

Merged
dralley merged 1 commit into
pulp:mainfrom
BaptisteCentreon:oidc-cargo-auth
Nov 17, 2026
Merged

dralley merged 1 commit into
pulp:mainfrom
BaptisteCentreon:oidc-cargo-auth

Conversation

@BaptisteCentreon

Copy link
Copy Markdown
Contributor

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.

Comment thread pulp_rust/app/views.py Outdated
class CargoAuthMixin:
"""Authenticate the Cargo token first, then the deployment's configured authenticators.

Cargo endpoints must not shadow ``DEFAULT_AUTHENTICATION_CLASSES``: hardcoding only

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@dralley

dralley commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Apologies for taking some time to getting around to review these. It has been a busy couple of weeks

Comment thread pulp_rust/app/views.py Outdated
"dl": self.base_download_url,
"api": self.base_api_url,
"auth-required": False,
"auth-required": bool(self.distribution.content_guard_id),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this a general change, or do you specifically have in mind a use case for mixing content guards with cargo download?

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.

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

@dralley dralley Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@dralley dralley Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@dralley

dralley commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

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 crg_ tokens and lets supported deployment credentials reach the Cargo API views.

I have a blocker on deriving auth-required from bool(distribution.content_guard_id). Cargo interprets this flag as a promise that its registry credential will be sent on sparse-index and crate-download requests. A Pulp ContentGuard is more general than that: it may use RBAC/default DRF authentication, mTLS, signed redirects, or an arbitrary header. In particular, the content app authenticates requests using only DEFAULT_AUTHENTICATION_CLASSES, whereas CargoTokenAuthentication remains installed only on these Cargo API views. Thus a stored crg_ token can authenticate the Cargo endpoint but cannot authenticate the content app for an RBAC-guarded download.

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 cargo fetch/cargo build test through a guarded distribution using a credential that the selected guard can actually accept.

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, Bearer <jwt>).

@dralley

dralley commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@pkriko See new comments

@pkriko

pkriko commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@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 cargo_auth_required is set ?

@dralley

dralley commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

I guess that I can create a new PR to reject anonymous reads of the index when the flag cargo_auth_required is set ?

Sure

@dralley

dralley commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

@pkriko Could you squash/rebase this to one commit?

@aKlimau Do you have any additional feedback? Looks fine to me for the time being, though we do need some additional work here.

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>
@pkriko

pkriko commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

see #71

@dralley
dralley merged commit 462e91b into pulp:main Nov 17, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants