Skip to content

Commit 914a574

Browse files
authored
Add an OperatingSystem package to our image SBOMs (#1690)
We are missing some information in our image SBOMs that cause trivy to generate warnings. The missing piece is a package declaring what operating system our images are using. --------- Signed-off-by: Łukasz 'sil2100' Zemczak <[email protected]>
1 parent 3b50586 commit 914a574

File tree

7 files changed

+79
-0
lines changed

7 files changed

+79
-0
lines changed

internal/cli/testdata/golden/sboms/sbom-aarch64.spdx.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
}
5656
]
5757
},
58+
{
59+
"SPDXID": "SPDXRef-OperatingSystem-replaces",
60+
"name": "replaces",
61+
"versionInfo": "1.0.0",
62+
"filesAnalyzed": false,
63+
"description": "Operating System",
64+
"downloadLocation": "NOASSERTION",
65+
"supplier": "Organization: Replaces",
66+
"primaryPackagePurpose": "OPERATING-SYSTEM"
67+
},
5868
{
5969
"SPDXID": "SPDXRef-Package-pretend-baselayout-1.0.0-r0",
6070
"name": "pretend-baselayout",

internal/cli/testdata/golden/sboms/sbom-x86_64.spdx.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@
5555
}
5656
]
5757
},
58+
{
59+
"SPDXID": "SPDXRef-OperatingSystem-replaces",
60+
"name": "replaces",
61+
"versionInfo": "1.0.0",
62+
"filesAnalyzed": false,
63+
"description": "Operating System",
64+
"downloadLocation": "NOASSERTION",
65+
"supplier": "Organization: Replaces",
66+
"primaryPackagePurpose": "OPERATING-SYSTEM"
67+
},
5868
{
5969
"SPDXID": "SPDXRef-Package-pretend-baselayout-1.0.0-r0",
6070
"name": "pretend-baselayout",

pkg/sbom/generator/spdx/spdx.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ func (sx *SPDX) Generate(opts *options.Options, path string) error {
134134
doc.DocumentDescribes = []string{imagePackage.ID}
135135
}
136136

137+
// Add the operating system package
138+
addOperatingSystem(doc, opts)
139+
137140
if opts.ImageInfo.VCSUrl != "" {
138141
if opts.ImageInfo.ImageDigest != "" {
139142
addSourcePackage(opts.ImageInfo.VCSUrl, doc, imagePackage, opts)
@@ -623,6 +626,22 @@ func (sx *SPDX) GenerateIndex(opts *options.Options, path string) error {
623626
return nil
624627
}
625628

629+
// addOperatingSystem adds a package describing the operating system
630+
func addOperatingSystem(doc *Document, opts *options.Options) {
631+
osPackage := Package{
632+
ID: fmt.Sprintf("SPDXRef-OperatingSystem-%s", stringToIdentifier(opts.OS.ID)),
633+
Name: opts.OS.ID,
634+
Version: opts.OS.Version,
635+
Supplier: supplier(opts),
636+
FilesAnalyzed: false,
637+
Description: "Operating System",
638+
DownloadLocation: NOASSERTION,
639+
PrimaryPurpose: "OPERATING-SYSTEM",
640+
}
641+
642+
doc.Packages = append(doc.Packages, osPackage)
643+
}
644+
626645
// addSourcePackage creates a package describing the source code
627646
func addSourcePackage(vcsURL string, doc *Document, parent *Package, opts *options.Options) {
628647
version := ""

pkg/sbom/generator/spdx/testdata/expected_image_sboms/custom-license.spdx.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
}
3333
]
3434
},
35+
{
36+
"SPDXID": "SPDXRef-OperatingSystem-unknown",
37+
"name": "unknown",
38+
"versionInfo": "3.0",
39+
"filesAnalyzed": false,
40+
"description": "Operating System",
41+
"downloadLocation": "NOASSERTION",
42+
"supplier": "Organization: unknown",
43+
"primaryPackagePurpose": "OPERATING-SYSTEM"
44+
},
3545
{
3646
"SPDXID": "SPDXRef-Package-font-ubuntu-0.869-r1",
3747
"name": "font-ubuntu",

pkg/sbom/generator/spdx/testdata/expected_image_sboms/no-supplier.spdx.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
}
3333
]
3434
},
35+
{
36+
"SPDXID": "SPDXRef-OperatingSystem-apko-images",
37+
"name": "apko-images",
38+
"versionInfo": "3.0",
39+
"filesAnalyzed": false,
40+
"description": "Operating System",
41+
"downloadLocation": "NOASSERTION",
42+
"supplier": "Organization: Apko Images, Plc",
43+
"primaryPackagePurpose": "OPERATING-SYSTEM"
44+
},
3545
{
3646
"SPDXID": "SPDXRef-Package-libattr1-2.5.1-r2",
3747
"name": "libattr1",

pkg/sbom/generator/spdx/testdata/expected_image_sboms/package-deduplicating.spdx.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
}
3333
]
3434
},
35+
{
36+
"SPDXID": "SPDXRef-OperatingSystem-unknown",
37+
"name": "unknown",
38+
"versionInfo": "3.0",
39+
"filesAnalyzed": false,
40+
"description": "Operating System",
41+
"downloadLocation": "NOASSERTION",
42+
"supplier": "Organization: unknown",
43+
"primaryPackagePurpose": "OPERATING-SYSTEM"
44+
},
3545
{
3646
"SPDXID": "SPDXRef-Package-logstash-8-8.15.3-r4",
3747
"name": "logstash-8",

pkg/sbom/generator/spdx/testdata/expected_image_sboms/unbound-package-dedupe.spdx.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@
3232
}
3333
]
3434
},
35+
{
36+
"SPDXID": "SPDXRef-OperatingSystem-unknown",
37+
"name": "unknown",
38+
"versionInfo": "3.0",
39+
"filesAnalyzed": false,
40+
"description": "Operating System",
41+
"downloadLocation": "NOASSERTION",
42+
"supplier": "Organization: unknown",
43+
"primaryPackagePurpose": "OPERATING-SYSTEM"
44+
},
3545
{
3646
"SPDXID": "SPDXRef-Package-unbound-libs-1.23.0-r0",
3747
"name": "unbound-libs",

0 commit comments

Comments
 (0)