mirror of
https://github.com/aquasecurity/trivy-action.git
synced 2026-05-14 11:12:40 +00:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eeb939f8a9 | |||
| 7b7aa264d8 | |||
| 63b6e4c61b | |||
| 49e970d7ac | |||
| c666240787 | |||
| e27605859b | |||
| 2b22459068 | |||
| 4b3b5f928b | |||
| 1a53202fc4 | |||
| df3fb7d00b | |||
| 987beb8186 | |||
| 4b9b6fb4ef | |||
| 2b30463ddb | |||
| d7a51817e8 | |||
| 9fbcc91008 | |||
| 40c4ca9e74 | |||
| f39d29766a | |||
| 296212627a | |||
| a7a829a434 | |||
| 9c21d3ca2c | |||
| 8f4c7160b4 | |||
| 81cc8cd841 | |||
| 0769bbf0d2 | |||
| 9ec80b5796 | |||
| a58433e1c9 | |||
| 7168e9ba5a | |||
| 2a2157eb22 | |||
| 1ccef265f5 | |||
| d62898dfb3 | |||
| 6bce46377c | |||
| 101d9bacf6 | |||
| 8eccb55397 | |||
| 9438b49cc3 |
@@ -0,0 +1,27 @@
|
|||||||
|
name: "build"
|
||||||
|
on: [push, pull_request]
|
||||||
|
env:
|
||||||
|
TRIVY_VERSION: 0.29.1
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: build
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- name: Setup BATS
|
||||||
|
uses: mig4/setup-bats@v1
|
||||||
|
with:
|
||||||
|
bats-version: 1.2.1
|
||||||
|
|
||||||
|
- name: Setup Bats libs
|
||||||
|
uses: brokenpip3/setup-bats-libs@0.1.0
|
||||||
|
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Install Trivy
|
||||||
|
run: |
|
||||||
|
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin v${{ env.TRIVY_VERSION }}
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: bats -r .
|
||||||
@@ -1 +1,4 @@
|
|||||||
.idea/
|
.idea/
|
||||||
|
*.test
|
||||||
|
!test/data/*.test
|
||||||
|
trivyignores
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
FROM aquasec/trivy:0.18.1
|
FROM ghcr.io/aquasecurity/trivy:0.29.1
|
||||||
COPY entrypoint.sh /
|
COPY entrypoint.sh /
|
||||||
RUN apk --no-cache add bash
|
RUN apk --no-cache add bash curl
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|||||||
@@ -35,11 +35,11 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Build an image from Dockerfile
|
- name: Build an image from Dockerfile
|
||||||
run: |
|
run: |
|
||||||
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
|
docker build -t docker.io/my-organization/my-app:${{ github.sha }} .
|
||||||
|
|
||||||
- name: Run Trivy vulnerability scanner
|
- name: Run Trivy vulnerability scanner
|
||||||
uses: aquasecurity/trivy-action@master
|
uses: aquasecurity/trivy-action@master
|
||||||
with:
|
with:
|
||||||
@@ -76,18 +76,53 @@ jobs:
|
|||||||
uses: aquasecurity/trivy-action@master
|
uses: aquasecurity/trivy-action@master
|
||||||
with:
|
with:
|
||||||
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
||||||
format: 'template'
|
format: 'sarif'
|
||||||
template: '@/contrib/sarif.tpl'
|
|
||||||
output: 'trivy-results.sarif'
|
output: 'trivy-results.sarif'
|
||||||
|
|
||||||
- name: Upload Trivy scan results to GitHub Security tab
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
uses: github/codeql-action/upload-sarif@v1
|
uses: github/codeql-action/upload-sarif@v2
|
||||||
with:
|
with:
|
||||||
sarif_file: 'trivy-results.sarif'
|
sarif_file: 'trivy-results.sarif'
|
||||||
```
|
```
|
||||||
|
|
||||||
You can find a more in-depth example here: https://github.com/aquasecurity/trivy-sarif-demo/blob/master/.github/workflows/scan.yml
|
You can find a more in-depth example here: https://github.com/aquasecurity/trivy-sarif-demo/blob/master/.github/workflows/scan.yml
|
||||||
|
|
||||||
|
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:
|
||||||
|
```yaml
|
||||||
|
name: build
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- 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/trivy-action@master
|
||||||
|
with:
|
||||||
|
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
||||||
|
format: 'sarif'
|
||||||
|
output: 'trivy-results.sarif'
|
||||||
|
|
||||||
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v2
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
sarif_file: 'trivy-results.sarif'
|
||||||
|
```
|
||||||
|
|
||||||
|
See this for more details: https://docs.github.com/en/actions/learn-github-actions/expressions#always
|
||||||
|
|
||||||
### Using Trivy to scan your Git repo
|
### Using Trivy to scan your Git repo
|
||||||
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.
|
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.
|
||||||
|
|
||||||
@@ -112,17 +147,118 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
scan-type: 'fs'
|
scan-type: 'fs'
|
||||||
ignore-unfixed: true
|
ignore-unfixed: true
|
||||||
format: 'template'
|
format: 'sarif'
|
||||||
template: '@/contrib/sarif.tpl'
|
|
||||||
output: 'trivy-results.sarif'
|
output: 'trivy-results.sarif'
|
||||||
severity: 'CRITICAL'
|
severity: 'CRITICAL'
|
||||||
|
|
||||||
- name: Upload Trivy scan results to GitHub Security tab
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
uses: github/codeql-action/upload-sarif@v1
|
uses: github/codeql-action/upload-sarif@v2
|
||||||
with:
|
with:
|
||||||
sarif_file: 'trivy-results.sarif'
|
sarif_file: 'trivy-results.sarif'
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using Trivy to scan your rootfs directories
|
||||||
|
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](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
|
||||||
|
name: build
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Run Trivy vulnerability scanner with rootfs command
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
scan-type: 'rootfs'
|
||||||
|
scan-ref: 'rootfs-example-binary'
|
||||||
|
ignore-unfixed: true
|
||||||
|
format: 'sarif'
|
||||||
|
output: 'trivy-results.sarif'
|
||||||
|
severity: 'CRITICAL'
|
||||||
|
|
||||||
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v2
|
||||||
|
with:
|
||||||
|
sarif_file: 'trivy-results.sarif'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using Trivy to scan Infrastucture as Code
|
||||||
|
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](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
|
||||||
|
name: build
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Run Trivy vulnerability scanner in IaC mode
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
scan-type: 'config'
|
||||||
|
hide-progress: false
|
||||||
|
format: 'table'
|
||||||
|
exit-code: '1'
|
||||||
|
ignore-unfixed: true
|
||||||
|
severity: 'CRITICAL,HIGH'
|
||||||
|
|
||||||
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
|
uses: github/codeql-action/upload-sarif@v2
|
||||||
|
with:
|
||||||
|
sarif_file: 'trivy-results.sarif'
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using Trivy to generate SBOM
|
||||||
|
It's possible for Trivy to generate an SBOM of your dependencies and submit them to a consumer like GitHub Dependency Snapshot.
|
||||||
|
|
||||||
|
The sending of SBOM to GitHub feature is only available if you currently have [GitHub Dependency Snapshot](https://docs.github.com/en/code-security/supply-chain-security/understanding-your-software-supply-chain/using-the-dependency-submission-api) available to you in your repo.
|
||||||
|
|
||||||
|
In order to send results to the GitHub Dependency Snapshot, you will need to create a [GitHub PAT](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
|
||||||
|
```yaml
|
||||||
|
---
|
||||||
|
name: Pull Request
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Checks
|
||||||
|
runs-on: ubuntu-20.04
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Run Trivy in GitHub SBOM mode and submit results to Dependency Snapshots
|
||||||
|
uses: aquasecurity/trivy-action@master
|
||||||
|
with:
|
||||||
|
scan-type: 'fs'
|
||||||
|
format: 'github'
|
||||||
|
output: 'dependency-results.sbom.json'
|
||||||
|
image-ref: '.'
|
||||||
|
github-pat: '<github_pat_token>'
|
||||||
|
```
|
||||||
|
|
||||||
### Using Trivy to scan your private registry
|
### 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.
|
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.
|
||||||
|
|
||||||
@@ -143,20 +279,19 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Run Trivy vulnerability scanner
|
- name: Run Trivy vulnerability scanner
|
||||||
uses: aquasecurity/trivy-action@master
|
uses: aquasecurity/trivy-action@master
|
||||||
with:
|
with:
|
||||||
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
||||||
format: 'template'
|
format: 'sarif'
|
||||||
template: '@/contrib/sarif.tpl'
|
|
||||||
output: 'trivy-results.sarif'
|
output: 'trivy-results.sarif'
|
||||||
env:
|
env:
|
||||||
TRIVY_USERNAME: Username
|
TRIVY_USERNAME: Username
|
||||||
TRIVY_PASSWORD: Password
|
TRIVY_PASSWORD: Password
|
||||||
|
|
||||||
- name: Upload Trivy scan results to GitHub Security tab
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
uses: github/codeql-action/upload-sarif@v1
|
uses: github/codeql-action/upload-sarif@v2
|
||||||
with:
|
with:
|
||||||
sarif_file: 'trivy-results.sarif'
|
sarif_file: 'trivy-results.sarif'
|
||||||
```
|
```
|
||||||
@@ -180,13 +315,12 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Run Trivy vulnerability scanner
|
- name: Run Trivy vulnerability scanner
|
||||||
uses: aquasecurity/trivy-action@master
|
uses: aquasecurity/trivy-action@master
|
||||||
with:
|
with:
|
||||||
image-ref: 'aws_account_id.dkr.ecr.region.amazonaws.com/imageName:${{ github.sha }}'
|
image-ref: 'aws_account_id.dkr.ecr.region.amazonaws.com/imageName:${{ github.sha }}'
|
||||||
format: 'template'
|
format: 'sarif'
|
||||||
template: '@/contrib/sarif.tpl'
|
|
||||||
output: 'trivy-results.sarif'
|
output: 'trivy-results.sarif'
|
||||||
env:
|
env:
|
||||||
AWS_ACCESS_KEY_ID: key_id
|
AWS_ACCESS_KEY_ID: key_id
|
||||||
@@ -194,7 +328,7 @@ jobs:
|
|||||||
AWS_DEFAULT_REGION: us-west-2
|
AWS_DEFAULT_REGION: us-west-2
|
||||||
|
|
||||||
- name: Upload Trivy scan results to GitHub Security tab
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
uses: github/codeql-action/upload-sarif@v1
|
uses: github/codeql-action/upload-sarif@v2
|
||||||
with:
|
with:
|
||||||
sarif_file: 'trivy-results.sarif'
|
sarif_file: 'trivy-results.sarif'
|
||||||
```
|
```
|
||||||
@@ -217,19 +351,18 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Run Trivy vulnerability scanner
|
- name: Run Trivy vulnerability scanner
|
||||||
uses: aquasecurity/trivy-action@master
|
uses: aquasecurity/trivy-action@master
|
||||||
with:
|
with:
|
||||||
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
||||||
format: 'template'
|
format: 'sarif'
|
||||||
template: '@/contrib/sarif.tpl'
|
|
||||||
output: 'trivy-results.sarif'
|
output: 'trivy-results.sarif'
|
||||||
env:
|
env:
|
||||||
GOOGLE_APPLICATION_CREDENTIAL: /path/to/credential.json
|
GOOGLE_APPLICATION_CREDENTIAL: /path/to/credential.json
|
||||||
|
|
||||||
- name: Upload Trivy scan results to GitHub Security tab
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
uses: github/codeql-action/upload-sarif@v1
|
uses: github/codeql-action/upload-sarif@v2
|
||||||
with:
|
with:
|
||||||
sarif_file: 'trivy-results.sarif'
|
sarif_file: 'trivy-results.sarif'
|
||||||
```
|
```
|
||||||
@@ -251,20 +384,19 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Run Trivy vulnerability scanner
|
- name: Run Trivy vulnerability scanner
|
||||||
uses: aquasecurity/trivy-action@master
|
uses: aquasecurity/trivy-action@master
|
||||||
with:
|
with:
|
||||||
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}'
|
||||||
format: 'template'
|
format: 'sarif'
|
||||||
template: '@/contrib/sarif.tpl'
|
|
||||||
output: 'trivy-results.sarif'
|
output: 'trivy-results.sarif'
|
||||||
env:
|
env:
|
||||||
TRIVY_USERNAME: Username
|
TRIVY_USERNAME: Username
|
||||||
TRIVY_PASSWORD: Password
|
TRIVY_PASSWORD: Password
|
||||||
|
|
||||||
- name: Upload Trivy scan results to GitHub Security tab
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
uses: github/codeql-action/upload-sarif@v1
|
uses: github/codeql-action/upload-sarif@v2
|
||||||
with:
|
with:
|
||||||
sarif_file: 'trivy-results.sarif'
|
sarif_file: 'trivy-results.sarif'
|
||||||
```
|
```
|
||||||
@@ -275,23 +407,29 @@ jobs:
|
|||||||
|
|
||||||
Following inputs can be used as `step.with` keys:
|
Following inputs can be used as `step.with` keys:
|
||||||
|
|
||||||
| Name | Type | Default | Description |
|
| Name | Type | Default | Description |
|
||||||
|------------------|---------|------------------------------------|-----------------------------------------------|
|
|-------------------|---------|------------------------------------|-------------------------------------------------------------------------------------------------|
|
||||||
| `scan-type` | String | `image` | Scan type, e.g. `image` or `fs`|
|
| `scan-type` | String | `image` | Scan type, e.g. `image` or `fs` |
|
||||||
| `input` | String | | Tar reference, e.g. `alpine-latest.tar` |
|
| `input` | String | | Tar reference, e.g. `alpine-latest.tar` |
|
||||||
| `image-ref` | String | | Image reference, e.g. `alpine:3.10.2` |
|
| `image-ref` | String | | Image reference, e.g. `alpine:3.10.2` |
|
||||||
| `scan-ref` | String | `/github/workspace/` | Scan reference, e.g. `/github/workspace/` or `.`|
|
| `scan-ref` | String | `/github/workspace/` | Scan reference, e.g. `/github/workspace/` or `.` |
|
||||||
| `format` | String | `table` | Output format (`table`, `json`, `template`) |
|
| `format` | String | `table` | Output format (`table`, `json`, `sarif`, `github`) |
|
||||||
| `template` | String | | Output template (`@/contrib/sarif.tpl`, `@/contrib/gitlab.tpl`, `@/contrib/junit.tpl`)|
|
| `template` | String | | Output template (`@/contrib/gitlab.tpl`, `@/contrib/junit.tpl`) |
|
||||||
| `output` | String | | Save results to a file |
|
| `output` | String | | Save results to a file |
|
||||||
| `exit-code` | String | `0` | Exit code when specified vulnerabilities are found |
|
| `exit-code` | String | `0` | Exit code when specified vulnerabilities are found |
|
||||||
| `ignore-unfixed` | Boolean | false | Ignore unpatched/unfixed vulnerabilities |
|
| `ignore-unfixed` | Boolean | false | Ignore unpatched/unfixed vulnerabilities |
|
||||||
| `vuln-type` | String | `os,library` | Vulnerability types (os,library) |
|
| `vuln-type` | String | `os,library` | Vulnerability types (os,library) |
|
||||||
| `severity` | String | `UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL` | Severities of vulnerabilities to scanned for and displayed |
|
| `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-dirs` | String | | Comma separated list of directories where traversal is skipped |
|
||||||
| `cache-dir` | String | | Cache directory |
|
| `skip-files` | String | | Comma separated list of files where traversal is skipped |
|
||||||
| `timeout` | String | `2m0s` | Scan timeout duration |
|
| `cache-dir` | String | | Cache directory |
|
||||||
| `ignore-policy` | String | | Filter vulnerabilities with OPA rego language |
|
| `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 |
|
||||||
|
| `security-checks` | 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 |
|
||||||
|
| `github-pat` | String | | GitHub Personal Access Token (PAT) for sending SBOM scan results to GitHub Dependency Snapshots |
|
||||||
|
|
||||||
[release]: https://github.com/aquasecurity/trivy-action/releases/latest
|
[release]: https://github.com/aquasecurity/trivy-action/releases/latest
|
||||||
[release-img]: https://img.shields.io/github/release/aquasecurity/trivy-action.svg?logo=github
|
[release-img]: https://img.shields.io/github/release/aquasecurity/trivy-action.svg?logo=github
|
||||||
|
|||||||
+34
-3
@@ -20,7 +20,6 @@ inputs:
|
|||||||
exit-code:
|
exit-code:
|
||||||
description: 'exit code when vulnerabilities were found'
|
description: 'exit code when vulnerabilities were found'
|
||||||
required: false
|
required: false
|
||||||
default: '0'
|
|
||||||
ignore-unfixed:
|
ignore-unfixed:
|
||||||
description: 'ignore unfixed vulnerabilities'
|
description: 'ignore unfixed vulnerabilities'
|
||||||
required: false
|
required: false
|
||||||
@@ -38,7 +37,7 @@ inputs:
|
|||||||
required: false
|
required: false
|
||||||
default: 'table'
|
default: 'table'
|
||||||
template:
|
template:
|
||||||
description: 'use an existing template for rendering output (@/contrib/sarif.tpl, @/contrib/gitlab.tpl, @/contrib/junit.tpl'
|
description: 'use an existing template for rendering output (@/contrib/gitlab.tpl, @/contrib/junit.tpl, @/contrib/html.tpl)'
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
output:
|
output:
|
||||||
@@ -49,18 +48,44 @@ inputs:
|
|||||||
description: 'comma separated list of directories where traversal is skipped'
|
description: 'comma separated list of directories where traversal is skipped'
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
|
skip-files:
|
||||||
|
description: 'comma separated list of files to be skipped'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
cache-dir:
|
cache-dir:
|
||||||
description: 'specify where the cache is stored'
|
description: 'specify where the cache is stored'
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
timeout:
|
timeout:
|
||||||
description: 'timeout (default 2m0s)'
|
description: 'timeout (default 5m0s)'
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
ignore-policy:
|
ignore-policy:
|
||||||
description: 'filter vulnerabilities with OPA rego language'
|
description: 'filter vulnerabilities with OPA rego language'
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
|
hide-progress:
|
||||||
|
description: 'hide progress output'
|
||||||
|
required: false
|
||||||
|
list-all-pkgs:
|
||||||
|
description: 'output all packages regardless of vulnerability'
|
||||||
|
required: false
|
||||||
|
default: 'false'
|
||||||
|
security-checks:
|
||||||
|
description: 'comma-separated list of what security issues to detect'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
trivyignores:
|
||||||
|
description: 'comma-separated list of relative paths in repository to one or more .trivyignore files'
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
artifact-type:
|
||||||
|
description: 'input artifact type (image, fs, repo, archive) for SBOM generation'
|
||||||
|
required: false
|
||||||
|
github-pat:
|
||||||
|
description: 'GitHub Personal Access Token (PAT) for submitting SBOM to GitHub Dependency Snapshot API'
|
||||||
|
required: false
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: "Dockerfile"
|
image: "Dockerfile"
|
||||||
@@ -80,3 +105,9 @@ runs:
|
|||||||
- '-m ${{ inputs.cache-dir }}'
|
- '-m ${{ inputs.cache-dir }}'
|
||||||
- '-n ${{ inputs.timeout }}'
|
- '-n ${{ inputs.timeout }}'
|
||||||
- '-o ${{ inputs.ignore-policy }}'
|
- '-o ${{ inputs.ignore-policy }}'
|
||||||
|
- '-p ${{ inputs.hide-progress }}'
|
||||||
|
- '-q ${{ inputs.skip-files }}'
|
||||||
|
- '-r ${{ inputs.list-all-pkgs }}'
|
||||||
|
- '-s ${{ inputs.security-checks }}'
|
||||||
|
- '-t ${{ inputs.trivyignores }}'
|
||||||
|
- '-u ${{ inputs.github-pat }}'
|
||||||
|
|||||||
+79
-6
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:" o; do
|
while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:" o; do
|
||||||
case "${o}" in
|
case "${o}" in
|
||||||
a)
|
a)
|
||||||
export scanType=${OPTARG}
|
export scanType=${OPTARG}
|
||||||
@@ -47,12 +47,30 @@ while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:" o; do
|
|||||||
o)
|
o)
|
||||||
export ignorePolicy=${OPTARG}
|
export ignorePolicy=${OPTARG}
|
||||||
;;
|
;;
|
||||||
|
p)
|
||||||
|
export hideProgress=${OPTARG}
|
||||||
|
;;
|
||||||
|
q)
|
||||||
|
export skipFiles=${OPTARG}
|
||||||
|
;;
|
||||||
|
r)
|
||||||
|
export listAllPkgs=${OPTARG}
|
||||||
|
;;
|
||||||
|
s)
|
||||||
|
export securityChecks=${OPTARG}
|
||||||
|
;;
|
||||||
|
t)
|
||||||
|
export trivyIgnores=${OPTARG}
|
||||||
|
;;
|
||||||
|
u)
|
||||||
|
export githubPAT=${OPTARG}
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
scanType=$(echo $scanType | tr -d '\r')
|
scanType=$(echo $scanType | tr -d '\r')
|
||||||
export artifactRef="${imageRef}"
|
export artifactRef="${imageRef}"
|
||||||
if [ "${scanType}" = "fs" ];then
|
if [ "${scanType}" = "repo" ] || [ "${scanType}" = "fs" ] || [ "${scanType}" = "config" ] || [ "${scanType}" = "rootfs" ];then
|
||||||
artifactRef=$(echo $scanRef | tr -d '\r')
|
artifactRef=$(echo $scanRef | tr -d '\r')
|
||||||
fi
|
fi
|
||||||
input=$(echo $input | tr -d '\r')
|
input=$(echo $input | tr -d '\r')
|
||||||
@@ -60,13 +78,16 @@ if [ $input ]; then
|
|||||||
artifactRef="--input $input"
|
artifactRef="--input $input"
|
||||||
fi
|
fi
|
||||||
ignoreUnfixed=$(echo $ignoreUnfixed | tr -d '\r')
|
ignoreUnfixed=$(echo $ignoreUnfixed | tr -d '\r')
|
||||||
|
hideProgress=$(echo $hideProgress | tr -d '\r')
|
||||||
|
|
||||||
GLOBAL_ARGS=""
|
GLOBAL_ARGS=""
|
||||||
if [ $cacheDir ];then
|
if [ $cacheDir ];then
|
||||||
GLOBAL_ARGS="$GLOBAL_ARGS --cache-dir $cacheDir"
|
GLOBAL_ARGS="$GLOBAL_ARGS --cache-dir $cacheDir"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
SARIF_ARGS=""
|
||||||
ARGS=""
|
ARGS=""
|
||||||
|
format=$(echo $format | xargs)
|
||||||
if [ $format ];then
|
if [ $format ];then
|
||||||
ARGS="$ARGS --format $format"
|
ARGS="$ARGS --format $format"
|
||||||
fi
|
fi
|
||||||
@@ -76,11 +97,16 @@ fi
|
|||||||
if [ $exitCode ];then
|
if [ $exitCode ];then
|
||||||
ARGS="$ARGS --exit-code $exitCode"
|
ARGS="$ARGS --exit-code $exitCode"
|
||||||
fi
|
fi
|
||||||
if [ "$ignoreUnfixed" == "true" ];then
|
if [ "$ignoreUnfixed" == "true" ] && [ "$scanType" != "config" ];then
|
||||||
ARGS="$ARGS --ignore-unfixed"
|
ARGS="$ARGS --ignore-unfixed"
|
||||||
|
SARIF_ARGS="$SARIF_ARGS --ignore-unfixed"
|
||||||
fi
|
fi
|
||||||
if [ $vulnType ];then
|
if [ $vulnType ] && [ "$scanType" != "config" ] && [ "$scanType" != "sbom" ];then
|
||||||
ARGS="$ARGS --vuln-type $vulnType"
|
ARGS="$ARGS --vuln-type $vulnType"
|
||||||
|
SARIF_ARGS="$SARIF_ARGS --vuln-type $vulnType"
|
||||||
|
fi
|
||||||
|
if [ $securityChecks ];then
|
||||||
|
ARGS="$ARGS --security-checks $securityChecks"
|
||||||
fi
|
fi
|
||||||
if [ $severity ];then
|
if [ $severity ];then
|
||||||
ARGS="$ARGS --severity $severity"
|
ARGS="$ARGS --severity $severity"
|
||||||
@@ -92,15 +118,62 @@ if [ $skipDirs ];then
|
|||||||
for i in $(echo $skipDirs | tr "," "\n")
|
for i in $(echo $skipDirs | tr "," "\n")
|
||||||
do
|
do
|
||||||
ARGS="$ARGS --skip-dirs $i"
|
ARGS="$ARGS --skip-dirs $i"
|
||||||
|
SARIF_ARGS="$SARIF_ARGS --skip-dirs $i"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
if [ $trivyIgnores ];then
|
||||||
|
for f in $(echo $trivyIgnores | tr "," "\n")
|
||||||
|
do
|
||||||
|
if [ -f "$f" ]; then
|
||||||
|
echo "Found ignorefile '${f}':"
|
||||||
|
cat "${f}"
|
||||||
|
cat "${f}" >> ./trivyignores
|
||||||
|
else
|
||||||
|
echo "ERROR: cannot find ignorefile '${f}'."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
ARGS="$ARGS --ignorefile ./trivyignores"
|
||||||
|
fi
|
||||||
if [ $timeout ];then
|
if [ $timeout ];then
|
||||||
ARGS="$ARGS --timeout $timeout"
|
ARGS="$ARGS --timeout $timeout"
|
||||||
fi
|
fi
|
||||||
if [ $ignorePolicy ];then
|
if [ $ignorePolicy ];then
|
||||||
ARGS="$ARGS --ignore-policy $ignorePolicy"
|
ARGS="$ARGS --ignore-policy $ignorePolicy"
|
||||||
|
SARIF_ARGS="$SARIF_ARGS --ignore-policy $ignorePolicy"
|
||||||
|
fi
|
||||||
|
if [ "$hideProgress" == "true" ];then
|
||||||
|
ARGS="$ARGS --no-progress"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Running trivy with options: " --no-progress "${ARGS}" "${artifactRef}"
|
listAllPkgs=$(echo $listAllPkgs | tr -d '\r')
|
||||||
|
if [ "$listAllPkgs" == "true" ];then
|
||||||
|
ARGS="$ARGS --list-all-pkgs"
|
||||||
|
fi
|
||||||
|
if [ "$skipFiles" ];then
|
||||||
|
for i in $(echo $skipFiles | tr "," "\n")
|
||||||
|
do
|
||||||
|
ARGS="$ARGS --skip-files $i"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Running trivy with options: ${ARGS}" "${artifactRef}"
|
||||||
echo "Global options: " "${GLOBAL_ARGS}"
|
echo "Global options: " "${GLOBAL_ARGS}"
|
||||||
trivy $GLOBAL_ARGS ${scanType} --no-progress $ARGS ${artifactRef}
|
trivy $GLOBAL_ARGS ${scanType} $ARGS ${artifactRef}
|
||||||
|
returnCode=$?
|
||||||
|
|
||||||
|
# SARIF is special. We output all vulnerabilities,
|
||||||
|
# regardless of severity level specified in this report.
|
||||||
|
# This is a feature, not a bug :)
|
||||||
|
if [[ "${format}" == "sarif" ]]; then
|
||||||
|
echo "Building SARIF report with options: ${SARIF_ARGS}" "${artifactRef}"
|
||||||
|
trivy --quiet ${scanType} --format sarif --output ${output} $SARIF_ARGS ${artifactRef}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${format}" == "github" ]] && [[ "$(echo $githubPAT | xargs)" != "" ]]; then
|
||||||
|
echo "Uploading GitHub Dependency Snapshot"
|
||||||
|
curl -u "${githubPAT}" -H 'Content-Type: application/json' 'https://api.github.com/repos/'$GITHUB_REPOSITORY'/dependency-graph/snapshots' -d @./$(echo $output | xargs)
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "returnCode: " $returnCode
|
||||||
|
exit $returnCode
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# test data #1 for trivy-ignores option
|
||||||
|
CVE-2020-25576
|
||||||
|
CVE-2019-15551
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
# test data #2 for trivy-ignores option
|
||||||
|
CVE-2019-15554
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
{
|
||||||
|
"SchemaVersion": 2,
|
||||||
|
"ArtifactName": ".",
|
||||||
|
"ArtifactType": "filesystem",
|
||||||
|
"Metadata": {
|
||||||
|
"ImageConfig": {
|
||||||
|
"architecture": "",
|
||||||
|
"created": "0001-01-01T00:00:00Z",
|
||||||
|
"os": "",
|
||||||
|
"rootfs": {
|
||||||
|
"type": "",
|
||||||
|
"diff_ids": null
|
||||||
|
},
|
||||||
|
"config": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Results": [
|
||||||
|
{
|
||||||
|
"Target": "Dockerfile",
|
||||||
|
"Class": "config",
|
||||||
|
"Type": "dockerfile",
|
||||||
|
"MisconfSummary": {
|
||||||
|
"Successes": 21,
|
||||||
|
"Failures": 1,
|
||||||
|
"Exceptions": 0
|
||||||
|
},
|
||||||
|
"Misconfigurations": [
|
||||||
|
{
|
||||||
|
"Type": "Dockerfile Security Check",
|
||||||
|
"ID": "DS002",
|
||||||
|
"Title": "Image user should not be 'root'",
|
||||||
|
"Description": "Running containers with 'root' user can lead to a container escape situation. It is a best practice to run containers as non-root users, which can be done by adding a 'USER' statement to the Dockerfile.",
|
||||||
|
"Message": "Specify at least 1 USER command in Dockerfile with non-root user as argument",
|
||||||
|
"Namespace": "builtin.dockerfile.DS002",
|
||||||
|
"Query": "data.builtin.dockerfile.DS002.deny",
|
||||||
|
"Resolution": "Add 'USER \u003cnon root user name\u003e' line to the Dockerfile",
|
||||||
|
"Severity": "HIGH",
|
||||||
|
"PrimaryURL": "https://avd.aquasec.com/misconfig/ds002",
|
||||||
|
"References": [
|
||||||
|
"https://docs.docker.com/develop/develop-images/dockerfile_best-practices/",
|
||||||
|
"https://avd.aquasec.com/misconfig/ds002"
|
||||||
|
],
|
||||||
|
"Status": "FAIL",
|
||||||
|
"Layer": {},
|
||||||
|
"CauseMetadata": {
|
||||||
|
"Provider": "Dockerfile",
|
||||||
|
"Service": "general",
|
||||||
|
"Code": {
|
||||||
|
"Lines": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
{
|
||||||
|
"SchemaVersion": 2,
|
||||||
|
"ArtifactName": ".",
|
||||||
|
"ArtifactType": "filesystem",
|
||||||
|
"Metadata": {
|
||||||
|
"ImageConfig": {
|
||||||
|
"architecture": "",
|
||||||
|
"created": "0001-01-01T00:00:00Z",
|
||||||
|
"os": "",
|
||||||
|
"rootfs": {
|
||||||
|
"type": "",
|
||||||
|
"diff_ids": null
|
||||||
|
},
|
||||||
|
"config": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Results": [
|
||||||
|
{
|
||||||
|
"Target": "Dockerfile",
|
||||||
|
"Class": "config",
|
||||||
|
"Type": "dockerfile",
|
||||||
|
"MisconfSummary": {
|
||||||
|
"Successes": 21,
|
||||||
|
"Failures": 1,
|
||||||
|
"Exceptions": 0
|
||||||
|
},
|
||||||
|
"Misconfigurations": [
|
||||||
|
{
|
||||||
|
"Type": "Dockerfile Security Check",
|
||||||
|
"ID": "DS002",
|
||||||
|
"Title": "Image user should not be 'root'",
|
||||||
|
"Description": "Running containers with 'root' user can lead to a container escape situation. It is a best practice to run containers as non-root users, which can be done by adding a 'USER' statement to the Dockerfile.",
|
||||||
|
"Message": "Specify at least 1 USER command in Dockerfile with non-root user as argument",
|
||||||
|
"Namespace": "builtin.dockerfile.DS002",
|
||||||
|
"Query": "data.builtin.dockerfile.DS002.deny",
|
||||||
|
"Resolution": "Add 'USER \u003cnon root user name\u003e' line to the Dockerfile",
|
||||||
|
"Severity": "HIGH",
|
||||||
|
"PrimaryURL": "https://avd.aquasec.com/misconfig/ds002",
|
||||||
|
"References": [
|
||||||
|
"https://docs.docker.com/develop/develop-images/dockerfile_best-practices/",
|
||||||
|
"https://avd.aquasec.com/misconfig/ds002"
|
||||||
|
],
|
||||||
|
"Status": "FAIL",
|
||||||
|
"Layer": {},
|
||||||
|
"CauseMetadata": {
|
||||||
|
"Provider": "Dockerfile",
|
||||||
|
"Service": "general",
|
||||||
|
"Code": {
|
||||||
|
"Lines": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"SchemaVersion": 2,
|
||||||
|
"ArtifactName": ".",
|
||||||
|
"ArtifactType": "filesystem",
|
||||||
|
"Metadata": {
|
||||||
|
"ImageConfig": {
|
||||||
|
"architecture": "",
|
||||||
|
"created": "0001-01-01T00:00:00Z",
|
||||||
|
"os": "",
|
||||||
|
"rootfs": {
|
||||||
|
"type": "",
|
||||||
|
"diff_ids": null
|
||||||
|
},
|
||||||
|
"config": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,34 @@
|
|||||||
|
{
|
||||||
|
"SchemaVersion": 2,
|
||||||
|
"ArtifactName": "https://github.com/krol3/demo-trivy/",
|
||||||
|
"ArtifactType": "repository",
|
||||||
|
"Metadata": {
|
||||||
|
"ImageConfig": {
|
||||||
|
"architecture": "",
|
||||||
|
"created": "0001-01-01T00:00:00Z",
|
||||||
|
"os": "",
|
||||||
|
"rootfs": {
|
||||||
|
"type": "",
|
||||||
|
"diff_ids": null
|
||||||
|
},
|
||||||
|
"config": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Results": [
|
||||||
|
{
|
||||||
|
"Target": "env",
|
||||||
|
"Class": "secret",
|
||||||
|
"Secrets": [
|
||||||
|
{
|
||||||
|
"RuleID": "github-pat",
|
||||||
|
"Category": "GitHub",
|
||||||
|
"Severity": "CRITICAL",
|
||||||
|
"Title": "GitHub Personal Access Token",
|
||||||
|
"StartLine": 5,
|
||||||
|
"EndLine": 5,
|
||||||
|
"Match": "export GITHUB_PAT=*****"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"SchemaVersion": 2,
|
||||||
|
"ArtifactName": ".",
|
||||||
|
"ArtifactType": "filesystem",
|
||||||
|
"Metadata": {
|
||||||
|
"ImageConfig": {
|
||||||
|
"architecture": "",
|
||||||
|
"created": "0001-01-01T00:00:00Z",
|
||||||
|
"os": "",
|
||||||
|
"rootfs": {
|
||||||
|
"type": "",
|
||||||
|
"diff_ids": null
|
||||||
|
},
|
||||||
|
"config": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/env bats
|
||||||
|
load '/usr/lib/bats-support/load.bash'
|
||||||
|
load '/usr/lib/bats-assert/load.bash'
|
||||||
|
|
||||||
|
@test "trivy image" {
|
||||||
|
# trivy image --severity CRITICAL --format json --output image.test knqyf263/vuln-image:1.2.3
|
||||||
|
./entrypoint.sh '-a image' '-i knqyf263/vuln-image:1.2.3' '-b json' '-h image.test' '-g CRITICAL'
|
||||||
|
result="$(diff ./test/data/image.test image.test)"
|
||||||
|
[ "$result" == '' ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "trivy image sarif report" {
|
||||||
|
# trivy image --severity CRITICAL -f sarif --output image-sarif.test knqyf263/vuln-image:1.2.3
|
||||||
|
./entrypoint.sh '-a image' '-i knqyf263/vuln-image:1.2.3' '-b sarif' '-h image-sarif.test' '-g CRITICAL'
|
||||||
|
result="$(diff ./test/data/image-sarif.test image-sarif.test)"
|
||||||
|
[ "$result" == '' ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "trivy config" {
|
||||||
|
# trivy config --format json --output config.test .
|
||||||
|
./entrypoint.sh '-a config' '-j .' '-b json' '-h config.test'
|
||||||
|
result="$(diff ./test/data/config.test config.test)"
|
||||||
|
[ "$result" == '' ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "trivy rootfs" {
|
||||||
|
# trivy rootfs --format json --output rootfs.test .
|
||||||
|
./entrypoint.sh '-a rootfs' '-j .' '-b json' '-h rootfs.test'
|
||||||
|
result="$(diff ./test/data/rootfs.test rootfs.test)"
|
||||||
|
[ "$result" == '' ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "trivy fs" {
|
||||||
|
# trivy fs --format json --output fs.test .
|
||||||
|
./entrypoint.sh '-a fs' '-j .' '-b json' '-h fs.test'
|
||||||
|
result="$(diff ./test/data/fs.test fs.test)"
|
||||||
|
[ "$result" == '' ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "trivy fs with securityChecks option" {
|
||||||
|
# trivy fs --format json --security-checks=vuln,config --output fs-scheck.test .
|
||||||
|
./entrypoint.sh '-a fs' '-j .' '-b json' '-s vuln,config,secret' '-h fs-scheck.test'
|
||||||
|
result="$(diff ./test/data/fs-scheck.test fs-scheck.test)"
|
||||||
|
[ "$result" == '' ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "trivy repo with securityCheck secret only" {
|
||||||
|
# trivy repo --format json --output repo.test --security-checks=secret https://github.com/krol3/demo-trivy/
|
||||||
|
./entrypoint.sh '-b json' '-h repo.test' '-s secret' '-a repo' '-j https://github.com/krol3/demo-trivy/'
|
||||||
|
result="$(diff ./test/data/repo.test repo.test)"
|
||||||
|
[ "$result" == '' ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "trivy image with trivyIgnores option" {
|
||||||
|
# cat ./test/data/.trivyignore1 ./test/data/.trivyignore2 > ./trivyignores ; trivy image --severity CRITICAL --format json --output image-trivyignores.test --ignorefile ./trivyignores knqyf263/vuln-image:1.2.3
|
||||||
|
./entrypoint.sh '-a image' '-i knqyf263/vuln-image:1.2.3' '-b json' '-h image-trivyignores.test' '-g CRITICAL' '-t ./test/data/.trivyignore1,./test/data/.trivyignore2'
|
||||||
|
result="$(diff ./test/data/image-trivyignores.test image-trivyignores.test)"
|
||||||
|
[ "$result" == '' ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "trivy image with sbom output" {
|
||||||
|
# trivy image --format github knqyf263/vuln-image:1.2.3
|
||||||
|
run ./entrypoint.sh "-a image" "-b github" "-i knqyf263/vuln-image:1.2.3"
|
||||||
|
assert_output --partial '"package_url": "pkg:apk/ca-certificates@20171114-r0",' # TODO: Output contains time, need to mock
|
||||||
|
}
|
||||||
+1
-1
@@ -29,6 +29,6 @@ jobs:
|
|||||||
severity: 'CRITICAL,HIGH'
|
severity: 'CRITICAL,HIGH'
|
||||||
|
|
||||||
- name: Upload Trivy scan results to GitHub Security tab
|
- name: Upload Trivy scan results to GitHub Security tab
|
||||||
uses: github/codeql-action/upload-sarif@v1
|
uses: github/codeql-action/upload-sarif@v2
|
||||||
with:
|
with:
|
||||||
sarif_file: 'trivy-results.sarif'
|
sarif_file: 'trivy-results.sarif'
|
||||||
|
|||||||
Reference in New Issue
Block a user