-
Notifications
You must be signed in to change notification settings - Fork 1.1k
68 lines (60 loc) · 2.21 KB
/
Copy pathimage-vulnerability.yml
File metadata and controls
68 lines (60 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Scan Docker Image Vulnerabilities
on:
# Trigger the workflow on push or pull request,
# but only for the main and release branches
push:
branches:
- master
- 'releases/**'
pull_request:
branches:
- master
- 'releases/**'
merge_group:
jobs:
docker-build-and-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
run: |
docker build -t skypilot-test:${{ github.sha }} .
- name: Run Trivy vulnerability scanner
id: trivy_scan
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.1
with:
image-ref: skypilot-test:${{ github.sha }}
format: 'json'
output: trivy-results.json
exit-code: '0'
ignore-unfixed: true
vuln-type: 'os,library'
scanners: 'vuln'
severity: 'HIGH,CRITICAL'
trivyignores: .trivyignore
- name: Evaluate Trivy scan results
run: |
mapfile -t high_vulns < <(jq -r '
.Results[]? as $result
| $result.Vulnerabilities[]?
| select(.Severity=="HIGH")
| "- \(.VulnerabilityID) | \(.PkgName) \(.InstalledVersion) -> \(.FixedVersion // "N/A") | component: \($result.Target // "unknown")"
' trivy-results.json)
if [ "${#high_vulns[@]}" -gt 0 ]; then
echo "::warning::Trivy found ${#high_vulns[@]} high severity vulnerabilities:"
printf '%s\n' "${high_vulns[@]}"
fi
mapfile -t critical_vulns < <(jq -r '
.Results[]? as $result
| $result.Vulnerabilities[]?
| select(.Severity=="CRITICAL")
| "- \(.VulnerabilityID) | \(.PkgName) \(.InstalledVersion) -> \(.FixedVersion // "N/A") | component: \($result.Target // "unknown")"
' trivy-results.json)
if [ "${#critical_vulns[@]}" -gt 0 ]; then
echo "Critical vulnerabilities detected (${#critical_vulns[@]}):"
printf '%s\n' "${critical_vulns[@]}"
exit 1
fi