Skip to content

add trivy cache #63

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all 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
31 changes: 30 additions & 1 deletion trivy-fs-scan/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ runs:
run: |
touch .trivyignore

- name: Setup oras
uses: oras-project/setup-oras@v1

- name: Get current date
shell: sh
id: date
run: |
echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
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're putting the date into the cache, what's the point? It's just going to accumulate cache entries. I would suggest we make caching optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed caching . since vulnerabilities are updated daily, we cannot cache it after a day.

Copy link
Contributor

Choose a reason for hiding this comment

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

How does pulling this manually via oras help? the rate limit is on ghcr. In the linked thread, they suggest you can just use their public ECR instead which can be passed as a flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

TRIVY_DB_REPOSITORY=ghcr.io/aquasecurity/trivy-db,public.ecr.aws/aquasecurity/trivy-db

Seems like this should fallback to the public ECR (should be a similar one for the java db). There's also rate limiting there but we can either set up a user or just hope that having two options should be good enough.


- name: Download and extract the vulnerability DB
shell: sh
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
shell: sh
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: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
Expand All @@ -88,6 +114,9 @@ runs:
skip-dirs: ${{ inputs.skip-dirs }}
skip-files: ${{ inputs.skip-files }}
exit-code: '1'
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@v2
Expand All @@ -100,4 +129,4 @@ runs:
if: ${{ (success() || failure()) && inputs.output-mode == 'github' && inputs.category != '' }}
with:
sarif_file: ${{ steps.output.outputs.TRIVY_OUTPUT }}
category: ${{ inputs.category }}
category: ${{ inputs.category }}
Loading