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

Trivy Scanning: Scan all images and only create issue for latest patch release #485

Merged
merged 10 commits into from
Jul 11, 2022

Conversation

sam-heilbron
Copy link
Collaborator

@sam-heilbron sam-heilbron commented Jun 26, 2022

Description

  • Fix bug in Trivy scanner which caused the scan to only run on the latest patch version
  • Expose new flag that allows Github issues to be created only for the latest patch version, as opposed to all versions

Context

Fix Trivy scan bug

In #478, we identified that our historical scan implementation would create a Github issue for every version scanned that contained a vulnerability, and that this was extremely noisy to developers.

As a result, we added a slight adjustment to the code in #479. The unintended side effect of this was in addition to only creating github issues only for the latest patch release, we also only scanned the latest patch release. This speeds up our weekly job tremendously, but it also no longer produces results for older versions that users might be on. Since vulnerabilities might be identified after that fact, we want to make sure we're scanning all versions, since there might be a new vulnerability identified that we want to make users aware of.

Expose new flag to only create issues for latest patch releases

We expose a new flag CreateGithubIssueForLatestPatchVersion, which when enabled will ensure that when a vulnerability is found for a given version, a github issue will be created only if that version is the latest patch release for that minor version.

Move code into distinct files

Though these changes are somewhat noisy, and perhaps distract from the PR, I think they are valuable. Reading through the code, I found it challenging at times to distinguish the different components in our scanner. I copied tightly coupled code (trivy, github, predicates) into their own files so that the main scan file can have only the main scanning code.

Stats logging follow-up

In #487 we added improvement to our stats utility, so that our logging endpoint handler does not throw a NPE. However, the goroutine responsible for waiting for a context to be cancelled and then initiating a server shutdown, was using the same context to shutdown the server, that it was using to determine if the server should be shutdown. This resulted in inconsistent behavior, and the server not being shutdown properly, which would lead to flakes.

This PR added a new context to be used for shutdown.

Testing

Testing the security scanner end-to-end is challenging. A lot of the code relies on a github.Client that cannot be mocked. Therefore for this change I propose the following

  1. I added unit tests to cover the case I am trying to solve, that we only create issues for the latest patch release
  2. After merging this, I will upgrade the dependency in Gloo, and run the job and manually verify the results.

Manual Testing

I use solo-io/gloo#6709 to manually verify these changes. In that PR, I outline the steps required to run the job locally and ways to verify both that (A) we scan all releases and (B) only generate github issues for the latest patch.

BOT NOTES:
resolves #478

@nfuden
Copy link
Contributor

nfuden commented Jun 26, 2022

As far as I can tell this is mainly addressing adding a repofilter that is applied only on the issue creation step which is a pretty easy update. Am I missing something else?

@sam-heilbron
Copy link
Collaborator Author

As far as I can tell this is mainly addressing adding a repofilter that is applied only on the issue creation step which is a pretty easy update. Am I missing something else?

Yup! That's it. I thought that was the set of changes we were trying to support

@solo-changelog-bot
Copy link

Issues linked to changelog:
#469
#478

@sam-heilbron sam-heilbron changed the title [DNM] Proposal For Trivy Scanning Trivy Scanning: Scan all images and only create issue for latest patch release Jul 10, 2022
@sam-heilbron sam-heilbron self-assigned this Jul 10, 2022
@sam-heilbron sam-heilbron marked this pull request as ready for review July 10, 2022 23:14
@sam-heilbron sam-heilbron requested a review from nfuden July 11, 2022 18:50
Copy link
Contributor

@nfuden nfuden left a comment

Choose a reason for hiding this comment

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

Yep this seems to cover it nicely

@soloio-bulldozer soloio-bulldozer bot merged commit 2415fab into master Jul 11, 2022
@soloio-bulldozer soloio-bulldozer bot deleted the sam/trivy-scan-reduce-issues branch July 11, 2022 19:00
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.

SecurityScanUtils should create fewer issues
2 participants