-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaction.yml
More file actions
526 lines (484 loc) · 19.2 KB
/
action.yml
File metadata and controls
526 lines (484 loc) · 19.2 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
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
name: 'agent-bom Scan'
description: 'Run agent-bom in CI/CD to scan AI agents, MCP servers, images, and IaC. Emit SARIF and map blast radius from packages to credentials and tools.'
author: 'agent-bom'
branding:
icon: 'shield'
color: 'green'
inputs:
scan-type:
description: 'Scan mode. Default `scan` runs the full agent/MCP discovery pipeline. Focused modes: image, fs, iac, sbom, secrets, code, and agents.'
required: false
default: 'scan'
scan-ref:
description: 'Target reference for focused modes — image reference, filesystem path, SBOM file path, or IaC paths (comma-separated). Not required for the default `scan` mode.'
required: false
default: ''
severity-threshold:
description: 'Fail if vulnerabilities at or above this severity (critical, high, medium, low). Empty = no gate.'
required: false
default: ''
warn-on-severity:
description: 'Warn (non-blocking) if vulnerabilities at or above this severity. Use with severity-threshold for two-tier gates.'
required: false
default: ''
policy:
description: 'Path to policy file (JSON/YAML) for policy-as-code gates.'
required: false
default: ''
enrich:
description: 'Enable NVD CVSS, EPSS, and CISA KEV enrichment.'
required: false
default: 'false'
format:
description: 'Output format. Core: sarif (default), json, html, cyclonedx, spdx. Plain/no-color: plain (alias: text). Other: console, mermaid, svg, graph, graph-html, badge, prometheus.'
required: false
default: 'sarif'
output:
description: 'Output file path for scan results. Default: agent-bom-results.sarif (for SARIF format).'
required: false
default: ''
upload-sarif:
description: 'Upload SARIF results to GitHub Security tab.'
required: false
default: 'false'
auto-update-db:
description: 'Auto-update vulnerability database if stale (>7 days). Disable for air-gapped or fully cached runs.'
required: false
default: 'true'
fail-on-kev:
description: 'Fail if any CISA Known Exploited Vulnerability is found.'
required: false
default: 'false'
ai-enrich:
description: 'Enable LLM-powered risk analysis (requires Ollama or API key).'
required: false
default: 'false'
ai-model:
description: 'LLM model for AI enrichment (e.g. ollama/llama3.2, openai/gpt-4o-mini).'
required: false
default: ''
python-version:
description: 'Python version to use.'
required: false
default: '3.11'
agent-bom-version:
description: 'agent-bom package version to install (for example 0.75.x). Empty = latest from PyPI.'
required: false
default: ''
install-from-source:
description: 'Install agent-bom from local source (pyproject.toml) instead of PyPI. Use in CI dogfood to test unreleased code.'
required: false
default: 'false'
image:
description: 'Docker image to scan (e.g. nginx:1.25).'
required: false
default: ''
config-dir:
description: 'Path to MCP config directory to scan.'
required: false
default: ''
sbom:
description: 'Path to existing SBOM file (CycloneDX or SPDX JSON) to ingest.'
required: false
default: ''
remediate:
description: 'Generate remediation plan at this path (e.g. remediation.md).'
required: false
default: ''
badge:
description: 'Generate shields.io badge JSON at this path (e.g. agent-bom-badge.json).'
required: false
default: ''
pr-comment:
description: 'Post a findings summary comment on the pull request (requires GITHUB_TOKEN with pull-requests: write).'
required: false
default: 'false'
ignore-file:
description: 'Path to ignore/allowlist file (default: .agent-bom-ignore.yaml). Suppress known false positives by CVE ID, package, or finding type.'
required: false
default: ''
iac:
description: 'Path(s) to scan for IaC misconfigurations (Dockerfile, Kubernetes, Terraform, CloudFormation). Comma-separated.'
required: false
default: ''
ai-inventory:
description: 'Path(s) to scan for AI component inventory (SDK imports, model references, deprecated models). Comma-separated.'
required: false
default: ''
os-packages:
description: 'Enable OS-level package scanning (dpkg/rpm/apk).'
required: false
default: 'false'
baseline:
description: 'Path to a baseline report JSON for delta scanning (only report new findings).'
required: false
default: ''
skill-only:
description: 'Scan ONLY skill/instruction files (CLAUDE.md, .cursorrules, AGENTS.md); skip agent/package/CVE scanning.'
required: false
default: 'false'
gpu-scan:
description: 'Enable GPU infrastructure scanning (NVIDIA NIM/CUDA containers, DCGM).'
required: false
default: 'false'
exclude-unfixable:
description: 'Exclude vulnerabilities without available fixes from SARIF output'
required: false
default: 'false'
outputs:
sarif-file:
description: 'Path to generated SARIF file (if format=sarif).'
value: ${{ steps.scan.outputs.sarif_file }}
exit-code:
description: 'Scan exit code (0=clean, 1=violations found).'
value: ${{ steps.scan.outputs.exit_code }}
vulnerability-count:
description: 'Number of vulnerabilities found.'
value: ${{ steps.scan.outputs.vuln_count }}
badge-file:
description: 'Path to generated badge JSON (if badge input is set).'
value: ${{ steps.scan.outputs.badge_file }}
runs:
using: 'composite'
steps:
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: ${{ inputs.python-version }}
- name: Cache agent-bom vulnerability database
uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
with:
path: ~/.agent-bom/vulns.db
key: agent-bom-vulndb-${{ runner.os }}-${{ inputs.python-version }}-v1
restore-keys: |
agent-bom-vulndb-${{ runner.os }}-
- name: Install agent-bom
shell: bash
env:
AGENT_BOM_VERSION: ${{ inputs.agent-bom-version }}
AI_ENRICH: ${{ inputs.ai-enrich }}
INSTALL_FROM_SOURCE: ${{ inputs.install-from-source }}
run: |
if [ "$INSTALL_FROM_SOURCE" = "true" ]; then
# Install from local source (pyproject.toml) — used by CI dogfood to test unreleased code
if [ "$AI_ENRICH" = "true" ]; then
pip install ".[ai-enrich]" packaging
else
pip install "." packaging
fi
else
PKG="agent-bom"
if [ -n "$AGENT_BOM_VERSION" ]; then
PKG="agent-bom==$AGENT_BOM_VERSION"
fi
if [ "$AI_ENRICH" = "true" ]; then
pip install "${PKG}[ai-enrich]" packaging
else
pip install "$PKG" packaging
fi
fi
- name: Run agent-bom agents
id: scan
shell: bash
env:
INPUT_SCAN_TYPE: ${{ inputs.scan-type }}
INPUT_SCAN_REF: ${{ inputs.scan-ref }}
INPUT_FORMAT: ${{ inputs.format }}
INPUT_OUTPUT: ${{ inputs.output }}
INPUT_SEVERITY: ${{ inputs.severity-threshold }}
INPUT_WARN_ON: ${{ inputs.warn-on-severity }}
INPUT_POLICY: ${{ inputs.policy }}
INPUT_ENRICH: ${{ inputs.enrich }}
INPUT_AUTO_UPDATE_DB: ${{ inputs.auto-update-db }}
INPUT_FAIL_ON_KEV: ${{ inputs.fail-on-kev }}
INPUT_AI_ENRICH: ${{ inputs.ai-enrich }}
INPUT_AI_MODEL: ${{ inputs.ai-model }}
INPUT_IMAGE: ${{ inputs.image }}
INPUT_CONFIG_DIR: ${{ inputs.config-dir }}
INPUT_SBOM: ${{ inputs.sbom }}
INPUT_REMEDIATE: ${{ inputs.remediate }}
INPUT_BADGE: ${{ inputs.badge }}
INPUT_IGNORE_FILE: ${{ inputs.ignore-file }}
INPUT_IAC: ${{ inputs.iac }}
INPUT_AI_INVENTORY: ${{ inputs.ai-inventory }}
INPUT_OS_PACKAGES: ${{ inputs.os-packages }}
INPUT_BASELINE: ${{ inputs.baseline }}
INPUT_SKILL_ONLY: ${{ inputs.skill-only }}
INPUT_GPU_SCAN: ${{ inputs.gpu-scan }}
INPUT_EXCLUDE_UNFIXABLE: ${{ inputs.exclude-unfixable }}
run: |
# Determine output file path
if [ -n "$INPUT_OUTPUT" ]; then
SARIF_FILE="$INPUT_OUTPUT"
else
SARIF_FILE="agent-bom-results.sarif"
fi
# Map scan-type to focused command (Trivy-style)
# scan → agent-bom agents (full auto-detect, default)
# image → agent-bom image <ref>
# fs → agent-bom fs <path>
# sbom → agent-bom sbom <path>
# iac → agent-bom iac <paths...>
case "${INPUT_SCAN_TYPE:-scan}" in
image)
if [ -z "$INPUT_SCAN_REF" ] && [ -n "$INPUT_IMAGE" ]; then
INPUT_SCAN_REF="$INPUT_IMAGE"
fi
if [ -z "$INPUT_SCAN_REF" ]; then
echo "::error::scan-type=image requires scan-ref (image reference) or image input"
exit 1
fi
ARGS="image $INPUT_SCAN_REF"
;;
fs)
ARGS="fs ${INPUT_SCAN_REF:-.}"
;;
sbom)
if [ -z "$INPUT_SCAN_REF" ] && [ -n "$INPUT_SBOM" ]; then
INPUT_SCAN_REF="$INPUT_SBOM"
fi
if [ -z "$INPUT_SCAN_REF" ]; then
echo "::error::scan-type=sbom requires scan-ref (SBOM file path) or sbom input"
exit 1
fi
ARGS="sbom $INPUT_SCAN_REF"
;;
iac)
if [ -z "$INPUT_SCAN_REF" ] && [ -n "$INPUT_IAC" ]; then
INPUT_SCAN_REF="$INPUT_IAC"
fi
if [ -z "$INPUT_SCAN_REF" ]; then
echo "::error::scan-type=iac requires scan-ref (IaC paths) or iac input"
exit 1
fi
ARGS="iac"
IFS=',' read -ra IAC_REFS <<< "$INPUT_SCAN_REF"
for p in "${IAC_REFS[@]}"; do
ARGS="$ARGS $(echo "$p" | xargs)"
done
;;
secrets)
ARGS="secrets ${INPUT_SCAN_REF:-.}"
;;
code)
ARGS="code ${INPUT_SCAN_REF:-.}"
;;
agents)
ARGS="agents"
;;
scan|"")
ARGS="scan"
;;
*)
echo "::error::Unknown scan-type: $INPUT_SCAN_TYPE. Use: scan, image, fs, sbom, iac, secrets, code, agents"
exit 1
;;
esac
# Output format
if [ "$INPUT_FORMAT" = "sarif" ]; then
ARGS="$ARGS -f sarif -o $SARIF_FILE"
elif [ -n "$INPUT_FORMAT" ]; then
ARGS="$ARGS -f $INPUT_FORMAT"
if [ -n "$INPUT_OUTPUT" ]; then
ARGS="$ARGS -o $INPUT_OUTPUT"
fi
fi
# Severity gate
if [ -n "$INPUT_SEVERITY" ]; then
ARGS="$ARGS --fail-on-severity $INPUT_SEVERITY"
fi
# Warn-on severity (non-blocking)
if [ -n "$INPUT_WARN_ON" ]; then
ARGS="$ARGS --warn-on $INPUT_WARN_ON"
fi
# Policy file
if [ -n "$INPUT_POLICY" ]; then
ARGS="$ARGS --policy $INPUT_POLICY"
fi
# Enrichment
if [ "$INPUT_ENRICH" = "true" ]; then
ARGS="$ARGS --enrich"
fi
# Auto-update vulnerability database
if [ "$INPUT_AUTO_UPDATE_DB" = "true" ]; then
ARGS="$ARGS --auto-update-db"
fi
# KEV gate
if [ "$INPUT_FAIL_ON_KEV" = "true" ]; then
ARGS="$ARGS --fail-on-kev"
fi
# Docker image (skip if scan-type=image — already in command)
if [ -n "$INPUT_IMAGE" ] && [ "$INPUT_SCAN_TYPE" != "image" ]; then
ARGS="$ARGS --image $INPUT_IMAGE"
fi
# Config directory
if [ -n "$INPUT_CONFIG_DIR" ]; then
ARGS="$ARGS --config-dir $INPUT_CONFIG_DIR"
fi
# Existing SBOM (skip if scan-type=sbom — already in command)
if [ -n "$INPUT_SBOM" ] && [ "$INPUT_SCAN_TYPE" != "sbom" ]; then
ARGS="$ARGS --sbom $INPUT_SBOM"
fi
# Remediation plan
if [ -n "$INPUT_REMEDIATE" ]; then
ARGS="$ARGS --remediate $INPUT_REMEDIATE"
fi
# AI enrichment
if [ "$INPUT_AI_ENRICH" = "true" ]; then
ARGS="$ARGS --ai-enrich"
if [ -n "$INPUT_AI_MODEL" ]; then
ARGS="$ARGS --ai-model $INPUT_AI_MODEL"
fi
fi
# Ignore file
if [ -n "$INPUT_IGNORE_FILE" ]; then
ARGS="$ARGS --ignore-file $INPUT_IGNORE_FILE"
fi
# IaC scanning paths (skip if scan-type=iac — already in command)
if [ -n "$INPUT_IAC" ] && [ "$INPUT_SCAN_TYPE" != "iac" ]; then
IFS=',' read -ra IAC_PATHS <<< "$INPUT_IAC"
for p in "${IAC_PATHS[@]}"; do
ARGS="$ARGS --iac $(echo "$p" | xargs)"
done
fi
# AI inventory scanning paths
if [ -n "$INPUT_AI_INVENTORY" ]; then
IFS=',' read -ra AI_PATHS <<< "$INPUT_AI_INVENTORY"
for p in "${AI_PATHS[@]}"; do
ARGS="$ARGS --ai-inventory $(echo "$p" | xargs)"
done
fi
# OS package scanning
if [ "$INPUT_OS_PACKAGES" = "true" ]; then
ARGS="$ARGS --os-packages"
fi
# Delta scanning baseline
if [ -n "$INPUT_BASELINE" ]; then
ARGS="$ARGS --baseline $INPUT_BASELINE --delta-mode new-only"
fi
# Skill-only mode
if [ "$INPUT_SKILL_ONLY" = "true" ]; then
ARGS="$ARGS --skill-only"
fi
# GPU infrastructure scanning
if [ "$INPUT_GPU_SCAN" = "true" ]; then
ARGS="$ARGS --gpu-scan"
fi
# Exclude unfixable findings from SARIF output
if [ "$INPUT_EXCLUDE_UNFIXABLE" = "true" ]; then
ARGS="$ARGS --exclude-unfixable"
fi
# Run scan, capture exit code
set +e
agent-bom $ARGS
EXIT_CODE=$?
set -e
# Extract vuln count from SARIF
VULN_COUNT=0
if [ -f "$SARIF_FILE" ]; then
VULN_COUNT=$(python3 -c "import json; d=json.load(open('$SARIF_FILE')); print(len(d.get('runs',[{}])[0].get('results',[])))" 2>/dev/null || echo 0)
fi
# Generate badge from SARIF results (no second scan)
BADGE_FILE=""
if [ -n "$INPUT_BADGE" ] && [ -f "$SARIF_FILE" ]; then
python3 -c "
import json, sys
try:
results = json.load(open('$SARIF_FILE')).get('runs', [{}])[0].get('results', [])
rules = {r['id']: r for r in json.load(open('$SARIF_FILE')).get('runs', [{}])[0].get('tool', {}).get('driver', {}).get('rules', [])}
critical = high = 0
for r in results:
rid = r.get('ruleId', '')
rule = rules.get(rid, {})
score = float(rule.get('properties', {}).get('security-severity', '0'))
if score > 9.0: critical += 1
elif score >= 7.0: high += 1
total = len(results)
if critical > 0:
color, msg = 'critical', f'{critical} critical, {high} high'
elif high > 0:
color, msg = 'orange', f'{high} high, {total} total'
elif total > 0:
color, msg = 'yellow', f'{total} findings'
else:
color, msg = 'brightgreen', 'clean'
badge = {'schemaVersion': 1, 'label': 'agent-bom', 'message': msg, 'color': color, 'namedLogo': 'shield'}
with open('$INPUT_BADGE', 'w') as f:
json.dump(badge, f, indent=2)
except Exception as e:
print(f'Badge generation failed: {e}', file=sys.stderr)
" 2>/dev/null || true
if [ -f "$INPUT_BADGE" ]; then
BADGE_FILE="$INPUT_BADGE"
fi
fi
echo "sarif_file=$SARIF_FILE" >> "$GITHUB_OUTPUT"
echo "exit_code=$EXIT_CODE" >> "$GITHUB_OUTPUT"
echo "vuln_count=$VULN_COUNT" >> "$GITHUB_OUTPUT"
echo "badge_file=$BADGE_FILE" >> "$GITHUB_OUTPUT"
exit $EXIT_CODE
- name: Post PR comment with findings summary
if: inputs.pr-comment == 'true' && github.event_name == 'pull_request'
shell: python
env:
GH_TOKEN: ${{ github.token }}
SARIF_FILE: ${{ steps.scan.outputs.sarif_file }}
VULN_COUNT: ${{ steps.scan.outputs.vuln_count }}
EXIT_CODE: ${{ steps.scan.outputs.exit_code }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REPO: ${{ github.repository }}
run: |
import json, os, subprocess
marker = "<!-- agent-bom-scan-comment -->"
sarif_file = os.environ.get("SARIF_FILE", "")
exit_code = os.environ.get("EXIT_CODE", "0")
vuln_count = os.environ.get("VULN_COUNT", "0")
pr_number = os.environ.get("PR_NUMBER", "")
repo = os.environ.get("REPO", "")
status = "✅ Clean — no violations found" if exit_code == "0" else f"⚠️ {vuln_count} vulnerability finding(s)"
# Map SARIF security-severity scores to agent-bom severity labels
def _score_to_severity(score: float) -> str:
if score > 9.0:
return "CRITICAL"
if score >= 7.0:
return "HIGH"
if score >= 4.0:
return "MEDIUM"
if score >= 0.1:
return "LOW"
return "NONE"
findings_lines = []
if sarif_file and os.path.isfile(sarif_file):
try:
sarif = json.load(open(sarif_file))
run = sarif.get("runs", [{}])[0]
results = run.get("results", [])
rules = {r["id"]: r for r in run.get("tool", {}).get("driver", {}).get("rules", [])}
for r in results[:10]:
rule_id = r.get("ruleId", "")
rule = rules.get(rule_id, {})
score = float(rule.get("properties", {}).get("security-severity", "0"))
severity = _score_to_severity(score)
msg = r.get("message", {}).get("text", "")
findings_lines.append(f"- **{severity}** `{rule_id}` — {msg}")
if len(results) > 10:
findings_lines.append(f"- ... and {len(results) - 10} more")
except Exception:
pass
findings_text = "\n".join(findings_lines) if findings_lines else "No findings."
body = f"{marker}\n## agent-bom Security Scan\n\n**Status:** {status}\n\n### Findings\n{findings_text}\n\n<sub>Generated by [agent-bom](https://github.com/msaad00/agent-bom)</sub>"
result = subprocess.run(
["gh", "api", f"repos/{repo}/issues/{pr_number}/comments", "--jq", f'.[] | select(.body | contains("{marker}")) | .id'],
capture_output=True, text=True
)
existing_id = result.stdout.strip().splitlines()[0] if result.stdout.strip() else ""
if existing_id:
subprocess.run(["gh", "api", f"repos/{repo}/issues/comments/{existing_id}", "-X", "PATCH", "-f", f"body={body}"], check=True)
else:
subprocess.run(["gh", "api", f"repos/{repo}/issues/{pr_number}/comments", "-f", f"body={body}"], check=True)
- name: Upload SARIF to GitHub Security tab
if: inputs.upload-sarif == 'true' && always()
uses: github/codeql-action/upload-sarif@9792ccaef0455e446c567163589397e8c3ac2e0d # v3
with:
sarif_file: ${{ steps.scan.outputs.sarif_file }}
category: agent-bom