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

Preserve package IDs on Syft JSON SBOM decode #963

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion internal/formats/syftjson/to_syft_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,12 @@ func toSyftPackage(p model.Package, idAliases map[string]string) pkg.Package {
Metadata: p.Metadata,
}

out.SetID()
// we don't know if this package ID is truly unique, however, we need to trust the user input in case there are
// external references to it. That is, we can't derive our own ID (using pkg.SetID()) since consumers won't
// be able to historically interact with data that references the IDs from the original SBOM document being decoded now.
out.OverrideID(artifact.ID(p.ID))

// this alias mapping is currently defunct, but could be useful in the future.
id := string(out.ID())
if id != p.ID {
idAliases[p.ID] = id
Expand Down
4 changes: 4 additions & 0 deletions syft/pkg/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ type Package struct {
Metadata interface{} // additional data found while parsing the package source
}

func (p *Package) OverrideID(id artifact.ID) {
p.id = id
}

func (p *Package) SetID() {
id, err := artifact.IDByHash(p)
if err != nil {
Expand Down