Skip to content

Use package ID from decoded SBOMs when provided#1872

Merged
wagoodman merged 5 commits intoanchore:mainfrom
jneate:use-cyclonedx-id-when-provided
May 8, 2025
Merged

Use package ID from decoded SBOMs when provided#1872
wagoodman merged 5 commits intoanchore:mainfrom
jneate:use-cyclonedx-id-when-provided

Conversation

@jneate
Copy link
Copy Markdown
Contributor

@jneate jneate commented Jun 10, 2023

Today if you use syft convert, the syft API (say via grype) with an SBOM, or use the SBOM cataloger, all packages raised up from the underlying SBOM get new IDs derived from the data discovered as opposed to using the ID found within the artifact. There are pros and cons with each approach, however, this PR is changing syft's opinion on this to prefer the ID of artifacts from the SBOM discovered.

This is done by using the existing pkg.Package.OverrideID() at decode-time when constructing the package. If the ID is blank then we fallback to the standard derived Syft artifact ID.

Note that this approach only affects package ID and not file IDs from decoded SBOMs --that will require further work since there could be drawbacks to adding an id field to file.Coordinates (which are heavily used as map keys).

Here's an example of before and after of a grype run with these changes integrated; now the artifact IDs in the grype JSON are the native SBOM ID:

Screenshot 2025-05-07 at 10 13 04 PM

Addresses anchore/grype#1265

Design alternatives

There was another approach considered where we persist the upstream cyclonedx and spdx library types onto the package and the SBOM object. This would go a long way towards lossless conversion, however, this was a little too much to bite off for now and the current approach selected (using ID overrides) does not conflict with that future goal.

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have added unit tests that cover changed behavior
  • I have tested my code in common scenarios and confirmed there are no regressions
  • I have added comments to my code, particularly in hard-to-understand sections

Signed-off-by: James Neate <jamesmneate@gmail.com>
@jneate
Copy link
Copy Markdown
Contributor Author

jneate commented Jun 10, 2023

The alternate is that the entire BOM-Ref field becomes the ID instead of the package-id suffix? Happy to make said change if needed.

Comment thread syft/formats/common/cyclonedxhelpers/decoder.go
Comment thread syft/formats/common/cyclonedxhelpers/decoder_test.go Outdated
Comment thread syft/formats/common/cyclonedxhelpers/decoder_test.go
@kzantow

This comment was marked as outdated.

@wagoodman

This comment was marked as outdated.

@wagoodman wagoodman closed this May 8, 2025
…-provided

Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@wagoodman wagoodman reopened this May 8, 2025
@wagoodman
Copy link
Copy Markdown
Contributor

wagoodman commented May 8, 2025

I've changed my mind on this -- if we can make this behavior change without introducing new fields then we should prefer that minimal approach. I'll get this across the finish line today.

wagoodman added 3 commits May 8, 2025 09:19
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@wagoodman wagoodman changed the title fix: use package id from cyclonedx when provided Use package ID from decoded SBOMs when provided May 8, 2025
@wagoodman wagoodman added enhancement New feature or request and removed hold labels May 8, 2025
@wagoodman wagoodman self-assigned this May 8, 2025
@wagoodman wagoodman added this to OSS May 8, 2025
@wagoodman wagoodman moved this to In Review in OSS May 8, 2025
@wagoodman wagoodman requested a review from a team May 8, 2025 13:41
@wagoodman wagoodman merged commit 00c4a4e into anchore:main May 8, 2025
13 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in OSS May 8, 2025
Copy link
Copy Markdown
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

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

Nothing blocking, but I something doesn't sit well for me seeing hashes no longer redacted in the snapshots it seems like something slightly different could be done for testing here

Comment thread syft/format/cyclonedxjson/encoder_test.go
Comment thread syft/format/cyclonedxxml/encoder_test.go
Comment thread syft/format/internal/testutil/redactor.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

5 participants