feat(nodes): scope final acceptance to reviewed change impact
This commit is contained in:
1 parent
d085e211b3
commit
4d667f37b2
9 files changed
+191
-26
No files matched your search
@@ -31,7 +31,30 @@ def snapshot(nodes):
|
||||
return sorted(result, key=lambda n: n['id'])
|
||||
|
||||
|
||||
def audit(before, after, report_bytes, qa_bytes, binding, plan_sha, expected_qas, now=None, ttl=900):
|
||||
def validate_impact(impact):
|
||||
if impact is None:
|
||||
return
|
||||
if not isinstance(impact, dict) or set(impact) != {'shared_changes', 'affected_snis', 'review'}:
|
||||
raise ValueError('Explicit reviewed impact required')
|
||||
if not isinstance(impact['review'], str) or not impact['review'].strip():
|
||||
raise ValueError('Impact review reference required')
|
||||
for key in ('shared_changes', 'affected_snis'):
|
||||
if not isinstance(impact[key], list) or any(not isinstance(x, str) or not x.strip() for x in impact[key]) or len(set(impact[key])) != len(impact[key]):
|
||||
raise ValueError('Invalid impact inventory')
|
||||
|
||||
|
||||
def verification_scope(nodes, impact=None):
|
||||
"""Unknown/shared impact keeps full tests; reviewed append uses light TLS probes."""
|
||||
nodes = snapshot(nodes)
|
||||
if impact is None:
|
||||
return {n['tag']: 'full' for n in nodes}
|
||||
validate_impact(impact)
|
||||
if not set(impact['affected_snis']).issubset({n['sni'] for n in nodes}):
|
||||
raise ValueError('Affected node absent from current authorization set')
|
||||
return {n['tag']: 'full' if impact['shared_changes'] or n['sni'] in impact['affected_snis'] else 'tls' for n in nodes}
|
||||
|
||||
|
||||
def audit(before, after, report_bytes, qa_bytes, binding, plan_sha, expected_qas, now=None, ttl=900, scope=None):
|
||||
now = time.time() if now is None else now
|
||||
before, after = snapshot(before), snapshot(after)
|
||||
if before != after or binding.get('snapshot_sha256') != digest(before):
|
||||
@@ -45,16 +68,27 @@ def audit(before, after, report_bytes, qa_bytes, binding, plan_sha, expected_qas
|
||||
for stamp in (binding.get('verified_at'), report.get('verified_at'), qas.get('captured_at')):
|
||||
if type(stamp) not in (int, float) or not 0 <= now-stamp <= ttl:
|
||||
raise ValueError('Evidence expired or future dated')
|
||||
modes = {n['tag']: 'full' for n in before} if scope is None else scope
|
||||
if set(modes) != {n['tag'] for n in before} or any(v not in ('full', 'tls') for v in modes.values()):
|
||||
raise ValueError('Incomplete verification scope')
|
||||
if scope is not None and binding.get('scope_sha256') != digest(modes):
|
||||
raise ValueError('Verification scope binding changed')
|
||||
if report.get('state') != 'live_verified' or len(report.get('results', [])) != len(before):
|
||||
raise ValueError('Incomplete live verification')
|
||||
expected = {(n['tag'], n['relay'], n['relay_port'], n['sni'], n['expected_exit'], n['country']) for n in before}
|
||||
actual = set()
|
||||
for n in report['results']:
|
||||
if n.get('live') is not True or n.get('strict_tls') is not True:
|
||||
raise ValueError('Live strict TLS required for every node')
|
||||
actual.add(tuple(n.get(k) for k in ('tag', 'relay', 'relay_port', 'sni', 'exit_ip', 'country')))
|
||||
if actual != expected:
|
||||
raise ValueError('Node/endpoint/exit/country mismatch')
|
||||
actual = {}
|
||||
for result in report['results']:
|
||||
tag = result.get('tag')
|
||||
if tag in actual or tag not in modes:
|
||||
raise ValueError('Unexpected or duplicate verification result')
|
||||
actual[tag] = result
|
||||
for node in before:
|
||||
result = actual.get(node['tag'], {})
|
||||
if result.get('live') is not True or result.get('strict_tls') is not True or result.get('verification', 'full') != modes[node['tag']]:
|
||||
raise ValueError('Required verification mode or strict TLS missing')
|
||||
if any(result.get(k) != node[k] for k in ('relay', 'relay_port', 'sni')):
|
||||
raise ValueError('Node endpoint mismatch')
|
||||
if modes[node['tag']] == 'full' and (result.get('exit_ip') != node['expected_exit'] or result.get('country') != node['country']):
|
||||
raise ValueError('Node exit/country mismatch')
|
||||
if qas.get('plan_sha256') != plan_sha or set(qas.get('users', {})) != set(expected_qas):
|
||||
raise ValueError('QA evidence identity mismatch')
|
||||
for key, identity in expected_qas.items():
|
||||
|
||||
Reference in new issue
Block a user