Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
# the Sigstore attestation that ships next to them.
crates/lpm-cli/tests/fixtures/release_manifests/*-SHA256SUMS.txt -text

# Sigstore's trust root and TUF metadata are checked against the lengths and
# hashes Sigstore signed, so a CRLF checkout must not rewrite them.
crates/lpm-cli/assets/sigstore_*.json -text
crates/lpm-cli/tests/fixtures/sigstore_tuf/*.json -text

# Lifecycle-script fixtures are the exact script bytes the static gate
# classifies; a CRLF checkout would hand it a `\r` no package.json string has.
crates/lpm-security/tests/fixtures/postinstall-scripts/scripts/*.txt -text
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions crates/lpm-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ rayon = { workspace = true }
p256 = { workspace = true }
# p384 for the Fulcio root chain (Phase 1.3) — Fulcio roots are P-384.
p384 = { workspace = true }
ed25519-dalek = { workspace = true }
ecdsa = { workspace = true }

# Phase 46 P4: x509 cert parsing for Sigstore attestation SAN extraction
Expand Down
141 changes: 141 additions & 0 deletions crates/lpm-cli/assets/sigstore_tuf_root.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
"signatures": [
{
"keyid": "e71a54d543835ba86adad9460379c7641fb8726d164ea766801a1c522aba7ea2",
"sig": "3045022065c68f28ebe44d0a4e047a6e287f9669c8e3b31e08536396c67a1483326be8c6022100e7524a889e40de0df84231dd40e1fcc57fbbbf62055c17076568307dbc509046"
},
{
"keyid": "22f4caec6d8e6f9555af66b3d4c3cb06a3bb23fdc7e39c916c61f462e6f52b06",
"sig": "304502206fedc4a382a0c5155e812c9b7461fe388ef704fef9e093c5c236e20abbf8e6620221008bbec36b63bf9baebc03a83c770cf9387efc90907eb83070b7a875129512d687"
},
{
"keyid": "61643838125b440b40db6942f5cb5a31c0dc04368316eb2aaa58b95904a58222",
"sig": "30450220468f4219db51c7e815e1e3d33d9987878aa12aeaf331604d5180dd60b19dfb350221009f778ef5e96647c08bd23d63f69c0cce6fc353d747b9d51f35dc0f8678de9fef"
},
{
"keyid": "a687e5bf4fab82b0ee58d46e05c9535145a2c9afb458f43d42b45ca0fdce2a70",
"sig": "3045022029e2518a7bcac05ec0b227809ce0c969406743412f90dc5255401afb13363f4602210087a64182249e41dd11de91c9f385a33659bd60147a93d13c86b7a64e447f9826"
},
{
"keyid": "183e64f37670dc13ca0d28995a3053f3740954ddce44321a41e46534cf44e632",
"sig": "30450221008051c456ed2bf48aa5fc5742928ab0904266c1d6bdde5fc75ae20f12d098a95502203cc683bd86793808e6c9f89e2ca93f80b00c6ea64880ac4e37db69e2e86b24e3"
}
],
"signed": {
"_type": "root",
"consistent_snapshot": true,
"expires": "2027-04-22T19:27:31Z",
"keys": {
"0c87432c3bf09fd99189fdc32fa5eaedf4e4a5fac7bab73fa04a2e0fc64af6f5": {
"keyid_hash_algorithms": [
"sha256",
"sha512"
],
"keytype": "ecdsa",
"keyval": {
"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEWRiGr5+j+3J5SsH+Ztr5nE2H2wO7\nBV+nO3s93gLca18qTOzHY1oWyAGDykMSsGTUBSt9D+An0KfKsD2mfSM42Q==\n-----END PUBLIC KEY-----\n"
},
"scheme": "ecdsa-sha2-nistp256",
"x-tuf-on-ci-online-uri": "gcpkms:projects/sigstore-root-signing/locations/global/keyRings/root/cryptoKeys/timestamp/cryptoKeyVersions/1"
},
"183e64f37670dc13ca0d28995a3053f3740954ddce44321a41e46534cf44e632": {
"keytype": "ecdsa",
"keyval": {
"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEMxpPOJCIZ5otG4106fGJseEQi3V9\npkMYQ4uyV9Tj1M7WHXIyLG+jkfvuG0glQ1JZbRZZBV3gAR4sojdGHISeow==\n-----END PUBLIC KEY-----\n"
},
"scheme": "ecdsa-sha2-nistp256",
"x-tuf-on-ci-keyowner": "@lance"
},
"22f4caec6d8e6f9555af66b3d4c3cb06a3bb23fdc7e39c916c61f462e6f52b06": {
"keyid_hash_algorithms": [
"sha256",
"sha512"
],
"keytype": "ecdsa",
"keyval": {
"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzBzVOmHCPojMVLSI364WiiV8NPrD\n6IgRxVliskz/v+y3JER5mcVGcONliDcWMC5J2lfHmjPNPhb4H7xm8LzfSA==\n-----END PUBLIC KEY-----\n"
},
"scheme": "ecdsa-sha2-nistp256",
"x-tuf-on-ci-keyowner": "@santiagotorres"
},
"61643838125b440b40db6942f5cb5a31c0dc04368316eb2aaa58b95904a58222": {
"keyid_hash_algorithms": [
"sha256",
"sha512"
],
"keytype": "ecdsa",
"keyval": {
"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEinikSsAQmYkNeH5eYq/CnIzLaacO\nxlSaawQDOwqKy/tCqxq5xxPSJc21K4WIhs9GyOkKfzueY3GILzcMJZ4cWw==\n-----END PUBLIC KEY-----\n"
},
"scheme": "ecdsa-sha2-nistp256",
"x-tuf-on-ci-keyowner": "@bobcallaway"
},
"a687e5bf4fab82b0ee58d46e05c9535145a2c9afb458f43d42b45ca0fdce2a70": {
"keyid_hash_algorithms": [
"sha256",
"sha512"
],
"keytype": "ecdsa",
"keyval": {
"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE0ghrh92Lw1Yr3idGV5WqCtMDB8Cx\n+D8hdC4w2ZLNIplVRoVGLskYa3gheMyOjiJ8kPi15aQ2//7P+oj7UvJPGw==\n-----END PUBLIC KEY-----\n"
},
"scheme": "ecdsa-sha2-nistp256",
"x-tuf-on-ci-keyowner": "@joshuagl"
},
"e71a54d543835ba86adad9460379c7641fb8726d164ea766801a1c522aba7ea2": {
"keyid_hash_algorithms": [
"sha256",
"sha512"
],
"keytype": "ecdsa",
"keyval": {
"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEEXsz3SZXFb8jMV42j6pJlyjbjR8K\nN3Bwocexq6LMIb5qsWKOQvLN16NUefLc4HswOoumRsVVaajSpQS6fobkRw==\n-----END PUBLIC KEY-----\n"
},
"scheme": "ecdsa-sha2-nistp256",
"x-tuf-on-ci-keyowner": "@mnm678"
}
},
"roles": {
"root": {
"keyids": [
"e71a54d543835ba86adad9460379c7641fb8726d164ea766801a1c522aba7ea2",
"22f4caec6d8e6f9555af66b3d4c3cb06a3bb23fdc7e39c916c61f462e6f52b06",
"61643838125b440b40db6942f5cb5a31c0dc04368316eb2aaa58b95904a58222",
"a687e5bf4fab82b0ee58d46e05c9535145a2c9afb458f43d42b45ca0fdce2a70",
"183e64f37670dc13ca0d28995a3053f3740954ddce44321a41e46534cf44e632"
],
"threshold": 3
},
"snapshot": {
"keyids": [
"0c87432c3bf09fd99189fdc32fa5eaedf4e4a5fac7bab73fa04a2e0fc64af6f5"
],
"threshold": 1,
"x-tuf-on-ci-expiry-period": 3650,
"x-tuf-on-ci-signing-period": 365
},
"targets": {
"keyids": [
"e71a54d543835ba86adad9460379c7641fb8726d164ea766801a1c522aba7ea2",
"22f4caec6d8e6f9555af66b3d4c3cb06a3bb23fdc7e39c916c61f462e6f52b06",
"61643838125b440b40db6942f5cb5a31c0dc04368316eb2aaa58b95904a58222",
"a687e5bf4fab82b0ee58d46e05c9535145a2c9afb458f43d42b45ca0fdce2a70",
"183e64f37670dc13ca0d28995a3053f3740954ddce44321a41e46534cf44e632"
],
"threshold": 3
},
"timestamp": {
"keyids": [
"0c87432c3bf09fd99189fdc32fa5eaedf4e4a5fac7bab73fa04a2e0fc64af6f5"
],
"threshold": 1,
"x-tuf-on-ci-expiry-period": 7,
"x-tuf-on-ci-signing-period": 6
}
},
"spec_version": "1.0",
"version": 16,
"x-tuf-on-ci-expiry-period": 197,
"x-tuf-on-ci-signing-period": 46
}
}
34 changes: 19 additions & 15 deletions crates/lpm-cli/src/commands/publish/npm_artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,20 @@ pub(crate) async fn prepare_npm_target_artifact(
})
}

pub(crate) fn load_provenance_file(path: &Path) -> Result<LoadedProvenanceFile, LpmError> {
pub(crate) async fn load_provenance_file(path: &Path) -> Result<LoadedProvenanceFile, LpmError> {
let file = open_provenance_file(path)?;
let bytes = read_open_provenance_file(file, path)?;
parse_provenance_file_bytes(path, bytes)
parse_provenance_file_bytes(path, bytes).await
}

pub(super) fn load_provenance_bytes(
pub(super) async fn load_provenance_bytes(
path: &Path,
bytes: Vec<u8>,
) -> Result<LoadedProvenanceFile, LpmError> {
if bytes.len() as u64 > PROVENANCE_FILE_MAX_BYTES {
return Err(provenance_file_too_large(path, bytes.len() as u64));
}
parse_provenance_file_bytes(path, bytes)
parse_provenance_file_bytes(path, bytes).await
}

pub(super) fn read_open_provenance_file(
Expand Down Expand Up @@ -138,7 +138,7 @@ fn provenance_file_too_large(path: &Path, size: u64) -> LpmError {
))
}

fn parse_provenance_file_bytes(
async fn parse_provenance_file_bytes(
path: &Path,
bytes: Vec<u8>,
) -> Result<LoadedProvenanceFile, LpmError> {
Expand All @@ -160,11 +160,13 @@ fn parse_provenance_file_bytes(
let statement = provenance_statement_from_bundle(&bundle)?;
validate_slsa_provenance_statement(&statement)?;

let verified = crate::sigstore_verify::verify_sigstore_bundle(
let verified = crate::sigstore_verify::verify_sigstore_bundle_refreshing(
data.as_bytes(),
&crate::sigstore_verify::IdentityExpectations::none(),
crate::sigstore_verify::VerifyOptions::npm_attestation(),
crate::sigstore_verify::TrustRefresh::WhenMissing,
)
.await
.map_err(|e| {
LpmError::Registry(format!(
"provenance file {} failed Sigstore verification: {e}",
Expand Down Expand Up @@ -629,22 +631,24 @@ mod tests {
assert!(error.to_string().contains("signing identity"));
}

#[test]
fn load_provenance_file_rejects_oversized_regular_file() {
#[tokio::test]
async fn load_provenance_file_rejects_oversized_regular_file() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("too-large.sigstore");
let file = std::fs::File::create(&path).unwrap();
file.set_len(PROVENANCE_FILE_MAX_BYTES + 1).unwrap();

let err = load_provenance_file(&path).unwrap_err();
let err = load_provenance_file(&path).await.unwrap_err();

assert!(err.to_string().contains("too large"));
}

#[cfg(unix)]
#[test]
fn load_provenance_file_rejects_special_file() {
let err = load_provenance_file(Path::new("/dev/null")).unwrap_err();
#[tokio::test]
async fn load_provenance_file_rejects_special_file() {
let err = load_provenance_file(Path::new("/dev/null"))
.await
.unwrap_err();

assert!(err.to_string().contains("regular file"));
}
Expand All @@ -665,8 +669,8 @@ mod tests {
}

#[cfg(unix)]
#[test]
fn load_provenance_file_rejects_fifo_without_blocking() {
#[tokio::test]
async fn load_provenance_file_rejects_fifo_without_blocking() {
use std::ffi::CString;
use std::os::unix::ffi::OsStrExt;

Expand All @@ -678,7 +682,7 @@ mod tests {
let rc = unsafe { libc::mkfifo(c_path.as_ptr(), 0o600) };
assert_eq!(rc, 0, "mkfifo must create the test fifo");

let err = load_provenance_file(&path).unwrap_err();
let err = load_provenance_file(&path).await.unwrap_err();

assert!(err.to_string().contains("regular file"));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/lpm-cli/src/commands/publish/orchestrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2621,7 +2621,7 @@ async fn precompute_file_provenance_artifacts(
let ProvenanceRequest::File(request) = input.provenance_request else {
return Ok(HashMap::new());
};
let file = load_provenance_request_file(request)?;
let file = load_provenance_request_file(request).await?;
let provenance = ResolvedProvenance::File(file);
let npm_target_count = input
.targets
Expand Down
12 changes: 7 additions & 5 deletions crates/lpm-cli/src/commands/publish/provenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub(crate) async fn materialize_provenance_request(
match request {
ProvenanceRequest::Disabled => Ok(None),
ProvenanceRequest::File(file) => load_provenance_request_file(&file)
.await
.map(ResolvedProvenance::File)
.map(Some),
ProvenanceRequest::Generate => {
Expand All @@ -59,11 +60,11 @@ pub(crate) async fn materialize_provenance_request(
}
}

pub(super) fn load_provenance_request_file(
pub(super) async fn load_provenance_request_file(
request: &ProvenanceFileRequest,
) -> Result<super::types::LoadedProvenanceFile, LpmError> {
match request {
ProvenanceFileRequest::AmbientPath(path) => load_provenance_file(path),
ProvenanceFileRequest::AmbientPath(path) => load_provenance_file(path).await,
ProvenanceFileRequest::ProjectFile {
display_path,
relative_path,
Expand All @@ -75,7 +76,7 @@ pub(super) fn load_provenance_request_file(
&display_path.to_string_lossy(),
)?;
let bytes = read_open_provenance_file_with_known_size(file, display_path, known_size)?;
load_provenance_bytes(display_path, bytes)
load_provenance_bytes(display_path, bytes).await
}
}
}
Expand Down Expand Up @@ -1317,8 +1318,8 @@ mod tests {
// replacement cannot happen there; see `publish_common`'s
// `an_open_tarball_source_root_keeps_its_directory_in_place`.
#[cfg(unix)]
#[test]
fn project_relative_provenance_keeps_the_selected_project_generation() {
#[tokio::test]
async fn project_relative_provenance_keeps_the_selected_project_generation() {
let root = tempfile::tempdir().unwrap();
let project = root.path().join("project");
let displaced = root.path().join("displaced");
Expand Down Expand Up @@ -1348,6 +1349,7 @@ mod tests {
};

let error = load_provenance_request_file(&request)
.await
.expect_err("the selected invalid provenance generation must be loaded")
.to_string();

Expand Down
Loading
Loading