-
Notifications
You must be signed in to change notification settings - Fork 572
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: use package id from cyclonedx when provided #1872
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -336,3 +336,41 @@ func Test_missingComponentsDecode(t *testing.T) { | |
|
||
assert.NoError(t, err) | ||
} | ||
|
||
func Test_useSyftIDWhenProvided(t *testing.T) { | ||
|
||
packageWithId := cyclonedx.Component{ | ||
BOMRef: "pkg:maven/org.springframework.boot/spring-boot-starter-test?package-id=646a5a71a4abeee0", | ||
Type: cyclonedx.ComponentTypeLibrary, | ||
Name: "spring-boot-starter-test", | ||
Version: "", | ||
PackageURL: "pkg:maven/org.springframework.boot/spring-boot-starter-test", | ||
} | ||
|
||
packageID := extractSyftPacakgeID(packageWithId.BOMRef) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a typo here |
||
|
||
packageWithoutId := cyclonedx.Component{ | ||
BOMRef: "pkg:maven/org.springframework.boot/spring-boot-starter-webflux", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Why don't we reuse the BomRef value ? I assume sboms use the BomRef as an unique reference, therefore I am wondering why this initial unique ID for this SBOM needs to be adapted as done on |
||
Type: cyclonedx.ComponentTypeLibrary, | ||
Name: "spring-boot-starter-webflux", | ||
Version: "", | ||
PackageURL: "pkg:maven/org.springframework.boot/spring-boot-starter-webflux", | ||
} | ||
|
||
bom := cyclonedx.BOM{Metadata: nil, | ||
Components: &[]cyclonedx.Component{ | ||
packageWithId, | ||
packageWithoutId, | ||
}} | ||
|
||
sbom, err := ToSyftModel(&bom) | ||
|
||
assert.Nil(t, err) | ||
assert.NotNil(t, sbom.Artifacts.Packages.Package(artifact.ID(packageID))) | ||
|
||
pkgsWithoutID := sbom.Artifacts.Packages.PackagesByName(packageWithoutId.Name) | ||
|
||
assert.Len(t, pkgsWithoutID, 1) | ||
assert.NotEqual(t, "", pkgsWithoutID[0].ID()) | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only way this
p.OverrideID
gets called is if thecomponent.BOMRef
is a PURL that contains thepackage-id
qualifier (which is probably only set when Syft generated the SBOM in the first place, using a PURL as the BOMRef). Additionally, thissyftID
might not even match the ID generated by the current version of Syft, so the way it's being used is probably wrong.It was originally a conscious decision to re-generate the IDs for components (by calling the
p.SetID()
instead of reusing whatever ID is provided by the format in order to get reasonably consistent output. For example: if we used the BOMRef as the Syft package ID, then re-encoded CycloneDX, we'd have something like:pkg:thing/name@version?package-id=pkg:thing/name@version?package-id=2a7443b435345b2
(ignore the lack of URL encoding). Obviously we can handle this during encoding, for example, by comparing the ID to whatSetID
would set.A few things here:
extractSyftPacakgeID
. I don't think this is providing any value -- at best it's extracting the same ID thatSetID()
would generate, but more likely it is setting some different ID that is not useful in any wayGenerateID
that could be used for comparison and/or anIsIDGenerated()
)If we want to support reading IDs from formats instead of always generating them based on the data (I'm not sure we always do -- this seems like a configurable option), I think your observation that we should be using the
BOMRef
is accurate, maybe something like this: