-
Notifications
You must be signed in to change notification settings - Fork 1
143 lines (119 loc) · 3.94 KB
/
security-scan.yml
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
name: Security Scan
on:
schedule:
# Run weekly on Sunday at 00:00 UTC
- cron: '0 0 * * 0'
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
security-events: write
actions: read
contents: read
jobs:
dependency-scan:
name: Dependency Security Scan
runs-on: ubuntu-latest
strategy:
matrix:
directory: ['src/backend', 'src/web']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
cache: 'npm'
cache-dependency-path: ${{ matrix.directory }}/package.json
- name: Install dependencies
working-directory: ${{ matrix.directory }}
run: npm ci
- name: Run npm audit
working-directory: ${{ matrix.directory }}
run: npm audit --audit-level=high
continue-on-error: true
- name: Setup Snyk
uses: snyk/actions/setup@v1
- name: Run Snyk scan
working-directory: ${{ matrix.directory }}
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
run: snyk test --severity-threshold=high
continue-on-error: true
- name: Upload Snyk report
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: snyk.sarif
code-analysis:
name: CodeQL Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: javascript, typescript
queries: security-extended,security-and-quality
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18.x'
- name: Install dependencies
run: |
cd src/backend && npm ci
cd ../web && npm ci
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:javascript"
container-scan:
name: Container Security Scan
runs-on: ubuntu-latest
strategy:
matrix:
image: ['backend', 'web']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Build container image
run: |
docker build -t saas-benchmarks-${{ matrix.image }}:${{ github.sha }} \
-f src/${{ matrix.image }}/Dockerfile .
- name: Run Trivy vulnerability scanner
uses: aquasecurity/[email protected]
with:
image-ref: saas-benchmarks-${{ matrix.image }}:${{ github.sha }}
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'HIGH,CRITICAL'
vuln-type: 'os,library'
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'
security-report:
name: Generate Security Report
needs: [dependency-scan, code-analysis, container-scan]
runs-on: ubuntu-latest
if: always()
steps:
- name: Generate summary
run: |
echo "# Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "## Scans Performed" >> $GITHUB_STEP_SUMMARY
echo "- Dependency Security Scan" >> $GITHUB_STEP_SUMMARY
echo "- CodeQL Analysis" >> $GITHUB_STEP_SUMMARY
echo "- Container Security Scan" >> $GITHUB_STEP_SUMMARY
echo "## Status" >> $GITHUB_STEP_SUMMARY
echo "- Dependency Scan: ${{ needs.dependency-scan.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Code Analysis: ${{ needs.code-analysis.result }}" >> $GITHUB_STEP_SUMMARY
echo "- Container Scan: ${{ needs.container-scan.result }}" >> $GITHUB_STEP_SUMMARY
- name: Notify on failure
if: failure()
run: |
echo "::error::Security scan failed. Please review the detailed reports."