Skip to content

Enable client/server mode for trivy by default to cache the vulnerability DB (closes #911)#1760

Merged
o1oo11oo merged 4 commits intosecureCodeBox:mainfrom
o1oo11oo:feature/trivy-database-cache
Jun 28, 2023
Merged

Enable client/server mode for trivy by default to cache the vulnerability DB (closes #911)#1760
o1oo11oo merged 4 commits intosecureCodeBox:mainfrom
o1oo11oo:feature/trivy-database-cache

Conversation

@o1oo11oo
Copy link
Contributor

@o1oo11oo o1oo11oo commented Jun 9, 2023

Description

This uses the trivy client/server functionality to download the vulnerability DB only once for multiple scans to avoid GitHub's rate limit. An additional container running trivy in server mode is started, and all scans connect to it. This integrates the functionality previously documented in the SCB docs for trivy, now that trivy supports remote scanning for more than just container image scans. Client/server support for other scan types was added in aquasecurity/trivy#1829 and aquasecurity/trivy#3131.

Closes #911.

Checklist

  • Test your changes as thoroughly as possible before you commit them. Preferably, automate your test by unit/integration tests.
  • Make sure that all your commits are signed-off and that you are added to the Contributors file.
  • Make sure that all CI finish successfully.
  • Optional (but appreciated): Make sure that all commits are Verified.

Copy link
Member

@J12934 J12934 left a comment

Choose a reason for hiding this comment

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

Looks really good 👍
One major thing missing is mentioning it in the docs. How it works and how it can be disabled and why somebody would want to do that.
Also the existing caching docs should then be tweaked as the no longer make much sense now that we have this in place.

labels:
app: trivy-database
spec:
replicas: 1
Copy link
Member

Choose a reason for hiding this comment

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

Should probably be configurable to have more then one replica available to support real HA setups

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've looked into kubernetes scaling and autoscaling but I guess it's enough to move this values so it can be configured at least?

@J12934 J12934 added the enhancement New feature or request label Jun 13, 2023
@o1oo11oo o1oo11oo force-pushed the feature/trivy-database-cache branch from 4652c82 to 0c2ab34 Compare June 14, 2023 12:03
@o1oo11oo
Copy link
Contributor Author

I've tested what happens when the trivy server cannot download the database, and it just exits with an error, so the pod gets restarted and then runs into CrashLoopBackoff. Since I didn't define a dependency on the cache service (other than using the url in a parameter), would the scan even wait for the cache to be ready?

@o1oo11oo o1oo11oo force-pushed the feature/trivy-database-cache branch 2 times, most recently from 307c8db to 6d9395b Compare June 27, 2023 13:59
@o1oo11oo o1oo11oo changed the title Create a download cache for trivy database (closes #911) Enable client/server mode for trivy by default to cache the vulnerability DB (closes #911) Jun 27, 2023
@o1oo11oo o1oo11oo marked this pull request as ready for review June 27, 2023 14:06
@o1oo11oo o1oo11oo force-pushed the feature/trivy-database-cache branch 2 times, most recently from a06927b to b914636 Compare June 27, 2023 14:31
Lukas Fischer added 4 commits June 28, 2023 09:29
This uses the trivy client/server functionality to download the
vulnerability DB only once for multiple scans to avoid GitHub's rate
limit. An additional container running trivy in server mode is started,
and all scans connect to it. This integrates the functionality
previously documented [in the SCB docs for trivy][1], now that trivy
supports remote scanning for more than just container image scans.

[1]: https://www.securecodebox.io/docs/scanners/trivy/#scanning-many-targets

Signed-off-by: Lukas Fischer <[email protected]>
Instead of hardcoding only one replica, allow any number of replicas for
the trivy download cache to be configured by using the the
trivyDatabaseCache.replicas value.

Signed-off-by: Lukas Fischer <[email protected]>
Trivy server provides a /healthz endpoint that always returns 200 (see
aquasecurity/trivy#534), and according to the logs/stdout trivy only
starts listening after downloading the database.

The helm chart provided by trivy (added in aquasecurity/trivy#751) uses
this endpoint for liveness and readiness checks as well. This change
therefore integrates the same checks.

Signed-off-by: Lukas Fischer <[email protected]>
Update the documentation to reflect that the trivy vulnerability DB is
now by default served by a trivy server container.

This shortens this section of the documentation quite a bit, because
most of it was example code to set up what is now integrated.

Signed-off-by: Lukas Fischer <[email protected]>
@o1oo11oo o1oo11oo force-pushed the feature/trivy-database-cache branch from b914636 to 8239741 Compare June 28, 2023 07:29
@o1oo11oo o1oo11oo merged commit 8239741 into secureCodeBox:main Jun 28, 2023
@o1oo11oo o1oo11oo deleted the feature/trivy-database-cache branch June 28, 2023 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Trivy: Build rule download cron similar to nuclei

2 participants