|
| 1 | +# Authentication & Authorization |
| 2 | + |
| 3 | +Pulp Rust uses per-user API tokens for Cargo protocol endpoints (publish, yank, unyank) and |
| 4 | +Pulp's standard RBAC system for controlling access to repositories, remotes, and distributions. |
| 5 | + |
| 6 | +## Cargo Token Authentication |
| 7 | + |
| 8 | +### Creating a Token |
| 9 | + |
| 10 | +Create a token via the Pulp REST API using your Pulp credentials: |
| 11 | + |
| 12 | +```bash |
| 13 | +http POST http://<pulp-host>/pulp/api/v3/cargo/tokens/ \ |
| 14 | + -a admin:password \ |
| 15 | + name="my-laptop" |
| 16 | +``` |
| 17 | + |
| 18 | +The response includes the token value (prefixed with `crg_`). This is shown **once** -- it |
| 19 | +cannot be retrieved again. Store it securely. |
| 20 | + |
| 21 | +### Using with Cargo |
| 22 | + |
| 23 | +Pass the token to Cargo via `cargo login`: |
| 24 | + |
| 25 | +```bash |
| 26 | +cargo login --registry my-crates |
| 27 | +# Paste the crg_... token when prompted |
| 28 | +``` |
| 29 | + |
| 30 | +Or set it directly in `~/.cargo/credentials.toml`: |
| 31 | + |
| 32 | +```toml |
| 33 | +[registries.my-crates] |
| 34 | +token = "crg_..." |
| 35 | +``` |
| 36 | + |
| 37 | +Cargo sends the token automatically on state-changing operations (publish, yank, unyank). |
| 38 | +Read-only operations (downloading crates, browsing the index) do not require a token. |
| 39 | + |
| 40 | +### Managing Tokens |
| 41 | + |
| 42 | +```bash |
| 43 | +# List your tokens (token values are not shown) |
| 44 | +http GET http://<pulp-host>/pulp/api/v3/cargo/tokens/ -a user:password |
| 45 | + |
| 46 | +# Revoke a token |
| 47 | +http DELETE http://<pulp-host>/pulp/api/v3/cargo/tokens/<token-uuid>/ -a user:password |
| 48 | +``` |
| 49 | + |
| 50 | +Users can only see and revoke their own tokens. |
| 51 | + |
| 52 | +## Distribution-Scoped Permissions |
| 53 | + |
| 54 | +Access to publish and yank is controlled per-distribution using Pulp's RBAC system. A user |
| 55 | +needs the appropriate role on a distribution before they can publish or yank crates through it. |
| 56 | + |
| 57 | +### Roles |
| 58 | + |
| 59 | +| Role | Permissions | |
| 60 | +|------|-------------| |
| 61 | +| `rust.rustdistribution_owner` | Full control: view, change, delete, manage roles, publish, yank | |
| 62 | +| `rust.rustdistribution_publisher` | Publish crates and yank/unyank versions | |
| 63 | +| `rust.rustdistribution_viewer` | View the distribution | |
| 64 | + |
| 65 | +The user who creates a distribution automatically receives the `owner` role on it. |
| 66 | + |
| 67 | +### Granting Access |
| 68 | + |
| 69 | +Grant a user permission to publish to a specific distribution: |
| 70 | + |
| 71 | +```bash |
| 72 | +http POST http://<pulp-host>/pulp/api/v3/distributions/rust/rust/<uuid>/add_role/ \ |
| 73 | + -a admin:password \ |
| 74 | + role="rust.rustdistribution_publisher" \ |
| 75 | + users:='["alice"]' |
| 76 | +``` |
| 77 | + |
| 78 | +Alice can now publish and yank crates on that distribution using her Cargo token. |
| 79 | + |
| 80 | +## Differences from crates.io |
| 81 | + |
| 82 | +| Feature | crates.io | Pulp Rust | |
| 83 | +|---------|-----------|-----------| |
| 84 | +| Access scope | Per-crate ownership | Per-distribution | |
| 85 | +| Owner management | `cargo owner --add` | Pulp REST API role assignment | |
| 86 | +| Token creation | Web UI at crates.io | Pulp REST API | |
| 87 | +| Per-crate ownership | Yes (user and team owners) | Not supported (planned) | |
| 88 | +| Token scoping | Scoped to endpoints/crates | Not yet supported | |
| 89 | + |
| 90 | +!!! warning "No per-crate ownership" |
| 91 | + Pulp Rust currently controls access at the distribution level, not per-crate. Any user with |
| 92 | + the `publisher` role on a distribution can publish any crate name to it. Per-crate ownership |
| 93 | + (where only the crate's owner can publish new versions) is planned for a future release. |
0 commit comments