Compare commits

..

6 Commits

Author SHA1 Message Date
Simar eeb939f8a9 debug 2022-06-28 17:15:06 -07:00
simar7 7b7aa264d8 feat(SBOM): Support SBOM generation (#129)
* feat(sbom): Support SBOM generation

Signed-off-by: Simar <simar@linux.com>

* Update README.md

Co-authored-by: Itay Shakury <itay@itaysk.com>

* feat(sbom): Send results within the entrypoint.sh

* fix(sbom): Fix leading whitespaces for format var.

Signed-off-by: Simar <simar@linux.com>

* docs(sbom): Update README.md

* docs(sbom): Update README.md

* chore(trivy): Bump Trivy version to 0.29.1

Signed-off-by: Simar <simar@linux.com>

* feat(sbom): Change to fs scan.

Signed-off-by: Simar <simar@linux.com>

* fix(tests): Update SARIF goldenfile

Co-authored-by: Itay Shakury <itay@itaysk.com>
2022-06-22 11:24:39 -07:00
nleconte-csgroup 63b6e4c61b docs: added missing HTML template and removed deprecated SARIF template (#132)
* docs: add missing template

* docs: add missing template and remove deprecated

Add missing HTML template
Remove deprecated SARIF template

* docs: remove deprecated SARIF template
2022-06-21 11:46:57 -07:00
Carol Valencia 49e970d7ac chore: pinning 0.29.0 trivy (#128)
Co-authored-by: carolina valencia <krol3@users.noreply.github.com>
2022-06-17 13:27:39 -07:00
Achton Smidt Winther c666240787 Add missing option to README. (#127) 2022-06-16 08:25:13 -07:00
David Calvert e27605859b feat: update codeql-action/upload-sarif to v2 (#124) 2022-06-15 09:16:34 -07:00
10 changed files with 2618 additions and 94 deletions
+4 -1
View File
@@ -1,7 +1,7 @@
name: "build" name: "build"
on: [push, pull_request] on: [push, pull_request]
env: env:
TRIVY_VERSION: 0.28.1 TRIVY_VERSION: 0.29.1
jobs: jobs:
build: build:
name: build name: build
@@ -13,6 +13,9 @@ jobs:
with: with:
bats-version: 1.2.1 bats-version: 1.2.1
- name: Setup Bats libs
uses: brokenpip3/setup-bats-libs@0.1.0
- name: Check out code - name: Check out code
uses: actions/checkout@v1 uses: actions/checkout@v1
+2 -2
View File
@@ -1,5 +1,5 @@
FROM ghcr.io/aquasecurity/trivy:0.28.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"]
+64 -30
View File
@@ -80,7 +80,7 @@ jobs:
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'
``` ```
@@ -115,7 +115,7 @@ jobs:
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
if: always() if: always()
with: with:
sarif_file: 'trivy-results.sarif' sarif_file: 'trivy-results.sarif'
@@ -152,7 +152,7 @@ jobs:
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'
``` ```
@@ -187,7 +187,7 @@ jobs:
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'
``` ```
@@ -222,11 +222,43 @@ 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'
``` ```
### 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.
@@ -259,7 +291,7 @@ jobs:
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'
``` ```
@@ -296,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'
``` ```
@@ -330,7 +362,7 @@ jobs:
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'
``` ```
@@ -364,7 +396,7 @@ jobs:
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'
``` ```
@@ -375,27 +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`, `sarif`) | | `format` | String | `table` | Output format (`table`, `json`, `sarif`, `github`) |
| `template` | String | | Output template (`@/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 |
| `skip-files` | String | | Comma separated list of files where traversal is skipped | | `skip-files` | String | | Comma separated list of files where traversal is skipped |
| `cache-dir` | String | | Cache directory | | `cache-dir` | String | | Cache directory |
| `timeout` | String | `5m0s` | Scan timeout duration | | `timeout` | String | `5m0s` | Scan timeout duration |
| `ignore-policy` | String | | Filter vulnerabilities with OPA rego language | | `ignore-policy` | String | | Filter vulnerabilities with OPA rego language |
| `list-all-pkgs` | String | | Output all packages regardless of vulnerability | | `hide-progress` | String | `true` | Suppress progress bar |
| `security-checks`| String | `vuln,secret` | comma-separated list of what security issues to detect (`vuln`,`secret`,`config`)| | `list-all-pkgs` | String | | Output all packages regardless of vulnerability |
| `trivyignores` | String | | comma-separated list of relative paths in repository to one or more `.trivyignore` files | | `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
+9 -3
View File
@@ -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:
@@ -68,7 +67,6 @@ inputs:
hide-progress: hide-progress:
description: 'hide progress output' description: 'hide progress output'
required: false required: false
default: 'true'
list-all-pkgs: list-all-pkgs:
description: 'output all packages regardless of vulnerability' description: 'output all packages regardless of vulnerability'
required: false required: false
@@ -81,6 +79,13 @@ inputs:
description: 'comma-separated list of relative paths in repository to one or more .trivyignore files' description: 'comma-separated list of relative paths in repository to one or more .trivyignore files'
required: false required: false
default: '' 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"
@@ -105,3 +110,4 @@ runs:
- '-r ${{ inputs.list-all-pkgs }}' - '-r ${{ inputs.list-all-pkgs }}'
- '-s ${{ inputs.security-checks }}' - '-s ${{ inputs.security-checks }}'
- '-t ${{ inputs.trivyignores }}' - '-t ${{ inputs.trivyignores }}'
- '-u ${{ inputs.github-pat }}'
+12 -2
View File
@@ -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:p:q:r:s:t:" 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}
@@ -62,6 +62,9 @@ while getopts "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:" o; do
t) t)
export trivyIgnores=${OPTARG} export trivyIgnores=${OPTARG}
;; ;;
u)
export githubPAT=${OPTARG}
;;
esac esac
done done
@@ -84,6 +87,7 @@ fi
SARIF_ARGS="" SARIF_ARGS=""
ARGS="" ARGS=""
format=$(echo $format | xargs)
if [ $format ];then if [ $format ];then
ARGS="$ARGS --format $format" ARGS="$ARGS --format $format"
fi fi
@@ -97,7 +101,7 @@ if [ "$ignoreUnfixed" == "true" ] && [ "$scanType" != "config" ];then
ARGS="$ARGS --ignore-unfixed" ARGS="$ARGS --ignore-unfixed"
SARIF_ARGS="$SARIF_ARGS --ignore-unfixed" SARIF_ARGS="$SARIF_ARGS --ignore-unfixed"
fi fi
if [ $vulnType ] && [ "$scanType" != "config" ];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" SARIF_ARGS="$SARIF_ARGS --vuln-type $vulnType"
fi fi
@@ -166,4 +170,10 @@ if [[ "${format}" == "sarif" ]]; then
trivy --quiet ${scanType} --format sarif --output ${output} $SARIF_ARGS ${artifactRef} trivy --quiet ${scanType} --format sarif --output ${output} $SARIF_ARGS ${artifactRef}
fi 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 exit $returnCode
+1 -1
View File
@@ -20,7 +20,7 @@
"Class": "config", "Class": "config",
"Type": "dockerfile", "Type": "dockerfile",
"MisconfSummary": { "MisconfSummary": {
"Successes": 22, "Successes": 21,
"Failures": 1, "Failures": 1,
"Exceptions": 0 "Exceptions": 0
}, },
+1 -1
View File
@@ -20,7 +20,7 @@
"Class": "config", "Class": "config",
"Type": "dockerfile", "Type": "dockerfile",
"MisconfSummary": { "MisconfSummary": {
"Successes": 22, "Successes": 21,
"Failures": 1, "Failures": 1,
"Exceptions": 0 "Exceptions": 0
}, },
+2516 -53
View File
File diff suppressed because it is too large Load Diff
+8
View File
@@ -1,4 +1,6 @@
#!/usr/bin/env bats #!/usr/bin/env bats
load '/usr/lib/bats-support/load.bash'
load '/usr/lib/bats-assert/load.bash'
@test "trivy image" { @test "trivy image" {
# trivy image --severity CRITICAL --format json --output image.test knqyf263/vuln-image:1.2.3 # trivy image --severity CRITICAL --format json --output image.test knqyf263/vuln-image:1.2.3
@@ -55,3 +57,9 @@
result="$(diff ./test/data/image-trivyignores.test image-trivyignores.test)" result="$(diff ./test/data/image-trivyignores.test image-trivyignores.test)"
[ "$result" == '' ] [ "$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
View File
@@ -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'