Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/site-route-controls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Site route supervisor controls

'on':
pull_request:
branches: [main]
paths:
- 'tools/site_route_supervisor.py'
- 'tests/site_route_supervisor_controls.py'
- '.github/workflows/site-route-controls.yml'

permissions:
contents: read
concurrency:
group: site-route-controls-${{ github.event.pull_request.number }}
cancel-in-progress: false

jobs:
supervisor-controls:
runs-on: ubuntu-24.04
timeout-minutes: 6
permissions:
contents: read
env:
SITE_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
SITE_BASE_SHA: ${{ github.event.pull_request.base.sha }}
SUPERVISOR_SHA256: 3d571d81e7b210efb6e9256c5d1915f1cfbc16bbfd93953e34365eb8f7f901c8
CONTROLS_SHA256: 9cf6c72558e5ef4fb02b392593ac9d68c8dcb630199aed8aba99dca0a38083d9
steps:
- name: Precreate pending and raw fallback before checkout
run: |
python3 -B -I -S - <<'PY'
import json, os
from pathlib import Path
root = Path(os.environ['RUNNER_TEMP'])/'site-route-pending'
root.mkdir(mode=0o700)
record = {'schema_version':1,'capture_complete':False,'disposition':'HOLD_INCOMPLETE',
'reason':'Source/setup/controls not completed','scientific_effect':'NONE'}
(root/'route.json').write_text(json.dumps(record,sort_keys=True)+'\n')
(root/'stdout.bin').write_bytes(b'')
(root/'stderr.bin').write_bytes(b'')
PY
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1
with:
ref: ${{ github.sha }}
fetch-depth: 1
persist-credentials: false
clean: true
- name: Stage exact controls outside checkout and join native merge
run: |
python3 -B -I -S - <<'PY'
import hashlib, os, re, subprocess
from pathlib import Path
stage = Path(os.environ['RUNNER_TEMP'])/'site-route-staged'
stage.mkdir(mode=0o700)
for source, target, pin in [
('tools/site_route_supervisor.py','supervisor.py',os.environ['SUPERVISOR_SHA256']),
('tests/site_route_supervisor_controls.py','controls.py',os.environ['CONTROLS_SHA256'])]:
raw = Path(source).read_bytes()
if hashlib.sha256(raw).hexdigest() != pin:
raise SystemExit('Source pin mismatch; HOLD')
(stage/target).write_bytes(raw)
(stage/target).chmod(0o444)
def bounded_git(arguments, limit):
import selectors, time
process = subprocess.Popen(['git','--no-replace-objects',*arguments],
stdin=subprocess.DEVNULL,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
poller = selectors.DefaultSelector()
os.set_blocking(process.stdout.fileno(),False)
poller.register(process.stdout,selectors.EVENT_READ)
raw, deadline = bytearray(), time.monotonic()+5
try:
while poller.get_map():
if time.monotonic()>=deadline: raise ValueError('Git read timeout; HOLD')
for key,_ in poller.select(0.05):
chunk=os.read(key.fileobj.fileno(),min(8192,limit+1-len(raw)))
if not chunk: poller.unregister(key.fileobj); break
raw.extend(chunk)
if len(raw)>limit: raise ValueError('Git output cap; HOLD')
if process.wait(timeout=2)!=0: raise ValueError('Git object read failed; HOLD')
return bytes(raw)
finally:
if process.poll() is None: process.kill(); process.wait(timeout=2)
process.stdout.close(); poller.close()
head_raw=bounded_git(['rev-parse','--verify','HEAD'],41)
if not re.fullmatch(rb'[0-9a-f]{40}\n',head_raw): raise ValueError('Invalid actual HEAD; HOLD')
head=head_raw[:-1].decode('ascii')
commit=bounded_git(['cat-file','-p',head],65536)
header, separator, message=commit.partition(b'\n\n')
if not separator or b'\0' in header: raise ValueError('Invalid commit header; HOLD')
lines=header.split(b'\n')
if len(lines)>128 or not re.fullmatch(rb'tree [0-9a-f]{40}',lines[0]): raise ValueError('Invalid tree header; HOLD')
if len(lines)<5 or not all(re.fullmatch(rb'parent [0-9a-f]{40}',line) for line in lines[1:3]):
raise ValueError('Exactly two literal ordered parents required; HOLD')
for line in lines[3:]:
if not line or (not line.startswith(b' ') and not re.fullmatch(rb'[a-z][a-z0-9-]* [^\0]+',line)):
raise ValueError('Malformed remaining commit header; HOLD')
if line.split(b' ',1)[0] in (b'parent',b'tree'): raise ValueError('Extra parent/tree header; HOLD')
if sum(line.startswith(b'author ') for line in lines)!=1 or sum(line.startswith(b'committer ') for line in lines)!=1:
raise ValueError('Missing/duplicate author or committer; HOLD')
parents=[line[7:].decode('ascii') for line in lines[1:3]]
if head != os.environ['GITHUB_SHA'] or parents != [os.environ['SITE_BASE_SHA'],os.environ['SITE_HEAD_SHA']]:
raise SystemExit('Native head/base/tested-merge join mismatch; HOLD')
PY
- name: Deterministic process and complete-carrier controls only
run: >-
python3 -B -I -S "$RUNNER_TEMP/site-route-staged/controls.py"
--supervisor "$RUNNER_TEMP/site-route-staged/supervisor.py"
--supervisor-sha256 "$SUPERVISOR_SHA256"
--evidence "$RUNNER_TEMP/site-route-controls"
- name: Preserve all complete control bytes in decoded job logs
if: always()
run: |
if [ ! -f "$RUNNER_TEMP/site-route-staged/supervisor.py" ]; then
echo 'SITE_ROUTE_CAPTURE_INCOMPLETE: no pinned emitter; no result is adoptable'
exit 2
fi
printf '%s %s\n' "$SUPERVISOR_SHA256" "$RUNNER_TEMP/site-route-staged/supervisor.py" | sha256sum --check --status
evidence="$RUNNER_TEMP/site-route-controls"
if [ ! -d "$evidence" ]; then evidence="$RUNNER_TEMP/site-route-pending"; fi
python3 -B -I -S "$RUNNER_TEMP/site-route-staged/supervisor.py" emit --evidence "$evidence"
Loading