In this case trivy.yaml is a YAML configuration that is checked in as part of the repo. Detailed information is available on the Trivy website but an example is as follows:
format:jsonexit-code:1severity:CRITICAL
It is possible to define all options in the trivy.yaml file. Specifying individual options via the action are left for backward compatibility purposes. Defining the following is required as they cannot be defined with the config file:
scan-ref: If using fs, repo scans.
image-ref: If using image scan.
scan-type: To define the scan type, e.g. image, fs, repo, etc.
Order of prerference for options
Trivy uses Viper which has a defined precedence order for options. The order is as follows:
GitHub Action flag
Environment variable
Config file
Default
Scanning a Tarball
name:buildon:push:branches: - masterpull_request:jobs:build:name:Buildruns-on:ubuntu-20.04steps: - name:Checkout codeuses:actions/checkout@v3 - name:Generate tarball from imagerun:| docker pull <your-docker-image> docker save -o vuln-image.tar <your-docker-image> - name:Run Trivy vulnerability scanner in tarball modeuses:aquasecurity/trivy-action@masterwith:input:/github/workspace/vuln-image.tarseverity:'CRITICAL,HIGH'
Using Trivy with GitHub Code Scanning
If you have GitHub code scanning available you can use Trivy as a scanning tool as follows:
If you would like to upload SARIF results to GitHub Code scanning even upon a non zero exit code from Trivy Scan, you can add the following to your upload step:
It's also possible to scan your git repos with Trivy's built-in repo scan. This can be handy if you want to run Trivy as a build time check on each PR that gets opened in your repo. This helps you identify potential vulnerablites that might get introduced with each PR.
If you have GitHub code scanning available you can use Trivy as a scanning tool as follows:
It's also possible to scan your rootfs directories with Trivy's built-in rootfs scan. This can be handy if you want to run Trivy as a build time check on each PR that gets opened in your repo. This helps you identify potential vulnerablites that might get introduced with each PR.
If you have GitHub code scanning available you can use Trivy as a scanning tool as follows:
It's also possible to scan your IaC repos with Trivy's built-in repo scan. This can be handy if you want to run Trivy as a build time check on each PR that gets opened in your repo. This helps you identify potential vulnerablites that might get introduced with each PR.
If you have GitHub code scanning available you can use Trivy as a scanning tool as follows:
---name:Pull Requeston:push:branches: - master## GITHUB_TOKEN authentication, add only if you're not going to use a PATpermissions:contents:writejobs:build:name:Checksruns-on:ubuntu-20.04steps: - name:Checkout codeuses:actions/checkout@v3 - name:Run Trivy in GitHub SBOM mode and submit results to Dependency Graphuses:aquasecurity/trivy-action@masterwith:scan-type:'fs'format:'github'output:'dependency-results.sbom.json'image-ref:'.'github-pat:${{ secrets.GITHUB_TOKEN }}# or ${{ secrets.github_pat_name }} if you're using a PAT
Using Trivy to scan your private registry
It's also possible to scan your private registry with Trivy's built-in image scan. All you have to do is set ENV vars.
Docker Hub registry
Docker Hub needs TRIVY_USERNAME and TRIVY_PASSWORD. You don't need to set ENV vars when downloading from a public repository.
Exit code when specified vulnerabilities are found
ignore-unfixed
Boolean
false
Ignore unpatched/unfixed vulnerabilities
vuln-type
String
os,library
Vulnerability types (os,library)
severity
String
UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL
Severities of vulnerabilities to scanned for and displayed
skip-dirs
String
Comma separated list of directories where traversal is skipped
skip-files
String
Comma separated list of files where traversal is skipped
cache-dir
String
Cache directory
timeout
String
5m0s
Scan timeout duration
ignore-policy
String
Filter vulnerabilities with OPA rego language
hide-progress
String
true
Suppress progress bar
list-all-pkgs
String
Output all packages regardless of vulnerability
scanners
String
vuln,secret
comma-separated list of what security issues to detect (vuln,secret,config)
trivyignores
String
comma-separated list of relative paths in repository to one or more .trivyignore files
trivy-config
String
Path to trivy.yaml config
github-pat
String
Authentication token to enable sending SBOM scan results to GitHub Dependency Graph. Can be either a GitHub Personal Access Token (PAT) or GITHUB_TOKEN
limit-severities-for-sarif
Boolean
false
By default SARIF format enforces output of all vulnerabilities regardless of configured severities. To override this behavior set this parameter to true