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

feat(security-actions/scan-docker-image): support trivy_db_cache as alternate #184

Merged
merged 7 commits into from
Dec 2, 2024

Conversation

dndx
Copy link
Member

@dndx dndx commented Nov 5, 2024

input which allows caching the Trivy DB to get around rate limiting issues

Trivy (ab)uses GHCR OCI as it's config update mechanism, and this is being heavily (targeted) rate limited by GitHub.

Inspired by aquasecurity/trivy#7591, this PR adds two optional arguments to the security-actions/scan-docker-image image that allows us to skip fetching fro GHCR completely:

trivy_db_cache:
    description: 'GitHub repository containing Trivy DB cache (format: owner/repo@ref). Database should be named `db.tar.gz` on the default branch.'
    required: false
trivy_db_cache_token:
    description: 'Token for accessing `trivy_db_cache`.'
    required: false

When provided, we will checkout the specific repo's branch using the PAT, look for a db.tar.gz file from it and untar it to the filesystem. We then instruct Trivy to not update it's database and instead use the local database only.

This ensures the action will always succeed because a database will always be available. https://github.com/Kong/trivy-db-mirror contains a workflow that automatically updates it's database every 6 hours, but update can also be manually triggered via Run workflow button on this page.

This PR also removed running Trivy inside the Docker container, as it appears that GitHub Actions does not support volume mounting with the docker:// method. Instead we simply download the trivy executable from the official release link and throw it into /usr/local/bin.

According to my tests, the scan image workflow now always succeeds.

Sister PR on Kong-ee: https://github.com/Kong/kong-ee/pull/10626

input which allows caching the Trivy DB to get around rate limiting
issues
@dndx dndx requested a review from a team as a code owner November 5, 2024 12:16
Copy link

github-actions bot commented Nov 5, 2024

Luacheck Report

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
4 tests ±0  4 ✅ ±0  0 💤 ±0  0 ❌ ±0 
8 runs  ±0  8 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit c0bb00e. ± Comparison against base commit 1a06695.

♻️ This comment has been updated with latest results.

@saisatishkarra saisatishkarra requested a review from a team as a code owner November 26, 2024 17:38
@saisatishkarra saisatishkarra force-pushed the feat/use_custom_registry branch 3 times, most recently from 7bc7818 to 7936c06 Compare November 26, 2024 20:45
…dated mirror for `trivy-db` and `trivy-java-db`

feat(security-actions/scan-docker-image): use existing token input with default
@saisatishkarra
Copy link
Collaborator

Based on the below discussions for the mentioned Issue,

@saisatishkarra saisatishkarra changed the title feat(security-actions/scan-docker-image): support trivy_db_cache as feat(security-actions/scan-docker-image): support trivy_db_cache as alternate Nov 26, 2024
saisatishkarra
saisatishkarra previously approved these changes Nov 26, 2024
Copy link
Collaborator

@saisatishkarra saisatishkarra left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@pankajmouriyakong pankajmouriyakong left a comment

Choose a reason for hiding this comment

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

LGTM

@saisatishkarra saisatishkarra merged commit 0ccacff into main Dec 2, 2024
13 checks passed
@saisatishkarra saisatishkarra deleted the feat/use_custom_registry branch December 2, 2024 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trivy vulnerability DB download fails during image scan
4 participants