Files
mtusi2026lab7/scripts/summarize-evidence.py
2026-11-18 11:36:21 +03:00

24 lines
3.4 KiB
Python

#!/usr/bin/env python3
"""Require concrete outputs before publishing the local verification summary."""
import datetime,hashlib,json,subprocess
from pathlib import Path
ROOT=Path(__file__).resolve().parents[1];E=ROOT/'evidence'
checks=[('Public HTTPS and external trust','public-checks.txt'),('Final HTTPS smoke','final-smoke.txt'),('TLS/identity/ACL matrix','security-run.txt'),('Argon2/rehash/session expiry','auth-run.txt'),('Leaf rotation/revocation','leaf-run.txt'),('Expired allowed-SAN leaf','cert-expiry-run.txt'),('Sealed OpenBao','sealed-run.txt'),('Real telemetry and canaries','telemetry-run.txt'),('Grafana authentication','admin-run.txt'),('Image/ACL negatives','images-run.txt'),('Staging/restore/retention','storage-run.txt'),('Broker volume durability','broker-run.txt'),('All stores restart/session persistence','persistence-run.txt'),('Public failover 1','failover-first.txt'),('Public failover 2','failover-second.txt'),('Both physical replicas','all-replicas-run.txt'),('Worker compromise/recovery','worker-experiment-run.txt'),('Independent source snapshot','clean-clone-run.txt')]
for _,filename in checks:
text=(E/filename).read_text();assert 'PASS:' in text and 'Traceback' not in text and 'FAIL:' not in text,filename
worker=json.loads((E/'worker-experiment.json').read_text());assert len(worker['repeats'])==3 and all(r['lost']==0 and r['old_s3_key_rejected'] and r['old_broker_identity_rejected'] for r in worker['repeats'])
assert json.loads((E/'secret-audit.json').read_text())['matches']==0
scan=json.loads((E/'image-scan.json').read_text());assert all(not r['findings'] for r in scan['results'])
assert 'No vulnerabilities found.' in (E/'govulncheck.txt').read_text()
manifest={}
for name in subprocess.check_output(['git','ls-files','--cached','--others','--exclude-standard','-z'],cwd=ROOT).decode().split('\0'):
p=ROOT/name
if name and p.is_file() and not name.startswith('evidence/'):manifest[name]=hashlib.sha256(p.read_bytes()).hexdigest()
(E/'source-manifest.json').write_text(json.dumps(manifest,sort_keys=True,indent=2)+'\n')
lines=['# Фактическая итоговая проверка','',datetime.datetime.now(datetime.timezone.utc).isoformat(),'','Результаты относятся к synthetic lab7 stand. Source snapshot: `source-manifest.json`; environment/image IDs: `environment.json` и `image-scan.json`.','','| Проверка | Результат | Вывод |','| --- | --- | --- |']
for label,filename in checks:lines.append(f'| {label} | PASS | [{filename}]({filename}) |')
lines+=['| Source vulnerability scan | 0 findings | [govulncheck.txt](govulncheck.txt) |','| Application image scan | 0 findings | [image-scan.json](image-scan.json) |','','## Worker experiment','']
for r in worker['repeats']:lines.append(f"- Повтор {r['repeat']}: {r['accepted']} accepted → {r['ready']} ready, lost={r['lost']}, duplicate_jobs={r['duplicate_jobs']}, recovery={r['recovery_seconds']:.3f} s; старые S3/broker/Bao identities отвергнуты.")
lines+=['','Скриншоты не используются вместо команд. GitHub CI настроен, удалённый workflow не запускался агентом. Диагностические неудачные запуски не включены в PASS-таблицу.']
(E/'verification-summary.md').write_text('\n'.join(lines)+'\n');print('All required evidence verified; summary and source hashes written.')