Skip to content

Commit

Permalink
fix: use cache for scan
Browse files Browse the repository at this point in the history
Doc-only: true

Required-githooks: true

Signed-off-by: Tomasz Gromadzki <[email protected]>
  • Loading branch information
grom72 committed Oct 25, 2024
1 parent 401f346 commit 0dd7302
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions .github/workflows/trivy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,40 @@ on:
permissions: {}

jobs:
build:
update-trivy-db:
name: Update Trivy DB
runs-on: ubuntu-latest
steps:
- name: Setup oras
uses: oras-project/setup-oras@v1

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 1: third-party GitHubAction not pinned by hash
Click Remediation section below to solve this issue

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT

- name: Download and extract the vulnerability DB
run: |
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/db
oras pull ghcr.io/aquasecurity/trivy-db:2
tar -xzf db.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/db
rm db.tar.gz
- name: Download and extract the Java DB
run: |
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/java-db
oras pull ghcr.io/aquasecurity/trivy-java-db:1
tar -xzf javadb.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/java-db
rm javadb.tar.gz
- name: Cache DBs
uses: actions/cache/save@v4

Check warning

Code scanning / Scorecard

Pinned-Dependencies Medium

score is 1: GitHub-owned GitHubAction not pinned by hash
Click Remediation section below to solve this issue
with:
path: ${{ github.workspace }}/.cache/trivy
key: cache-trivy-${{ steps.date.outputs.date }}
scan:
name: Scan with Trivy
runs-on: ubuntu-20.04
needs: update-trivy-db
runs-on: ubuntu-latest
permissions:
security-events: write
steps:
Expand All @@ -31,6 +62,9 @@ jobs:
scan-type: 'fs'
scan-ref: '.'
trivy-config: 'utils/trivy/trivy.yaml'
env:
TRIVY_SKIP_DB_UPDATE: true
TRIVY_SKIP_JAVA_DB_UPDATE: true

- name: Prepare the report to be uploaded to the GitHub artifact store
run: |
Expand All @@ -57,6 +91,9 @@ jobs:
scan-ref: '.'
trivy-config: 'utils/trivy/trivy.yaml'
skip-setup-trivy: true
env:
TRIVY_SKIP_DB_UPDATE: true
TRIVY_SKIP_JAVA_DB_UPDATE: true

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@afb54ba388a7dca6ecae48f608c4ff05ff4cc77a
Expand All @@ -77,3 +114,6 @@ jobs:
scan-ref: '.'
trivy-config: 'utils/trivy/trivy.yaml'
skip-setup-trivy: true
env:
TRIVY_SKIP_DB_UPDATE: true
TRIVY_SKIP_JAVA_DB_UPDATE: true

0 comments on commit 0dd7302

Please sign in to comment.