Skip to content

Commit 26a17e4

Browse files
ci(witness): independently attest AEGIS repository enforcement (#33)
Install an external fail-closed witness for the AEGIS default-branch protection state.
2 parents 281ebb8 + faa034d commit 26a17e4

1 file changed

Lines changed: 109 additions & 0 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: AEGIS Repository Enforcement External Witness
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- '.github/workflows/aegis-repository-enforcement-witness.yml'
8+
workflow_dispatch:
9+
schedule:
10+
- cron: '23 4 * * *'
11+
12+
permissions:
13+
contents: write
14+
15+
env:
16+
SOURCE_REPOSITORY: Aegis-Omega/AEGIS-OMEGA
17+
SOURCE_BRANCH: main
18+
WITNESS_PATH: witness-results/aegis-repository-enforcement.json
19+
20+
jobs:
21+
witness:
22+
runs-on: ubuntu-24.04
23+
timeout-minutes: 5
24+
steps:
25+
- name: Checkout independent witness repository
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Observe source repository enforcement
31+
id: observe
32+
shell: bash
33+
run: |
34+
set -euo pipefail
35+
mkdir -p witness-results
36+
python3 - <<'PY'
37+
import datetime
38+
import json
39+
import os
40+
import urllib.request
41+
from pathlib import Path
42+
43+
repo = os.environ['SOURCE_REPOSITORY']
44+
branch = os.environ['SOURCE_BRANCH']
45+
url = f'https://api.github.com/repos/{repo}/branches/{branch}'
46+
req = urllib.request.Request(
47+
url,
48+
headers={
49+
'Accept': 'application/vnd.github+json',
50+
'X-GitHub-Api-Version': '2022-11-28',
51+
'User-Agent': 'aegis-independent-enforcement-witness/1',
52+
},
53+
)
54+
with urllib.request.urlopen(req, timeout=20) as response:
55+
data = json.load(response)
56+
57+
protected = bool(data.get('protected'))
58+
protection = data.get('protection') if isinstance(data.get('protection'), dict) else {}
59+
required = protection.get('required_status_checks') if isinstance(protection, dict) else {}
60+
required = required if isinstance(required, dict) else {}
61+
commit = data.get('commit') if isinstance(data.get('commit'), dict) else {}
62+
63+
witness = {
64+
'schema_version': 1,
65+
'witness_kind': 'AEGIS_REPOSITORY_ENFORCEMENT_EXTERNAL_OBSERVATION_V1',
66+
'source_repository': repo,
67+
'source_branch': branch,
68+
'source_head_sha': commit.get('sha'),
69+
'observed_at_utc': datetime.datetime.now(datetime.timezone.utc).isoformat(),
70+
'protected': protected,
71+
'required_status_checks_enforcement_level': required.get('enforcement_level'),
72+
'required_status_check_contexts': required.get('contexts') or [],
73+
'production_admission': 'UNKNOWN_PENDING_DETAILED_POLICY' if protected else 'FORBIDDEN',
74+
'authority': 'EXTERNAL_OBSERVATION_ONLY',
75+
'observation_endpoint': url,
76+
}
77+
Path(os.environ['WITNESS_PATH']).write_text(
78+
json.dumps(witness, indent=2, sort_keys=True) + '\n', encoding='utf-8'
79+
)
80+
Path('/tmp/aegis-enforcement-exit').write_text('0' if protected else '1')
81+
print(json.dumps(witness, sort_keys=True))
82+
PY
83+
84+
- name: Commit exact external witness
85+
shell: bash
86+
run: |
87+
set -euo pipefail
88+
git config user.name 'aegis-enforcement-witness-bot'
89+
git config user.email '228550385+tarikskalic33@users.noreply.github.com'
90+
git add "$WITNESS_PATH"
91+
if git diff --cached --quiet; then
92+
echo 'AEGIS_ENFORCEMENT_WITNESS_CHANGED=false'
93+
else
94+
sha="$(python3 -c 'import json,os; print(json.load(open(os.environ["WITNESS_PATH"]))["source_head_sha"])')"
95+
git commit -m "witness(aegis): repository enforcement ${sha}"
96+
git push origin HEAD:main
97+
echo 'AEGIS_ENFORCEMENT_WITNESS_CHANGED=true'
98+
fi
99+
100+
- name: Enforce fail-closed external observation
101+
shell: bash
102+
run: |
103+
set -euo pipefail
104+
code="$(cat /tmp/aegis-enforcement-exit)"
105+
if [[ "$code" != '0' ]]; then
106+
echo 'AEGIS_REPOSITORY_ENFORCEMENT_EXTERNAL_WITNESS=FAIL_CLOSED' >&2
107+
exit 1
108+
fi
109+
echo 'AEGIS_REPOSITORY_ENFORCEMENT_EXTERNAL_WITNESS=PROTECTED_BUT_DETAILED_POLICY_PENDING'

0 commit comments

Comments
 (0)