-
Notifications
You must be signed in to change notification settings - Fork 0
451 lines (405 loc) · 17.5 KB
/
Copy pathsecrets-and-sast-vendored.yml
File metadata and controls
451 lines (405 loc) · 17.5 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
# ============================================================================
# Secrets & SAST Scanning — VENDORED from eSolia/devkit
# ============================================================================
# Source: https://github.com/eSolia/devkit/blob/main/.github/workflows/secrets-and-sast.yml
# Vendored: 2026-04-29
#
# Why vendored: hibana is public + cross-org from eSolia/devkit (private).
# GitHub blocks public consumers from calling private reusable workflows,
# and also blocks cross-org calls to private reusable workflows. So we keep
# a local copy here, matching the pattern in RickCogley/pub-cogley,
# RickCogley/tedasuke, and eSolia/marquis.
#
# Drift policy: re-sync periodically by diffing against the upstream file. No
# automated sync — hibana is intentionally not a devkit sync consumer.
#
# Triggered by: .github/workflows/security.yml (the wrapper).
#
# Scanners:
# - Trivy filesystem vuln/secret/license scan
# - Gitleaks secret scan
# - Semgrep SAST (multi-language)
# - Syft SBOM (optional — Syft auto-detects ecosystems)
# - collect-scan-results bridge → scan-results artifact
# - security-summary
# ============================================================================
name: Secrets and SAST
on:
workflow_call:
inputs:
source-paths:
description: "Space-separated paths for Semgrep to scan"
required: false
type: string
default: "."
semgrep-config:
description: "Semgrep rule configurations (space-separated)"
required: false
type: string
default: "p/owasp-top-ten p/secrets p/security-audit"
run-sbom:
description: "Run Syft SBOM generation (Syft auto-detects ecosystems)"
required: false
type: boolean
default: true
upload-sarif:
description: "Upload SARIF to GitHub Security tab (requires Code Security enabled, paid for private repos)"
required: false
type: boolean
default: false
secrets:
SEMGREP_APP_TOKEN:
description: "Optional Semgrep App token for enhanced rules"
required: false
# Cancel in-flight scans when a new commit arrives on the same PR ref.
# Push/release events keep running so evidence always completes for
# merged commits and tagged releases.
concurrency:
group: secrets-and-sast-${{ github.repository }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
# NOTE: Per-job permissions blocks are intentionally omitted.
# GitHub Actions does not support per-job permissions in reusable workflows
# called via workflow_call — they cause startup_failure. The caller's
# permissions (org default: read) apply to all jobs.
jobs:
# ==========================================================================
# Trivy — filesystem vuln/secret/license scan
# ==========================================================================
trivy:
name: Trivy Security Scan
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Compute weekly cache key
id: week
run: echo "key=$(date -u +%Y-%V)" >> "$GITHUB_OUTPUT"
- name: Cache Trivy vulnerability database
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ~/.cache/trivy
key: trivy-db-v1-${{ steps.week.outputs.key }}
restore-keys: |
trivy-db-v1-
- name: Prepare reports directory
run: mkdir -p reports
- name: Trivy filesystem scan — vulnerabilities
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
scan-type: fs
scanners: vuln
format: json
output: reports/trivy-vulns.json
exit-code: "0"
continue-on-error: true
- name: Trivy filesystem scan — secrets
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
scan-type: fs
scanners: secret
format: json
output: reports/trivy-secrets.json
exit-code: "0"
skip-setup-trivy: true
continue-on-error: true
- name: Trivy filesystem scan — licenses
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
scan-type: fs
scanners: license
format: json
output: reports/trivy-licenses.json
exit-code: "0"
skip-setup-trivy: true
continue-on-error: true
- name: Trivy filesystem scan — table summary
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
scan-type: fs
format: table
exit-code: "0"
skip-setup-trivy: true
continue-on-error: true
- name: Upload Trivy reports
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: always()
with:
name: trivy-reports
path: reports/trivy-*.json
retention-days: 30
if-no-files-found: ignore
- name: Trivy Summary
if: always()
run: |
echo "## Trivy Security Scan Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -f "reports/trivy-vulns.json" ]; then
CRITICAL=$(cat reports/trivy-vulns.json | jq '[.Results[]?.Vulnerabilities[]? | select(.Severity=="CRITICAL")] | length' 2>/dev/null || echo "0")
HIGH=$(cat reports/trivy-vulns.json | jq '[.Results[]?.Vulnerabilities[]? | select(.Severity=="HIGH")] | length' 2>/dev/null || echo "0")
echo "### Vulnerabilities" >> $GITHUB_STEP_SUMMARY
echo "- Critical: $CRITICAL" >> $GITHUB_STEP_SUMMARY
echo "- High: $HIGH" >> $GITHUB_STEP_SUMMARY
fi
if [ -f "reports/trivy-secrets.json" ]; then
SECRETS=$(cat reports/trivy-secrets.json | jq '[.Results[]?.Secrets[]?] | length' 2>/dev/null || echo "0")
echo "### Secrets" >> $GITHUB_STEP_SUMMARY
echo "- Found: $SECRETS" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "See artifacts for full details." >> $GITHUB_STEP_SUMMARY
# ==========================================================================
# Gitleaks secret scan
# ==========================================================================
secret-scan:
name: Secret Scanning
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
fetch-depth: 0
- name: Install Gitleaks
run: |
GITLEAKS_VERSION="8.21.2"
curl -sSfL "https://github.com/gitleaks/gitleaks/releases/download/v${GITLEAKS_VERSION}/gitleaks_${GITLEAKS_VERSION}_linux_x64.tar.gz" | tar -xz
chmod +x gitleaks
sudo mv gitleaks /usr/local/bin/
- name: Run Gitleaks
run: |
mkdir -p reports
gitleaks detect --source . --report-path reports/gitleaks.json --report-format json || true
gitleaks detect --source . --report-path reports/gitleaks.sarif --report-format sarif || true
continue-on-error: true
- name: Upload Gitleaks report
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
if: always()
with:
name: gitleaks-report
path: reports/gitleaks.*
retention-days: 30
if-no-files-found: ignore
- name: Gitleaks Summary
if: always()
run: |
echo "## Secret Scanning Results" >> $GITHUB_STEP_SUMMARY
if [ -f "reports/gitleaks.json" ]; then
FINDINGS=$(cat reports/gitleaks.json | jq 'length' 2>/dev/null || echo "0")
if [ "$FINDINGS" = "0" ] || [ "$FINDINGS" = "null" ]; then
echo "No secrets detected" >> $GITHUB_STEP_SUMMARY
else
echo "**$FINDINGS** potential secrets found" >> $GITHUB_STEP_SUMMARY
fi
else
echo "No secrets detected" >> $GITHUB_STEP_SUMMARY
fi
# ==========================================================================
# Semgrep SAST
# ==========================================================================
semgrep:
name: Semgrep SAST
runs-on: ubuntu-latest
container:
image: semgrep/semgrep
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Run Semgrep
env:
SEMGREP_APP_TOKEN: ${{ secrets.SEMGREP_APP_TOKEN }}
SEMGREP_CONFIG: ${{ inputs.semgrep-config }}
SCAN_PATHS: ${{ inputs.source-paths }}
run: |
mkdir -p reports
CONFIG_ARGS=""
for config in $SEMGREP_CONFIG; do
CONFIG_ARGS="$CONFIG_ARGS --config $config"
done
# Single scan pass — SARIF is derived below via jq to avoid
# scanning the codebase twice.
semgrep scan \
$CONFIG_ARGS \
--json \
--output reports/semgrep.json \
$SCAN_PATHS \
|| true
continue-on-error: true
- name: Derive SARIF from Semgrep JSON
run: |
if [ ! -f reports/semgrep.json ]; then
echo '{"version":"2.1.0","runs":[{"tool":{"driver":{"name":"semgrep"}},"results":[]}]}' > reports/semgrep.sarif
exit 0
fi
jq '{
"$schema": "https://schemastore.azurewebsites.net/schemas/json/sarif-2.1.0.json",
version: "2.1.0",
runs: [{
tool: {driver: {name: "semgrep", informationUri: "https://semgrep.dev"}},
results: [(.results // [])[] | {
ruleId: .check_id,
level: (
if (.extra.severity // "INFO") == "ERROR" then "error"
elif (.extra.severity // "INFO") == "WARNING" then "warning"
else "note" end
),
message: {text: (.extra.message // .check_id)},
locations: [{
physicalLocation: {
artifactLocation: {uri: .path},
region: {startLine: (.start.line // 1)}
}
}]
}]
}]
}' reports/semgrep.json > reports/semgrep.sarif
- name: Upload Semgrep reports
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: semgrep-report
path: reports/semgrep.*
retention-days: 30
- name: Upload to GitHub Security
uses: github/codeql-action/upload-sarif@95e58e9a2cdfd71adc6e0353d5c52f41a045d225 # v4.35.2
if: inputs.upload-sarif
with:
sarif_file: reports/semgrep.sarif
- name: Semgrep Summary
if: always()
run: |
echo "## Semgrep SAST Results" >> $GITHUB_STEP_SUMMARY
if [ -f reports/semgrep.json ]; then
FINDINGS=$(cat reports/semgrep.json | python3 -c "import json,sys; d=json.load(sys.stdin); print(len(d.get('results', [])))" 2>/dev/null || echo "0")
echo "Found **$FINDINGS** potential issues" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "See uploaded artifact for details." >> $GITHUB_STEP_SUMMARY
else
echo "No report generated" >> $GITHUB_STEP_SUMMARY
fi
# ==========================================================================
# SBOM Generation (Syft) — optional; Syft auto-detects ecosystems
# ==========================================================================
sbom:
name: Generate SBOM
runs-on: ubuntu-latest
# SBOM runs only on non-PR events — the release-time SBOM is what
# ships with evidence; per-PR SBOM is noise.
if: inputs.run-sbom && github.event_name != 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Install Syft
uses: anchore/sbom-action/download-syft@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
- name: Generate CycloneDX SBOM
run: |
mkdir -p reports
syft dir:. -o cyclonedx-json="reports/sbom.cdx.json" --quiet
echo "SBOM size: $(wc -c < reports/sbom.cdx.json) bytes"
echo "Packages: $(jq '.components | length' reports/sbom.cdx.json)"
- name: Upload SBOM
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: sbom
path: reports/sbom.cdx.json
retention-days: 90
# ==========================================================================
# Collect Scan Results — produces the artifact attest-and-ship.yml consumes
# ==========================================================================
collect-scan-results:
name: Collect Scan Results
runs-on: ubuntu-latest
needs: [trivy, secret-scan, semgrep, sbom]
if: always()
steps:
- name: Download all scan artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
path: ./all-scans
- name: Aggregate into scan-results
run: |
mkdir -p scan-results
cp all-scans/gitleaks-report/gitleaks.sarif scan-results/ 2>/dev/null || true
cp all-scans/semgrep-report/semgrep.sarif scan-results/ 2>/dev/null || true
cp all-scans/gitleaks-report/gitleaks.json scan-results/ 2>/dev/null || true
cp all-scans/semgrep-report/semgrep.json scan-results/ 2>/dev/null || true
cp all-scans/trivy-reports/trivy-vulns.json scan-results/ 2>/dev/null || true
cp all-scans/trivy-reports/trivy-secrets.json scan-results/ 2>/dev/null || true
cp all-scans/trivy-reports/trivy-licenses.json scan-results/ 2>/dev/null || true
cp all-scans/sbom/sbom.cdx.json scan-results/ 2>/dev/null || true
TRIVY_JSON="all-scans/trivy-reports/trivy-vulns.json"
if [[ -f "$TRIVY_JSON" ]]; then
CRITICAL=$(jq '[.Results[]?.Vulnerabilities[]? | select(.Severity=="CRITICAL")] | length' "$TRIVY_JSON" 2>/dev/null || echo 0)
HIGH=$(jq '[.Results[]?.Vulnerabilities[]? | select(.Severity=="HIGH")] | length' "$TRIVY_JSON" 2>/dev/null || echo 0)
else
CRITICAL=0
HIGH=0
fi
GITLEAKS_JSON="all-scans/gitleaks-report/gitleaks.json"
if [[ -f "$GITLEAKS_JSON" ]]; then
SECRETS=$(jq 'length' "$GITLEAKS_JSON" 2>/dev/null || echo 0)
else
SECRETS=0
fi
SCANNERS='["trivy", "gitleaks", "semgrep"]'
if [[ -f "all-scans/sbom/sbom.cdx.json" ]]; then
SCANNERS='["trivy", "gitleaks", "semgrep", "syft"]'
fi
jq -n \
--argjson c "${CRITICAL:-0}" \
--argjson h "${HIGH:-0}" \
--argjson s "${SECRETS:-0}" \
--argjson scanners "$SCANNERS" \
'{
sarif_critical: $c,
sarif_high: $h,
secrets_found: $s,
scan_status: "completed",
scanners: $scanners
}' > scan-results/summary.json
echo "=== scan-results contents ==="
ls -la scan-results/
echo ""
echo "=== summary.json ==="
cat scan-results/summary.json
- name: Upload unified scan-results artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: scan-results
path: scan-results/
retention-days: 90
# ==========================================================================
# Security Summary
# ==========================================================================
security-summary:
name: Security Summary
runs-on: ubuntu-latest
needs: [trivy, secret-scan, semgrep, sbom, collect-scan-results]
if: always()
steps:
- name: Generate Summary
env:
TRIVY_RESULT: ${{ needs.trivy.result }}
SECRET_RESULT: ${{ needs.secret-scan.result }}
SEMGREP_RESULT: ${{ needs.semgrep.result }}
SBOM_RESULT: ${{ needs.sbom.result }}
COLLECT_RESULT: ${{ needs.collect-scan-results.result }}
run: |
echo "## Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Trivy (vulns/secrets/licenses) | $TRIVY_RESULT |" >> $GITHUB_STEP_SUMMARY
echo "| Gitleaks Secrets | $SECRET_RESULT |" >> $GITHUB_STEP_SUMMARY
echo "| Semgrep SAST | $SEMGREP_RESULT |" >> $GITHUB_STEP_SUMMARY
echo "| Syft SBOM | $SBOM_RESULT |" >> $GITHUB_STEP_SUMMARY
echo "| Scan Results Aggregation | $COLLECT_RESULT |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "See individual job artifacts for detailed reports." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "*Workflow vendored from [eSolia/devkit](https://github.com/eSolia/devkit) — see .github/workflows/secrets-and-sast-vendored.yml header for sync policy.*" >> $GITHUB_STEP_SUMMARY