Compare commits

...
8 Commits
Author SHA1 Message Date
simar7 18f2510ee3 chore(deps): Bump trivy to v0.57.1 (#434)
* chore(deps): Bump trivy to v0.57.1

* update tests

* use mirrors from mirror.gcr.io

* update workflow for tests

* Revert "use mirrors from mirror.gcr.io"

This reverts commit 529a941eed.
2024-11-19 17:11:53 -07:00
Nikita Pivkin 93941cebba docs: remove ignore-unfixed from IaC scan example (#429)
Signed-off-by: Nikita Pivkin <[email protected]>
2024-11-18 16:54:58 -07:00
DmitriyLewenandsimar7 d2a392a137 fix: bump setup-trivy and add new contrib directory path info (#424)
* chore(deps): use fork for setup-trivy

* docs: add info about templates

* refactor: use `setup-trivy` v0.2.2

* docs: remove `./` prefix

* Merge branch 'main' into 'fix/contrib-dir'

* docs: fix link

* docs: fix typo

Co-authored-by: simar7 <[email protected]>

---------

Co-authored-by: simar7 <[email protected]>
2024-10-25 00:45:28 -06:00
DmitriyLewen ee8934673c feat: add token for setup-trivy (#421)
* feat: add `token-setup-trivy` input.

* docs: add info about `token-setup-trivy`

* fix: use correct commit

* refactor: use `default: ${{ github.token }}` for `token-setup-trivy`

* refactor: use `setup-trivy` v0.2.2
2024-10-24 23:32:23 -06:00
simar7 cf990b19d8 Update README.md (#420) 2024-10-21 22:43:57 -06:00
Daisuke Sato bff40be51b docs: Fix oras command not found (#413) 2024-10-21 22:43:42 -06:00
Rob Vesseandsimar7 fc1500abdc feat: Allow skipping setup (#414)
If a user is invoking the action multiple times then the trivy binary
gets installed multiple times.  Users can avoid this by managing the
installation themselves and setting the skip-setup input to true, or by
letting the action install in on their first invocation and then setting
skip-setup to true on subsequent invocations

Co-authored-by: simar7 <[email protected]>
2024-10-15 19:57:47 -06:00
DmitriyLewen 915b19bbe7 chore(deps): bump setup-trivy to v0.2.1 (#411)
* chore(deps): bump setup-trivy

* chore(deps): bump setup-trivy

* chore(deps): bump setup-trivy to `v0.2.1`
2024-10-15 10:04:03 -06:00
6 changed files with 1197 additions and 42 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ on:
workflow_dispatch:
env:
TRIVY_VERSION: 0.56.1
TRIVY_VERSION: 0.57.1
BATS_LIB_PATH: '/usr/lib/'
jobs:
+195 -22
View File
@@ -14,7 +14,9 @@
* [Scan CI Pipeline](#scan-ci-pipeline)
* [Scan CI Pipeline (w/ Trivy Config)](#scan-ci-pipeline-w-trivy-config)
* [Cache](#cache)
* [Trivy Setup](#trivy-setup)
* [Scanning a Tarball](#scanning-a-tarball)
* [Using Trivy with templates](#using-trivy-with-templates)
* [Using Trivy with GitHub Code Scanning](#using-trivy-with-github-code-scanning)
* [Using Trivy to scan your Git repo](#using-trivy-to-scan-your-git-repo)
* [Using Trivy to scan your rootfs directories](#using-trivy-to-scan-your-rootfs-directories)
@@ -48,7 +50,7 @@ jobs:
- name: Build an image from Dockerfile
run: docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'table'
@@ -76,7 +78,7 @@ jobs:
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner in fs mode
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
scan-type: 'fs'
scan-ref: '.'
@@ -117,7 +119,7 @@ If you want to disable caching, set the `cache` input to `false`, but we recomme
```yaml
- name: Run Trivy scanner without cache
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
scan-type: 'fs'
scan-ref: '.'
@@ -146,6 +148,9 @@ jobs:
update-trivy-db:
runs-on: ubuntu-latest
steps:
- name: Setup oras
uses: oras-project/setup-oras@v1
- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
@@ -175,7 +180,7 @@ When running a scan, set the environment variables `TRIVY_SKIP_DB_UPDATE` and `T
```yaml
- name: Run Trivy scanner without downloading DBs
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
scan-type: 'image'
scan-ref: 'myimage'
@@ -184,6 +189,113 @@ When running a scan, set the environment variables `TRIVY_SKIP_DB_UPDATE` and `T
TRIVY_SKIP_JAVA_DB_UPDATE: true
```
### Trivy Setup
By default the action calls [`aquasecurity/setup-trivy`](https://github.com/aquasecurity/setup-trivy) as the first step
which installs the `trivy` version specified by the `version` input. If you have already installed `trivy` by other
means, e.g. calling `aquasecurity/setup-trivy` directly, or are invoking this action multiple times then you can use the
`skip-setup-trivy` input to disable this step.
#### Setting up Trivy Manually
```yaml
name: build
on:
push:
branches:
- main
pull_request:
jobs:
build:
name: Build
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Manual Trivy Setup
uses: aquasecurity/[email protected]
with:
cache: true
version: v0.57.1
- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
ignore-unfixed: true
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL'
skip-setup-trivy: true
```
#### Skipping Setup when Calling Trivy Action multiple times
Another common use case is when a build calls this action multiple times, in this case we can set `skip-setup-trivy` to
`true` on subsequent invocations e.g.
```yaml
name: build
on:
push:
branches:
- main
pull_request:
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Check out Git repository
uses: actions/checkout@v4
# The first call to the action will invoke setup-trivy and install trivy
- name: Generate Trivy Vulnerability Report
uses: aquasecurity/trivy-action@master
with:
scan-type: "fs"
output: trivy-report.json
format: json
scan-ref: .
exit-code: 0
- name: Upload Vulnerability Scan Results
uses: actions/upload-artifact@v4
with:
name: trivy-report
path: trivy-report.json
retention-days: 30
- name: Fail build on High/Criticial Vulnerabilities
uses: aquasecurity/trivy-action@master
with:
scan-type: "fs"
format: table
scan-ref: .
severity: HIGH,CRITICAL
ignore-unfixed: true
exit-code: 1
# On a subsequent call to the action we know trivy is already installed so can skip this
skip-setup-trivy: true
```
#### Use non-default token to install Trivy
GitHub Enterprise Server (GHES) uses an invalid `github.token` for `https://github.com` server.
Therefore, you can't install `Trivy` using the `setup-trivy` action.
To fix this problem, you need to overwrite the token for `setup-trivy` using `token-setup-trivy` input:
```yaml
- name: Run Trivy scanner without cache
uses: aquasecurity/[email protected]
with:
scan-type: 'fs'
scan-ref: '.'
token-setup-trivy: ${{ secrets.GITHUB_PAT }}
```
GitHub even has [create-github-app-token](https://github.com/actions/create-github-app-token) for similar cases.
### Scanning a Tarball
```yaml
name: build
@@ -206,12 +318,70 @@ jobs:
docker save -o vuln-image.tar <your-docker-image>
- name: Run Trivy vulnerability scanner in tarball mode
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
input: /github/workspace/vuln-image.tar
severity: 'CRITICAL,HIGH'
```
### Using Trivy with templates
The action supports [Trivy templates][trivy-templates].
Use `template` input to specify path (remember to prefix the path with `@`) to template file.
```yaml
name: build
on:
push:
branches:
- main
pull_request:
jobs:
build:
name: Build
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
scan-type: "fs"
scan-ref: .
format: 'template'
template: "@path/to/my_template.tpl"
```
#### Default templates
Trivy has [default templates][trivy-default-templates].
By default, `setup-trivy` installs them into the `$HOME/.local/bin/trivy-bin/contrib` directory.
```yaml
name: build
on:
push:
branches:
- main
pull_request:
jobs:
build:
name: Build
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
scan-type: "fs"
scan-ref: .
format: 'template'
template: "@$HOME/.local/bin/trivy-bin/contrib/html.tpl"
```
### Using Trivy with GitHub Code Scanning
If you have [GitHub code scanning](https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/about-code-scanning) available you can use Trivy as a scanning tool as follows:
```yaml
@@ -234,7 +404,7 @@ jobs:
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'sarif'
@@ -269,7 +439,7 @@ jobs:
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'sarif'
@@ -304,7 +474,7 @@ jobs:
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner in repo mode
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
scan-type: 'fs'
ignore-unfixed: true
@@ -338,7 +508,7 @@ jobs:
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner with rootfs command
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
scan-type: 'rootfs'
scan-ref: 'rootfs-example-binary'
@@ -373,14 +543,13 @@ jobs:
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner in IaC mode
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
scan-type: 'config'
hide-progress: true
format: 'sarif'
output: 'trivy-results.sarif'
exit-code: '1'
ignore-unfixed: true
severity: 'CRITICAL,HIGH'
- name: Upload Trivy scan results to GitHub Security tab
@@ -417,7 +586,7 @@ jobs:
uses: actions/checkout@v4
- name: Run Trivy in GitHub SBOM mode and submit results to Dependency Graph
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
scan-type: 'fs'
format: 'github'
@@ -448,7 +617,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Scan image in a private registry
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
image-ref: "private_image_registry/image_name:image_tag"
scan-type: image
@@ -491,7 +660,7 @@ jobs:
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'sarif'
@@ -527,7 +696,7 @@ jobs:
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
image-ref: 'aws_account_id.dkr.ecr.region.amazonaws.com/imageName:${{ github.sha }}'
format: 'sarif'
@@ -563,7 +732,7 @@ jobs:
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'sarif'
@@ -596,7 +765,7 @@ jobs:
uses: actions/checkout@v4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
format: 'sarif'
@@ -619,7 +788,7 @@ This step is especially useful for private repositories without [GitHub Advanced
```yaml
- name: Run Trivy scanner
uses: aquasecurity/[email protected]0.0
uses: aquasecurity/[email protected]8.0
with:
scan-type: config
hide-progress: true
@@ -659,8 +828,8 @@ Following inputs can be used as `step.with` keys:
| `input` | String | | Tar reference, e.g. `alpine-latest.tar` |
| `image-ref` | String | | Image reference, e.g. `alpine:3.10.2` |
| `scan-ref` | String | `/github/workspace/` | Scan reference, e.g. `/github/workspace/` or `.` |
| `format` | String | `table` | Output format (`table`, `json`, `template`, `sarif`, `cyclonedx`, `spdx`, `spdx-json`, `github`, `cosign-vuln`) |
| `template` | String | | Output template (`@/contrib/gitlab.tpl`, `@/contrib/junit.tpl`) |
| `format` | String | `table` | Output format (`table`, `json`, `template`, `sarif`, `cyclonedx`, `spdx`, `spdx-json`, `github`, `cosign-vuln`) |
| `template` | String | | Output template (`@$HOME/.local/bin/trivy-bin/contrib/gitlab.tpl`, `@$HOME/.local/bin/trivy-bin/contrib/junit.tpl`) |
| `tf-vars` | String | | path to Terraform variables file |
| `output` | String | | Save results to a file |
| `exit-code` | String | `0` | Exit code when specified vulnerabilities are found |
@@ -674,13 +843,15 @@ Following inputs can be used as `step.with` keys:
| `ignore-policy` | String | | Filter vulnerabilities with OPA rego language |
| `hide-progress` | String | `false` | Suppress progress bar and log output |
| `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`,`misconfig`,`license`) |
| `scanners` | String | `vuln,secret` | comma-separated list of what security issues to detect (`vuln`,`secret`,`misconfig`,`license`) |
| `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** |
| `docker-host` | String | | By default it is set to `unix://var/run/docker.sock`, but can be updated to help with containerized infrastructure values |
| `version` | String | `v0.56.1` | Trivy version to use, e.g. `latest` or `v0.56.1` |
| `version` | String | `v0.56.2` | Trivy version to use, e.g. `latest` or `v0.56.2` |
| `skip-setup-trivy` | Boolean | false | Skip calling the `setup-trivy` action to install `trivy` |
| `token-setup-trivy` | Boolean | | Overwrite `github.token` used by `setup-trivy` to checkout the `trivy` repository |
### Environment variables
You can use [Trivy environment variables][trivy-env] to set the necessary options (including flags that are not supported by [Inputs](#inputs), such as `--secret-config`).
@@ -696,3 +867,5 @@ When using the `trivy-config` [Input](#inputs), you can set options using the [T
[license-img]: https://img.shields.io/github/license/aquasecurity/trivy-action
[trivy-env]: https://aquasecurity.github.io/trivy/latest/docs/configuration/#environment-variables
[trivy-config]: https://aquasecurity.github.io/trivy/latest/docs/references/configuration/config-file/
[trivy-templates]: https://aquasecurity.github.io/trivy/latest/docs/configuration/reporting/#template
[trivy-default-templates]: https://aquasecurity.github.io/trivy/latest/docs/configuration/reporting/#default-templates
+17 -2
View File
@@ -98,20 +98,35 @@ inputs:
version:
description: 'Trivy version to use'
required: false
default: 'v0.56.1'
default: 'v0.57.1'
cache:
description: 'Used to specify whether caching is needed. Set to false, if you would like to disable caching.'
required: false
default: 'true'
skip-setup-trivy:
description: 'skip calling the setup-trivy action to install trivy'
required: false
default: 'false'
token-setup-trivy:
description: >
`token-setup-trivy` is required when `github.token` in invalid for `https://github.com` server.
See https://github.com/aquasecurity/setup-trivy/?tab=readme-ov-file#install-trivy-with-non-default-token for more details.
`token-setup-trivy` is only used to fetch the Trivy repository in `setup-trivy`
required: false
## ${{ github.token }} is default value for actions/checkout
## cf. https://github.com/actions/checkout/blob/eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871/action.yml#L24
default: ${{ github.token }}
runs:
using: 'composite'
steps:
- name: Install Trivy
uses: aquasecurity/[email protected]
if: ${{ inputs.skip-setup-trivy == 'false' }}
uses: aquasecurity/[email protected]
with:
version: ${{ inputs.version }}
cache: ${{ inputs.cache }}
token: ${{ inputs.token-setup-trivy }}
- name: Get current date
id: date
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large Load Diff
+2 -3
View File
@@ -20,9 +20,8 @@
"Class": "config",
"Type": "terraform",
"MisconfSummary": {
"Successes": 2,
"Failures": 0,
"Exceptions": 0
"Successes": 19,
"Failures": 0
}
},
{