57 lines
2.8 KiB
Python
57 lines
2.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Bind explicitly reviewed evidence to ISO/OSTree identities for publication."""
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def digest(path):
|
|
with Path(path).open('rb') as stream:
|
|
return hashlib.file_digest(stream, 'sha256').hexdigest()
|
|
|
|
|
|
def prepare(config):
|
|
records = []
|
|
for item in config['candidates']:
|
|
root = Path(item['directory'])
|
|
iso = root / 'build/output' / item['iso_name'] if item.get('iso_name') else None
|
|
repo = root / 'build/repo'
|
|
sha = digest(iso) if iso else None
|
|
rust = item.get('rust_evidence')
|
|
# D-098: installed-VM acceptance is not part of the cycle. A release is
|
|
# admitted only through source-bound Rust evidence; boot, firmware and
|
|
# GUI coverage is declared as a manual user check.
|
|
if not rust:
|
|
raise ValueError('D-098 requires frozen-source Rust evidence')
|
|
evidence = json.loads(Path(rust).read_text())
|
|
if evidence.get('policy') != 'D-098' or evidence.get('passed') is not True or digest(evidence['source']) != evidence['source_sha256']:
|
|
raise ValueError('Successful frozen-source Rust evidence required')
|
|
for check in evidence['checks']:
|
|
if digest(check['path']) != check['sha256']:
|
|
raise ValueError('Rust test evidence changed')
|
|
checks = []
|
|
for check in item['checks']:
|
|
path = Path(check['path'])
|
|
if check.get('contains') and check['contains'] not in path.read_text():
|
|
raise ValueError('Missing check marker: ' + str(path))
|
|
checks.append(dict(path=str(path), sha256=digest(path)))
|
|
def resolve(ref):
|
|
return subprocess.check_output(['ostree', '--repo=' + str(repo), 'rev-parse', ref], text=True).strip()
|
|
record = dict(variant=item['variant'], version=item['version'], iso=str(iso) if iso else None, repo=str(repo),
|
|
sha256=sha, image_commit=resolve('core'), layer_commit=resolve('layers/core'),
|
|
acceptance=str(root / 'release-acceptance.json'))
|
|
if item['variant'] in ('gnome', 'kde'):
|
|
record['purpose_layer_commit'] = resolve('layers/purpose/desktop/' + item['variant'])
|
|
if item.get('expected_image_commit') and record['image_commit'] != item['expected_image_commit']:
|
|
raise ValueError('Reviewed image differs from repository')
|
|
Path(record['acceptance']).write_text(json.dumps(record | dict(scope='rust-manual',
|
|
accepted=True, rust_evidence=rust, vm_acceptance='manual-only',
|
|
checks=checks, limitations=item.get('limitations', [])), indent=2) + '\n')
|
|
records.append(record)
|
|
Path(config['output']).write_text(json.dumps(records, indent=2) + '\n')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
prepare(json.loads(Path(sys.argv[1]).read_text()))
|