Skip to content

Commit 3b20907

Browse files
committed
Auto merge of #12551 - arlosi:asymmetric-token, r=Eh2406
Create dedicated unstable flag for asymmetric-token Asymmetric tokens are gated by `-Zcredential-process`. Since we're considering stabilizing that soon, this moves asymmetric token support to have its own unstable flag. It was previously gated by `-Zregistry-auth`, and some of the docs were not updated when it moved. r? `@Eh2406`
2 parents d7ee260 + 8c13e9a commit 3b20907

File tree

9 files changed

+36
-31
lines changed

9 files changed

+36
-31
lines changed

src/cargo/core/features.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ unstable_cli_options!(
718718
// All other unstable features.
719719
// Please keep this list lexicographically ordered.
720720
advanced_env: bool = (HIDDEN),
721+
asymmetric_token: bool = ("Allows authenticating with asymmetric tokens"),
721722
avoid_dev_deps: bool = ("Avoid installing dev-dependencies if possible"),
722723
binary_dep_depinfo: bool = ("Track changes to dependency artifacts"),
723724
bindeps: bool = ("Allow Cargo packages to depend on bin, cdylib, and staticlib crates, and use the artifacts built by those crates"),
@@ -744,7 +745,7 @@ unstable_cli_options!(
744745
panic_abort_tests: bool = ("Enable support to run tests with -Cpanic=abort"),
745746
profile_rustflags: bool = ("Enable the `rustflags` option in profiles in .cargo/config.toml file"),
746747
publish_timeout: bool = ("Enable the `publish.timeout` key in .cargo/config.toml file"),
747-
registry_auth: bool = ("Authentication for alternative registries, and generate registry authentication tokens using asymmetric cryptography"),
748+
registry_auth: bool = ("Authentication for alternative registries"),
748749
rustdoc_map: bool = ("Allow passing external documentation mappings to rustdoc"),
749750
rustdoc_scrape_examples: bool = ("Allows Rustdoc to scrape code examples from reverse-dependencies"),
750751
script: bool = ("Enable support for single-file, `.rs` packages"),
@@ -1087,6 +1088,7 @@ impl CliUnstable {
10871088
// Unstable features
10881089
// Sorted alphabetically:
10891090
"advanced-env" => self.advanced_env = parse_empty(k, v)?,
1091+
"asymmetric-token" => self.asymmetric_token = parse_empty(k, v)?,
10901092
"avoid-dev-deps" => self.avoid_dev_deps = parse_empty(k, v)?,
10911093
"binary-dep-depinfo" => self.binary_dep_depinfo = parse_empty(k, v)?,
10921094
"bindeps" => self.bindeps = parse_empty(k, v)?,

src/cargo/util/auth/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,8 @@ impl RegistryConfigExtended {
7676
/// Get the list of credential providers for a registry source.
7777
fn credential_provider(config: &Config, sid: &SourceId) -> CargoResult<Vec<Vec<String>>> {
7878
let cfg = registry_credential_config_raw(config, sid)?;
79-
let allow_cred_proc = config.cli_unstable().credential_process;
8079
let default_providers = || {
81-
if allow_cred_proc {
80+
if config.cli_unstable().asymmetric_token {
8281
// Enable the PASETO provider
8382
vec![
8483
vec!["cargo:token".to_string()],
@@ -90,7 +89,7 @@ fn credential_provider(config: &Config, sid: &SourceId) -> CargoResult<Vec<Vec<S
9089
};
9190
let global_providers = config
9291
.get::<Option<Vec<Value<String>>>>("registry.global-credential-providers")?
93-
.filter(|p| !p.is_empty() && allow_cred_proc)
92+
.filter(|p| !p.is_empty() && config.cli_unstable().credential_process)
9493
.map(|p| {
9594
p.iter()
9695
.rev()
@@ -108,7 +107,7 @@ fn credential_provider(config: &Config, sid: &SourceId) -> CargoResult<Vec<Vec<S
108107
token,
109108
secret_key,
110109
..
111-
}) if allow_cred_proc => {
110+
}) if config.cli_unstable().credential_process => {
112111
if let Some(token) = token {
113112
config.shell().warn(format!(
114113
"{sid} has a token configured in {} that will be ignored \
@@ -131,7 +130,7 @@ fn credential_provider(config: &Config, sid: &SourceId) -> CargoResult<Vec<Vec<S
131130
token: Some(token),
132131
secret_key: Some(secret_key),
133132
..
134-
}) if allow_cred_proc => {
133+
}) if config.cli_unstable().asymmetric_token => {
135134
let token_pos = global_providers
136135
.iter()
137136
.position(|p| p.first().map(String::as_str) == Some("cargo:token"));
@@ -182,7 +181,7 @@ fn credential_provider(config: &Config, sid: &SourceId) -> CargoResult<Vec<Vec<S
182181
Some(RegistryConfig {
183182
secret_key: Some(token),
184183
..
185-
}) if allow_cred_proc => {
184+
}) if config.cli_unstable().asymmetric_token => {
186185
if !global_providers
187186
.iter()
188187
.any(|p| p.first().map(String::as_str) == Some("cargo:paseto"))
@@ -454,7 +453,10 @@ fn credential_action(
454453
tracing::debug!("attempting credential provider: {args:?}");
455454
let provider: Box<dyn Credential> = match process {
456455
"cargo:token" => Box::new(TokenCredential::new(config)),
457-
"cargo:paseto" => Box::new(PasetoCredential::new(config)),
456+
"cargo:paseto" if config.cli_unstable().asymmetric_token => {
457+
Box::new(PasetoCredential::new(config))
458+
}
459+
"cargo:paseto" => bail!("cargo:paseto requires -Zasymmetric-token"),
458460
"cargo:token-from-stdout" => Box::new(BasicProcessCredential {}),
459461
"cargo:wincred" => Box::new(cargo_credential_wincred::WindowsCredential {}),
460462
"cargo:macos-keychain" => Box::new(cargo_credential_macos_keychain::MacKeychain {}),

src/doc/src/reference/unstable.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ can go to get a token.
989989
WWW-Authenticate: Cargo login_url="https://test-registry-login/me
990990
```
991991

992-
This same flag is also used to enable asymmetric authentication tokens.
992+
### asymmetric-token
993993
* Tracking Issue: [10519](https://github.com/rust-lang/cargo/issues/10519)
994994
* RFC: [#3231](https://github.com/rust-lang/rfcs/pull/3231)
995995

@@ -1115,7 +1115,7 @@ executed within the Cargo process. They are identified with the `cargo:` prefix.
11151115
* `CARGO_REGISTRY_INDEX_URL` --- The URL of the registry index.
11161116
* `CARGO_REGISTRY_NAME_OPT` --- Optional name of the registry. Should not be used as a storage key. Not always available.
11171117

1118-
* `cargo:paseto` - implements asymmetric token support (RFC3231) as a credential provider.
1118+
* `cargo:paseto` - implements asymmetric token support (RFC3231) as a credential provider. Requires `-Zasymmetric-token`.
11191119

11201120

11211121
`cargo-credential-1password` uses the 1password `op` CLI to store the token. You must

tests/testsuite/credential_process.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ fn both_asymmetric_and_token() {
492492
)
493493
.unwrap();
494494

495-
cargo_process("login -Z credential-process -v abcdefg")
496-
.masquerade_as_nightly_cargo(&["credential-process"])
495+
cargo_process("login -Zasymmetric-token -v abcdefg")
496+
.masquerade_as_nightly_cargo(&["asymmetric-token"])
497497
.replace_crates_io(server.index_url())
498498
.with_stderr(
499499
r#"[UPDATING] [..]

tests/testsuite/login.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ fn bad_asymmetric_token_args() {
197197
.build();
198198

199199
// These cases are kept brief as the implementation is covered by clap, so this is only smoke testing that we have clap configured correctly.
200-
cargo_process("login -Zcredential-process -- --key-subject")
201-
.masquerade_as_nightly_cargo(&["credential-process"])
200+
cargo_process("login -Zcredential-process -Zasymmetric-token -- --key-subject")
201+
.masquerade_as_nightly_cargo(&["credential-process", "asymmetric-token"])
202202
.replace_crates_io(registry.index_url())
203203
.with_stderr_contains(
204204
" error: a value is required for '--key-subject <SUBJECT>' but none was supplied",
@@ -228,7 +228,7 @@ fn login_with_asymmetric_token_and_subject_on_stdin() {
228228
.no_configure_token()
229229
.build();
230230
let credentials = credentials_toml();
231-
cargo_process("login -v -Z credential-process -- --key-subject=foo")
231+
cargo_process("login -v -Z credential-process -Z asymmetric-token -- --key-subject=foo")
232232
.masquerade_as_nightly_cargo(&["credential-process"])
233233
.replace_crates_io(registry.index_url())
234234
.with_stderr_contains(
@@ -286,8 +286,8 @@ fn login_with_asymmetric_token_on_stdin() {
286286
.no_configure_token()
287287
.build();
288288
let credentials = credentials_toml();
289-
cargo_process("login -vZ credential-process --registry alternative")
290-
.masquerade_as_nightly_cargo(&["credential-process"])
289+
cargo_process("login -vZ credential-process -Z asymmetric-token --registry alternative")
290+
.masquerade_as_nightly_cargo(&["credential-process", "asymmetric-token"])
291291
.with_stderr(
292292
"\
293293
[UPDATING] [..]
@@ -308,8 +308,8 @@ fn login_with_generate_asymmetric_token() {
308308
.no_configure_token()
309309
.build();
310310
let credentials = credentials_toml();
311-
cargo_process("login -Z credential-process --registry alternative")
312-
.masquerade_as_nightly_cargo(&["credential-process"])
311+
cargo_process("login -Z credential-process -Z asymmetric-token --registry alternative")
312+
.masquerade_as_nightly_cargo(&["credential-process", "asymmetric-token"])
313313
.with_stderr("[UPDATING] `alternative` index\nk3.public.[..]")
314314
.run();
315315
let credentials = fs::read_to_string(&credentials).unwrap();

tests/testsuite/owner.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ fn simple_add_with_asymmetric() {
117117
// The http_api server will check that the authorization is correct.
118118
// If the authorization was not sent then we would get an unauthorized error.
119119
p.cargo("owner -a username")
120-
.arg("-Zcredential-process")
121-
.masquerade_as_nightly_cargo(&["credential-process"])
120+
.arg("-Zasymmetric-token")
121+
.masquerade_as_nightly_cargo(&["asymmetric-token"])
122122
.replace_crates_io(registry.index_url())
123123
.with_status(0)
124124
.run();
@@ -184,9 +184,9 @@ fn simple_remove_with_asymmetric() {
184184
// The http_api server will check that the authorization is correct.
185185
// If the authorization was not sent then we would get an unauthorized error.
186186
p.cargo("owner -r username")
187-
.arg("-Zcredential-process")
187+
.arg("-Zasymmetric-token")
188188
.replace_crates_io(registry.index_url())
189-
.masquerade_as_nightly_cargo(&["credential-process"])
189+
.masquerade_as_nightly_cargo(&["asymmetric-token"])
190190
.with_status(0)
191191
.run();
192192
}

tests/testsuite/publish.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ fn simple_publish_with_asymmetric() {
194194
.file("src/main.rs", "fn main() {}")
195195
.build();
196196

197-
p.cargo("publish --no-verify -Zcredential-process --registry dummy-registry")
198-
.masquerade_as_nightly_cargo(&["credential-process"])
197+
p.cargo("publish --no-verify -Zasymmetric-token --registry dummy-registry")
198+
.masquerade_as_nightly_cargo(&["asymmetric-token"])
199199
.with_stderr(
200200
"\
201201
[UPDATING] `dummy-registry` index

tests/testsuite/registry_auth.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use cargo_test_support::{project, Execs, Project};
66

77
fn cargo(p: &Project, s: &str) -> Execs {
88
let mut e = p.cargo(s);
9-
e.masquerade_as_nightly_cargo(&["registry-auth", "credential-process"])
9+
e.masquerade_as_nightly_cargo(&["registry-auth", "credential-process", "asymmetric-token"])
1010
.arg("-Zregistry-auth")
11-
.arg("-Zcredential-process");
11+
.arg("-Zcredential-process")
12+
.arg("-Zasymmetric-token");
1213
e
1314
}
1415

tests/testsuite/yank.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ fn explicit_version_with_asymmetric() {
7676
// The http_api server will check that the authorization is correct.
7777
// If the authorization was not sent then we would get an unauthorized error.
7878
p.cargo("yank --version 0.0.1")
79-
.arg("-Zcredential-process")
80-
.masquerade_as_nightly_cargo(&["credential-process"])
79+
.arg("-Zasymmetric-token")
80+
.masquerade_as_nightly_cargo(&["asymmetric-token"])
8181
.replace_crates_io(registry.index_url())
8282
.run();
8383

8484
p.cargo("yank --undo --version 0.0.1")
85-
.arg("-Zcredential-process")
86-
.masquerade_as_nightly_cargo(&["credential-process"])
85+
.arg("-Zasymmetric-token")
86+
.masquerade_as_nightly_cargo(&["asymmetric-token"])
8787
.replace_crates_io(registry.index_url())
8888
.run();
8989
}

0 commit comments

Comments
 (0)