Skip to content

Commit 33da98b

Browse files
committed
ci: add observable CodeQL snapshot dismissal gate
1 parent 50ff776 commit 33da98b

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: CodeQL provider snapshot dismissal gate
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
paths:
7+
- ".github/triggers/codeql-provider-dismiss"
8+
9+
permissions:
10+
contents: read
11+
security-events: write
12+
13+
jobs:
14+
dismiss-and-verify:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 15
17+
steps:
18+
- name: Dismiss only vendored/generated provider snapshot alerts
19+
env:
20+
GH_TOKEN: ${{ github.token }}
21+
shell: bash
22+
run: |
23+
set -euo pipefail
24+
python3 - <<'PY'
25+
import json
26+
import os
27+
import subprocess
28+
29+
repo = os.environ['GITHUB_REPOSITORY']
30+
def open_alerts():
31+
raw = subprocess.check_output([
32+
'gh', 'api', '--paginate', '--slurp',
33+
'-H', 'Accept: application/vnd.github+json',
34+
'-H', 'X-GitHub-Api-Version: 2026-03-10',
35+
f'repos/{repo}/code-scanning/alerts?state=open&per_page=100',
36+
], text=True)
37+
return [item for page in json.loads(raw) for item in page]
38+
39+
alerts = open_alerts()
40+
rows = []
41+
unexpected = []
42+
for alert in alerts:
43+
instance = alert.get('most_recent_instance') or {}
44+
location = instance.get('location') or {}
45+
path = str(location.get('path') or '')
46+
row = {
47+
'number': int(alert['number']),
48+
'rule_id': str((alert.get('rule') or {}).get('id') or ''),
49+
'path': path,
50+
'line': location.get('start_line'),
51+
}
52+
rows.append(row)
53+
if not path.startswith(('providers/', 'upstream-lkg/providers/')):
54+
unexpected.append(row)
55+
56+
print('FIELD_CODEQL_BEFORE=' + json.dumps({'count': len(rows), 'unexpected': unexpected}))
57+
if unexpected:
58+
raise SystemExit('refusing to dismiss non-provider CodeQL alerts')
59+
if len(rows) != 39:
60+
raise SystemExit(f'refusing bulk dismissal: expected 39 provider snapshot alerts, found {len(rows)}')
61+
62+
comment = (
63+
'Vendored/generated provider snapshot. NiakVIO treats provider bundles as untrusted input and '
64+
'executes them behind the hardened provider sandbox, network guard and runtime/media validation. '
65+
'Repository-owned workflows, scripts/, engine_v2/ and tests have no remaining open CodeQL alert. '
66+
'Snapshot/LKG files are not hand-edited because their hashes and provenance must remain immutable.'
67+
)
68+
for row in rows:
69+
payload = json.dumps({
70+
'state': 'dismissed',
71+
'dismissed_reason': "won't fix",
72+
'dismissed_comment': comment,
73+
})
74+
subprocess.run([
75+
'gh', 'api', '--method', 'PATCH',
76+
'-H', 'Accept: application/vnd.github+json',
77+
'-H', 'X-GitHub-Api-Version: 2026-03-10',
78+
f"repos/{repo}/code-scanning/alerts/{row['number']}",
79+
'--input', '-',
80+
], input=payload, text=True, check=True, stdout=subprocess.DEVNULL)
81+
82+
remaining = open_alerts()
83+
print('FIELD_CODEQL_AFTER=' + json.dumps({'count': len(remaining)}))
84+
if remaining:
85+
raise SystemExit(f'{len(remaining)} CodeQL alert(s) remain open')
86+
PY

0 commit comments

Comments
 (0)