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

Several SPDX SBOM adjustments. #760

Merged
merged 1 commit into from
Jul 11, 2022
Merged
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
54 changes: 43 additions & 11 deletions internal/sbom/spdx.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ func GenerateImageSPDX(koVersion string, mod []byte, img oci.SignedImage) ([]byt
ExternalRefs: []ExternalRef{{
Category: "PACKAGE_MANAGER",
Type: "purl",
Locator: ociRef("image", imgDigest),
Locator: ociRef("image", imgDigest, qualifier{
key: "mediaType",
value: string(m.MediaType),
}),
}},
})

Expand Down Expand Up @@ -218,6 +221,10 @@ func GenerateIndexSPDX(koVersion string, sii oci.SignedImageIndex) ([]byte, erro
if err != nil {
return nil, err
}
im, err := sii.IndexManifest()
if err != nil {
return nil, err
}

doc, indexID := starterDocument(koVersion, *date, indexDigest)
doc.Packages = []Package{{
Expand All @@ -235,14 +242,13 @@ func GenerateIndexSPDX(koVersion string, sii oci.SignedImageIndex) ([]byte, erro
ExternalRefs: []ExternalRef{{
Category: "PACKAGE_MANAGER",
Type: "purl",
Locator: ociRef("index", indexDigest),
Locator: ociRef("index", indexDigest, qualifier{
key: "mediaType",
value: string(im.MediaType),
}),
}},
}}

im, err := sii.IndexManifest()
if err != nil {
return nil, err
}
if err := addBaseImage(&doc, im.Annotations, indexDigest); err != nil {
return nil, err
}
Expand All @@ -263,10 +269,39 @@ func GenerateIndexSPDX(koVersion string, sii oci.SignedImageIndex) ([]byte, erro

doc.Relationships = append(doc.Relationships, Relationship{
Element: ociPackageName(indexDigest),
Type: "CONTAINS",
Type: "VARIANT_OF",
Related: depID,
})

qual := []qualifier{{
Copy link
Member

Choose a reason for hiding this comment

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

This makes me want a newQualifier(k, v string) qualifier helper method, and/or a platformQualifiers(p v1.Platform) []qualifier.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it's worth surveying our usage of qualifiers as this evolves and figuring out what helpers make sense. I'd also be inclined to just create a decent OCI pURL library in GGCR and use that TBH.

key: "mediaType",
value: string(desc.MediaType),
}, {
key: "arch",
value: desc.Platform.Architecture,
}, {
key: "os",
value: desc.Platform.OS,
}}
if desc.Platform.Variant != "" {
qual = append(qual, qualifier{
key: "variant",
value: desc.Platform.Variant,
})
}
if desc.Platform.OSVersion != "" {
qual = append(qual, qualifier{
key: "os-version",
value: desc.Platform.OSVersion,
})
}
for _, feat := range desc.Platform.OSFeatures {
qual = append(qual, qualifier{
key: "os-feature",
value: feat,
})
}

doc.Packages = append(doc.Packages, Package{
ID: depID,
Name: imageDigest.String(),
Expand All @@ -280,10 +315,7 @@ func GenerateIndexSPDX(koVersion string, sii oci.SignedImageIndex) ([]byte, erro
ExternalRefs: []ExternalRef{{
Category: "PACKAGE_MANAGER",
Type: "purl",
Locator: ociRef("image", imageDigest, qualifier{
key: "arch",
value: desc.Platform.Architecture,
}),
Locator: ociRef("image", imageDigest, qual...),
}},
Checksums: []Checksum{{
Algorithm: strings.ToUpper(imageDigest.Algorithm),
Expand Down