Q: Your security team discovers that developer container images running in production contain unpatched Critical CVEs and run as root with dangerous capabilities. How do you implement Aqua Trivy in CI/CD pipelines to scan container images and Dockerfiles, block builds with Critical fixable vulnerabilities, and export SARIF reports directly to GitHub Security?
Production guide for integrating Aqua Trivy into CI/CD pipelines to scan container images, Dockerfiles, and Helm charts for CVEs and security misconfigurations with automated build-blocking thresholds.
Want to master this scenario in a live sandbox? KodeKloud's Enterprise GitOps with ArgoCD & Kubernetes Rollouts covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: Deploying un-scanned container images into production leads to immediate CVE exploitation. We integrated Aqua Trivy into our container build pipelines to scan OS packages, language dependencies, and Dockerfile misconfigurations with automated severity-based build gates.
Configure Trivy Container Image Scanning with Severity Filters
Scan newly built container images before pushing to registries:
- Trivy Image Scan: Executed
trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1 payment-service:latest. - Ignore Unfixed CVEs: Setting
--ignore-unfixedensures the build fails only if a patched version of the vulnerable package actually exists in upstream repositories.
Scan Dockerfile Misconfigurations & Secrets with Trivy Config
Catch insecure container configurations before image compilation:
- Config Scanning: Executed
trivy config ./Dockerfile. - Policy Checks: Trivy checks for compliance against CIS Docker Benchmarks: catching missing
USERinstructions (running as root), exposed sensitive ports, and missing health checks. - Secret Scanning: Scans the repository and image filesystem for leaked API keys, tokens, and private SSH certificates.
Export SARIF Reports & Upload to GitHub Code Scanning
Integrate findings natively into GitHub Advanced Security dashboards:
- SARIF Export: Executed
trivy image --format sarif --output trivy-results.sarif payment-service:latest. - Upload Action: Integrated
github/codeql-action/upload-sarif@v3 with: { sarif_file: 'trivy-results.sarif' }. - GitHub Security Alerts: Vulnerabilities display directly in the GitHub repository's Security tab with remediation advice.
Optimize Trivy Vulnerability Database Caching in CI Runners
Accelerate scanning speed by caching the vulnerability database:
- DB Cache Sharing: Configured CI cache for
~/.cache/trivy, downloading differential DB updates in 4 seconds instead of 45 seconds. - Private Registry Push: Only images that pass 100% of Trivy gates are tagged and pushed to the enterprise container registry.
- Scan container images with trivy image --severity HIGH,CRITICAL --ignore-unfixed --exit-code 1.
- Scan Dockerfiles for CIS benchmark misconfigurations and embedded secrets with trivy config.
- Export findings to SARIF format and upload directly to GitHub Code Scanning.
- Cache the Trivy vulnerability database to keep scans blazing fast (<15 seconds).
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Promoting application releases to production without an automated, canary-validated rollback mechanism when configuring Container Security Gates Pipelines that lack automated rollback mechanisms force engineering teams to scramble manual hotfixes during severe production regressions.
- Running concurrent deployment pipeline jobs without stage mutex locking on shared target environments when configuring Container Security Gates Concurrent pipeline runs on the same environment race to apply state changes, causing out-of-order commits and unpredictable deployment state.
- Omitting dependency lockfiles (package-lock.json, go.sum, Cargo.lock) from continuous integration builds when configuring Container Security Gates Omitting lockfiles allows upstream package updates to break builds unpredictably without any changes to application codebase.
- Failing to define dynamic cache invalidation keys for CI package managers and layer caches when configuring Container Security Gates Stale build caches mask underlying dependency incompatibilities or pull outdated libraries, while un-cached runs slow feedback loops.