Skip to content

Preauthenticate crate download redirects - #74

Open
pkriko wants to merge 1 commit into
pulp:mainfrom
BaptisteCentreon:signed-crate-redirects
Open

pkriko wants to merge 1 commit into
pulp:mainfrom
BaptisteCentreon:signed-crate-redirects

Conversation

@pkriko

@pkriko pkriko commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📜 Checklist

  • Commits are cleanly separated with meaningful messages (simple features and bug fixes should be squashed to one commit)
  • A changelog entry or entries has been added for any significant changes
  • Follows the Pulp policy on AI Usage
  • (For new features) - User documentation and test coverage has been added

Follow-up of #71, which left the .crate files out: the download endpoint redirects to the content app, and the content app does not know Cargo tokens.

  • With an RBAC content guard, a Cargo token request reaches the content app as anonymous and gets a 403 ("Authentication credentials were not provided."), even for a user with the viewer role. Adding CargoTokenAuthentication to the instance-wide authentication classes would fix the download, but would make a Cargo token valid on every API endpoint, outside its distribution and action scopes.
  • When the distribution has a content redirect guard (core.content_redirect), the download endpoint now redirects to a URL signed with preauthenticate_url(), as pulp_ansible and pulp_container do. The content app then relies on the check the download endpoint already made, token scopes included. The signature expires after an hour.
  • Signing only happens when cargo_auth_required is set, i.e. when the download endpoint actually checked the credential; otherwise the redirect stays unsigned and the guard still applies.
  • A signed URL stays valid until it expires (one hour), even if the user loses access meanwhile; documented.
  • Distributions without a guard, or with another guard type, are unchanged.
  • Docs: the authentication guide shows how to attach the guard.

See: Pull Request Walkthrough

@pkriko
pkriko marked this pull request as ready for review November 26, 2026 14:04
@pkriko
pkriko force-pushed the signed-crate-redirects branch from df5c8a8 to 7bb329e Compare November 26, 2026 14:07
The download endpoint checks the credential, including the
distributions and actions a Cargo token is scoped to, then redirects
to the content app. The content app does not know Cargo tokens, so a
content guard that checks the user (an RBAC content guard) sees a
Cargo token request as anonymous and refuses it, and cargo_auth_required
alone leaves the crate files readable by anyone who knows their path.

When cargo_auth_required is set and the distribution has a content
guard that can preauthenticate a URL, the content redirect guard, the
redirect now points to a signed URL that expires after an hour, so the
content app relies on the check the download endpoint already made.
Without cargo_auth_required the endpoint checks nothing, so the
redirect stays unsigned and the guard still applies.

Assisted By: Claude Opus 5.5
@pkriko
pkriko force-pushed the signed-crate-redirects branch from 516a43b to ec10d2f Compare November 26, 2026 14:38
@pkriko pkriko closed this Nov 27, 2026
@pkriko pkriko reopened this Nov 27, 2026
@pkriko

pkriko commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Closed by mistake.

This branch has not been deployed

No deployments
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.

1 participant