-
Notifications
You must be signed in to change notification settings - Fork 3
585 lines (511 loc) · 19.7 KB
/
Copy pathsecurity-comprehensive.yml
File metadata and controls
585 lines (511 loc) · 19.7 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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
# =====================================
# Comprehensive Security Scanning Workflow
# =====================================
# This workflow provides ZERO-TOLERANCE security scanning using multiple
# industry-leading security tools. The pipeline FAILS on ANY detected finding.
#
# Security Scanners Included:
# 1. Trivy - Vulnerability, secret, and misconfiguration scanning
# 2. Checkov - Infrastructure as Code (IaC) security analysis
# 3. KICS - Keeping Infrastructure as Code Secure
# 4. Bandit - Python security linter
# 5. gosec - Go security checker
# 6. ShellCheck - Shell script static analysis
#
# Policy: FAIL-FAST, ZERO-TOLERANCE
# All findings at any severity level will fail the pipeline.
name: Security Comprehensive Scan
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
workflow_dispatch:
inputs:
scan_type:
description: 'Type of scan to run'
required: false
default: 'all'
type: choice
options:
- all
- trivy
- checkov
- kics
- bandit
- gosec
- shellcheck
schedule:
# Run weekly at 2 AM UTC on Mondays for security monitoring
- cron: '0 2 * * 1'
# Cancel in-progress runs when a new commit is pushed to the same branch/PR
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions:
contents: read
security-events: write
env:
# Tool versions for reproducibility (synced with versions.yaml)
TRIVY_VERSION: '0.72.0'
CHECKOV_VERSION: '3.3.6'
KICS_VERSION: 'v2.1.20'
GOSEC_VERSION: 'v2.27.1'
PYTHON_VERSION: '3.14'
GO_VERSION: '1.25'
jobs:
# =====================================================================
# Job 1: Trivy Comprehensive Scan
# =====================================================================
trivy-scan:
name: Trivy Security Scan (Zero-Tolerance)
runs-on: ubuntu-26.04
if: ${{ github.event.inputs.scan_type == 'all' || github.event.inputs.scan_type == 'trivy' || github.event_name != 'workflow_dispatch' }}
steps:
- name: Checkout code
uses: actions/checkout@v7.0.0
- name: Run Trivy filesystem scan (STRICT)
uses: aquasecurity/trivy-action@master
with:
scan-type: 'fs'
scan-ref: '.'
format: 'table'
output: 'trivy-fs-results.txt'
severity: 'CRITICAL,HIGH,MEDIUM,LOW'
scanners: 'vuln,secret,misconfig,license'
exit-code: '1'
trivyignores: '.trivyignore'
- name: Run Trivy config scan for IaC
uses: aquasecurity/trivy-action@master
with:
scan-type: 'config'
scan-ref: '.'
format: 'table'
output: 'trivy-config-results.txt'
severity: 'CRITICAL,HIGH,MEDIUM,LOW'
exit-code: '1'
trivyignores: '.trivyignore'
- name: Run Trivy SARIF scan
uses: aquasecurity/trivy-action@master
if: always()
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH,MEDIUM,LOW'
scanners: 'vuln,secret,misconfig'
trivyignores: '.trivyignore'
- name: Display Trivy results
if: always()
run: |
echo "🔍 Trivy Filesystem Scan Results:"
echo "=================================="
[ -f "trivy-fs-results.txt" ] && cat trivy-fs-results.txt || echo "No results"
echo ""
echo "🔍 Trivy Config Scan Results:"
echo "=================================="
[ -f "trivy-config-results.txt" ] && cat trivy-config-results.txt || echo "No results"
- name: Upload Trivy SARIF to GitHub Security
uses: github/codeql-action/upload-sarif@v4
if: always()
continue-on-error: true
with:
sarif_file: 'trivy-results.sarif'
category: 'trivy'
- name: Upload Trivy results as artifact
uses: actions/upload-artifact@v6
if: always()
with:
name: trivy-results
path: trivy-*.txt
retention-days: 30
# =====================================================================
# Job 2: Checkov IaC Security Scanner
# =====================================================================
checkov-scan:
name: Checkov IaC Scan (Zero-Tolerance)
runs-on: ubuntu-26.04
if: ${{ github.event.inputs.scan_type == 'all' || github.event.inputs.scan_type == 'checkov' || github.event_name != 'workflow_dispatch' }}
steps:
- name: Checkout code
uses: actions/checkout@v7.0.0
- name: Set up Python
uses: actions/setup-python@v6.3.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Checkov
run: |
pip install checkov==${{ env.CHECKOV_VERSION }}
- name: Run Checkov on Terraform
id: checkov-terraform
run: |
echo "🔍 Running Checkov on Terraform files..."
checkov -d terraform/ \
--framework terraform \
--output cli \
--output sarif \
--output-file-path . \
--soft-fail-on LOW \
--hard-fail-on CRITICAL,HIGH,MEDIUM \
--compact \
--skip-check CKV_TF_1 \
2>&1 | tee checkov-terraform-results.txt
- name: Run Checkov on Kubernetes manifests
id: checkov-k8s
run: |
echo "🔍 Running Checkov on Kubernetes manifests..."
checkov -d k8s/ \
--framework kubernetes \
--output cli \
--output sarif \
--output-file-path . \
--soft-fail-on LOW \
--hard-fail-on CRITICAL,HIGH,MEDIUM \
--compact \
2>&1 | tee checkov-k8s-results.txt
- name: Run Checkov on Dockerfiles
id: checkov-docker
run: |
echo "🔍 Running Checkov on Dockerfiles..."
if [ -f "warp/Dockerfile" ]; then
checkov -f warp/Dockerfile \
--framework dockerfile \
--output cli \
--soft-fail-on LOW \
--hard-fail-on CRITICAL,HIGH,MEDIUM \
--compact \
2>&1 | tee checkov-docker-results.txt
else
echo "No Dockerfile found" > checkov-docker-results.txt
fi
- name: Run Checkov on GitHub Actions
id: checkov-gha
run: |
echo "🔍 Running Checkov on GitHub Actions workflows..."
checkov -d .github/workflows/ \
--framework github_actions \
--output cli \
--soft-fail-on LOW \
--hard-fail-on CRITICAL,HIGH,MEDIUM \
--compact \
2>&1 | tee checkov-gha-results.txt
- name: Display Checkov results
if: always()
run: |
echo "📊 Checkov Scan Summary:"
echo "========================"
for f in checkov-*-results.txt; do
if [ -f "$f" ]; then
echo ""
echo "=== $f ==="
cat "$f"
fi
done
- name: Upload Checkov SARIF
uses: github/codeql-action/upload-sarif@v4
if: always()
continue-on-error: true
with:
sarif_file: 'results_sarif.sarif'
category: 'checkov'
- name: Upload Checkov results as artifact
uses: actions/upload-artifact@v6
if: always()
with:
name: checkov-results
path: checkov-*.txt
retention-days: 30
# =====================================================================
# Job 3: KICS (Keeping Infrastructure as Code Secure)
# =====================================================================
kics-scan:
name: KICS IaC Scan (Zero-Tolerance)
runs-on: ubuntu-26.04
if: ${{ github.event.inputs.scan_type == 'all' || github.event.inputs.scan_type == 'kics' || github.event_name != 'workflow_dispatch' }}
steps:
- name: Checkout code
uses: actions/checkout@v7.0.0
- name: Run KICS scan
uses: Checkmarx/kics-github-action@v2.1.20
with:
path: '.'
fail_on: high,medium,low
config_path: kics.config
output_path: kics-results/
output_formats: 'json,sarif'
exclude_paths: '.git,node_modules,venv,.trivycache'
enable_comments: true
ignore_on_exit: results
- name: Display KICS results
if: always()
run: |
echo "🔍 KICS Infrastructure Security Scan Results:"
echo "=============================================="
if [ -f "kics-results/results.json" ]; then
cat kics-results/results.json | jq '.queries_total, .total_counter'
fi
- name: Upload KICS SARIF
uses: github/codeql-action/upload-sarif@v4
if: always()
continue-on-error: true
with:
sarif_file: kics-results/results.sarif
category: 'kics'
- name: Upload KICS results as artifact
uses: actions/upload-artifact@v6
if: always()
with:
name: kics-results
path: kics-results/
retention-days: 30
# =====================================================================
# Job 4: Bandit Python Security Linter
# =====================================================================
bandit-scan:
name: Bandit Python Scan (Zero-Tolerance)
runs-on: ubuntu-26.04
if: ${{ github.event.inputs.scan_type == 'all' || github.event.inputs.scan_type == 'bandit' || github.event_name != 'workflow_dispatch' }}
steps:
- name: Checkout code
uses: actions/checkout@v7.0.0
- name: Set up Python
uses: actions/setup-python@v6.3.0
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Bandit
run: pip install bandit[toml] sarif-om jschema-to-python
- name: Run Bandit on Python projects (warp + openemr_dr)
run: |
echo "🔍 Running Bandit Python Security Scanner..."
bandit -r warp/ scripts/openemr_dr/ \
-c scripts/openemr_dr/pyproject.toml \
-f sarif \
-o bandit-results.sarif \
--severity-level low \
--confidence-level low \
-x '**/tests/**,**/test_*.py,**/*_test.py' \
2>&1 | tee bandit-results.txt || true
bandit -r warp/ scripts/openemr_dr/ \
-c scripts/openemr_dr/pyproject.toml \
-f txt \
--severity-level low \
--confidence-level low \
-x '**/tests/**,**/test_*.py,**/*_test.py' \
2>&1 | tee -a bandit-results.txt
- name: Check Bandit results
run: |
echo "📊 Bandit Scan Summary:"
echo "======================="
cat bandit-results.txt
# Fail if any issues found
if grep -q "Issue:" bandit-results.txt; then
echo "❌ Bandit found security issues!"
exit 1
else
echo "✅ No security issues found by Bandit"
fi
- name: Upload Bandit SARIF
uses: github/codeql-action/upload-sarif@v4
if: always()
continue-on-error: true
with:
sarif_file: bandit-results.sarif
category: 'bandit'
- name: Upload Bandit results as artifact
uses: actions/upload-artifact@v6
if: always()
with:
name: bandit-results
path: bandit-results.*
retention-days: 30
# =====================================================================
# Job 5: gosec Go Security Checker
# =====================================================================
gosec-scan:
name: gosec Go Security Scan (Zero-Tolerance)
runs-on: ubuntu-26.04
if: ${{ github.event.inputs.scan_type == 'all' || github.event.inputs.scan_type == 'gosec' || github.event_name != 'workflow_dispatch' }}
steps:
- name: Checkout code
uses: actions/checkout@v7.0.0
- name: Set up Go
uses: actions/setup-go@v6.5.0
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: console/go.sum
- name: Install gosec
run: go install github.com/securego/gosec/v2/cmd/gosec@${{ env.GOSEC_VERSION }}
- name: Run gosec
working-directory: console/
run: |
echo "🔍 Running gosec Go Security Scanner..."
gosec -fmt sarif -out ../gosec-results.sarif -severity low ./... 2>&1 | tee ../gosec-results.txt || true
gosec -fmt text -severity low ./... 2>&1 | tee -a ../gosec-results.txt
- name: Check gosec results
run: |
echo "📊 gosec Scan Summary:"
echo "======================"
cat gosec-results.txt
# Fail if any issues found (excluding informational)
if grep -q "\[HIGH\]\|\[MEDIUM\]\|\[LOW\]" gosec-results.txt; then
echo "❌ gosec found security issues!"
exit 1
else
echo "✅ No security issues found by gosec"
fi
- name: Upload gosec SARIF
uses: github/codeql-action/upload-sarif@v4
if: always()
continue-on-error: true
with:
sarif_file: gosec-results.sarif
category: 'gosec'
- name: Upload gosec results as artifact
uses: actions/upload-artifact@v6
if: always()
with:
name: gosec-results
path: gosec-results.*
retention-days: 30
# =====================================================================
# Job 6: ShellCheck Shell Script Analysis
# =====================================================================
shellcheck-scan:
name: ShellCheck Shell Scan (Zero-Tolerance)
runs-on: ubuntu-26.04
if: ${{ github.event.inputs.scan_type == 'all' || github.event.inputs.scan_type == 'shellcheck' || github.event_name != 'workflow_dispatch' }}
steps:
- name: Checkout code
uses: actions/checkout@v7.0.0
- name: Install ShellCheck
run: |
sudo apt-get update
sudo apt-get install -y shellcheck
- name: Run ShellCheck on all shell scripts
run: |
echo "🔍 Running ShellCheck Shell Script Analysis..."
# Find all shell scripts and run shellcheck
# -S warning: Include warnings and above (warning, error)
# -f gcc: Output in GCC format for easy parsing
find . -name "*.sh" -type f \
! -path "./.git/*" \
! -path "./node_modules/*" \
! -path "./.terraform/*" \
-print0 | xargs -0 shellcheck -S warning -f gcc 2>&1 | tee shellcheck-results.txt
# Check if any issues were found
if [ -s shellcheck-results.txt ]; then
echo ""
echo "📊 ShellCheck Summary:"
echo "======================"
cat shellcheck-results.txt
echo ""
echo "❌ ShellCheck found issues!"
exit 1
else
echo "✅ No ShellCheck issues found"
fi
- name: Upload ShellCheck results as artifact
uses: actions/upload-artifact@v6
if: always()
with:
name: shellcheck-results
path: shellcheck-results.txt
retention-days: 30
# =====================================================================
# Job 7: Security Summary and Enforcement
# =====================================================================
security-summary:
name: Security Summary & Enforcement
runs-on: ubuntu-26.04
needs: [trivy-scan, checkov-scan, kics-scan, bandit-scan, gosec-scan, shellcheck-scan]
if: always()
steps:
- name: Download all artifacts
uses: actions/download-artifact@v7
with:
path: security-results/
- name: Generate security summary
run: |
echo "# 🔒 Comprehensive Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Zero-Tolerance Policy Enforcement" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Scanner | Status | Description |" >> $GITHUB_STEP_SUMMARY
echo "|---------|--------|-------------|" >> $GITHUB_STEP_SUMMARY
# Check each job result
if [ "${{ needs.trivy-scan.result }}" == "success" ]; then
echo "| ✅ Trivy | PASSED | Vulnerability, Secret, Config scan |" >> $GITHUB_STEP_SUMMARY
else
echo "| ❌ Trivy | FAILED | Vulnerability, Secret, Config scan |" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.checkov-scan.result }}" == "success" ]; then
echo "| ✅ Checkov | PASSED | IaC security (Terraform, K8s, Docker) |" >> $GITHUB_STEP_SUMMARY
else
echo "| ❌ Checkov | FAILED | IaC security (Terraform, K8s, Docker) |" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.kics-scan.result }}" == "success" ]; then
echo "| ✅ KICS | PASSED | IaC security analysis |" >> $GITHUB_STEP_SUMMARY
else
echo "| ❌ KICS | FAILED | IaC security analysis |" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.bandit-scan.result }}" == "success" ]; then
echo "| ✅ Bandit | PASSED | Python security |" >> $GITHUB_STEP_SUMMARY
else
echo "| ❌ Bandit | FAILED | Python security |" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.gosec-scan.result }}" == "success" ]; then
echo "| ✅ gosec | PASSED | Go security |" >> $GITHUB_STEP_SUMMARY
else
echo "| ❌ gosec | FAILED | Go security |" >> $GITHUB_STEP_SUMMARY
fi
if [ "${{ needs.shellcheck-scan.result }}" == "success" ]; then
echo "| ✅ ShellCheck | PASSED | Shell script analysis |" >> $GITHUB_STEP_SUMMARY
else
echo "| ❌ ShellCheck | FAILED | Shell script analysis |" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Policy" >> $GITHUB_STEP_SUMMARY
echo "- **Mode**: Zero-Tolerance" >> $GITHUB_STEP_SUMMARY
echo "- **Severity Threshold**: LOW, MEDIUM, HIGH, CRITICAL" >> $GITHUB_STEP_SUMMARY
echo "- **Action on Finding**: FAIL pipeline" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "*All findings must be remediated before merging.*" >> $GITHUB_STEP_SUMMARY
- name: Enforce zero-tolerance policy
run: |
FAILED=false
if [ "${{ needs.trivy-scan.result }}" != "success" ]; then
echo "❌ Trivy scan failed"
FAILED=true
fi
if [ "${{ needs.checkov-scan.result }}" != "success" ]; then
echo "❌ Checkov scan failed"
FAILED=true
fi
if [ "${{ needs.kics-scan.result }}" != "success" ]; then
echo "❌ KICS scan failed"
FAILED=true
fi
if [ "${{ needs.bandit-scan.result }}" != "success" ]; then
echo "❌ Bandit scan failed"
FAILED=true
fi
if [ "${{ needs.gosec-scan.result }}" != "success" ]; then
echo "❌ gosec scan failed"
FAILED=true
fi
if [ "${{ needs.shellcheck-scan.result }}" != "success" ]; then
echo "❌ ShellCheck scan failed"
FAILED=true
fi
if [ "$FAILED" = true ]; then
echo ""
echo "🚫 SECURITY SCAN FAILED - Zero-tolerance policy violated"
echo "All findings must be remediated before merging."
exit 1
else
echo ""
echo "✅ ALL SECURITY SCANS PASSED"
echo "🔒 Zero-tolerance policy enforced successfully"
fi