-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
246 lines (220 loc) · 8.41 KB
/
Copy pathskill-security-audit.yml
File metadata and controls
246 lines (220 loc) · 8.41 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
---
name: Skill Security Audit
'on':
pull_request:
types: [opened, synchronize, reopened]
paths:
- 'engineering/**'
- 'engineering-team/**'
- 'business-growth/**'
- 'c-level-advisor/**'
- 'documentation/**'
- 'finance/**'
- 'marketing-skill/**'
- 'product-team/**'
- 'project-management/**'
- 'ra-qm-team/**'
- 'agents/**'
- 'templates/**'
concurrency:
group: security-audit-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
detect-changes:
name: Detect changed skills
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
skills: ${{ steps.find.outputs.skills }}
has_skills: ${{ steps.find.outputs.has_skills }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Find changed skill directories
id: find
run: |
# Get list of changed files in PR
CHANGED=$(git diff --name-only origin/${{ github.base_ref }}...HEAD 2>/dev/null || echo "")
if [ -z "$CHANGED" ]; then
echo "skills=[]" >> "$GITHUB_OUTPUT"
echo "has_skills=false" >> "$GITHUB_OUTPUT"
exit 0
fi
# Extract unique skill root directories (top-level dirs containing SKILL.md)
SKILLS=()
SEEN=()
while IFS= read -r file; do
# Get the top-level directory
dir=$(echo "$file" | cut -d'/' -f1-2)
# Skip non-skill paths
case "$dir" in
.github/*|.claude/*|.codex/*|.gemini/*|docs/*|scripts/*|commands/*|standards/*|eval-workspace/*) continue ;;
esac
# Check if this directory has a SKILL.md (is a skill)
skill_root=$(echo "$file" | cut -d'/' -f1)
# Walk up to find the skill root that contains SKILL.md
for candidate in "$skill_root" "$dir"; do
if [ -f "$candidate/SKILL.md" ] && [[ ! " ${SEEN[*]} " =~ " $candidate " ]]; then
SKILLS+=("$candidate")
SEEN+=("$candidate")
break
fi
done
done <<< "$CHANGED"
if [ ${#SKILLS[@]} -eq 0 ]; then
echo "skills=[]" >> "$GITHUB_OUTPUT"
echo "has_skills=false" >> "$GITHUB_OUTPUT"
else
# Build JSON array
JSON="["
for i in "${!SKILLS[@]}"; do
[ $i -gt 0 ] && JSON+=","
JSON+="\"${SKILLS[$i]}\""
done
JSON+="]"
echo "skills=$JSON" >> "$GITHUB_OUTPUT"
echo "has_skills=true" >> "$GITHUB_OUTPUT"
echo "Changed skills: $JSON"
fi
audit:
name: Security audit
needs: detect-changes
if: needs.detect-changes.outputs.has_skills == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Run security auditor on changed skills
id: audit
run: |
AUDITOR="engineering/skill-security-auditor/scripts/skill_security_auditor.py"
SKILLS='${{ needs.detect-changes.outputs.skills }}'
REPORT_FILE=$(mktemp)
OVERALL_EXIT=0
echo "## 🔒 Skill Security Audit Results" > "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
# Parse JSON array of skill dirs
for skill_dir in $(echo "$SKILLS" | python3 -c "import sys,json; [print(s) for s in json.load(sys.stdin)]"); do
echo "::group::Auditing $skill_dir"
echo "Scanning: $skill_dir"
# Run auditor in strict mode with JSON output
JSON_OUT=$(python3 "$AUDITOR" "$skill_dir" --strict --json 2>&1) && EXIT_CODE=$? || EXIT_CODE=$?
# Try to parse JSON output
VERDICT=$(echo "$JSON_OUT" | python3 -c "
import sys, json
try:
d = json.load(sys.stdin)
v = d.get('verdict', 'UNKNOWN')
c = d.get('summary', {}).get('critical', 0)
h = d.get('summary', {}).get('high', 0)
i = d.get('summary', {}).get('info', 0)
t = d.get('summary', {}).get('total', 0)
print(f'{v}|{c}|{h}|{i}|{t}')
except:
print('ERROR|0|0|0|0')
" 2>/dev/null || echo "ERROR|0|0|0|0")
IFS='|' read -r V CRIT HIGH INFO TOTAL <<< "$VERDICT"
# Map verdict to emoji
case "$V" in
PASS) ICON="✅" ;;
WARN) ICON="⚠️" ;;
FAIL) ICON="❌"; OVERALL_EXIT=1 ;;
*) ICON="❓"; OVERALL_EXIT=1 ;;
esac
echo "### $ICON \`$skill_dir\` — $V" >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
if [ "$TOTAL" -gt 0 ]; then
echo "| Severity | Count |" >> "$REPORT_FILE"
echo "|----------|-------|" >> "$REPORT_FILE"
[ "$CRIT" -gt 0 ] && echo "| 🔴 Critical | $CRIT |" >> "$REPORT_FILE"
[ "$HIGH" -gt 0 ] && echo "| 🟡 High | $HIGH |" >> "$REPORT_FILE"
[ "$INFO" -gt 0 ] && echo "| ⚪ Info | $INFO |" >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
# Include finding details for WARN/FAIL
if [ "$V" != "PASS" ]; then
echo "<details><summary>Findings detail</summary>" >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
echo '```json' >> "$REPORT_FILE"
echo "$JSON_OUT" | python3 -c "
import sys, json
try:
d = json.load(sys.stdin)
findings = d.get('findings', [])
for f in findings:
if f.get('severity') in ('CRITICAL', 'HIGH'):
print(json.dumps(f, indent=2))
except:
pass
" >> "$REPORT_FILE"
echo '```' >> "$REPORT_FILE"
echo "</details>" >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
fi
else
echo "No findings." >> "$REPORT_FILE"
echo "" >> "$REPORT_FILE"
fi
echo "::endgroup::"
done
# Save report for comment step
echo "report_file=$REPORT_FILE" >> "$GITHUB_OUTPUT"
echo "exit_code=$OVERALL_EXIT" >> "$GITHUB_OUTPUT"
- name: Post audit results to job summary
if: always()
run: |
REPORT_FILE="${{ steps.audit.outputs.report_file }}"
if [ -f "$REPORT_FILE" ]; then
cat "$REPORT_FILE" >> "$GITHUB_STEP_SUMMARY"
fi
- name: Post audit results as PR comment
if: always()
continue-on-error: true # Fork PRs have read-only GITHUB_TOKEN
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const reportFile = '${{ steps.audit.outputs.report_file }}';
let body = '## 🔒 Skill Security Audit\n\nNo report generated.';
try {
body = fs.readFileSync(reportFile, 'utf8');
} catch (e) {
console.log('Could not read report file:', e.message);
}
// Find and update existing comment or create new
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const marker = '## 🔒 Skill Security Audit';
const existing = comments.find(c => c.body.startsWith(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: body,
});
}
- name: Fail on critical findings
if: steps.audit.outputs.exit_code == '1'
run: |
echo "::error::Security audit found CRITICAL findings. Merge blocked."
exit 1