-
Notifications
You must be signed in to change notification settings - Fork 4
129 lines (110 loc) · 4.03 KB
/
Copy pathpr-security-scan.yml
File metadata and controls
129 lines (110 loc) · 4.03 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: PR Security Scan
on:
pull_request:
branches:
- "**"
merge_group:
types:
- checks_requested
permissions:
contents: read
security-events: write
pull-requests: write # For adding comments to PRs
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
TRIVY_SEVERITY: "CRITICAL,HIGH,MEDIUM,LOW"
jobs:
build-and-scan:
runs-on: ubuntu-latest
strategy:
matrix:
image:
- name: "refiner-app"
dockerfile: "Dockerfile.app"
- name: "refiner-lambda"
dockerfile: "Dockerfile.lambda"
- name: "refiner-ops"
dockerfile: "Dockerfile.ops"
fail-fast: false
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build image locally (no push)
uses: docker/build-push-action@v7
with:
context: .
file: ${{ matrix.image.dockerfile }}
load: true # Load locally for scanning only
tags: local-scan/${{ matrix.image.name }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Run Trivy vulnerability scanner (SARIF)
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
with:
image-ref: local-scan/${{ matrix.image.name }}:${{ github.sha }}
format: "sarif"
output: "trivy-${{ matrix.image.name }}-results.sarif"
severity: ${{ env.TRIVY_SEVERITY }}
ignore-unfixed: true
timeout: "10m"
- name: Run Trivy vulnerability scanner (JSON for PR comment)
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
with:
image-ref: local-scan/${{ matrix.image.name }}:${{ github.sha }}
format: "json"
output: "trivy-${{ matrix.image.name }}-results.json"
severity: ${{ env.TRIVY_SEVERITY }}
ignore-unfixed: true
timeout: "10m"
- name: Display Trivy results as table
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # v0.35.0
with:
image-ref: local-scan/${{ matrix.image.name }}:${{ github.sha }}
format: "table"
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: "trivy-${{ matrix.image.name }}-results.sarif"
category: "pr-scan-${{ matrix.image.name }}"
- name: Upload JSON results as artifact
uses: actions/upload-artifact@v7
if: always()
with:
name: trivy-results-${{ matrix.image.name }}
path: trivy-${{ matrix.image.name }}-results.json
retention-days: 5
- name: Generate scan summary
if: always()
run: |
echo "## Security Scan Results for ${{ matrix.image.name }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f "trivy-${{ matrix.image.name }}-results.sarif" ]; then
echo "Vulnerability scan completed successfully" >> $GITHUB_STEP_SUMMARY
echo "Results uploaded to Security tab" >> $GITHUB_STEP_SUMMARY
echo "Category: pr-scan-${{ matrix.image.name }}" >> $GITHUB_STEP_SUMMARY
else
echo "Scan failed or no results generated" >> $GITHUB_STEP_SUMMARY
fi
scan-summary:
runs-on: ubuntu-latest
needs: build-and-scan
if: always()
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Download scan results
uses: actions/download-artifact@v8
with:
pattern: trivy-results-*
merge-multiple: true
- name: PR Security Summary with Details
uses: actions/github-script@v7
with:
script: |
const script = require('./.github/scripts/security-summary.js');
await script.generatePRSummary(github, context, core);