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

fix(sbom): use root package for unknown dependencies (if exists) #8104

Conversation

DmitriyLewen
Copy link
Contributor

@DmitriyLewen DmitriyLewen commented Dec 16, 2024

Description

Use root package for unknown dependencies (if exists)
e.g. for GoBinaries (see update test).
See #8102 for more details.

Also this PR fixes problem with VEX with subcomponents:
before:

➜ trivy -q i -s HIGH,CRITICAL --vex repo --cache-backend memory --pkg-types library --show-suppressed rancher/fleet:v0.10.2

usr/bin/fleet (gobinary)

Total: 1 (HIGH: 0, CRITICAL: 1)

┌─────────────────────┬────────────────┬──────────┬────────┬───────────────────┬───────────────┬────────────────────────────────────────────────────────┐
│       Library       │ Vulnerability  │ Severity │ Status │ Installed Version │ Fixed Version │                         Title                          │
├─────────────────────┼────────────────┼──────────┼────────┼───────────────────┼───────────────┼────────────────────────────────────────────────────────┤
│ golang.org/x/crypto │ CVE-2024-45337 │ CRITICAL │ fixed  │ v0.25.0           │ 0.31.0        │ golang.org/x/crypto/ssh: Misuse of                     │
│                     │                │          │        │                   │               │ ServerConfig.PublicKeyCallback may cause authorization │
│                     │                │          │        │                   │               │ bypass in golang.org/x/crypto                          │
│                     │                │          │        │                   │               │ https://avd.aquasec.com/nvd/cve-2024-45337             │
└─────────────────────┴────────────────┴──────────┴────────┴───────────────────┴───────────────┴────────────────────────────────────────────────────────┘

usr/bin/fleetcontroller (gobinary)

Total: 1 (HIGH: 0, CRITICAL: 1)

┌─────────────────────┬────────────────┬──────────┬────────┬───────────────────┬───────────────┬────────────────────────────────────────────────────────┐
│       Library       │ Vulnerability  │ Severity │ Status │ Installed Version │ Fixed Version │                         Title                          │
├─────────────────────┼────────────────┼──────────┼────────┼───────────────────┼───────────────┼────────────────────────────────────────────────────────┤
│ golang.org/x/crypto │ CVE-2024-45337 │ CRITICAL │ fixed  │ v0.25.0           │ 0.31.0        │ golang.org/x/crypto/ssh: Misuse of                     │
│                     │                │          │        │                   │               │ ServerConfig.PublicKeyCallback may cause authorization │
│                     │                │          │        │                   │               │ bypass in golang.org/x/crypto                          │
│                     │                │          │        │                   │               │ https://avd.aquasec.com/nvd/cve-2024-45337             │
└─────────────────────┴────────────────┴──────────┴────────┴───────────────────┴───────────────┴────────────────────────────────────────────────────────┘

after:

➜  ./trivy -q i -s HIGH,CRITICAL --vex repo --cache-backend memory --pkg-types library --show-suppressed rancher/fleet:v0.10.2

usr/bin/fleet (gobinary)

Total: 0 (HIGH: 0, CRITICAL: 0)


Suppressed Vulnerabilities (Total: 1)

┌─────────────────────┬────────────────┬──────────┬──────────────┬─────────────────────────────────────┬──────────────────────────────────────────┐
│       Library       │ Vulnerability  │ Severity │    Status    │              Statement              │                  Source                  │
├─────────────────────┼────────────────┼──────────┼──────────────┼─────────────────────────────────────┼──────────────────────────────────────────┤
│ golang.org/x/crypto │ CVE-2024-45337 │ CRITICAL │ not_affected │ vulnerable_code_not_in_execute_path │ VEX Repository: default                  │
│                     │                │          │              │                                     │ (https://github.com/aquasecurity/vexhub) │
└─────────────────────┴────────────────┴──────────┴──────────────┴─────────────────────────────────────┴──────────────────────────────────────────┘

usr/bin/fleetcontroller (gobinary)

Total: 0 (HIGH: 0, CRITICAL: 0)


Suppressed Vulnerabilities (Total: 1)

┌─────────────────────┬────────────────┬──────────┬──────────────┬─────────────────────────────────────┬──────────────────────────────────────────┐
│       Library       │ Vulnerability  │ Severity │    Status    │              Statement              │                  Source                  │
├─────────────────────┼────────────────┼──────────┼──────────────┼─────────────────────────────────────┼──────────────────────────────────────────┤
│ golang.org/x/crypto │ CVE-2024-45337 │ CRITICAL │ not_affected │ vulnerable_code_not_in_execute_path │ VEX Repository: default                  │
│                     │                │          │              │                                     │ (https://github.com/aquasecurity/vexhub) │
└─────────────────────┴────────────────┴──────────┴──────────────┴─────────────────────────────────────┴──────────────────────────────────────────┘
➜  trivy git:(fix/bom-encode-relationshops-unknown-and-root) ✗ 

Related issues

Related PRs

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this Dec 16, 2024
@DmitriyLewen DmitriyLewen marked this pull request as ready for review December 16, 2024 07:33
@@ -417,20 +417,33 @@ func (*Encoder) belongToParent(pkg ftypes.Package, parents map[string]ftypes.Pac
// All packages are included in the parent
// Case 3: Relationship: known , DependsOn: unknown (e.g., go.mod without $GOPATH)
// All packages are included in the parent
// Case 4: Relationship: unknown, DependsOn: known (e.g., OS packages)
// All packages are included in the parent even if they have parents
// Case 4: Relationship: unknown, DependsOn: known (e.g., GoBinaries, OS packages)
Copy link
Collaborator

@knqyf263 knqyf263 Dec 19, 2024

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

@DmitriyLewen DmitriyLewen Dec 20, 2024

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:

  • this is direct package (like in out logic for dep tree)
  • this is orphan package and it makes sense to add it for parent (OS/Application) component.

Also, after changes, dependencies graph looks logical:
before:

{
	Ref: "3ff14136-e09f-4df9-80ea-000000000002", // OS component
	Dependencies: &[]string{
		"pkg:rpm/centos/acl@2.2.53-1.el8?arch=aarch64&distro=centos-8.3.2011&epoch=1",
		"pkg:rpm/centos/glibc@2.28-151.el8?arch=aarch64&distro=centos-8.3.2011",
	},
},
{
	Ref: "pkg:rpm/centos/acl@2.2.53-1.el8?arch=aarch64&distro=centos-8.3.2011&epoch=1",
	Dependencies: &[]string{
		"pkg:rpm/centos/glibc@2.28-151.el8?arch=aarch64&distro=centos-8.3.2011",
	},
},

after:

{
	Ref: "3ff14136-e09f-4df9-80ea-000000000002",
	Dependencies: &[]string{
		"pkg:rpm/centos/acl@2.2.53-1.el8?arch=aarch64&distro=centos-8.3.2011&epoch=1",
	},
},
{
	Ref: "pkg:rpm/centos/acl@2.2.53-1.el8?arch=aarch64&distro=centos-8.3.2011&epoch=1",
	Dependencies: &[]string{
		"pkg:rpm/centos/glibc@2.28-151.el8?arch=aarch64&distro=centos-8.3.2011",
	},
},

I updated logic in 17c3735 (tests - fbe7fd5)


BTW, I found compositions. We may want to fill in this field to represent incomplete relationships.

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.

Copy link
Collaborator

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.

It is RECOMMENDED to leverage compositions to indicate unknown dependency graphs.

And I didn't find any other ways to represent the dependency graph is incomplete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created #8157

@DmitriyLewen DmitriyLewen marked this pull request as draft December 20, 2024 08:33
@DmitriyLewen DmitriyLewen marked this pull request as ready for review December 20, 2024 09:57
@knqyf263 knqyf263 added this pull request to the merge queue Dec 23, 2024
Merged via the queue into aquasecurity:main with commit 7558df7 Dec 23, 2024
12 checks passed
@DmitriyLewen DmitriyLewen deleted the fix/bom-encode-relationshops-unknown-and-root branch December 23, 2024 06:36
@DmitriyLewen
Copy link
Contributor Author

@aqua-bot backport release/v0.58

@aqua-bot
Copy link
Contributor

Backport PR created: #8156

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(bom): unknown dependencies are related to application component and not root component
3 participants