-
Notifications
You must be signed in to change notification settings - Fork 4
281 lines (236 loc) · 12.1 KB
/
security.yml
File metadata and controls
281 lines (236 loc) · 12.1 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
# ReasonKit Core - Security Scanning
# Dependency audits, license checks, SAST, secret scanning
name: Security
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
schedule:
# Run daily at 00:00 UTC
- cron: "0 0 * * *"
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
# Override .cargo/config.toml target-cpu=native to prevent SIGILL on different runners
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS: ""
jobs:
# ═══════════════════════════════════════════════════════════════════════════
# Dependency Vulnerability Scanning
# ═══════════════════════════════════════════════════════════════════════════
cargo-audit:
name: "Cargo Audit"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # stable
with:
toolchain: stable
- name: Install cargo-audit
run: cargo install cargo-audit --locked
- name: Run security audit
run: cargo audit --deny warnings
- name: Generate audit report
if: always()
run: |
cargo audit --json > audit-report.json || true
- name: Upload audit report
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v4
with:
name: security-audit-report
path: audit-report.json
# ═══════════════════════════════════════════════════════════════════════════
# Supply Chain Security with cargo-deny
# ═══════════════════════════════════════════════════════════════════════════
cargo-deny:
name: "Cargo Deny"
runs-on: ubuntu-latest
strategy:
matrix:
checks:
- advisories
- licenses
- bans
- sources
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
- name: Run cargo-deny (${{ matrix.checks }})
uses: EmbarkStudios/cargo-deny-action@3fd3802e88374d3fe9159b834c7714ec57d6c979 # v2.0.15
with:
log-level: warn
command: check ${{ matrix.checks }}
# ═══════════════════════════════════════════════════════════════════════════
# License Compliance Check
# ═══════════════════════════════════════════════════════════════════════════
license-check:
name: "License Check"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # stable
with:
toolchain: stable
- name: Install cargo-license
run: cargo install cargo-license
- name: Generate license report
run: |
cargo license --json > licenses.json
cargo license --tsv > licenses.tsv
- name: Check for GPL licenses
run: |
if grep -i "GPL" licenses.tsv; then
echo "❌ GPL licenses found (incompatible with Apache 2.0)"
exit 1
else
echo "✅ No GPL licenses found"
fi
- name: Upload license report
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v4
with:
name: license-report
path: |
licenses.json
licenses.tsv
# ═══════════════════════════════════════════════════════════════════════════
# Secret Scanning with Gitleaks
# ═══════════════════════════════════════════════════════════════════════════
gitleaks:
name: "Secret Scanning"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
with:
fetch-depth: 0
- name: Run Gitleaks
uses: gitleaks/gitleaks-action@ff98106e4c7b2bc287b24eaf42907196329070c7 # v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
# ═══════════════════════════════════════════════════════════════════════════
# Static Application Security Testing (SAST)
# ═══════════════════════════════════════════════════════════════════════════
clippy-security:
name: "Clippy Security Lints"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # stable
with:
toolchain: stable
components: clippy
- name: Cache cargo
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-security-${{ hashFiles('**/Cargo.lock') }}
- name: Run security-focused Clippy lints
run: |
cargo clippy --all-features -- \
-W clippy::suspicious \
-W clippy::perf \
-W clippy::correctness \
-W clippy::unwrap_used \
-W clippy::expect_used \
-W clippy::panic \
-W clippy::todo \
-W clippy::unimplemented
# ═══════════════════════════════════════════════════════════════════════════
# Semgrep SAST Scanning
# ═══════════════════════════════════════════════════════════════════════════
semgrep:
name: "Semgrep SAST"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
- name: Run Semgrep
uses: returntocorp/semgrep-action@713efdd345f3035192eaa63f56867b88e63e4e5d # v1
with:
config: >-
p/rust
p/security-audit
p/secrets
continue-on-error: true
# ═══════════════════════════════════════════════════════════════════════════
# SBOM Generation
# ═══════════════════════════════════════════════════════════════════════════
sbom:
name: "SBOM Generation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@efa25f7f19611383d5b0ccf2d1c8914531636bf9 # stable
with:
toolchain: stable
- name: Install cargo-sbom
run: cargo install cargo-sbom
- name: Generate SBOM (CycloneDX)
run: cargo sbom --output-format cyclone_dx_json_1_4 > sbom-cyclonedx.json
- name: Generate SBOM (SPDX)
run: cargo sbom --output-format spdx_json_2_3 > sbom-spdx.json
- name: Upload SBOM
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v4
with:
name: sbom
path: |
sbom-cyclonedx.json
sbom-spdx.json
- name: Attach SBOM to release
if: startsWith(github.ref, 'refs/tags/v')
uses: softprops/action-gh-release@26994186c0ac3ef5cae75ac16aa32e8153525f77 # v1
with:
files: |
sbom-cyclonedx.json
sbom-spdx.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# ═══════════════════════════════════════════════════════════════════════════
# Dependency Review (PR only)
# ═══════════════════════════════════════════════════════════════════════════
dependency-review:
name: "Dependency Review"
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4
- name: Dependency Review
uses: actions/dependency-review-action@05fe4576374b728f0c523d6a13d64c25081e0803 # v4
with:
fail-on-severity: moderate
deny-licenses: GPL-3.0, AGPL-3.0
# ═══════════════════════════════════════════════════════════════════════════
# Security Summary
# ═══════════════════════════════════════════════════════════════════════════
security-summary:
name: "Security Summary"
runs-on: ubuntu-latest
needs: [cargo-audit, cargo-deny, license-check, gitleaks, clippy-security]
if: always()
steps:
- name: Generate summary
run: |
echo "## 🔒 Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Cargo Audit | ${{ needs.cargo-audit.result == 'success' && '✅ Pass' || '❌ Fail' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Cargo Deny | ${{ needs.cargo-deny.result == 'success' && '✅ Pass' || '❌ Fail' }} |" >> $GITHUB_STEP_SUMMARY
echo "| License Check | ${{ needs.license-check.result == 'success' && '✅ Pass' || '❌ Fail' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Secret Scanning | ${{ needs.gitleaks.result == 'success' && '✅ Pass' || '❌ Fail' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Clippy Security | ${{ needs.clippy-security.result == 'success' && '✅ Pass' || '❌ Fail' }} |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ needs.cargo-audit.result }}" = "success" ] && \
[ "${{ needs.cargo-deny.result }}" = "success" ] && \
[ "${{ needs.license-check.result }}" = "success" ] && \
[ "${{ needs.gitleaks.result }}" = "success" ]; then
echo "✅ **All security checks passed!**" >> $GITHUB_STEP_SUMMARY
else
echo "⚠️ **Some security checks failed. Review above.**" >> $GITHUB_STEP_SUMMARY
fi