You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -95,6 +104,86 @@ Trivy uses [Viper](https://github.com/spf13/viper) which has a defined precedenc
95
104
- Config file
96
105
- Default
97
106
107
+
### Cache
108
+
The action has a built-in functionality for caching and restoring [the vulnerability DB](https://github.com/aquasecurity/trivy-db), [the Java DB](https://github.com/aquasecurity/trivy-java-db) and [the checks bundle](https://github.com/aquasecurity/trivy-checks) if they are downloaded during the scan.
109
+
The cache is stored in the `$GITHUB_WORKSPACE/.cache/trivy` directory by default.
110
+
The cache is restored before the scan starts and saved after the scan finishes.
111
+
112
+
It uses [actions/cache](https://github.com/actions/cache) under the hood but requires less configuration settings.
113
+
The cache input is optional, and caching is turned on by default.
114
+
115
+
#### Disabling caching
116
+
If you want to disable caching, set the `cache` input to `false`, but we recommend keeping it enabled to avoid rate limiting issues.
Please note that there are [restrictions on cache access](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache) between branches in GitHub Actions.
129
+
By default, a workflow can access and restore a cache created in either the current branch or the default branch (usually `main` or `master`).
130
+
If you need to share caches across branches, you may need to create a cache in the default branch and restore it in the current branch.
131
+
132
+
To optimize your workflow, you can set up a cron job to regularly update the cache in the default branch.
133
+
This allows subsequent scans to use the cached DB without downloading it again.
134
+
135
+
```yaml
136
+
# Note: This workflow only updates the cache. You should create a separate workflow for your actual Trivy scans.
137
+
# In your scan workflow, set TRIVY_SKIP_DB_UPDATE=true and TRIVY_SKIP_JAVA_DB_UPDATE=true.
Recently, there has been an increase in cases of receiving the `TOOMANYREQUESTS` error when downloading the Trivy databases (`trivy-db`, `trivy-java-db` and `trivy-checks`).
128
-
129
-
If you’re performing multiple scans, it makes sense to use [action/cache](https://github.com/actions/cache) to cache one or more databases.
130
-
131
-
The example below saves the `trivy-db` for each day in the cache:
132
-
133
-
```yaml
134
-
name: build
135
-
on:
136
-
push:
137
-
branches:
138
-
- main
139
-
pull_request:
140
-
141
-
jobs:
142
-
build:
143
-
name: Build
144
-
runs-on: ubuntu-20.04
145
-
steps:
146
-
- name: Checkout code
147
-
uses: actions/checkout@v4
148
-
149
-
## To avoid the trivy-db becoming outdated, we save the cache for one day
## But `action/cache` use `runner` user by default
171
-
## So we need to change the permissions before caching the database.
172
-
- name: change permissions for trivy.db
173
-
run: sudo chmod 0644 ./cache/db/trivy.db
174
-
```
175
-
176
215
### Using Trivy with GitHub Code Scanning
177
216
If you have [GitHub code scanning](https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/about-code-scanning) available you can use Trivy as a scanning tool as follows:
178
217
```yaml
@@ -630,7 +669,7 @@ Following inputs can be used as `step.with` keys:
630
669
|`severity`| String |`UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL`| Severities of vulnerabilities to scanned for and displayed |
631
670
|`skip-dirs`| String || Comma separated list of directories where traversal is skipped |
632
671
|`skip-files`| String || Comma separated list of files where traversal is skipped |
|`ignore-policy`| String || Filter vulnerabilities with OPA rego language |
636
675
|`hide-progress`| String |`false`| Suppress progress bar and log output |
@@ -641,6 +680,7 @@ Following inputs can be used as `step.with` keys:
641
680
|`github-pat`| String || Authentication token to enable sending SBOM scan results to GitHub Dependency Graph. Can be either a GitHub Personal Access Token (PAT) or GITHUB_TOKEN |
642
681
|`limit-severities-for-sarif`| Boolean | false | By default *SARIF* format enforces output of all vulnerabilities regardless of configured severities. To override this behavior set this parameter to **true**|
643
682
|`docker-host`| String || By default it is set to `unix://var/run/docker.sock`, but can be updated to help with containerized infrastructure values |
683
+
|`version`| String |`v0.56.1`| Trivy version to use, e.g. `latest` or `v0.56.1`|
644
684
645
685
### Environment variables
646
686
You can use [Trivy environment variables][trivy-env] to set the necessary options (including flags that are not supported by [Inputs](#inputs), such as `--secret-config`).
0 commit comments