-
Notifications
You must be signed in to change notification settings - Fork 0
311 lines (269 loc) Β· 9 KB
/
security.yml
File metadata and controls
311 lines (269 loc) Β· 9 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
name: Security and Dependency Updates
on:
schedule:
# Run daily at 2 AM UTC
- cron: '0 2 * * *'
workflow_dispatch:
permissions:
contents: write
pull-requests: write
security-events: write
jobs:
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Dependency Review
uses: actions/dependency-review-action@v3
with:
fail-on-severity: moderate
deny-licenses: GPL-2.0, GPL-3.0
update-dotnet-dependencies:
name: Update .NET Dependencies
runs-on: ubuntu-latest
env:
UPDATES_FOUND: 'false'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Install dotnet-outdated
run: dotnet tool install --global dotnet-outdated-tool
- name: Check for outdated packages
working-directory: ./backend
run: |
echo "## .NET Package Updates Available" > ../dependency-updates.md
echo "" >> ../dependency-updates.md
if dotnet outdated --output json > outdated.json; then
if [ -s outdated.json ] && [ "$(jq '.Projects | length' outdated.json)" -gt 0 ]; then
echo "Updates found, creating PR..."
echo "UPDATES_FOUND=true" >> $GITHUB_ENV
# Parse and format updates
jq -r '.Projects[] | "### \(.Name)\n\n| Package | Current | Latest | Severity |\n|---------|---------|--------|----------|\n\(.Frameworks[].Dependencies[] | "| \(.Name) | \(.ResolvedVersion) | \(.LatestVersion) | \(.Severity // "N/A") |")\n"' outdated.json >> ../dependency-updates.md
else
echo "No updates found"
echo "UPDATES_FOUND=false" >> $GITHUB_ENV
fi
fi
- name: Update packages (minor versions only)
if: env.UPDATES_FOUND == 'true'
working-directory: ./backend
run: |
# Update to latest minor versions (safer)
dotnet outdated --upgrade --version-lock Major
- name: Create Pull Request
if: env.UPDATES_FOUND == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore(deps): update .NET dependencies'
title: 'π Automated .NET Dependency Updates'
body-path: dependency-updates.md
branch: chore/update-dotnet-deps
delete-branch: true
labels: |
dependencies
automated-pr
.NET
update-npm-dependencies:
name: Update NPM Dependencies
runs-on: ubuntu-latest
env:
NPM_UPDATES_FOUND: 'false'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install npm-check-updates
run: npm install -g npm-check-updates
- name: Check for outdated packages
working-directory: ./frontend
run: |
echo "## NPM Package Updates Available" > ../npm-updates.md
echo "" >> ../npm-updates.md
if ncu --jsonUpgraded > updates.json 2>/dev/null; then
if [ -s updates.json ] && [ "$(jq '. | length' updates.json)" -gt 0 ]; then
echo "Updates found, creating PR..."
echo "NPM_UPDATES_FOUND=true" >> $GITHUB_ENV
# Format updates table
echo "| Package | Current | Latest |" >> ../npm-updates.md
echo "|---------|---------|--------|" >> ../npm-updates.md
jq -r 'to_entries[] | "| \(.key) | \(.value.from) | \(.value.to) |"' updates.json >> ../npm-updates.md
else
echo "No updates found"
echo "NPM_UPDATES_FOUND=false" >> $GITHUB_ENV
fi
else
echo "No updates found or ncu failed"
echo "NPM_UPDATES_FOUND=false" >> $GITHUB_ENV
fi
- name: Update packages (minor and patch only)
if: env.NPM_UPDATES_FOUND == 'true'
working-directory: ./frontend
run: |
# Update to latest minor/patch versions (safer than major)
ncu --target minor -u
npm install
- name: Run tests after updates
if: env.NPM_UPDATES_FOUND == 'true'
working-directory: ./frontend
run: |
npm run lint
npm run type-check
npm run test:unit
- name: Create Pull Request
if: env.NPM_UPDATES_FOUND == 'true'
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore(deps): update NPM dependencies'
title: 'π Automated NPM Dependency Updates'
body-path: npm-updates.md
branch: chore/update-npm-deps
delete-branch: true
labels: |
dependencies
automated-pr
frontend
security-audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: .NET Security Audit
working-directory: ./backend
run: |
dotnet restore
dotnet list package --vulnerable --include-transitive | tee ../dotnet-vulnerabilities.txt
- name: NPM Security Audit
working-directory: ./frontend
run: |
npm install
npm audit --audit-level=moderate | tee ../npm-vulnerabilities.txt
- name: Upload security reports
uses: actions/upload-artifact@v4
with:
name: security-audit-reports
path: |
dotnet-vulnerabilities.txt
npm-vulnerabilities.txt
retention-days: 30
codeql-analysis:
name: CodeQL Security Analysis
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read
strategy:
matrix:
language: ['csharp', 'javascript']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-extended
- name: Setup .NET (for C#)
if: matrix.language == 'csharp'
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Build .NET (for C#)
if: matrix.language == 'csharp'
working-directory: ./backend
run: |
dotnet restore
dotnet build --no-restore
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
docker-security-scan:
name: Docker Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Trivy filesystem scan
uses: aquasecurity/[email protected]
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-fs-results.sarif'
severity: 'CRITICAL,HIGH,MEDIUM'
exit-code: '0'
- name: Verify Trivy SARIF file exists
run: |
if [ -f "trivy-fs-results.sarif" ]; then
echo "β
Trivy SARIF file exists and is readable"
echo "π File size: $(wc -c < trivy-fs-results.sarif) bytes"
else
echo "β Trivy SARIF file not found"
ls -la *.sarif 2>/dev/null || echo "No SARIF files found"
exit 1
fi
- name: Upload Trivy scan results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: 'trivy-fs-results.sarif'
continue-on-error: true
if: success()
- name: Run Hadolint on Dockerfiles
uses: hadolint/[email protected]
with:
dockerfile: backend/src/StackShare.API/Dockerfile
format: sarif
output-file: hadolint-api.sarif
- name: Verify Hadolint SARIF file exists
run: |
if [ -f "hadolint-api.sarif" ]; then
echo "β
Hadolint SARIF file exists and is readable"
echo "π File size: $(wc -c < hadolint-api.sarif) bytes"
else
echo "β Hadolint SARIF file not found"
ls -la *.sarif 2>/dev/null || echo "No SARIF files found"
exit 1
fi
- name: Upload Hadolint scan results
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: hadolint-api.sarif
continue-on-error: true
if: success()
- name: Upload security scan artifacts (fallback)
uses: actions/upload-artifact@v4
with:
name: security-scan-results
path: |
trivy-fs-results.sarif
hadolint-api.sarif
retention-days: 30
if: always()