Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(publish): provenance attestation #22573

Merged
merged 26 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,22 @@ notify.workspace = true
once_cell.workspace = true
open = "5.0.1"
os_pipe.workspace = true
p256.workspace = true
percent-encoding.workspace = true
phf.workspace = true
pin-project.workspace = true
quick-junit = "^0.3.5"
rand = { workspace = true, features = ["small_rng"] }
regex.workspace = true
reqwest.workspace = true
ring.workspace = true
rustyline.workspace = true
rustyline-derive = "=0.7.0"
serde.workspace = true
serde_repr.workspace = true
sha2.workspace = true
shell-escape = "=0.1.5"
spki = { version = "0.7", features = ["pem"] }
tar.workspace = true
tempfile.workspace = true
text-size = "=1.1.0"
Expand Down
28 changes: 28 additions & 0 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ pub struct PublishFlags {
pub token: Option<String>,
pub dry_run: bool,
pub allow_slow_types: bool,
pub provenance: bool,
}

#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -2395,6 +2396,12 @@ fn publish_subcommand() -> Command {
.help("Allow publishing with slow types")
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("provenance")
.long("provenance")
.help("From CI/CD system, publicly links the package to where it was built and published from.")
.action(ArgAction::SetTrue)
)
Comment on lines +2399 to +2404
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also do this in a follow up, but can we enable provenance by default when we are using GH OIDC for auth?

And then add a --no-provenance option to force it off, and --provenance option to force it on.

We can then also use --provenance to do enable provenance for local publishes at some later date.

.arg(check_arg(/* type checks by default */ true))
.arg(no_check_arg())
})
Expand Down Expand Up @@ -3835,6 +3842,7 @@ fn publish_parse(flags: &mut Flags, matches: &mut ArgMatches) {
token: matches.remove_one("token"),
dry_run: matches.get_flag("dry-run"),
allow_slow_types: matches.get_flag("allow-slow-types"),
provenance: matches.get_flag("provenance"),
});
}

Expand Down Expand Up @@ -8565,6 +8573,26 @@ mod tests {
token: Some("asdf".to_string()),
dry_run: true,
allow_slow_types: true,
provenance: false,
}),
type_check_mode: TypeCheckMode::Local,
..Flags::default()
}
);
}

#[test]
fn publish_provenance_args() {
let r =
flags_from_vec(svec!["deno", "publish", "--provenance", "--token=asdf",]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Publish(PublishFlags {
token: Some("asdf".to_string()),
dry_run: false,
allow_slow_types: false,
provenance: true,
}),
type_check_mode: TypeCheckMode::Local,
..Flags::default()
Expand Down
8 changes: 8 additions & 0 deletions cli/tools/registry/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ pub struct OidcConfig {
pub token: String,
}

pub(crate) fn is_gha() -> bool {
std::env::var("GITHUB_ACTIONS").unwrap_or_default() == "true"
}

pub(crate) fn gha_oidc_token() -> Option<String> {
std::env::var("ACTIONS_ID_TOKEN_REQUEST_TOKEN").ok()
}

fn get_gh_oidc_env_vars() -> Option<Result<(String, String), AnyError>> {
if std::env::var("GITHUB_ACTIONS").unwrap_or_default() == "true" {
let url = std::env::var("ACTIONS_ID_TOKEN_REQUEST_URL");
Expand Down