-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaction.yml
More file actions
295 lines (247 loc) · 8.56 KB
/
action.yml
File metadata and controls
295 lines (247 loc) · 8.56 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
name: 'Adversarial Debate Security Analysis'
description: 'AI Red Team Security Testing using adversarial agent mesh'
author: 'Gareth Roberts'
branding:
icon: 'shield'
color: 'red'
inputs:
target:
description: 'File or directory to analyze'
required: false
default: '.'
agent:
description: 'Single agent to run (exploit, break, chaos) or "all" for full pipeline'
required: false
default: 'all'
provider:
description: 'LLM provider (anthropic, openai, azure, ollama, mock)'
required: false
default: 'anthropic'
anthropic-api-key:
description: 'Anthropic API key (if using anthropic provider)'
required: false
openai-api-key:
description: 'OpenAI API key (if using openai provider)'
required: false
azure-openai-key:
description: 'Azure OpenAI API key (if using azure provider)'
required: false
azure-openai-endpoint:
description: 'Azure OpenAI endpoint URL (if using azure provider)'
required: false
output-format:
description: 'Output format (json, sarif, html, markdown)'
required: false
default: 'sarif'
output-file:
description: 'Output file path'
required: false
default: 'security-analysis.sarif'
baseline-file:
description: 'Path to baseline bundle (in repo) used for PR regression gating'
required: false
default: '.adversarial-baseline.json'
baseline-mode:
description: 'Baseline gating mode (off, only-new)'
required: false
default: 'only-new'
fail-on-findings:
description: 'Fail the action if security findings are detected'
required: false
default: 'true'
severity-threshold:
description: 'Minimum severity to fail on (critical, high, medium, low)'
required: false
default: 'high'
time-budget:
description: 'Time budget in seconds for analysis'
required: false
default: '300'
python-version:
description: 'Python version to use'
required: false
default: '3.11'
outputs:
findings-count:
description: 'Total number of security findings'
value: ${{ steps.analyze.outputs.findings-count }}
critical-count:
description: 'Number of critical severity findings'
value: ${{ steps.analyze.outputs.critical-count }}
high-count:
description: 'Number of high severity findings'
value: ${{ steps.analyze.outputs.high-count }}
verdict:
description: 'Overall verdict (BLOCK, WARN, PASS)'
value: ${{ steps.analyze.outputs.verdict }}
output-file:
description: 'Path to the output file'
value: ${{ steps.analyze.outputs.output-file }}
runs:
using: 'composite'
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- name: Install adversarial-debate (from action source)
shell: bash
run: |
set -euo pipefail
PROVIDER="${{ inputs.provider }}"
if [ "$PROVIDER" = "openai" ] || [ "$PROVIDER" = "azure" ]; then
pip install "$GITHUB_ACTION_PATH[openai]"
else
pip install "$GITHUB_ACTION_PATH"
fi
- name: Run security analysis
id: analyze
shell: bash
env:
ANTHROPIC_API_KEY: ${{ inputs.anthropic-api-key }}
OPENAI_API_KEY: ${{ inputs.openai-api-key }}
AZURE_OPENAI_API_KEY: ${{ inputs.azure-openai-key }}
AZURE_OPENAI_ENDPOINT: ${{ inputs.azure-openai-endpoint }}
LLM_PROVIDER: ${{ inputs.provider }}
run: |
set +e
TARGET="${{ inputs.target }}"
OUTPUT_FILE="${{ inputs.output-file }}"
FORMAT="${{ inputs.output-format }}"
AGENT="${{ inputs.agent }}"
BASELINE_FILE="${{ inputs.baseline-file }}"
BASELINE_MODE="${{ inputs.baseline-mode }}"
# Always write a canonical bundle for downstream parsing
BUNDLE_FILE="results.bundle.json"
if [ "$AGENT" = "all" ]; then
adversarial-debate run "$TARGET" \
--time-budget "${{ inputs.time-budget }}" \
--bundle-file "$BUNDLE_FILE" \
--report-file "$OUTPUT_FILE" \
--format "$FORMAT" \
--baseline-mode "$BASELINE_MODE" \
--baseline-file "$BASELINE_FILE" \
--min-severity "${{ inputs.severity-threshold }}" \
--fail-on never
TOOL_EXIT=$?
else
adversarial-debate --json-output --output results.raw.json analyze "$AGENT" "$TARGET"
TOOL_EXIT=$?
python3 - <<'PY'
import json
from datetime import UTC, datetime
from pathlib import Path
from adversarial_debate.results import (
normalize_break_findings,
normalize_chaos_experiments,
normalize_exploit_findings,
)
raw = json.loads(Path("results.raw.json").read_text())
agent = "${{ inputs.agent }}"
if agent == "exploit":
findings = normalize_exploit_findings(raw.get("findings", []))
elif agent == "break":
findings = normalize_break_findings(raw.get("findings", []), target_file_path="${{ inputs.target }}")
elif agent == "chaos":
findings = normalize_chaos_experiments(raw.get("experiments", []))
else:
findings = []
severity_counts = {}
for f in findings:
sev = str(f.get("severity", "UNKNOWN")).upper()
severity_counts[sev] = severity_counts.get(sev, 0) + 1
bundle = {
"metadata": {
"run_id": f"action-{agent}-{datetime.now(UTC).strftime('%Y%m%d%H%M%S')}",
"target": "${{ inputs.target }}",
"provider": "${{ inputs.provider }}",
"started_at": datetime.now(UTC).isoformat(),
"finished_at": datetime.now(UTC).isoformat(),
"files_analyzed": [],
"time_budget_seconds": int("${{ inputs.time-budget }}"),
"finding_counts": {"total": len(findings), "by_severity": severity_counts},
},
"findings": findings,
"verdict": {},
}
Path("results.bundle.json").write_text(json.dumps(bundle, indent=2))
PY
python3 - <<'PY'
import json
from pathlib import Path
from adversarial_debate.formatters import FormatterConfig, get_formatter
bundle = json.loads(Path("results.bundle.json").read_text())
fmt = "${{ inputs.output-format }}"
out = "${{ inputs.output-file }}"
formatter = get_formatter(fmt, FormatterConfig(tool_name="adversarial-debate"))
Path(out).write_text(formatter.format(bundle))
PY
fi
set -e
python3 - <<'PY'
import json
import os
from pathlib import Path
bundle = json.loads(Path("results.bundle.json").read_text())
baseline = bundle.get("baseline") or {}
if baseline.get("mode") == "only-new" and isinstance(baseline.get("new"), list):
findings = baseline.get("new") or []
total = len(findings)
by_sev = {}
for f in findings:
sev = str((f or {}).get("severity", "UNKNOWN")).upper()
by_sev[sev] = by_sev.get(sev, 0) + 1
else:
counts = (bundle.get("metadata") or {}).get("finding_counts") or {}
by_sev = counts.get("by_severity") or {}
total = counts.get("total", 0)
verdict = bundle.get("verdict") or {}
summary = verdict.get("summary") or {}
decision = summary.get("decision", "UNKNOWN")
out_path = os.environ["GITHUB_OUTPUT"]
with open(out_path, "a") as f:
f.write(f"findings-count={total}\n")
f.write(f"critical-count={by_sev.get('CRITICAL', 0)}\n")
f.write(f"high-count={by_sev.get('HIGH', 0)}\n")
f.write(f"verdict={decision}\n")
f.write(f"output-file=${{ inputs.output-file }}\n")
PY
echo "tool-exit=$TOOL_EXIT" >> $GITHUB_OUTPUT
- name: Upload SARIF to GitHub Security
if: inputs.output-format == 'sarif'
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ inputs.output-file }}
continue-on-error: true
- name: Check severity threshold
if: inputs.fail-on-findings == 'true'
shell: bash
run: |
VERDICT="${{ steps.analyze.outputs.verdict }}"
THRESHOLD="${{ inputs.severity-threshold }}"
CRITICAL="${{ steps.analyze.outputs.critical-count }}"
HIGH="${{ steps.analyze.outputs.high-count }}"
SHOULD_FAIL=false
case "$THRESHOLD" in
critical)
if [ "$CRITICAL" -gt 0 ]; then
SHOULD_FAIL=true
fi
;;
high)
if [ "$CRITICAL" -gt 0 ] || [ "$HIGH" -gt 0 ]; then
SHOULD_FAIL=true
fi
;;
medium|low)
if [ "$VERDICT" = "BLOCK" ] || [ "$VERDICT" = "WARN" ]; then
SHOULD_FAIL=true
fi
;;
esac
if [ "$SHOULD_FAIL" = "true" ]; then
echo "::error::Security findings exceed threshold ($THRESHOLD)"
echo "Verdict: $VERDICT"
echo "Critical: $CRITICAL, High: $HIGH"
exit 1
fi