Skip to content

Commit b695faf

Browse files
committed
build: cve scan
1 parent a038e9e commit b695faf

File tree

2 files changed

+68
-34
lines changed

2 files changed

+68
-34
lines changed

.github/workflows/reusable-cve-scan-main.yml

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CVE Scan Main
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
image_tag:
7+
description: 'Image tag to scan'
8+
required: true
9+
type: string
10+
severities:
11+
description: 'Severities to include in the scan'
12+
required: false
13+
default: 'CRITICAL,HIGH'
14+
type: string
15+
add_to_github_security:
16+
description: 'Whether to add the scan results to the GitHub Security tab'
17+
required: false
18+
default: false
19+
type: boolean
20+
trivy_version:
21+
description: 'Trivy version to use'
22+
required: false
23+
default: 'v0.67.2'
24+
type: string
25+
26+
jobs:
27+
cve_scan:
28+
permissions:
29+
security-events: write
30+
runs-on: ubuntu-latest
31+
steps:
32+
- name: Run Trivy
33+
uses: aquasecurity/[email protected]
34+
with:
35+
image-ref: 'ghcr.io/${{ github.repository }}:${{ inputs.image_tag }}'
36+
format: 'table'
37+
ignore-unfixed: true
38+
severity: ${{ inputs.severities }}
39+
output: 'trivy-results.table'
40+
version: ${{ inputs.trivy_version }}
41+
exit-code: 1
42+
43+
- name: Append Trivy results to Step Summary
44+
if: always()
45+
run: |
46+
while IFS= read -r line; do
47+
if [[ $line == "┌"* ]]; then echo '```' >> $GITHUB_STEP_SUMMARY; fi
48+
echo "$line" >> $GITHUB_STEP_SUMMARY
49+
if [[ $line == *"┘" ]]; then echo '```' >> $GITHUB_STEP_SUMMARY; fi
50+
done < "trivy-results.table"
51+
52+
- name: Run Trivy again for Github Security
53+
uses: aquasecurity/[email protected]
54+
if: ${{ always() && inputs.add_to_github_security }}
55+
with:
56+
image-ref: 'ghcr.io/${{ github.repository }}:${{ inputs.image_tag }}'
57+
format: 'sarif'
58+
ignore-unfixed: true
59+
severity: ${{ inputs.severities }}
60+
output: 'trivy-results.sarif'
61+
version: '${{ inputs.trivy_version }}
62+
skip-setup-trivy: 'true'
63+
64+
- name: Upload Trivy scan results to GitHub Security tab
65+
uses: github/codeql-action/upload-sarif@v3
66+
if: ${{ always() && inputs.add_to_github_security }}
67+
with:
68+
sarif_file: 'trivy-results.sarif'

0 commit comments

Comments
 (0)