How do you ignore accepted risks in Trivy with .trivyignore?
IntermediateHands-onTrivy
Answer
Short answer
List the CVE IDs (or misconfiguration IDs) you've reviewed and accepted in a .trivyignore file in the scanned directory, ideally with a reason and expiry date. Trivy then skips them. For richer rules (per package, per path) use the YAML ignore format or a Rego policy.
Simple .trivyignore
# Not exploitable: we don't use the affected XML parser feature. Review by 2027-01-31 (SEC-142)
CVE-2023-12345
# Base image fix not released yet; tracked in SEC-150
CVE-2024-23456 exp:2027-02-28
# Accepted IaC finding: public bucket hosts the static website
AVD-AWS-0086
The exp: date makes the ignore expire automatically, so accepted risks get re-reviewed.
YAML format (more precise)
# .trivyignore.yaml
vulnerabilities:
- id: CVE-2023-12345
paths: ["app/lib/legacy.jar"]
statement: "Feature not used; see SEC-142"
expired_at: 2027-01-31
trivy image --ignorefile .trivyignore.yaml shop-api:1.4.0
Governance
- Every ignore needs a ticket and owner.
- Ignore file changes go through code review (CODEOWNERS = security team).
- Prefer
--ignore-unfixedfor "no fix exists yet" instead of listing each CVE.
What to say in the interview
"Accepted risks go in .trivyignore with a reason, ticket and expiry date, or the YAML format for package or path-specific ignores. Changes are reviewed by security, and expiry forces periodic re-assessment."
More on Trivy
What is Trivy and how do you scan an image with it?BeginnerWhat is a CVE and what do severity levels mean?BeginnerWhat is Trivy and what can it scan?BeginnerHow do you scan a Docker image with Trivy?BeginnerHow do you fail a CI build when Trivy finds HIGH or CRITICAL vulnerabilities?BeginnerWhat does trivy fs do?Beginner