Supply chainTrivy
Scan container images with Trivy in CI
By default, Trivy exits with code 0 even when it detects security issues. The exit code, the severity filter and an ignore file decide which findings fail a build.

The command and three flags
trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 my-app:1.4.2trivy image lists the known vulnerabilities in the operating system packages and language packages of an image. It also runs a secret scanner by default. Pass --scanners vuln to turn that off.
--severityfilters the report. Without it, Trivy reports every level fromUNKNOWNtoCRITICAL.--exit-code 1sets the exit code for a run that finds security issues. By default Trivy exits with code 0 even when it detects them.--ignore-unfixedskips vulnerabilities for which the distribution has not provided a patch. It is shorthand for--ignore-status affected,will_not_fix,fix_deferred,end_of_life.
Trivy's documentation shows a split into two runs: one reports MEDIUM,HIGH with --exit-code 0, and the other uses --exit-code 1 --severity CRITICAL, so the job fails only when a critical vulnerability is found.
An ignore file with reasons
Trivy reads the IDs of findings to ignore from a file. The --ignorefile flag defaults to .trivyignore. This example follows the one in Trivy's documentation, with a date that is yours to choose:
# No impact in our settings
CVE-2019-1543
# Accept the risk until the date below
CVE-2019-14697 exp:2027-01-31The lines that start with # hold the reason, as in the documented example, and exp: ends the entry on that date. --show-suppressed shows the suppressed results. A YAML form, .trivyignore.yaml, adds fields such as paths, statement and expired_at to each entry. It is experimental, and you must name the file with --ignorefile.
The GitHub Action, pinned
On March 19, 2026 an attacker force-pushed 76 of the 77 version tags of aquasecurity/trivy-action to malicious commits. The maintainers' advisory tells users to pin GitHub Actions to full commit SHA hashes and to stop using mutable version tags. The original tags 0.0.1 to 0.34.2 were deleted, and the new tags carry a v prefix.
jobs:
scan:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
steps:
- uses: actions/checkout@v7
- run: docker build -t my-app:${{ github.sha }} .
- uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
image-ref: my-app:${{ github.sha }}
format: sarif
output: trivy-results.sarif
severity: CRITICAL,HIGH
limit-severities-for-sarif: true
ignore-unfixed: true
exit-code: '1'
- uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: trivy-results.sarifThe hash in this example is the commit that the v0.36.0 tag points to in the action's repository. Look it up there yourself before you use it. The severity list and the exit code are choices to adjust. The trivyignores input takes the path of one or more .trivyignore files.
Results in code scanning
format: sarif writes a SARIF file, and upload-sarif sends it to GitHub code scanning. Three details matter:
- The job needs
security-events: write. if: always()uploads the file even when Trivy returns a non-zero exit code.- In SARIF format the action outputs every severity unless
limit-severities-for-sarifistrue.
A private or internal repository gets code scanning once GitHub Code Security is enabled for it. For repositories with no code scanning, the action's README shows another route: write the result to a file with the output input and append that file to the workflow summary.
The vulnerability database cache
Trivy fetches its vulnerability database automatically when it needs it. The action caches that database, the Java database and the checks bundle with actions/cache, and the cache is on by default. Its README recommends keeping it enabled to avoid rate limiting issues.
A workflow can restore a cache created on its own branch or on the default branch. To share a cache across branches, the README says to create it on the default branch, and it shows a scheduled workflow that updates the cache there once a day.
Outside the action, trivy image --download-db-only updates the database with no scan and populates the cache for the scans that follow.
What an image scan cannot see
Trivy's documentation states these limits itself:
- Advisory sources. Trivy detects known vulnerabilities, and it only consumes security advisories from the sources its documentation lists.
- Software that no package manager installed. Trivy detects vulnerabilities in it in some cases only, such as Go and Rust binaries with embedded module information.
- Third-party repositories. Trivy skips packages installed from third-party repositories such as EPEL, because official OS security advisories do not cover them.
- Old images. You can get 0 vulnerabilities from an image whose packages have no fixed versions when
--ignore-unfixedis set, or from an outdated OS.--exit-on-eol 1fails the scan when the OS has reached end of life. - The image configuration. Misconfiguration and secret checks on the image configuration are disabled by default.
--image-config-scannersenables them.
The same documentation says Trivy prioritizes precision and accepts some false negatives to keep false positives low.
Where to start
- Run the scan with the default exit code of 0 and read the report.
- Add
--exit-code 1 --severity CRITICAL, the gate that Trivy's own example uses. - Record each accepted finding in
.trivyignorewith a comment and anexp:date. - Pin the action to a commit SHA, as the maintainers' advisory asks, and keep its cache on.
Sources
- Container Image, Trivy documentation
- Filtering, Trivy documentation
- Others, Trivy documentation
- Vulnerability, Trivy documentation
- Databases, Trivy documentation
- aquasecurity/trivy-action
- Trivy ecosystem supply chain temporarily compromised, advisory GHSA-69fq-xp46-6x23
- Uploading a SARIF file to GitHub, GitHub Docs
Want a second pair of eyes on yours? We do this work for a living.
More guides

SBOMs: generate one for every build
Supply chain · 3 min read
Generate an SBOM in CI, attest it to the image, scan it with Grype and keep it with the release.

Software supply chain: pin, sign and verify
Supply chain · 2 min read
Pin your actions, sign what you build and check the signature before you deploy.

Scan Terraform before it applies: Checkov and Trivy
Supply chain · 4 min read
Checkov and Trivy on Terraform code and plans, with skip comments and a gate you can roll out.