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

fix(publish): ensure provenance is spec compliant #25200

Merged
merged 3 commits into from
Aug 31, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cli/tools/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,8 @@ async fn publish_package(
sha256: faster_hex::hex_string(&sha2::Sha256::digest(&meta_bytes)),
},
};
let bundle = provenance::generate_provenance(http_client, subject).await?;
let bundle =
provenance::generate_provenance(http_client, vec![subject]).await?;

let tlog_entry = &bundle.verification_material.tlog_entries[0];
log::info!("{}",
Expand Down
21 changes: 13 additions & 8 deletions cli/tools/registry/provenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,16 @@ impl Predicate {
struct ProvenanceAttestation {
#[serde(rename = "type")]
_type: &'static str,
subject: Subject,
subject: Vec<Subject>,
predicate_type: &'static str,
predicate: Predicate,
}

impl ProvenanceAttestation {
pub fn new_github_actions(subject: Subject) -> Self {
pub fn new_github_actions(subjects: Vec<Subject>) -> Self {
Self {
_type: INTOTO_STATEMENT_TYPE,
subject,
subject: subjects,
predicate_type: SLSA_PREDICATE_TYPE,
predicate: Predicate::new_github_actions(),
}
Expand Down Expand Up @@ -296,7 +296,7 @@ pub struct ProvenanceBundle {

pub async fn generate_provenance(
http_client: &HttpClient,
subject: Subject,
subjects: Vec<Subject>,
) -> Result<ProvenanceBundle, AnyError> {
if !is_gha() {
bail!("Automatic provenance is only available in GitHub Actions");
Expand All @@ -308,7 +308,7 @@ pub async fn generate_provenance(
);
};

let slsa = ProvenanceAttestation::new_github_actions(subject);
let slsa = ProvenanceAttestation::new_github_actions(subjects);

let attestation = serde_json::to_string(&slsa)?;
let bundle = attest(http_client, &attestation, INTOTO_PAYLOAD_TYPE).await?;
Expand Down Expand Up @@ -738,8 +738,13 @@ mod tests {
sha256: "yourmom".to_string(),
},
};
let slsa = ProvenanceAttestation::new_github_actions(subject);
assert_eq!(slsa.subject.name, "jsr:@divy/sdl2@0.0.1");
assert_eq!(slsa.subject.digest.sha256, "yourmom");
let slsa = ProvenanceAttestation::new_github_actions(vec![subject]);
assert_eq!(
slsa.subject.len(),
1,
"Subject should be an array per the in-toto specification"
);
assert_eq!(slsa.subject[0].name, "jsr:@divy/sdl2@0.0.1");
assert_eq!(slsa.subject[0].digest.sha256, "yourmom");
}
}