Repository navigation
297 lines (263 loc) · 12 KB
/
Copy pathsecurity-scanning.yml
File metadata and controls
297 lines (263 loc) · 12 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
# Security Scanning CI Workflow
# Issue #740: Automated security scanning in CI/CD pipeline
#
# Runs on: push to main/develop, all PRs, and weekly schedule
# Covers: SAST (Clippy + CodeQL), dependency audits, secret scanning
name: Security Scanning
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
schedule:
# Weekly full scan every Monday at 02:00 UTC
- cron: "0 2 * * 1"
workflow_dispatch:
permissions:
contents: read
security-events: write
actions: read
jobs:
# ─────────────────────────────────────────────────────────────────────────────
# 1. SAST — Rust (Clippy deny + cargo-audit)
# ─────────────────────────────────────────────────────────────────────────────
rust-sast:
name: Rust SAST
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: ${{ runner.os }}-cargo-
- name: Clippy (deny warnings + security lints)
run: |
cargo clippy --all-targets --all-features -- \
-D warnings \
-D clippy::unwrap_used \
-D clippy::expect_used \
-D clippy::panic \
-D clippy::integer_arithmetic \
-W clippy::pedantic
- name: Install cargo-audit
run: cargo install --locked cargo-audit@0.21.0
- name: Dependency vulnerability audit (Rust)
run: cargo audit --deny warnings
# ─────────────────────────────────────────────────────────────────────────────
# 2. SAST — CodeQL (multi-language)
# ─────────────────────────────────────────────────────────────────────────────
codeql:
name: CodeQL Analysis
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
language: [javascript-typescript]
steps:
- uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
queries: security-extended,security-and-quality
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: /language:${{ matrix.language }}
upload: true
# ─────────────────────────────────────────────────────────────────────────────
# 3. Dependency Scanning — pnpm (single root workspace lockfile)
# ─────────────────────────────────────────────────────────────────────────────
dependency-audit:
name: Dependency Audit (pnpm)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 12.11.2
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: pnpm audit (moderate+)
run: |
pnpm audit --audit-level=moderate \
--json > pnpm-audit.json || true
- name: Check for high/critical vulnerabilities
run: |
CRITICAL=$(jq '.metadata.vulnerabilities.critical // 0' pnpm-audit.json)
HIGH=$(jq '.metadata.vulnerabilities.high // 0' pnpm-audit.json)
MODERATE=$(jq '.metadata.vulnerabilities.moderate // 0' pnpm-audit.json)
echo "Critical: $CRITICAL, High: $HIGH, Moderate: $MODERATE"
if [ "$CRITICAL" -gt "0" ]; then
echo "::error::Critical pnpm vulnerabilities found in the workspace"
exit 1
fi
if [ "$HIGH" -gt "0" ]; then
echo "::error::High pnpm vulnerabilities found in the workspace"
exit 1
fi
- name: Upload pnpm audit report
uses: actions/upload-artifact@v4
if: always()
with:
name: pnpm-audit-report
path: pnpm-audit.json
retention-days: 30
# ─────────────────────────────────────────────────────────────────────────────
# 4. Secret Scanning (gitleaks) - Enhanced with custom config
# ─────────────────────────────────────────────────────────────────────────────
secret-scan:
name: Secret Scanning
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # full history for gitleaks
- name: Run gitleaks with custom config
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }} # optional for SARIF upload
with:
config-path: .gitleaks.toml
- name: Upload gitleaks SARIF
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: results.sarif
continue-on-error: true # SARIF upload is best-effort
- name: Generate remediation report on failure
if: failure()
run: |
echo "## Secret Detection Report" >> $GITHUB_STEP_SUMMARY
echo "Secrets were detected in the repository. Please review and remediate:" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Next Steps" >> $GITHUB_STEP_SUMMARY
echo "1. Run \`./scripts/secret-detection.sh scan\` locally" >> $GITHUB_STEP_SUMMARY
echo "2. Review the generated remediation suggestions" >> $GITHUB_STEP_SUMMARY
echo "3. Remove or rotate any real credentials found" >> $GITHUB_STEP_SUMMARY
echo "4. Update documentation to use placeholder tokens" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Prevention" >> $GITHUB_STEP_SUMMARY
echo "- Install pre-commit hooks: \`./scripts/secret-detection.sh install-hooks\`" >> $GITHUB_STEP_SUMMARY
echo "- Use environment variables for all secrets" >> $GITHUB_STEP_SUMMARY
echo "- Never commit real credentials" >> $GITHUB_STEP_SUMMARY
# ─────────────────────────────────────────────────────────────────────────────
# 5. Container Scanning (Trivy)
# ─────────────────────────────────────────────────────────────────────────────
container-scan:
name: Container Scanning
runs-on: ubuntu-latest
strategy:
matrix:
image:
- context: frontend
tag: scavngr-frontend
- context: backend
tag: scavngr-backend
- context: indexer
tag: scavngr-indexer
steps:
- uses: actions/checkout@v4
- name: Build Docker image
run: |
docker build \
-t ${{ matrix.image.tag }}:${{ github.sha }} \
./${{ matrix.image.context }}
- name: Scan image with Trivy
uses: aquasecurity/trivy-action@0.28.0
with:
image-ref: ${{ matrix.image.tag }}:${{ github.sha }}
format: sarif
output: trivy-${{ matrix.image.tag }}.sarif
severity: CRITICAL,HIGH
exit-code: "1"
ignore-unfixed: true
- name: Upload Trivy SARIF
uses: github/codeql-action/upload-sarif@v3
if: always()
with:
sarif_file: trivy-${{ matrix.image.tag }}.sarif
category: container-${{ matrix.image.tag }}
# ─────────────────────────────────────────────────────────────────────────────
# 6. Security Policy Enforcement (OSSF Scorecard)
# ─────────────────────────────────────────────────────────────────────────────
scorecard:
name: OSSF Scorecard
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'schedule'
permissions:
security-events: write
id-token: write
contents: read
actions: read
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Run Scorecard
uses: ossf/scorecard-action@v2.4.0
with:
results_file: scorecard.sarif
results_format: sarif
publish_results: true
- name: Upload Scorecard SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: scorecard.sarif
category: ossf-scorecard
# ─────────────────────────────────────────────────────────────────────────────
# 7. Vulnerability Reporting — aggregate summary
# ─────────────────────────────────────────────────────────────────────────────
report:
name: Security Report
runs-on: ubuntu-latest
needs:
- rust-sast
- dependency-audit
- secret-scan
if: always()
steps:
- name: Download all audit artifacts
uses: actions/download-artifact@v4
with:
pattern: pnpm-audit-*
merge-multiple: true
- 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 "| Rust SAST (Clippy + cargo-audit) | ${{ needs.rust-sast.result }} |" \
>> $GITHUB_STEP_SUMMARY
echo "| pnpm Dependency Audit | ${{ needs.dependency-audit.result }} |" \
>> $GITHUB_STEP_SUMMARY
echo "| Secret Scanning (gitleaks) | ${{ needs.secret-scan.result }} |" \
>> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Scan triggered by: \`${{ github.event_name }}\` on \`${{ github.ref_name }}\`" \
>> $GITHUB_STEP_SUMMARY
- name: Fail if any critical check failed
if: |
needs.rust-sast.result == 'failure' ||
needs.secret-scan.result == 'failure'
run: |
echo "::error::One or more critical security checks failed."
exit 1