Skip to content

Commit 1b8b83d

Browse files
authored
docs: add usage info about action/cache for trivy databases (#397)
* docs: add info about using `action/cache` for `trivy-db` * docs: add info about trivy-java-db and trivy-checks
1 parent f781cce commit 1b8b83d

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,56 @@ jobs:
123123
severity: 'CRITICAL,HIGH'
124124
```
125125

126+
### Using cache for Trivy databases
127+
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
150+
- name: Get data
151+
id: date
152+
run: echo "date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT
153+
154+
- name: Restore trivy cache
155+
uses: actions/cache@v4
156+
with:
157+
path: cache/db
158+
key: trivy-cache-${{ steps.date.outputs.date }}
159+
restore-keys:
160+
trivy-cache-
161+
162+
- name: Run Trivy vulnerability scanner in fs mode
163+
uses: aquasecurity/[email protected]
164+
with:
165+
scan-type: 'fs'
166+
scan-ref: '.'
167+
cache-dir: "./cache"
168+
169+
## Trivy-db uses `0600` permissions.
170+
## 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+
126176
### Using Trivy with GitHub Code Scanning
127177
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:
128178
```yaml

0 commit comments

Comments
 (0)