| name | trivy |
| description | Auth/lab ref: broad vulnerability scanner for containers, filesystems, repos, IaC, and SBOMs. |
| license | Apache-2.0 |
| compatibility | Linux / macOS / Windows. |
| metadata | {"author":"AeonDave","version":"1.0"} |
trivy
Container / code / IaC vulnerability scanner — CVEs, misconfigs, secrets.
Quick Start
trivy image nginx:latest
trivy fs /path/to/code
trivy repo https://github.com/org/project
Scan Types
| Command | Target |
|---|
trivy image <image> | Docker/OCI image |
trivy fs <path> | Local filesystem |
trivy repo <url> | Remote git repository |
trivy rootfs <path> | Root filesystem (extracted container) |
trivy config <path> | IaC / config files (Terraform, k8s, Dockerfile) |
trivy sbom <file> | Analyze SBOM file |
trivy k8s | Kubernetes cluster scan |
trivy aws | AWS account misconfiguration scan |
trivy vm <path> | Virtual machine image scan |
Core Flags
| Flag | Purpose |
|---|
--severity <lvl> | Filter: UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL |
--vuln-type <type> | os / library (both by default) |
--scanners <list> | vuln,secret,misconfig,license |
--ignore-unfixed | Skip vulns without available fix |
--format <fmt> | table / json / sarif / cyclonedx / spdx / template |
--output <file> | Save output to file |
--template <tmpl> | Custom output template |
--timeout <n> | Timeout (default 5m0s) |
--exit-code <n> | Exit code when vulns found (default 0) |
--no-progress | Disable progress bar |
--quiet | Suppress progress + status |
--skip-dirs <dirs> | Skip specific directories |
--skip-files <files> | Skip specific files |
--ignore-policy <file> | OPA policy file to filter findings |
--dependency-tree | Show package dependency graph |
--compliance <spec> | Compliance check: docker-cis-1.6.0 / k8s-cis-1.23 / aws-cis-1.2 |
--include-non-failures | Show passing checks alongside failures |
--list-all-pkgs | Include all packages even without CVEs |
--trivyignore <file> | File with CVE/AVD IDs to ignore (default .trivyignore) |
--db-repository <repo> | Custom vulnerability DB repository |
--cache-dir <dir> | Cache directory |
--clear-cache |
Common Workflows
trivy image --severity HIGH,CRITICAL nginx:latest
trivy image --format json --output nginx_scan.json nginx:latest
trivy image --ignore-unfixed nginx:latest
trivy image --scanners vuln,secret nginx:latest
trivy image --username admin --password secret registry.company.com/app:v1.0
trivy fs --scanners vuln,secret,misconfig /path/to/project
trivy repo --scanners vuln,secret https://github.com/target/repo
trivy config ./infrastructure/
trivy config --severity HIGH,CRITICAL k8s/
trivy image --format cyclonedx --output sbom.json nginx:latest
trivy image --format spdx-json --output sbom.spdx.json nginx:latest
trivy sbom sbom.json
trivy k8s --severity HIGH,CRITICAL --report summary cluster
trivy aws --severity HIGH,CRITICAL --region us-east-1
trivy aws --service s3,iam,ec2 --severity CRITICAL
trivy image --compliance docker-cis-1.6.0 nginx:latest
trivy k8s --compliance k8s-cis-1.23 cluster
trivy vm --severity HIGH,CRITICAL machine.vmdk
trivy image --dependency-tree nginx:latest
trivy image --exit-code 1 --severity HIGH,CRITICAL myapp:latest
echo $?
Scanners
trivy image --scanners vuln nginx:latest
trivy fs --scanners secret .
trivy config --scanners misconfig ./k8s/
trivy fs --scanners vuln,secret,misconfig,license .
Secret Detection
trivy fs --scanners secret --format json -o secrets.json /path/to/project
trivy image --scanners secret --format json myapp:latest
cat > custom-secret-config.yaml << 'EOF'
rules:
- id: custom-api-key
category: general
title: Custom API Key
severity: HIGH
regex: 'MYAPI_[A-Z0-9]{32}'
EOF
trivy fs --secret-config custom-secret-config.yaml --scanners secret .
Misconfiguration Detection
trivy config --severity HIGH,CRITICAL ./terraform/
trivy config ./k8s/
trivy config Dockerfile
Output Parsing
trivy image --format json -o scan.json nginx:latest
cat scan.json | jq '.Results[] | .Vulnerabilities[]? | {cve: .VulnerabilityID, pkg: .PkgName, severity: .Severity, fixed: .FixedVersion}'
cat scan.json | jq '.Results[] | .Vulnerabilities[]? | select(.Severity == "CRITICAL") | {cve: .VulnerabilityID, pkg: .PkgName}'
cat scan.json | jq '[.Results[] | .Vulnerabilities[]? | .Severity] | group_by(.) | map({severity: .[0], count: length})'
cat scan.json | jq '.Results[] | .Vulnerabilities[]? | select(.FixedVersion != null and .FixedVersion != "") | {cve: .VulnerabilityID, current: .InstalledVersion, fixed: .FixedVersion}'
trivy image --format sarif -o trivy.sarif myapp:latest
.trivyignore File
cat > .trivyignore << 'EOF'
CVE-2022-1234
CVE-2021-5678
EOF
trivy image --trivyignore .trivyignore nginx:latest
CI Integration
trivy fs --exit-code 1 --severity CRITICAL --scanners secret .
Resources
| File | When to load |
|---|
references/container-security.md | Container hardening, Docker security best practices, k8s scanning |