Skip to content

Commit a7b6a3c

Browse files
committed
Auto merge of #12334 - arlosi:cred-ext, r=ehuss
credential provider implementation The current credential process protocol only allows sending the credential without any additional information. This changes the protocol in two important ways: Cargo will tell the credential provider what the token is needed for, and the credential provider can tell Cargo how the token can be used. Since the credential provider knows why Cargo needs a token (`publish` for example), it can produce a signed token specifically for that operation. This would enable a credential process to produce an asymmetric token, or a token with restricted scope such as PASETO or Biscuit. The credential process can also indicate back to Cargo if the token can be cached in-memory for subsequent requests. For example, if a credential provider integrates with an SSO identity provider that provides short-lived tokens, Cargo will only continue to use the token while it is valid. ### Summary of changes * Rename `credential-process` to `credential-provider` in config. * Add a new line-oriented JSON protocol for communicating with external credential providers via stdin/stdout. * Allow built-in credential providers to run in the Cargo process. * Move support for asymmetric tokens (RFC3231) into a built-in credential provider (`cargo:paseto`). * Change the unstable key for asymmetric tokens from `registry-auth` to `credential-process` * Add a new built-in provider to represent the current config/token based system (`cargo:token`). * Add a new built-in provider for the a "basic" provider that prints only the token on stdout (`cargo:basic`). * Create a new config key for the fallback credential providers (`registry.credential-providers`) as a list. * The provider for `crates.io` no longer also acts as a fallback for other registries. * Adds a `[credential-alias]` table for defining aliases of credential providers. * Collect all headers from `http_registry` requests, passing them through to the cred provider. Everything remains unstable under the `-Zcredential-process` flag. ### How to review this: I recommend starting with the changes in `unstable.md` for a more detailed description. ### Open questions * [x] Should we pass all the HTTP headers rather than just `www-authenticate`
2 parents b40be8b + 6151a41 commit a7b6a3c

File tree

48 files changed

+2313
-1857
lines changed

Some content is hidden

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

48 files changed

+2313
-1857
lines changed

Cargo.lock

+14-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ anyhow = "1.0.47"
1919
base64 = "0.21.0"
2020
bytesize = "1.0"
2121
cargo = { path = "" }
22-
cargo-credential = { version = "0.2.0", path = "credential/cargo-credential" }
22+
cargo-credential = { version = "0.3.0", path = "credential/cargo-credential" }
23+
cargo-credential-1password = { version = "0.3.0", path = "credential/cargo-credential-1password" }
24+
cargo-credential-wincred = { version = "0.3.0", path = "credential/cargo-credential-wincred" }
25+
cargo-credential-macos-keychain = { version = "0.3.0", path = "credential/cargo-credential-macos-keychain" }
2326
cargo-platform = { path = "crates/cargo-platform", version = "0.1.4" }
2427
cargo-test-macro = { path = "crates/cargo-test-macro" }
2528
cargo-test-support = { path = "crates/cargo-test-support" }
@@ -88,7 +91,7 @@ tar = { version = "0.4.38", default-features = false }
8891
tempfile = "3.1.0"
8992
termcolor = "1.1.2"
9093
thiserror = "1.0.40"
91-
time = { version = "0.3", features = ["parsing", "formatting"] }
94+
time = { version = "0.3", features = ["parsing", "formatting", "serde"] }
9295
toml = "0.7.0"
9396
toml_edit = "0.19.0"
9497
unicode-width = "0.1.5"
@@ -119,6 +122,10 @@ anyhow.workspace = true
119122
base64.workspace = true
120123
bytesize.workspace = true
121124
cargo-platform.workspace = true
125+
cargo-credential.workspace = true
126+
cargo-credential-1password.workspace = true
127+
cargo-credential-macos-keychain.workspace = true
128+
cargo-credential-wincred.workspace = true
122129
cargo-util.workspace = true
123130
clap = { workspace = true, features = ["wrap_help"] }
124131
crates-io.workspace = true

crates/cargo-test-support/src/compare.rs

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ fn substitute_macros(input: &str) -> String {
192192
("[CHECKING]", " Checking"),
193193
("[COMPLETED]", " Completed"),
194194
("[CREATED]", " Created"),
195+
("[CREDENTIAL]", " Credential"),
195196
("[DOWNGRADING]", " Downgrading"),
196197
("[FINISHED]", " Finished"),
197198
("[ERROR]", "error:"),

crates/cargo-test-support/src/registry.rs

+36
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ pub struct RegistryBuilder {
104104
not_found_handler: RequestCallback,
105105
/// If nonzero, the git index update to be delayed by the given number of seconds.
106106
delayed_index_update: usize,
107+
/// Credential provider in configuration
108+
credential_provider: Option<String>,
107109
}
108110

109111
pub struct TestRegistry {
@@ -172,6 +174,7 @@ impl RegistryBuilder {
172174
custom_responders: HashMap::new(),
173175
not_found_handler: Box::new(not_found),
174176
delayed_index_update: 0,
177+
credential_provider: None,
175178
}
176179
}
177180

@@ -266,6 +269,13 @@ impl RegistryBuilder {
266269
self
267270
}
268271

272+
/// The credential provider to configure for this registry.
273+
#[must_use]
274+
pub fn credential_provider(mut self, provider: &[&str]) -> Self {
275+
self.credential_provider = Some(format!("['{}']", provider.join("','")));
276+
self
277+
}
278+
269279
/// Initializes the registry.
270280
#[must_use]
271281
pub fn build(self) -> TestRegistry {
@@ -336,6 +346,18 @@ impl RegistryBuilder {
336346
.as_bytes(),
337347
)
338348
.unwrap();
349+
if let Some(p) = &self.credential_provider {
350+
append(
351+
&config_path,
352+
&format!(
353+
"
354+
credential-provider = {p}
355+
"
356+
)
357+
.as_bytes(),
358+
)
359+
.unwrap()
360+
}
339361
} else {
340362
append(
341363
&config_path,
@@ -351,6 +373,20 @@ impl RegistryBuilder {
351373
.as_bytes(),
352374
)
353375
.unwrap();
376+
377+
if let Some(p) = &self.credential_provider {
378+
append(
379+
&config_path,
380+
&format!(
381+
"
382+
[registry]
383+
credential-provider = {p}
384+
"
385+
)
386+
.as_bytes(),
387+
)
388+
.unwrap()
389+
}
354390
}
355391
}
356392

credential/cargo-credential-1password/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cargo-credential-1password"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition.workspace = true
55
license.workspace = true
66
repository = "https://github.com/rust-lang/cargo"

0 commit comments

Comments
 (0)