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

ci: pull trivy DB from public AWS ECR #84

Merged
merged 5 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/download_trivy_db.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Update Trivy Cache

on:
schedule:
- cron: '0 0 * * *' # Update daily at 00:00 - before scheduled trivy scan
workflow_dispatch: # Allow manual triggering
Copy link
Member

Choose a reason for hiding this comment

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

if you want to make it reusable you should add

on:
  workflow_call:
    inputs: [...] # not sure if these are needed

Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 If we make this reusable, we we'll also need to open 20+ PRs for all the repositories using them, right? I guess we cannot have a cross-repo cache...

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 guess these PRs need to be open as well to reference this one, yes 🫠

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added in 1f03e76


jobs:
update-trivy-db:
runs-on: ubuntu-22.04
steps:
- name: Setup oras
uses: oras-project/setup-oras@v1

- 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
# try GHCR, fallback to ECR
{ oras pull ghcr.io/aquasecurity/trivy-db:2 } || { oras pull public.ecr.aws/aquasecurity/trivy-db:2 }
tar -xzf db.tar.gz -C $GITHUB_WORKSPACE/.cache/trivy/db
rm db.tar.gz

# Also recommended by trivy docs for non-java projects as jars could be embedded in unexpected places
- name: Download and extract the Java DB
run: |
mkdir -p $GITHUB_WORKSPACE/.cache/trivy/java-db
# try GHCR, fallback to ECR
{ oras pull ghcr.io/aquasecurity/trivy-java-db:1 } || { oras pull public.ecr.aws/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
with:
path: ${{ github.workspace }}/.cache/trivy
key: cache-trivy-${{ steps.date.outputs.date }}
8 changes: 8 additions & 0 deletions .github/workflows/reusable_security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ jobs:
severity: 'HIGH,CRITICAL'
skip-dirs: "${{ inputs.skip-dirs }}"
skip-files: "${{ inputs.skip-files }}"
env:
# dbs are downloaded async in download_trivy_db.yml
TRIVY_SKIP_DB_UPDATE: true
TRIVY_SKIP_JAVA_DB_UPDATE: true

- name: Run Trivy vulnerability scanner sarif output
uses: aquasecurity/[email protected]
Expand All @@ -47,6 +51,10 @@ jobs:
output: 'trivy-results.sarif'
skip-dirs: "${{ inputs.skip-dirs }}"
skip-files: "${{ inputs.skip-files }}"
env:
# dbs are downloaded async in download_trivy_db.yml
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@v3
Expand Down