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

feat: Expose Ubuntu fix status for downstream consumption #407

Merged
merged 26 commits into from
Sep 6, 2024

Conversation

skahn007gl
Copy link
Contributor

@skahn007gl skahn007gl commented Jun 4, 2024

Summary

resolves #408

Trivy Ubuntu advisories provide a FixedVersion when there is a released fix for a package, Affected can be inferred when the advisory is present without a FixedVersion, it does not expose any other status that Canonical use to indicate the status of a fix. This is insufficient to infer a status of ignored, pending or needed as these status show the package is affected and in the process of getting to a fixed version or not if the status is ignored.

This change exposes the Status provided in launchpad advisories without changed existing behaviour to populate the notes field in an advisory with Status:$status

Changes

  • gitignore:21 :: name change of cache, assets to _cache, _assets to reflect directory name change to support gopls lint ignore declaration of _ prefix on directories.

  • MakeFile :: Adjusting naming convention of cache & _assets to avoid gopls linter causing max open file errors on MacOS.

  • pkg/types/status.go :: New status added to support all potential status on launchpad advisories.

  • pkg/vulnsrc/ubuntu/ubuntu.go :: Expanded target status to capture all provided status's. Adjusted logic to use these status. Added ubuntu status to trivy status normalisation function.

  • pkg/vulnsrc/ubuntu/ubuntu_test.go :: Added test for status normalisation.

@skahn007gl skahn007gl requested a review from knqyf263 as a code owner June 4, 2024 01:21
@CLAassistant
Copy link

CLAassistant commented Jun 4, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@jhebden-gl jhebden-gl left a comment

Choose a reason for hiding this comment

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

Whilst I'm not a maintainer here, I am aware of the scope of this work and did work on the RHEL changes for fix status, so thought I'd add some review comments to try and help to save some time for the reviewers.

.gitignore Outdated Show resolved Hide resolved
pkg/types/status.go Outdated Show resolved Hide resolved
pkg/types/status.go Outdated Show resolved Hide resolved
pkg/types/status.go Outdated Show resolved Hide resolved
pkg/types/status.go Outdated Show resolved Hide resolved
pkg/vulnsrc/ubuntu/ubuntu.go Outdated Show resolved Hide resolved
pkg/vulnsrc/ubuntu/ubuntu_test.go Outdated Show resolved Hide resolved
@skahn007gl
Copy link
Contributor Author

Whilst I'm not a maintainer here, I am aware of the scope of this work and did work on the RHEL changes for fix status, so thought I'd add some review comments to try and help to save some time for the reviewers.

@jhebden-gl Thanks or the feedback. I have pushed a new change set with your suggested changes

@jhebden-gl
Copy link
Contributor

Hi @knqyf263 👋🏻 - I was wondering if you might be able to assist with a review on this PR? We are hoping to use this data downstream. Thank you!

.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
// StatusFromUbuntuStatus normalises Ubuntu status into common Trivy Types
func StatusFromUbuntuStatus(status string) types.Status {
switch status {
case "not-affected", "DNE", "not-vulnerable", "ignored":
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think not-affected, DNE and not-vulnerable are "Will not fix". They're "Not affected", and we don't want to save them in the database as it increases the size.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree.
I will push a change set for this today.

Copy link
Collaborator

Choose a reason for hiding this comment

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

ignored makes sense to me as it's considered "Will not fix".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@knqyf263 I have pushed all the tidy up changes. Please re-review when you have a chance.
Thanks

Co-authored-by: Teppei Fukuda <knqyf263@gmail.com>
pkg/vulnsrc/ubuntu/ubuntu.go Outdated Show resolved Hide resolved
pkg/vulnsrc/ubuntu/ubuntu.go Outdated Show resolved Hide resolved
pkg/vulnsrc/ubuntu/ubuntu_test.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

@skahn007gl
Copy link
Contributor Author

@knqyf263
Copy link
Collaborator

@skahn007gl Thanks for updating. At last, could you add a test with a non-fixed status? Adding a new advisory or updating the existing one.

"Note": ""
}
},
"trusty": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The key must be a package name. Isn't trusty a codename?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yes it should be. I read xen as xenial, Will change the test data and get it pushed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

test data updated and pushed.

@skahn007gl
Copy link
Contributor Author

@skahn007gl Also, could you open a PR with this change in Trivy? It's better to test this change with Trivy before merging this PR.

Tips: Use replace until this PR gets merged.

Hey @knqyf263 I am unsure what needs to change in the existing integration tests.
Is my understanding of the tests correct that it tests 2 scenarios?

  1. Include all findings
  2. Include findings with fixes only

This includes the status field in the .golden test data.

I have made the other changes and raised a PR to Trivy :)
Trivy PR7020

@knqyf263
Copy link
Collaborator

knqyf263 commented Jun 26, 2024

@skahn007gl
Copy link
Contributor Author

skahn007gl commented Jun 27, 2024

There is a DB fixture here. https://github.com/aquasecurity/trivy/blob/8d618e48a2f1b60c2e4c49cdd9deb8eb45c972b0/integration/testdata/fixtures/db/ubuntu.yaml

We need to add a status here and ensure the status appears in the result.

This bucket must also be updated if you want to add a new vulnerability. https://github.com/aquasecurity/trivy/blob/8d618e48a2f1b60c2e4c49cdd9deb8eb45c972b0/integration/testdata/fixtures/db/vulnerability.yaml

When adding a new bucket for Ubuntu, that needs to be added here. https://github.com/aquasecurity/trivy/blob/8d618e48a2f1b60c2e4c49cdd9deb8eb45c972b0/integration/testdata/fixtures/db/data-source.yaml#L137-L141

@knqyf263 How are the .golden files generated/created?

I have updated the DB fixture with an existing CVE for ubuntu 18.04 that would have a non fixed status, but i'm unable to trigger a failure on the existing ubuntu18.04 integration tests.

- bucket: ubuntu 18.04
  pairs:
    - bucket: libspring-java
      pairs:
        - key: CVE-2022-22965
          value:
            Status: deferred

@knqyf263
Copy link
Collaborator

deferred is not our status.

Statuses = []string{
"unknown",
"not_affected",
"affected",
"fixed",
"under_investigation",
"will_not_fix",
"fix_deferred",
"end_of_life",
}

@skahn007gl
Copy link
Contributor Author

deferred is not our status.

Statuses = []string{
"unknown",
"not_affected",
"affected",
"fixed",
"under_investigation",
"will_not_fix",
"fix_deferred",
"end_of_life",
}

Corrected to fix_deferred, but still no failure in the test run.

I am assuming I need to update ubuntu-1804.json.golden to update the expected results for the tests linked https://github.com/aquasecurity/trivy/blob/bbaf5952bc8059c537401bd4364e019eecd16c9a/integration/standalone_tar_test.go#L217-L233

If this is the case, How are the .golden files generated/created?

Thanks for the help and guidance on this as I work through it.

@knqyf263
Copy link
Collaborator

knqyf263 commented Jun 27, 2024

I am assuming I need to update ubuntu-1804.json.golden to update the expected results for the tests linked https://github.com/aquasecurity/trivy/blob/bbaf5952bc8059c537401bd4364e019eecd16c9a/integration/standalone_tar_test.go#L217-L233

No, the test should fail due to a mismatch with the golden file. You need to update the golden file once you confirm the test fails. Did you update all the buckets I listed above? It may be easier for us to debug if you push the change to your PR in Trivy.

@skahn007gl
Copy link
Contributor Author

I am assuming I need to update ubuntu-1804.json.golden to update the expected results for the tests linked https://github.com/aquasecurity/trivy/blob/bbaf5952bc8059c537401bd4364e019eecd16c9a/integration/standalone_tar_test.go#L217-L233

No, the test should fail due to a mismatch with the golden file. You need to update the golden file once you confirm the test fails. Did you update all the buckets I listed above? It may be easier for us to debug if you push the change to your PR in Trivy.

Thanks for confirming, I agree it will be easier to debug if i share my changes. I will update the PR shortly.

@skahn007gl
Copy link
Contributor Author

@knqyf263 I have pushed the updated DB fixture and OS bucket.
I used an existing vulnerability.

Note the changes do not include the use of replace in go.mod, but i do use it locally.
e.g: replace github.com/aquasecurity/trivy-db => /xxx/yyy/zzz/trivy-db

@knqyf263
Copy link
Collaborator

You added Ubuntu 21.10, but the scanned image is not Ubuntu 21.10. The data is not used.

@skahn007gl
Copy link
Contributor Author

You added Ubuntu 21.10, but the scanned image is not Ubuntu 21.10. The data is not used.

Adjusted to ubuntu 16.04 as there is an image under integration/testdata/fixtures/images
Added test for ubuntu 16.04 into integration/standalone_tar_test.go
note: Test does not use the correct json.golden as there is no existing one for ubuntu 16.04

Successfully generated a failed test result.

I am running the tests via mage test:integration(mage is new to me) or go test -timeout 15m -v -tags=integration ./integration/...
But i do not see any test artefacts generated, only pass/fail stat's.

Is there a way to generate the output from the comparison?.

I have pushed my updates.

@skahn007gl
Copy link
Contributor Author

Hey @knqyf263
Sorry for the delays on my side, I've had some personal life stuff crop up.

I have simplified the integration test to use as much as existing as possible to understand how these tests hang together, I believe I am still missing something here.

  • Added a CVE to the db fixture
  • Added the CVE to the vulnerability fixture
  • As i re-used ubuntu 18.04, I did not add a new bucket to data-source

When i run the integration test's, there is no test failure for ubuntu-1804

I added some dummy data to to ubuntu-1804.json.golden This induces an error, but the error indicates it did not expect the new vulnerability.

	-   Vulnerabilities: ([]types.DetectedVulnerability) (len=6) {
	+   Vulnerabilities: ([]types.DetectedVulnerability) (len=5) {

skahn007gl and others added 2 commits August 20, 2024 14:20
Co-authored-by: DmitriyLewen <91113035+DmitriyLewen@users.noreply.github.com>
Copy link
Collaborator

@DmitriyLewen DmitriyLewen left a comment

Choose a reason for hiding this comment

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

LGTM

func StatusFromUbuntuStatus(status string) types.Status {
switch status {
case "ignored":
return types.StatusWillNotFix
Copy link
Collaborator

Choose a reason for hiding this comment

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

I took another read of the document.
https://askubuntu.com/questions/1509705/cve-questions-about-status/1509706#1509706

"ignored" support has ended for one reason or another/ end-of-life.

It looks like Ubuntu doesn't determine if the package is affected. So, if I understand correctly, we should not show this type of vulnerability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We consider this an intentional decision that is vendor will not fix, this status is important in our downstream workflow and was included for this reason.

Copy link
Collaborator

Choose a reason for hiding this comment

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

"Will not fix" means "this package is affected by this flaw on this platform, but there is currently no intention to fix it." It's a Red Hat definition, but we follow it.
https://access.redhat.com/blogs/product-security/posts/2066793

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@knqyf263 Are you happy to proceed with this?
What do you need from me to get this merged?

Copy link
Contributor

Choose a reason for hiding this comment

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

@skahn007gl - it seems that treating ignored as wontfix is the issue here, as ignored/EOL findings are typically not ingested to reduce Trivy DB size. I think we can just skip ingesting ignored, we still have the "notaffected" status to determine if the outcome of analysis is that Ubuntu decided not to fix it. For EOL stuff, we can work that out another way on our end, and treat findings for EOL releases as wontfix if they don't have another status.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Trivy is designed to minimize false positives as much as possible. EOL means unknown and is possibly a false positive, which is why we currently do not detect it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While i see the reasoning behind this and do not disagree, I am happy to follow guidance and remove the status for ubuntu.

@knqyf263 let me know if you feel strongly on removing ignored for Ubuntu and i will make the changes.

I would like to highlight the ignored is ingested for Debian in pkg/vulnsrc/debian.go:682

func newStatus(s string) types.Status {
	switch strings.ToLower(s) {
	// "end-of-life" is considered as vulnerable
	// e.g. https://security-tracker.debian.org/tracker/CVE-2022-1488
	case "no-dsa", "unfixed":
		return types.StatusAffected
	case "ignored":
		return types.StatusWillNotFix
	case "postponed":
		return types.StatusFixDeferred
	case "end-of-life":
		return types.StatusEndOfLife
	}
	return types.StatusUnknown
} 

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would like to highlight the ignored is ingested for Debian in pkg/vulnsrc/debian.go:682

We believe "ignored" in Debian differs from "ignored" in Ubuntu. They use the same term by chance. Please let us know if you find a document in which Debian also uses "ignored" for EOL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @knqyf263, @jhebden-gl
I have removed ignored status as we can make an assumption on wontfix by presence of data (Affected), Deferred status, No fix version.

skahn007gl and others added 2 commits September 5, 2024 12:46
Signed-off-by: knqyf263 <knqyf263@gmail.com>
@knqyf263 knqyf263 merged commit 42b851c into aquasecurity:main Sep 6, 2024
2 checks passed
knqyf263 added a commit that referenced this pull request Sep 10, 2024
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.

feat: Expose Ubuntu fix status for downstream consumtion.
5 participants