diff --git a/.github/workflows/trivy.yml b/.github/workflows/trivy.yml new file mode 100644 index 0000000000..6c03920d01 --- /dev/null +++ b/.github/workflows/trivy.yml @@ -0,0 +1,52 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: trivy + +on: + push: + branches: + - '*' + pull_request: + branches: + - '*' + schedule: + - cron: '39 17 * * 3' + +permissions: + contents: read + +jobs: + build: + permissions: + contents: read # for actions/checkout to fetch code + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + #- 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@7b7aa264d83dc58691451798b4d117d53d21edfe + with: + # image-ref: 'docker.io/my-organization/my-app:${{ github.sha }}' + scan-type: 'fs' + scan-ref: '.' + template: '/sarif.tpl' + output: 'trivy-scan-results.sarif' + severity: 'CRITICAL,HIGH' + + - name: Upload Trivy scan results to GitHub Security tab + uses: github/codeql-action/upload-sarif@v2 + with: + name: trivy-results + path: trivy-scan-results.sarif + sarif_file: 'trivy-scan-results.sarif' diff --git a/sarif.tpl b/sarif.tpl new file mode 100644 index 0000000000..0f291ff785 --- /dev/null +++ b/sarif.tpl @@ -0,0 +1,58 @@ +{ + "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", + "version": "2.1.0", + "runs": [ + { + "tool": { + "driver": { + "name": "Trivy", + "version": "0.12.0" + } + }, + "results": [ + { + "ruleId": "Vulnerability", + "level": "error", + "message": { + "text": "Critical vulnerability found in the Docker image." + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "https://example.com/repo/docker-image.tar.gz" + } + } + } + ], + "properties": { + "severity": "Critical", + "vulnerabilityId": "CVE-2021-12345", + "description": "Description of the vulnerability." + } + }, + { + "ruleId": "Vulnerability", + "level": "warning", + "message": { + "text": "Medium severity vulnerability found in the Docker image." + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "https://example.com/repo/docker-image.tar.gz" + } + } + } + ], + "properties": { + "severity": "Medium", + "vulnerabilityId": "CVE-2021-67890", + "description": "Description of the vulnerability." + } + } + ] + } + ] +} diff --git a/trivy-scan-results-sarif b/trivy-scan-results-sarif new file mode 100644 index 0000000000..67ccfdc1d3 --- /dev/null +++ b/trivy-scan-results-sarif @@ -0,0 +1,73 @@ +{ + "$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json", + "version": "2.1.0", + "runs": [ + { + "tool": { + "driver": { + "name": "Trivy", + "version": "0.12.0", + "informationUri": "https://github.com/aquasecurity/trivy", + "rules": [ + { + "id": "TRIVY_SCAN_RESULT", + "name": "Trivy Vulnerability Scan Result", + "shortDescription": { + "text": "Trivy scan result for vulnerabilities" + }, + "fullDescription": { + "text": "Trivy scan result for vulnerabilities found in the scanned image." + } + } + ] + } + }, + "results": [ + { + "ruleId": "TRIVY_SCAN_RESULT", + "level": "error", + "message": { + "text": "High severity vulnerability found in package XYZ" + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "file:///path/to/scanned/image" + } + } + } + ], + "properties": { + "CVE": "CVE-2021-1234", + "package": "XYZ", + "version": "1.2.3", + "severity": "High" + } + }, + { + "ruleId": "TRIVY_SCAN_RESULT", + "level": "warning", + "message": { + "text": "Medium severity vulnerability found in package ABC" + }, + "locations": [ + { + "physicalLocation": { + "artifactLocation": { + "uri": "file:///path/to/scanned/image" + } + } + } + ], + "properties": { + "CVE": "CVE-2021-5678", + "package": "ABC", + "version": "4.5.6", + "severity": "Medium" + } + } + ] + } + ] +}