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: allow slsa spec compliant subjects in provenance #699

Merged
merged 5 commits into from
Aug 26, 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
2 changes: 1 addition & 1 deletion api/src/api/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,7 @@ mod test {
.unwrap();

fn update_bundle_subject(bundle: &mut ProvenanceBundle, subject: Subject) {
let subject = serde_json::json!({ "subject": subject });
let subject = serde_json::json!({ "subject": [subject] });
bundle.content.dsse_envelope.payload = BASE64_STANDARD
.encode(serde_json::to_string(&subject).unwrap().as_bytes());
}
Expand Down
22 changes: 21 additions & 1 deletion api/src/provenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,17 @@ pub struct Subject {
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ProvenanceAttestation {
pub subject: Subject,
pub subject: ProvenanceAttestationSubject,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ProvenanceAttestationSubject {
Subjects(Vec<Subject>),
// NOTE: this should be removed in the future. It is only here to support
// old Deno CLI versions that sent invalid SLSA attestations where the subject
// was not wrapped in an array.
Subject(Subject),
}

pub fn verify(
Expand All @@ -118,6 +128,16 @@ pub fn verify(
serde_json::from_slice::<ProvenanceAttestation>(&payload)?.subject
};

let subject = match subject {
ProvenanceAttestationSubject::Subjects(subjects) => {
if subjects.len() != 1 {
bail!("Invalid subject");
}
subjects.into_iter().next().unwrap()
}
ProvenanceAttestationSubject::Subject(subject) => subject,
};

if subject.name != subject_name {
bail!("Invalid subject name");
}
Expand Down
Loading