Skip to content

Reject anonymous reads of private Cargo registries - #71

Open
pkriko wants to merge 2 commits into
pulp:mainfrom
BaptisteCentreon:private-cargo-index
Open

pkriko wants to merge 2 commits into
pulp:mainfrom
BaptisteCentreon:private-cargo-index

Conversation

@pkriko

@pkriko pkriko commented Nov 17, 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 #61, as discussed there: when cargo_auth_required is set, the registry is now private.

  • config.json, the sparse index and the download endpoint require rust.view_rustdistribution on the distribution (e.g. the rust.rustdistribution_viewer role).
  • Anonymous requests get a 401 with WWW-Authenticate: Cargo, so Cargo retries with its credential; authenticated users without the permission get a 403.
  • The index views accept the same credentials as the other Cargo endpoints (Cargo token first, then the instance's authenticators), and a Cargo token scoped to other distributions cannot read this one.
  • The default access policy of the index views changes; deployments that customized it keep their version.
  • Not covered: the download endpoint redirects to the content app, so the .crate files still need a content guard. Happy to discuss how to handle that in a separate PR.

This branch is based on #61 and includes its commit until it merges; only the last commit is new.

See: Pull Request Walkthrough

pkriko and others added 2 commits November 17, 2026 09:04
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>
When cargo_auth_required is set on a distribution, the index
config.json, the sparse index files and the download endpoint now
require the rust.view_rustdistribution permission on the distribution.
Anonymous requests get a 401 with a "WWW-Authenticate: Cargo"
challenge, so Cargo retries with its credential.

A Cargo token scoped to other distributions cannot read this one.

The index views now accept the same credentials as the other Cargo
endpoints: the Cargo token first, then the instance's default
authentication classes.

The download endpoint redirects to the content app, which this does
not cover; a content guard is still needed to protect the crate files.

Assisted By: Claude Opus 5.5

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