-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sbom): deduplicate SBOM packages by ID (#1366)
In chainguard-dev/melange#1474, we updated our SBOMs to have distinct SPDX packages for the APK itself, vs. the build config used to produce it, vs. the upstream source(s) pulled in for the build. This helps us produce more idiomatic and descriptive SPDX data. But this caused a problem downstream in apko — when we aggregate APKs' SBOMs, and specifically their SPDX packages, into a single list of SPDX packages for the image, we end up with duplicate package IDs when multiple APKs were build from the same build config or the same upstream source. This PR adds tests to catch this case, and it fixes the duplicate package issue by dropping subsequent instances of a given package ID. It also further improves on the existing SBOM-related tests. Signed-off-by: Dan Luhring <[email protected]>
- Loading branch information
Showing
12 changed files
with
434 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
|
||
set -euo pipefail | ||
|
||
# Define an array of package name-version strings | ||
packages=( | ||
"font-ubuntu-0.869-r1" | ||
"libattr1-2.5.1-r2" | ||
"logstash-8-8.15.3-r4" | ||
"logstash-8-compat-8.15.3-r4" | ||
) | ||
|
||
# Base URL for downloading APKs | ||
base_url="https://packages.wolfi.dev/os/x86_64" | ||
|
||
# Loop through the array and process each package | ||
for pkg in "${packages[@]}"; do | ||
url="${base_url}/${pkg}.apk" | ||
output_path="${pkg}.spdx.json" | ||
curl -q "$url" | tar Ozx "var/lib/db/sbom/${pkg}.spdx.json" >"$output_path" 2>/dev/null | ||
done |
File renamed without changes.
File renamed without changes.
87 changes: 87 additions & 0 deletions
87
pkg/sbom/generator/spdx/testdata/apk_sboms/logstash-8-8.15.3-r4.spdx.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
{ | ||
"SPDXID": "SPDXRef-DOCUMENT", | ||
"name": "apk-logstash-8-8.15.3-r4", | ||
"spdxVersion": "SPDX-2.3", | ||
"creationInfo": { | ||
"created": "2024-10-24T15:16:49Z", | ||
"creators": [ | ||
"Tool: melange (v0.14.7)", | ||
"Organization: Chainguard, Inc" | ||
], | ||
"licenseListVersion": "3.22" | ||
}, | ||
"dataLicense": "CC0-1.0", | ||
"documentNamespace": "https://spdx.org/spdxdocs/chainguard/melange/0434ffabb9f0343f5dada78abdb2e419b2be48fb", | ||
"documentDescribes": [ | ||
"SPDXRef-Package-logstash-8-8.15.3-r4" | ||
], | ||
"packages": [ | ||
{ | ||
"SPDXID": "SPDXRef-Package-logstash-8-8.15.3-r4", | ||
"name": "logstash-8", | ||
"versionInfo": "8.15.3-r4", | ||
"filesAnalyzed": false, | ||
"licenseConcluded": "NOASSERTION", | ||
"licenseDeclared": "Apache-2.0", | ||
"downloadLocation": "NOASSERTION", | ||
"originator": "Organization: Wolfi", | ||
"supplier": "Organization: Wolfi", | ||
"copyrightText": "\n", | ||
"externalRefs": [ | ||
{ | ||
"referenceCategory": "PACKAGE-MANAGER", | ||
"referenceLocator": "pkg:apk/wolfi/[email protected]?arch=x86_64", | ||
"referenceType": "purl" | ||
} | ||
] | ||
}, | ||
{ | ||
"SPDXID": "SPDXRef-Package-logstash-8.yaml-c7d40faa38ddffa98700cfa4c2f9bde196acc504", | ||
"name": "logstash-8.yaml", | ||
"versionInfo": "c7d40faa38ddffa98700cfa4c2f9bde196acc504", | ||
"filesAnalyzed": false, | ||
"licenseConcluded": "NOASSERTION", | ||
"licenseDeclared": "Apache-2.0", | ||
"downloadLocation": "NOASSERTION", | ||
"originator": "Organization: Wolfi", | ||
"supplier": "Organization: Wolfi", | ||
"externalRefs": [ | ||
{ | ||
"referenceCategory": "PACKAGE-MANAGER", | ||
"referenceLocator": "pkg:github/wolfi-dev/os@c7d40faa38ddffa98700cfa4c2f9bde196acc504#logstash-8.yaml", | ||
"referenceType": "purl" | ||
} | ||
] | ||
}, | ||
{ | ||
"SPDXID": "SPDXRef-Package-github.com-elastic-logstash-v8.15.3-8364c8e89cfb113e38ec3f966df7eb1e9abe9d33-0", | ||
"name": "logstash", | ||
"versionInfo": "v8.15.3", | ||
"filesAnalyzed": false, | ||
"licenseConcluded": "NOASSERTION", | ||
"licenseDeclared": "Apache-2.0", | ||
"downloadLocation": "NOASSERTION", | ||
"originator": "Organization: Elastic", | ||
"supplier": "Organization: Elastic", | ||
"externalRefs": [ | ||
{ | ||
"referenceCategory": "PACKAGE-MANAGER", | ||
"referenceLocator": "pkg:github/elastic/[email protected]", | ||
"referenceType": "purl" | ||
} | ||
] | ||
} | ||
], | ||
"relationships": [ | ||
{ | ||
"spdxElementId": "SPDXRef-Package-logstash-8-8.15.3-r4", | ||
"relationshipType": "DESCRIBED_BY", | ||
"relatedSpdxElement": "SPDXRef-Package-logstash-8.yaml-c7d40faa38ddffa98700cfa4c2f9bde196acc504" | ||
}, | ||
{ | ||
"spdxElementId": "SPDXRef-Package-logstash-8-8.15.3-r4", | ||
"relationshipType": "GENERATED_FROM", | ||
"relatedSpdxElement": "SPDXRef-Package-github.com-elastic-logstash-v8.15.3-8364c8e89cfb113e38ec3f966df7eb1e9abe9d33-0" | ||
} | ||
] | ||
} |
Oops, something went wrong.