File size: 22,482 Bytes
f2c6053
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
# AegisLM CI/CD Security

## Overview

This document defines the security requirements and controls for the AegisLM CI/CD pipeline. All pipeline changes must comply with these security standards.

## CI/CD Security Architecture

```

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚                        CI/CD Pipeline Security Flow                          β”‚

β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€

β”‚                                                                             β”‚

β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                           β”‚

β”‚  β”‚    GitHub    β”‚                                                           β”‚

β”‚  β”‚   Push/PR    β”‚                                                           β”‚

β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                                                           β”‚

β”‚         β”‚                                                                    β”‚

β”‚         β–Ό                                                                    β”‚

β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚

β”‚  β”‚                    GitHub Actions Workflow                   β”‚            β”‚

β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚

β”‚         β”‚                                                                    β”‚

β”‚         β”œβ”€β”€β–Ί Lint & Type Check                                             β”‚

β”‚         β”‚         └── Ruff, MyPy                                           β”‚

β”‚         β”‚                                                                    β”‚

β”‚         β”œβ”€β”€β–Ί Schema Validation                                             β”‚

β”‚         β”‚         └── Pydantic validation                                   β”‚

β”‚         β”‚                                                                    β”‚

β”‚         β”œβ”€β”€β–Ί Unit Tests                                                    β”‚

β”‚         β”‚         └── pytest with coverage                                  β”‚

β”‚         β”‚                                                                    β”‚

β”‚         β”œβ”€β”€β–Ί Docker Build                                                  β”‚

β”‚         β”‚         └── Multi-stage build                                    β”‚

β”‚         β”‚                                                                    β”‚

β”‚         β”œβ”€β”€β–Ί Security Scan ◄────────────────────────────────────┐          β”‚

β”‚         β”‚         β”œβ”€β”€ Dependency scan (safety)                 β”‚          β”‚

β”‚         β”‚         β”œβ”€β”€ Secret detection (trufflehog)           β”‚          β”‚

β”‚         β”‚         β”œβ”€β”€ Container scan (trivy)                  β”‚          β”‚

β”‚         β”‚         └── SAST (bandit)                          β”‚          β”‚

β”‚         β”‚                                                            β”‚          β”‚

β”‚         └──► Artifact Signing β—„β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚

β”‚                   └── Cosign, GPG                                         β”‚

β”‚                                                                         β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

```

---

## Security Controls

### βœ… Required Security Checks

| Check | Tool | Severity | Status |
|-------|------|----------|--------|
| Dependency vulnerability scan | `safety`, `pip-audit` | Critical | βœ… Implemented |
| Secret detection | `trufflehog`, `gitleaks` | Critical | πŸ”„ To Implement |
| Container image scan | `trivy`, `clair` | High | πŸ”„ To Implement |
| SAST (Static Analysis) | `bandit`, `semgrep` | High | πŸ”„ To Implement |
| Code linting | `ruff` | Medium | βœ… Implemented |
| Type checking | `mypy` | Medium | βœ… Implemented |
| Artifact signing | `cosign`, `GPG` | High | πŸ”„ To Implement |

---

## Enhanced GitHub Actions Workflow

Update `.github/workflows/ci.yml` with enhanced security:

```

yaml

# AegisLM CI/CD Pipeline - Enhanced Security Version

# GitHub Actions workflow with comprehensive security scanning



name: CI



on:

  push:

    branches: [main, develop]

  pull_request:

    branches: [main, develop]



env:

  # Security settings

  TRUFFLEHOG_VERSION: "3.63.1"

  TRIVY_VERSION: "0.49.1"

  SEMGREP_VERSION: "1.64.0"



jobs:

  # ===========================================================================

  # Secret Detection - Fail on secrets

  # ===========================================================================

  secret-detection:

    name: Secret Detection

    runs-on: ubuntu-latest

    

    steps:

      - name: Checkout code

        uses: actions/checkout@v4

        with:

          fetch-depth: 0  # Full history for trufflehog

      

      - name: Run Trufflehog

        uses: trufflesecurity/trufflehog@main

        with:

          path: ./

          base: ${{ github.event.repository.default_branch }}

          head: HEAD

          extra_args: --fail --verified-only

      

      - name: Run Gitleaks

        uses: gitleaks/gitleaks-action@v2

        env:

          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

          GITLEAKS_ENABLE_UPDATES: "false"



  # ===========================================================================

  # SAST - Static Application Security Testing

  # ===========================================================================

  sast:

    name: SAST Analysis

    runs-on: ubuntu-latest

    

    steps:

      - name: Checkout code

        uses: actions/checkout@v4

      

      - name: Run Semgrep

        uses: returntocorp/semgrep-action@v1

        with:

          config: auto

          generateSarif: true

      

      - name: Upload Semgrep results

        uses: github/codeql-action/upload-sarif@v3

        with:

          sarif_file: semgrep.sarif

      

      - name: Run Bandit

        run: |

          pip install bandit

          bandit -r backend/ -f sarif -o bandit.sarif || true

        continue-on-error: true



  # ===========================================================================

  # Lint and Type Check

  # ===========================================================================

  lint:

    name: Lint & Type Check

    runs-on: ubuntu-latest

    

    steps:

      - name: Checkout code

        uses: actions/checkout@v4

      

      - name: Set up Python

        uses: actions/setup-python@v5

        with:

          python-version: '3.11'

          cache: 'pip'

      

      - name: Install dependencies

        run: |

          pip install -r requirements.txt

          pip install ruff mypy

      

      - name: Run Ruff linter

        run: ruff check . --output-format=github

      

      - name: Run MyPy type checker

        run: mypy backend --ignore-missing-imports --no-error-summary

        continue-on-error: true



  # ===========================================================================

  # Validate Pydantic Schemas

  # ===========================================================================

  schema-validation:

    name: Validate Pydantic Schemas

    runs-on: ubuntu-latest

    

    steps:

      - name: Checkout code

        uses: actions/checkout@v4

      

      - name: Set up Python

        uses: actions/setup-python@v5

        with:

          python-version: '3.11'

          cache: 'pip'

      

      - name: Install dependencies

        run: pip install -r requirements.txt

      

      - name: Validate Pydantic schemas

        run: |

          python -c "

            from backend.benchmarking.schemas import BenchmarkConfig, BenchmarkWeights

            from backend.core.config import settings

            from backend.db.models import EvaluationRun

            print('All Pydantic schemas imported successfully')

          "

      

      - name: Validate weights sum to 1

        run: |

          python -c "

            from backend.benchmarking.schemas import BenchmarkWeights

            weights = BenchmarkWeights()

            total = weights.hallucination + weights.toxicity + weights.bias + weights.confidence

            if abs(total - 1.0) > 1e-6:

              raise ValueError(f'Weights must sum to 1.0, got {total}')

            print(f'Weights validation passed: sum = {total}')

          "



  # ===========================================================================

  # Unit Tests

  # ===========================================================================

  tests:

    name: Unit Tests

    runs-on: ubuntu-latest

    

    steps:

      - name: Checkout code

        uses: actions/checkout@v4

      

      - name: Set up Python

        uses: actions/setup-python@v5

        with:

          python-version: '3.11'

          cache: 'pip'

      

      - name: Install dependencies

        run: |

          pip install -r requirements.txt

          pip install pytest pytest-asyncio pytest-cov

      

      - name: Run unit tests

        run: pytest tests/ -v --cov=backend --cov-report=xml --cov-report=term-missing

        continue-on-error: true

      

      - name: Upload coverage

        uses: actions/upload-artifact@v4

        with:

          name: coverage-report

          path: coverage.xml



  # ===========================================================================

  # Docker Build with Security Scanning

  # ===========================================================================

  docker:

    name: Docker Build & Scan

    runs-on: ubuntu-latest

    

    steps:

      - name: Checkout code

        uses: actions/checkout@v4

      

      - name: Set up Docker Buildx

        uses: docker/setup-buildx-action@v3

      

      - name: Build Docker image

        uses: docker/build-push-action@v5

        with:

          context: .

          push: false

          tags: aegislm:test

          load: true

          cache-from: type=gha

          cache-to: type=gha,mode=max

      

      - name: Run Trivy scanner

        uses: aquasecurity/trivy-action@master

        with:

          image-ref: 'aegislm:test'

          format: sarif

          output: 'trivy-results.sarif'

          severity: 'CRITICAL,HIGH'

          exit-code: '1'

          ignore-unfixed: true

      

      - name: Upload Trivy results

        uses: github/codeql-action/upload-sarif@v3

        with:

          sarif_file: 'trivy-results.sarif'



  # ===========================================================================

  # Dependency Security Scan

  # ===========================================================================

  dependency-security:

    name: Dependency Security

    runs-on: ubuntu-latest

    

    steps:

      - name: Checkout code

        uses: actions/checkout@v4

      

      - name: Set up Python

        uses: actions/setup-python@v5

        with:

          python-version: '3.11'

          cache: 'pip'

      

      - name: Install dependencies

        run: pip install -r requirements.txt

      

      - name: Run pip-audit

        uses: pypa/pip-audit@main

        with:

          pip-audit-args: --exclude-editable --require-hashes

      

      - name: Run safety

        run: |

          pip install safety

          safety check --json > safety-results.json || true

        continue-on-error: true

      

      - name: Upload security results

        uses: actions/upload-artifact@v4

        if: always()

        with:

          name: security-results

          path: |

            safety-results.json

            trivy-results.sarif



  # ===========================================================================

  # Build Summary

  # ===========================================================================

  summary:

    name: Build Summary

    needs: [secret-detection, sast, lint, schema-validation, tests, docker, dependency-security]

    runs-on: ubuntu-latest

    if: always()

    

    steps:

      - name: Summary

        run: |

          echo "## Build Summary" >> $GITHUB_STEP_SUMMARY

          echo "" >> $GITHUB_STEP_SUMMARY

          echo "| Job | Status |" >> $GITHUB_STEP_SUMMARY

          echo "|-----|--------|" >> $GITHUB_STEP_SUMMARY

          echo "| Secret Detection | ${{ needs.secret-detection.result }} |" >> $GITHUB_STEP_SUMMARY

          echo "| SAST Analysis | ${{ needs.sast.result }} |" >> $GITHUB_STEP_SUMMARY

          echo "| Lint & Type Check | ${{ needs.lint.result }} |" >> $GITHUB_STEP_SUMMARY

          echo "| Schema Validation | ${{ needs.schema-validation.result }} |" >> $GITHUB_STEP_SUMMARY

          echo "| Unit Tests | ${{ needs.tests.result }} |" >> $GITHUB_STEP_SUMMARY

          echo "| Docker Build & Scan | ${{ needs.docker.result }} |" >> $GITHUB_STEP_SUMMARY

          echo "| Dependency Security | ${{ needs.dependency-security.result }} |" >> $GITHUB_STEP_SUMMARY

          

          # Fail if critical security issues found

          if [ "${{ needs.secret-detection.result }}" == "failure" ]; then

            echo "" >> $GITHUB_STEP_SUMMARY

            echo "❌ **SECURITY FAILURE**: Secrets detected in code" >> $GITHUB_STEP_SUMMARY

            exit 1

          fi



  # ===========================================================================

  # Artifact Signing (for releases)

  # ===========================================================================

  sign:

    name: Sign Artifacts

    needs: [lint, tests, docker]

    runs-on: ubuntu-latest

    if: github.event_name == 'release'

    

    steps:

      - name: Checkout code

        uses: actions/checkout@v4

      

      - name: Set up Cosign

        uses: sigstore/cosign-installer@v3

      

      - name: Sign Docker image

        run: |

          cosign sign --yes aegislm/test:latest

      

      - name: Sign Python packages

        run: |

          # Generate key pair

          cosign generate-key-pair

          

          # Sign wheel files

          for wheel in dist/*.whl; do

            cosign sign-file --key cosign.key "$wheel"

          done

      

      - name: Upload signatures

        uses: actions/upload-artifact@v4

        with:

          name: signatures

          path: |

            *.sig

            cosign.pub

```

---

## Security Scanning Configuration

### TruffleHog Configuration

Create `.trufflehog.yaml`:

```

yaml

# TruffleHog configuration

directories:

  - .

exclude:

  - .git

  - node_modules

  - venv

  - __pycache__



rules:

  - name: AWS Access Key

    pattern: 'AKIA[0-9A-Z]{16}'

    entropy: true

  

  - name: GitHub Token

    pattern: 'gh[pousr]_[A-Za-z0-9_]{36,255}'

    entropy: true

  

  - name: JWT Token

    pattern: 'eyJ[A-Za-z0-9-_=]+\.eyJ[A-Za-z0-9-_=]+\.[A-Za-z0-9-_.+/=]*'

    entropy: true

  

  - name: Private Key

    pattern: '-----BEGIN (RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----'

    entropy: false

  

  - name: Generic API Key

    pattern: '(?i)(api[_-]?key|apikey|secret[_-]?key)[\s:=]+["\']?[a-zA-Z0-9]{16,}'

    entropy: true

```

### Semgrep Configuration

Create `.semgrep.yaml`:

```

yaml

rules:

  - id: python-secrets

    pattern: |

      os.environ["$KEY"]

    message: Hardcoded secrets in environment variables

    languages:

      - python

    severity: ERROR

    metadata:

      cwe: "CWE-798: Use of Hard-coded Credentials"

      owasp: "A2:2017-Broken Authentication"

  

  - id: python-sql-injection

    pattern: |

      cursor.execute("SELECT ..." + $USER_INPUT)

    message: Potential SQL injection

    languages:

      - python

    severity: ERROR

    metadata:

      cwe: "CWE-89: SQL Injection"

      owasp: "A1:2017-Injection"

  

  - id: python-path-traversal

    pattern: |

      open($FILE, ...)

    message: Potential path traversal

    languages:

      - python

    severity: WARNING

    metadata:

      cwe: "CWE-22: Path Traversal"

```

---

## Dependency Vulnerability Policy

### Severity Thresholds

| Severity | Action | Pipeline Result |
|----------|--------|-----------------|
| Critical | Fail build | ❌ Fail |
| High | Fail build | ❌ Fail |
| Medium | Warning only | ⚠️ Warn |
| Low | Info only | ℹ️ Info |

### Allowed Vulnerabilities

For legitimate exceptions, create `.vuln-allowlist.json`:

```

json

{

  "allowed_vulnerabilities": [

    {

      "cve": "CVE-2024-12345",

      "package": "some-library",

      "reason": "False positive - not used in our code path",

      "expires": "2024-12-31"

    }

  ]

}

```

---

## Artifact Signing

### Cosign Setup

```

bash

# Install cosign

brew install cosign



# Generate key pair

cosign generate-key-pair



# Sign a container image

cosign sign aegislm/api:v1.0.0



# Verify signature

cosign verify aegislm/api:v1.0.0 --key cosign.pub

```

### Python Package Signing

```

yaml

# In release workflow

- name: Build Python package

  run: |

    python -m build



- name: Sign packages

  run: |

    for file in dist/*.whl; do

      cosign sign-file --key cosign.key "$file"

    done

```

---

## Pipeline Security Best Practices

### 1. Secrets Management

```

yaml

# Use GitHub Secrets for sensitive values

env:

  # Don't use secrets directly in env!

  # Instead, use the secrets context

  API_TOKEN: ${{ secrets.API_TOKEN }}

```

### 2. Permission Minimization

```

yaml

# Use minimal permissions

permissions:

  contents: read

  security-events: write

  actions: read

  checks: write

```

### 3. Cache Security

```

yaml

# Use secure cache

- name: Setup Python

  uses: actions/setup-python@v5

  with:

    python-version: '3.11'

    cache: 'pip'  # Uses hash of requirements.txt

```

---

## Compliance Mapping

| Control | Implementation | Standard |
|---------|---------------|----------|
| Secret scanning | TruffleHog, Gitleaks | PCI DSS 6.5.10 |
| SAST | Semgrep, Bandit | OWASP Top 10 |
| Dependency scanning | pip-audit, Safety | NIST 800-53 |
| Container scanning | Trivy | CIS Docker |
| Code signing | Cosign | NIST 800-53 |

---

## Emergency Procedures

### Handling Security Vulnerabilities

1. **Immediate**: Block vulnerable images in registry
2. **Short-term**: Patch vulnerable dependencies
3. **Long-term**: Update to secure alternatives

### Pipeline Failure Response

```

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

β”‚                 Security Failure Response                         β”‚

β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€

β”‚                                                                  β”‚

β”‚  Security Scan Fails                                            β”‚

β”‚         β”‚                                                        β”‚

β”‚         β–Ό                                                        β”‚

β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                 β”‚

β”‚  β”‚ Identify    β”‚  β†’ Review vulnerability details                 β”‚

β”‚  β”‚ Issue       β”‚  β†’ Check if applicable to our code             β”‚

β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜                                                 β”‚

β”‚         β”‚                                                        β”‚

β”‚         β–Ό                                                        β”‚

β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                 β”‚

β”‚  β”‚ Decide      β”‚  β†’ Patch available? Use it                     β”‚

β”‚  β”‚ Action      β”‚  β†’ No patch? Add to allowlist (temp)          β”‚

β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜  β†’ Critical? Block deployment                β”‚

β”‚         β”‚                                                        β”‚

β”‚         β–Ό                                                        β”‚

β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                 β”‚

β”‚  β”‚ Document    β”‚  β†’ Create security issue                       β”‚

β”‚  β”‚ & Notify    β”‚  β†’ Notify security team                        β”‚

β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                 β”‚

β”‚                                                                  β”‚

β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

```

---

## References

- [GitHub Actions Security](https://docs.github.com/en/actions/security-guides)
- [OWASP Top 10](https://owasp.org/www-project-top-ten/)
- [NIST 800-53 Security Controls](https://csrc.nist.gov/publications/detail/sp/800-53/rev-5/final)
- [Cosign Documentation](https://docs.sigstore.dev/cosign/signing/overview/)
- [TruffleHog](https://trufflesecurity.com/trufflehog/)