-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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(sbom): use root package for unknown
dependencies (if exists)
#8104
Merged
knqyf263
merged 4 commits into
aquasecurity:main
from
DmitriyLewen:fix/bom-encode-relationshops-unknown-and-root
Dec 23, 2024
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,6 +171,61 @@ func TestEncoder_Encode(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
{ | ||
Target: "trivy", | ||
Type: ftypes.GoBinary, | ||
Class: types.ClassLangPkg, | ||
Packages: []ftypes.Package{ | ||
{ | ||
ID: "github.com/aquasecurity/[email protected]", | ||
Name: "github.com/aquasecurity/trivy", | ||
Version: "v0.57.1", | ||
Identifier: ftypes.PkgIdentifier{ | ||
UID: "106fee7e57f0b952", | ||
PURL: &packageurl.PackageURL{ | ||
Type: packageurl.TypeGolang, | ||
Namespace: "github.com/aquasecurity", | ||
Name: "trivy", | ||
Version: "v0.57.1", | ||
}, | ||
}, | ||
Relationship: ftypes.RelationshipRoot, | ||
DependsOn: []string{ | ||
"github.com/aquasecurity/[email protected]", | ||
"[email protected]", | ||
}, | ||
}, | ||
{ | ||
ID: "[email protected]", | ||
Name: "stdlib", | ||
Version: "v1.22.9", | ||
Identifier: ftypes.PkgIdentifier{ | ||
UID: "62e7c8aaebd94b1e", | ||
PURL: &packageurl.PackageURL{ | ||
Type: packageurl.TypeGolang, | ||
Name: "stdlib", | ||
Version: "v1.22.9", | ||
}, | ||
}, | ||
Relationship: ftypes.RelationshipDirect, | ||
}, | ||
{ | ||
ID: "github.com/aquasecurity/[email protected]", | ||
Name: "github.com/aquasecurity/go-version", | ||
Version: "v0.0.0-20240603093900-cf8a8d29271d", | ||
Identifier: ftypes.PkgIdentifier{ | ||
UID: "350aed171d8ebed5", | ||
PURL: &packageurl.PackageURL{ | ||
Type: packageurl.TypeGolang, | ||
Namespace: "github.com/aquasecurity", | ||
Name: "go-version", | ||
Version: "v0.0.0-20240603093900-cf8a8d29271d", | ||
}, | ||
}, | ||
Relationship: ftypes.RelationshipUnknown, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
wantComponents: map[uuid.UUID]*core.Component{ | ||
|
@@ -351,6 +406,100 @@ func TestEncoder_Encode(t *testing.T) { | |
BOMRef: "3ff14136-e09f-4df9-80ea-000000000006", | ||
}, | ||
}, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000007"): { | ||
Type: core.TypeApplication, | ||
Name: "trivy", | ||
Properties: []core.Property{ | ||
{ | ||
Name: core.PropertyClass, | ||
Value: "lang-pkgs", | ||
}, | ||
{ | ||
Name: core.PropertyType, | ||
Value: "gobinary", | ||
}, | ||
}, | ||
PkgIdentifier: ftypes.PkgIdentifier{ | ||
BOMRef: "3ff14136-e09f-4df9-80ea-000000000007", | ||
}, | ||
}, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000008"): { | ||
Type: core.TypeLibrary, | ||
Name: "github.com/aquasecurity/trivy", | ||
Version: "v0.57.1", | ||
SrcFile: "trivy", | ||
Properties: []core.Property{ | ||
{ | ||
Name: core.PropertyPkgID, | ||
Value: "github.com/aquasecurity/[email protected]", | ||
}, | ||
{ | ||
Name: core.PropertyPkgType, | ||
Value: "gobinary", | ||
}, | ||
}, | ||
PkgIdentifier: ftypes.PkgIdentifier{ | ||
UID: "106fee7e57f0b952", | ||
PURL: &packageurl.PackageURL{ | ||
Type: packageurl.TypeGolang, | ||
Namespace: "github.com/aquasecurity", | ||
Name: "trivy", | ||
Version: "v0.57.1", | ||
}, | ||
BOMRef: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
}, | ||
}, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000009"): { | ||
Type: core.TypeLibrary, | ||
Name: "stdlib", | ||
Version: "v1.22.9", | ||
SrcFile: "trivy", | ||
Properties: []core.Property{ | ||
{ | ||
Name: core.PropertyPkgID, | ||
Value: "[email protected]", | ||
}, | ||
{ | ||
Name: core.PropertyPkgType, | ||
Value: "gobinary", | ||
}, | ||
}, | ||
PkgIdentifier: ftypes.PkgIdentifier{ | ||
UID: "62e7c8aaebd94b1e", | ||
PURL: &packageurl.PackageURL{ | ||
Type: packageurl.TypeGolang, | ||
Name: "stdlib", | ||
Version: "v1.22.9", | ||
}, | ||
BOMRef: "pkg:golang/[email protected]", | ||
}, | ||
}, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000010"): { | ||
Type: core.TypeLibrary, | ||
Name: "github.com/aquasecurity/go-version", | ||
Version: "v0.0.0-20240603093900-cf8a8d29271d", | ||
SrcFile: "trivy", | ||
Properties: []core.Property{ | ||
{ | ||
Name: core.PropertyPkgID, | ||
Value: "github.com/aquasecurity/[email protected]", | ||
}, | ||
{ | ||
Name: core.PropertyPkgType, | ||
Value: "gobinary", | ||
}, | ||
}, | ||
PkgIdentifier: ftypes.PkgIdentifier{ | ||
UID: "350aed171d8ebed5", | ||
PURL: &packageurl.PackageURL{ | ||
Type: packageurl.TypeGolang, | ||
Namespace: "github.com/aquasecurity", | ||
Name: "go-version", | ||
Version: "v0.0.0-20240603093900-cf8a8d29271d", | ||
}, | ||
BOMRef: "pkg:golang/github.com/aquasecurity/[email protected]", | ||
}, | ||
}, | ||
}, | ||
wantRels: map[uuid.UUID][]core.Relationship{ | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000001"): { | ||
|
@@ -366,6 +515,10 @@ func TestEncoder_Encode(t *testing.T) { | |
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"), | ||
Type: core.RelationshipContains, | ||
}, | ||
{ | ||
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000007"), | ||
Type: core.RelationshipContains, | ||
}, | ||
}, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000002"): { | ||
{ | ||
|
@@ -386,6 +539,24 @@ func TestEncoder_Encode(t *testing.T) { | |
}, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000005"): nil, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000006"): nil, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000007"): { | ||
{ | ||
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000008"), | ||
Type: core.RelationshipContains, | ||
}, | ||
}, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000008"): { | ||
{ | ||
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000010"), | ||
Type: core.RelationshipDependsOn, | ||
}, | ||
{ | ||
Dependency: uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000009"), | ||
Type: core.RelationshipDependsOn, | ||
}, | ||
}, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000009"): nil, | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000010"): nil, | ||
}, | ||
wantVulns: map[uuid.UUID][]core.Vulnerability{ | ||
uuid.MustParse("3ff14136-e09f-4df9-80ea-000000000004"): { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Given that
RelationshipUnknown
has been introduced now, I'm wondering if this behavior is good in the first place.In OS packages, packages with no parent are sure to be direct dependencies, but other packages are unknown, so it may be better not to add them as direct dependencies. Then, our logic is simple: no parent packages belong to a non-package parent (
OS
,Application
component, etc.).This will not be a problem when applying VEX, etc., since packages with at least one parent can always be present in the dependency tree.
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.
BTW, I found compositions. We may want to fill in this field to represent incomplete relationships.
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.
hm... you solution looks logical.
if
Relationship
is unknown and packages has parents - most likely it is one of two options:Also, after changes, dependencies graph looks logical:
before:
after:
I updated logic in 17c3735 (tests - fbe7fd5)
I'm not sure about that.
This may complicate the logic of understanding and processing cyclonedx files.
Also, we need to use different logic for CycloneDX and SPDX files.
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.
Yes, I agree, but it's recommended here.
And I didn't find any other ways to represent the dependency graph is incomplete.
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.
Created #8157