-
Notifications
You must be signed in to change notification settings - Fork 0
240 lines (207 loc) · 8.42 KB
/
security.yml
File metadata and controls
240 lines (207 loc) · 8.42 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
# ─────────────────────────────────────────────────────────────────────────────
# DevSec Vault — Security Scanning Pipeline
# All actions pinned to full commit SHA (Scorecard: Pinned-Dependencies)
# ─────────────────────────────────────────────────────────────────────────────
name: Security
on:
push:
branches: ["main", "develop"]
pull_request:
schedule:
- cron: "0 3 * * 1" # Weekly Monday 03:00 UTC
# Minimal global permissions — each job declares only what it needs
permissions:
contents: read
jobs:
# ── 1. Secret Scanning ────────────────────────────────────────────────────
secret-scan:
name: Secret Scan (file + history)
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write # SARIF upload — scoped to this job only
steps:
- name: Checkout (full history)
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: "3.11"
cache: "pip"
- name: Install DevSec Vault dependencies
run: pip install "click==8.1.8" "rich==13.9.4"
- name: Create reports directory
run: mkdir -p reports
- name: Scan source files
run: |
python src/cli.py scan src/ \
--format json \
--output reports/file-scan.json \
--baseline .devsec-baseline.json \
--fail-on high
env:
DEVSEC_EXCLUDE: "src/fake_secrets.py"
- name: Scan git history (last 300 commits)
run: |
python src/cli.py history \
--max-commits 300 \
--format sarif \
--output reports/history-scan.sarif \
--baseline .devsec-baseline.json
continue-on-error: true
- name: Upload SARIF — history scan
uses: github/codeql-action/upload-sarif@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
if: always() && hashFiles('reports/history-scan.sarif') != ''
with:
sarif_file: reports/history-scan.sarif
category: devsec-vault-history
continue-on-error: true
- name: Upload scan artifacts
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
if: always()
with:
name: scan-reports
path: reports/
retention-days: 30
# ── 2. Static Analysis (Bandit) ───────────────────────────────────────────
static-analysis:
name: Static Analysis (Bandit)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: "3.11"
- name: Install Bandit
run: pip install "bandit==1.8.3"
- name: Create reports directory
run: mkdir -p reports
- name: Run Bandit
run: |
bandit -r src/ \
--exclude src/fake_secrets.py \
--format json \
--output reports/bandit.json \
--severity-level medium \
--confidence-level medium || true
- name: Print Bandit summary
if: always()
run: |
python3 -c "
import json, sys
try:
d = json.load(open('reports/bandit.json'))
m = d.get('metrics', {}).get('_totals', {})
issues = d.get('results', [])
print(f'Bandit: {len(issues)} issue(s) found')
for sev in ['HIGH','MEDIUM']:
count = m.get(f'SEVERITY.{sev}', 0)
if count: print(f' {sev}: {count}')
if any(r[\"issue_severity\"] == \"HIGH\" for r in issues):
print('HIGH severity issues found — failing')
sys.exit(1)
except Exception as e:
print(f'Could not parse bandit report: {e}')
"
- name: Upload Bandit report
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
if: always()
with:
name: bandit-report
path: reports/bandit.json
retention-days: 30
# ── 3. CodeQL ─────────────────────────────────────────────────────────────
codeql:
name: CodeQL (Python)
runs-on: ubuntu-latest
continue-on-error: true
permissions:
contents: read
actions: read
security-events: write # SARIF upload — scoped to this job only
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Initialize CodeQL
uses: github/codeql-action/init@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
with:
languages: python
queries: security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@0d579ffd059c29b07949a3cce3983f0780820c98 # v4.32.6
with:
category: "/language:python"
continue-on-error: true
# ── 4. Dependency Audit ───────────────────────────────────────────────────
dependency-audit:
name: Dependency Audit (pip-audit)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: "3.11"
- name: Install pip-audit
run: pip install "pip-audit==2.9.0"
- name: Create reports directory
run: mkdir -p reports
- name: Run pip-audit
run: |
pip-audit \
--requirement requirements.txt \
--format json \
--output reports/pip-audit.json \
--progress-spinner off
continue-on-error: true
- name: Print pip-audit summary
if: always()
run: |
python3 -c "
import json
try:
d = json.load(open('reports/pip-audit.json'))
vulns = [dep for dep in d if dep.get('vulns')]
print(f'pip-audit: {len(vulns)} package(s) with vulnerabilities')
for dep in vulns:
for v in dep['vulns']:
print(f' {dep[\"name\"]}=={dep[\"version\"]}: {v[\"id\"]} ({v.get(\"fix_versions\",[])})')
except Exception as e:
print(f'Could not parse pip-audit report: {e}')
"
- name: Upload pip-audit report
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
if: always()
with:
name: dependency-audit
path: reports/pip-audit.json
retention-days: 30
# ── 5. Unit Tests ─────────────────────────────────────────────────────────
test:
name: Unit Tests
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- name: Set up Python
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with:
python-version: "3.11"
cache: "pip"
- name: Install dependencies
run: pip install "click==8.1.8" "rich==13.9.4" "pytest==9.0.3"
- name: Run tests
run: pytest tests/ -v --tb=short