| index 83ad1bfc2..6cb6d47e0 100755 |
| --- a/scripts/ppv2-step.py |
| +++ b/scripts/ppv2-step.py |
| @@ -696,12 +696,17 @@ def cmd_reverify(args, cloud): |
| if sorted(targets) != sorted(made_with): |
| raise Refused(f"--targets must be the step's targets ({', '.join(made_with)}); a target cannot leave " |
| 'a step before it converges') |
| - # A trust-violation signal in this step's evidence is S3 on some node (spec 6.4). |
| + # A trust-violation signal anywhere in this step's evidence is S3 on some |
| + # node (spec 6.4): in a verdict, its history, or any saved poll of any |
| + # run of the step, including an interrupted one that wrote no verdict. |
| prior = load_record(record_dir / f'{args.step}.json') or {} |
| - signals = [h for h in [prior] + list(prior.get('history') or []) if h.get('s3_signal')] |
| + signals = [f'{args.step}.json' for h in [prior] + list(prior.get('history') or []) if h.get('s3_signal')] |
| + signals += [f"{args.step}-polls.jsonl at {e.get('at')}: {'; '.join(e.get('s3_reasons') or [])}" |
| + for e in logged_s3_signals(record_dir / f'{args.step}-polls.jsonl')] |
| if signals and not args.incident_cleared: |
| - raise Refused(f'{args.step}.json records an S3 signal (marker_trusted or no_client_refused moved); ' |
| - 'run the S3 incident procedure (runbook) first, then reverify with --incident-cleared') |
| + raise Refused(f'{args.step} has an S3 signal (marker_trusted or no_client_refused moved): ' |
| + f'{signals[0]}; run the S3 incident procedure (runbook) first, then reverify with ' |
| + '--incident-cleared') |
| applied = basis.get('applied') |
| try: |
| doc = json.loads((root / TFVARS_FILE).read_bytes()) |
| @@ -977,6 +982,13 @@ def converge(cloud, record_dir, applied, paths, timeout): |
| poll_health() |
| schedule['health'] = now + HEALTH_EVERY |
| |
| + def log_trust(job): |
| + """Logs a trust poll with any S3 signal it shows against this run's |
| + baseline, as it is observed, so no later run can miss it.""" |
| + entry = job.entry() |
| + found = s3_reasons(entry['status'], applied.get('baseline') or {}) |
| + return log.add(dict(entry, s3_signal=bool(found), s3_reasons=found)) |
| + |
| next_trust = clock.time() |
| job = None |
| try: |
| @@ -985,7 +997,7 @@ def converge(cloud, record_dir, applied, paths, timeout): |
| if job is None and clock.time() >= next_trust: |
| job = TrustJob(cloud, targets) |
| if job is not None and job.check(): |
| - log.add(job.entry()) |
| + log_trust(job) |
| next_trust, job = job.started + TRUST_EVERY, None |
| if probes_ready(paths, clock) or clock.time() >= deadline: |
| break |
| @@ -998,7 +1010,7 @@ def converge(cloud, record_dir, applied, paths, timeout): |
| while not job.check(): |
| health_due() |
| clock.sleep(TICK) |
| - entry = log.add(job.entry()) |
| + entry = log_trust(job) |
| if not any(isinstance(s, str) for s in entry['status'].values()): |
| break |
| health_due() |
| @@ -1112,6 +1124,38 @@ def coverage_reasons(times, window, gap, what): |
| return reasons |
| |
| |
| +S3_COUNTERS = ('marker_trusted', 'no_client_refused') |
| + |
| + |
| +def s3_reasons(status, baseline): |
| + """The S3 signals (spec 6.4) in one poll's statuses against a run's baseline.""" |
| + found = [] |
| + for iid, s in status.items(): |
| + base = baseline.get(iid) |
| + if is_status(s) and is_status(base): |
| + for counter in S3_COUNTERS: |
| + if s['counters'][counter] > base['counters'][counter]: |
| + found.append(f"{iid}: {counter} moved from {base['counters'][counter]} to {s['counters'][counter]}") |
| + return found |
| + |
| + |
| +def logged_s3_signals(path): |
| + """Every saved trust poll with an S3 signal, for any anchor, verdict written or not.""" |
| + try: |
| + lines = path.read_text().splitlines() |
| + except FileNotFoundError: |
| + return [] |
| + out = [] |
| + for line in lines: |
| + try: |
| + entry = json.loads(line) |
| + except ValueError: |
| + continue |
| + if entry.get('kind') == 'trust' and entry.get('s3_signal'): |
| + out.append(entry) |
| + return out |
| + |
| + |
| def continuous_reasons(times, start, end, gap, what, start_label): |
| """Observations (this host's clock) from start to end, never more than gap apart.""" |
| points = sorted(t for t in times if start <= t <= end) |