-
Notifications
You must be signed in to change notification settings - Fork 0
313 lines (258 loc) · 8.8 KB
/
security.yml
File metadata and controls
313 lines (258 loc) · 8.8 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
312
313
name: Security Scan
on:
schedule:
# Run security scans daily at 2 AM UTC
- cron: '0 2 * * *'
workflow_dispatch:
push:
branches: [ main ]
paths:
- '**/requirements.txt'
- '**/package.json'
- '**/package-lock.json'
- '**/Containerfile'
jobs:
dependency-scan:
name: Dependency Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Python dependencies
working-directory: ./backend
run: |
python -m pip install --upgrade pip
pip install safety bandit
- name: Run Python security scan with Safety
working-directory: ./backend
run: |
safety check --json --output safety-report.json || true
cat safety-report.json
- name: Run Python security scan with Bandit
working-directory: ./backend
run: |
bandit -r . -f json -o bandit-report.json || true
cat bandit-report.json
- name: Install Node.js dependencies
working-directory: ./frontend
run: npm ci
- name: Run npm audit
working-directory: ./frontend
run: |
npm audit --audit-level=moderate --json > npm-audit-report.json || true
cat npm-audit-report.json
- name: Upload security reports
uses: actions/upload-artifact@v3
with:
name: security-reports
path: |
backend/safety-report.json
backend/bandit-report.json
frontend/npm-audit-report.json
container-scan:
name: Container Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Podman
run: |
sudo apt-get update
sudo apt-get install -y podman
- name: Build backend image
working-directory: ./backend
run: |
podman build -t redhat-learning-paths-backend:scan -f Containerfile .
- name: Build frontend image
working-directory: ./frontend
run: |
podman build -t redhat-learning-paths-frontend:scan -f Containerfile .
- name: Run Trivy scan on backend image
uses: aquasecurity/trivy-action@master
with:
image-ref: 'redhat-learning-paths-backend:scan'
format: 'sarif'
output: 'backend-trivy-results.sarif'
- name: Run Trivy scan on frontend image
uses: aquasecurity/trivy-action@master
with:
image-ref: 'redhat-learning-paths-frontend:scan'
format: 'sarif'
output: 'frontend-trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'backend-trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'frontend-trivy-results.sarif'
codeql-analysis:
name: CodeQL Security Analysis
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [ 'python', 'javascript' ]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: ${{ matrix.language }}
queries: security-extended,security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
secrets-scan:
name: Secrets Scan
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run TruffleHog OSS
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: main
head: HEAD
extra_args: --debug --only-verified
sbom-generation:
name: Generate SBOM
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Podman
run: |
sudo apt-get update
sudo apt-get install -y podman
- name: Build images
run: |
cd backend && podman build -t redhat-learning-paths-backend:sbom -f Containerfile .
cd ../frontend && podman build -t redhat-learning-paths-frontend:sbom -f Containerfile .
- name: Generate SBOM for backend
uses: anchore/sbom-action@v0
with:
image: redhat-learning-paths-backend:sbom
format: spdx-json
output-file: backend-sbom.spdx.json
- name: Generate SBOM for frontend
uses: anchore/sbom-action@v0
with:
image: redhat-learning-paths-frontend:sbom
format: spdx-json
output-file: frontend-sbom.spdx.json
- name: Upload SBOM artifacts
uses: actions/upload-artifact@v3
with:
name: sbom-reports
path: |
backend-sbom.spdx.json
frontend-sbom.spdx.json
compliance-check:
name: Compliance Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check for required security files
run: |
echo "Checking for security-related files..."
# Check for security policy
if [ ! -f "SECURITY.md" ]; then
echo "❌ SECURITY.md file not found"
exit 1
else
echo "✅ SECURITY.md found"
fi
# Check for license
if [ ! -f "LICENSE" ] && [ ! -f "LICENSE.md" ] && [ ! -f "LICENSE.txt" ]; then
echo "❌ LICENSE file not found"
exit 1
else
echo "✅ LICENSE found"
fi
# Check for contributing guidelines
if [ ! -f "CONTRIBUTING.md" ]; then
echo "⚠️ CONTRIBUTING.md not found (recommended)"
else
echo "✅ CONTRIBUTING.md found"
fi
- name: Check container security best practices
run: |
echo "Checking Containerfile security practices..."
# Check for non-root user in Containerfiles
if ! grep -q "USER.*[^0]" backend/Containerfile; then
echo "❌ Backend Containerfile should run as non-root user"
exit 1
fi
if ! grep -q "USER.*[^0]" frontend/Containerfile; then
echo "❌ Frontend Containerfile should run as non-root user"
exit 1
fi
echo "✅ Containerfiles use non-root users"
security-summary:
name: Security Summary
runs-on: ubuntu-latest
needs: [dependency-scan, container-scan, codeql-analysis, secrets-scan, sbom-generation, compliance-check]
if: always()
steps:
- name: Generate security summary
run: |
echo "# Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.dependency-scan.result }}" == "success" ]; then
echo "| Dependency Scan | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
else
echo "| Dependency Scan | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.container-scan.result }}" == "success" ]; then
echo "| Container Scan | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
else
echo "| Container Scan | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.codeql-analysis.result }}" == "success" ]; then
echo "| CodeQL Analysis | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
else
echo "| CodeQL Analysis | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.secrets-scan.result }}" == "success" ]; then
echo "| Secrets Scan | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
else
echo "| Secrets Scan | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.sbom-generation.result }}" == "success" ]; then
echo "| SBOM Generation | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
else
echo "| SBOM Generation | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.compliance-check.result }}" == "success" ]; then
echo "| Compliance Check | ✅ Passed |" >> $GITHUB_STEP_SUMMARY
else
echo "| Compliance Check | ❌ Failed |" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "For detailed results, check the individual job logs and security tab." >> $GITHUB_STEP_SUMMARY