Skip to content

Commit 4d5c036

Browse files
committedNov 17, 2022
Auto merge of #10592 - arlosi:auth, r=ehuss
Implement RFC 3139: alternative registry authentication support Allows registries to request Cargo to send the authentication token for all requests, rather than just publish/yank, implementing [RFC 3139](#10474). ### Items from the [tracking issue](#10474) > Do registries need a more fine-grained switch for which API commands require authentication? This PR uses the `auth_required` boolean as described in the RFC. > The RFC mentions adding --token to additional commands like install and search These flags are not added by this PR. > Consider changing the name and form of the X- header Changed to the `www-authenticate` header as suggested by the comments. > Will there be any concerns with the interaction with rust-lang/rfcs#3231 Not that I know of. ------------- Adds a new field `"auth-required": true` to `config.json` that indicates Cargo should include the token in all requests to a registry. For HTTP registries, Cargo first attempts an un-authenticated request, then if that fails with HTTP 401, an authenticated request is attempted. The registry server may include a `www-authenticate` header with the HTTP 401 to instruct Cargo with URL the user can visit to acquire a token (crates.io/me). Since the API URL is not known (because it's stored in the index), the unstable credential provider feature is modified to key off the index url, and the registry name is no longer provided. To handle the case where an alternative registry's name is not known (such as coming from a lock file, or via `--index`), Cargo can now look up the token in the configuration by matching on the index URL. This introduces a new error if two alternative registries are configured with the same index URL. Several operations, such as `cargo install` could have had a `--token` argument added, however it appears that Cargo would like to move away from passing the token on the command line for security reasons. In this case, users would need to configure the registry via the config file (or environment variables) when using `cargo install --index ...` or similar.
2 parents b690ab4 + 9827412 commit 4d5c036

File tree

42 files changed

+1468
-661
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1468
-661
lines changed
 

‎CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@
326326
- Added `-Zcheck-cfg=output` to support build-scripts declaring their
327327
supported set of `cfg` values with `cargo:rustc-check-cfg`.
328328
[#10539](https://github.com/rust-lang/cargo/pull/10539)
329-
- `-Z http-registry` now uses https://index.crates.io/ when accessing crates-io.
329+
- `-Z sparse-registry` now uses https://index.crates.io/ when accessing crates-io.
330330
[#10725](https://github.com/rust-lang/cargo/pull/10725)
331331
- Fixed formatting of `.workspace` key in `cargo add` for workspace inheritance.
332332
[#10705](https://github.com/rust-lang/cargo/pull/10705)

‎Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ git2-curl = "0.16.0"
3333
glob = "0.3.0"
3434
hex = "0.4"
3535
home = "0.5"
36+
http-auth = { version = "0.1.6", default-features = false }
3637
humantime = "2.0.0"
3738
indexmap = "1"
3839
ignore = "0.4.7"

0 commit comments

Comments
 (0)