From 86a541a90ce7a4f1b50671ed6fde00c15a60bb68 Mon Sep 17 00:00:00 2001 From: Xmesh Creator Date: Fri, 27 Nov 2026 08:09:00 +0300 Subject: [PATCH] Pin every original retirement inode and durably retain nonauthorizing evidence --- docs/QUOTA_V2_GENESIS_QUARANTINE_HANDOFF.md | 17 ++ .../public_tls_meter_retirement.py | 241 ++++++++++++------ .../public_tls_wal_watch.py | 19 +- ...st_quota_v2_public_tls_meter_retirement.py | 80 +++++- tests/test_quota_v2_public_tls_wal_watch.py | 14 + 5 files changed, 296 insertions(+), 75 deletions(-) diff --git a/docs/QUOTA_V2_GENESIS_QUARANTINE_HANDOFF.md b/docs/QUOTA_V2_GENESIS_QUARANTINE_HANDOFF.md index 678d9718..9559c4bc 100644 --- a/docs/QUOTA_V2_GENESIS_QUARANTINE_HANDOFF.md +++ b/docs/QUOTA_V2_GENESIS_QUARANTINE_HANDOFF.md @@ -602,6 +602,23 @@ permit, proof of delivery, complete pre-bootstrap history, terminal settlement or a refund. No installer, persistent service or public issuer uses it. Real installed two-Node retirement still requires hosted qualification. +The subsequent inode-continuity check rejects even a byte-identical file +replacement between signed readback, durable fencing and actual exit, +including the original caps, inventory, streams, and every durable fence +and checkpoint. The instance-lock descriptor is retained from before the +authenticated live readback, then exclusively acquired after the original +pidfd exits and held until the proof object closes. A bounded full-ledger +scan includes exact private regular-file identities, mode, owner, timestamps, +size and SHA-256. Optional `publish_exited()` retains a root-private, +unsigned observation and the exact authentic original Nexus response +bytes under an immutable no-replace, file/directory-fsynced record. Before +the final link it repeats the original exit, same lock, all ledger and +Docker proof while retaining that lock; an interrupted pending record +denies publication/recovery. The record explicitly denies delivered-byte +verification, Node signature, public/start/resume/settlement and refund +authority. No dead-process-only reconstruction or permanent restart +prevention is claimed. + ## Sealed TLS material before any future public spawn The dormant certificate verifier now snapshots the root-owned Certbot diff --git a/experiments/quota-v2-physical-stop/public_tls_meter_retirement.py b/experiments/quota-v2-physical-stop/public_tls_meter_retirement.py index 78d9df86..80e3993f 100644 --- a/experiments/quota-v2-physical-stop/public_tls_meter_retirement.py +++ b/experiments/quota-v2-physical-stop/public_tls_meter_retirement.py @@ -10,12 +10,12 @@ quiesce the disposable workers, and independently verify the enrolled first-Genesis roster and installed executable before using it. """ -from contextlib import contextmanager import fcntl import hashlib import os from pathlib import Path import select +import secrets import stat import time import uuid @@ -26,6 +26,8 @@ wal = watch.wal journal = wal.journal DIRECTORY = Path("/var/lib/xmesh-first-meter/runtime/ledger") +RECORD_DIRECTORY = Path("/var/lib/xmesh-ci-first-meter-retirement") +MAX_RECORD = 8192 FENCE_NAMESPACE = uuid.UUID("74df852d-a5a6-47d8-bac9-55f84d9b102a") MAX_RETIRE_NS = 30_000_000_000 @@ -45,7 +47,9 @@ def _poll_exit(fd): events = poll.poll(0) if not events: return False - if len(events) != 1 or events[0][0] != fd or not events[0][1] & select.POLLIN: + if (len(events) != 1 or events[0][0] != fd + or not events[0][1] & select.POLLIN + or events[0][1] & (select.POLLERR | select.POLLNVAL)): raise ValueError("invalid original meter pidfd exit evidence") return True @@ -102,58 +106,97 @@ def _check_docker(docker, measured, running): raise ValueError("original isolated Docker incarnation changed or restarted") -def _file_hash(fd, name, limit): +def _file_evidence(fd, name, deadline): + """Exact immutable file metadata plus hash, including the empty lock.""" + before = os.stat(name, dir_fd=fd, follow_symlinks=False) + if (not stat.S_ISREG(before.st_mode) or before.st_uid != os.geteuid() + or stat.S_IMODE(before.st_mode) != 0o600 or before.st_nlink != 1 + or not 0 <= before.st_size <= watch.MAX_SCAN + or ((before.st_size == 0) != (name == watch.INSTANCE_LOCK))): + raise ValueError("invalid original WAL file during retirement") + expected = watch._file_identity(before) flags = os.O_RDONLY | os.O_NOFOLLOW | os.O_CLOEXEC | os.O_NONBLOCK with os.fdopen(os.open(name, flags, dir_fd=fd), "rb") as source: - info = os.fstat(source.fileno()) - if (not stat.S_ISREG(info.st_mode) or info.st_uid != os.geteuid() - or stat.S_IMODE(info.st_mode) != 0o600 or info.st_nlink != 1 - or not 0 < info.st_size <= limit): - raise ValueError("invalid original WAL file during retirement") + if watch._file_identity(os.fstat(source.fileno())) != expected: + raise ValueError("original WAL file replaced at open") digest = hashlib.sha256() - remaining = info.st_size + remaining = before.st_size while remaining: + deadline() chunk = source.read(min(65536, remaining)) if not chunk: raise ValueError("original WAL truncated while reading") digest.update(chunk) remaining -= len(chunk) - if source.read(1): - raise ValueError("original WAL grew while reading") - current = os.fstat(source.fileno()) - named = os.stat(name, dir_fd=fd, follow_symlinks=False) - def identity(item): - return (item.st_dev, item.st_ino, item.st_size, item.st_mtime_ns, - item.st_ctime_ns, item.st_mode, item.st_uid, item.st_nlink) - if identity(current) != identity(info) or identity(named) != identity(info): + if (source.read(1) + or watch._file_identity(os.fstat(source.fileno())) != expected + or watch._file_identity(os.stat(name, dir_fd=fd, follow_symlinks=False)) != expected): raise ValueError("original WAL file changed while reading") - return digest.hexdigest() - - -@contextmanager -def _released_lifetime_lock(fd, expected): - lock = os.open(watch.INSTANCE_LOCK, os.O_RDONLY | os.O_NOFOLLOW - | os.O_CLOEXEC | os.O_NONBLOCK, dir_fd=fd) + deadline() + return (expected, digest.hexdigest()) + + +def _manifest(fd, names, deadline): + if set(os.listdir(fd)) != names: + raise ValueError("missing, additional or uncertain first-meter retirement WAL files") + entries = {} + total = 0 + for name in sorted(names): + deadline() + total += os.stat(name, dir_fd=fd, follow_symlinks=False).st_size + if total > watch.MAX_SCAN: + raise ValueError("retirement WAL scan exceeds bounded budget") + entries[name] = _file_evidence(fd, name, deadline) + _check_manifest(fd, entries) + os.fsync(fd) + deadline() + return entries + + +def _check_manifest(fd, entries): + if (set(os.listdir(fd)) != set(entries) + or any(watch._file_identity(os.stat(name, dir_fd=fd, follow_symlinks=False)) + != identity for name, (identity, _) in entries.items())): + raise ValueError("original meter journal inode changed during audit") + + +def _publish_record(directory, runtime, raw, before_link): + """No-replace, fsynced, private historical record. Not a Node signature.""" + if not wal._hex(runtime, 64) or not 0 < len(raw) <= MAX_RECORD: + raise ValueError("invalid retirement record identity or size") + fd = journal._validate_directory(directory) try: - def check(): - inode = os.fstat(lock) - named = os.stat(watch.INSTANCE_LOCK, dir_fd=fd, follow_symlinks=False) - for info in (inode, named): - if ((info.st_dev, info.st_ino) != expected[:2] - or not stat.S_ISREG(info.st_mode) or info.st_uid != os.geteuid() - or info.st_nlink != 1 or info.st_size != 0 - or stat.S_IMODE(info.st_mode) != 0o600): - raise ValueError("original lifetime lock inode changed") - check() + fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB) + if any(name.startswith(".retirement-pending-") for name in os.listdir(fd)): + raise ValueError("interrupted retirement publication requires investigation") + name = "retired-" + runtime + ".json" try: - fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB) - except BlockingIOError as exc: - raise ValueError("original lifetime lock still held") from exc - check() - yield check - check() + existing = wal.observed.read_private_record(fd, name) + except FileNotFoundError: + pass + else: + if existing != raw: + raise ValueError("conflicting immutable retirement evidence") + before_link() + os.fsync(fd) + return + pending = ".retirement-pending-" + secrets.token_hex(16) + out = os.open(pending, os.O_WRONLY | os.O_CREAT | os.O_EXCL | + os.O_NOFOLLOW | os.O_CLOEXEC, 0o600, dir_fd=fd) + with os.fdopen(out, "wb") as handle: + handle.write(raw) + handle.flush() + os.fsync(handle.fileno()) + os.fsync(fd) + before_link() + os.link(pending, name, src_dir_fd=fd, dst_dir_fd=fd, follow_symlinks=False) + os.fsync(fd) + os.unlink(pending, dir_fd=fd) + os.fsync(fd) + if wal.observed.read_private_record(fd, name) != raw: + raise ValueError("retirement evidence changed after publication") finally: - os.close(lock) + os.close(fd) class FirstGenesisRetirement: @@ -168,7 +211,7 @@ def __init__(self, roster, user, measured, remeasure): or type(measured[2]) is not int or measured[2] <= 1): raise ValueError("independently authenticated first-Genesis roster required") self._roster, self._measured, self._remeasure = roster, measured, remeasure - self._pidfd = self._directory_fd = None + self._pidfd = self._directory_fd = self._instance_fd = None self._started = time.monotonic_ns() self._checkpoints = {} self._prestop = None @@ -176,6 +219,10 @@ def __init__(self, roster, user, measured, remeasure): self._pidfd = os.pidfd_open(measured[2], 0) self._directory_fd = journal._validate_directory(DIRECTORY) self._identity = _directory_identity(self._directory_fd) + self._instance_fd = os.open( + watch.INSTANCE_LOCK, os.O_RDONLY | os.O_NOFOLLOW | os.O_CLOEXEC | + os.O_NONBLOCK, dir_fd=self._directory_fd) + self._instance_identity = watch._file_identity(os.fstat(self._instance_fd)) self._live() readback_start = time.monotonic_ns() @@ -184,10 +231,13 @@ def readback_deadline(): if not 0 <= time.monotonic_ns() - readback_start < watch.MAX_CHECK_NS: raise ValueError("first-Genesis WAL readback exceeded time budget") - self._snapshot, self._witness_sha = watch._checked_evidence( + self._snapshot, self._witness_raw = watch._checked_evidence( roster, user, measured, os.fspath(DIRECTORY), remeasure, readback_deadline) - if self._snapshot["identity"] != self._identity: - raise ValueError("WAL witness used another directory") + self._witness_sha = hashlib.sha256(self._witness_raw).hexdigest() + if (self._snapshot["identity"] != self._identity + or self._snapshot["inodes"][watch.INSTANCE_LOCK] != self._instance_identity): + raise ValueError("WAL witness used another directory or lock inode") + self._check_lock() self._live() except BaseException: self.close() @@ -208,11 +258,21 @@ def _bound(self, running): or _directory_identity(self._directory_fd) != self._identity): raise ValueError("retirement WAL directory changed") current = os.stat(DIRECTORY, follow_symlinks=False) - if not stat.S_ISDIR(current.st_mode) or (current.st_dev, current.st_ino) != self._identity: + if (not stat.S_ISDIR(current.st_mode) or current.st_uid != os.geteuid() + or stat.S_IMODE(current.st_mode) != 0o700 + or (current.st_dev, current.st_ino) != self._identity): raise ValueError("retirement WAL pathname replaced") + self._check_lock() self._deadline() return docker + def _check_lock(self): + named = os.stat(watch.INSTANCE_LOCK, dir_fd=self._directory_fd, + follow_symlinks=False) + if (watch._file_identity(named) != self._instance_identity + or watch._file_identity(os.fstat(self._instance_fd)) != self._instance_identity): + raise ValueError("original lifetime lock inode changed") + def _live(self): if self._pidfd is None or _poll_exit(self._pidfd): raise ValueError("original meter exited before retirement proof") @@ -238,22 +298,24 @@ def _ledger(self, docker): expected.add(wal.registry.NAME) hashes[wal.registry.NAME] = self._snapshot["sha256"] expected.update(_fence_names(self._roster._grants)) - if set(os.listdir(fd)) != expected: - raise ValueError("missing, additional or uncertain first-meter retirement WAL files") + hashes[watch.INSTANCE_LOCK] = hashlib.sha256(b"").hexdigest() + entries = _manifest(fd, expected, self._deadline) for name, digest in sorted(hashes.items()): self._deadline() - if _file_hash(fd, name, watch.MAX_SCAN) != digest: + if entries[name][1] != digest: raise ValueError("committed original WAL bytes changed after signed readback") + if entries[name][0] != self._snapshot["inodes"][name]: + raise ValueError("committed original WAL inode changed after signed readback") if set(self._checkpoints) != set(self._roster._grants): raise ValueError("one or more signed users lack a durable deny") fences = {} for user, checkpoint in sorted(self._checkpoints.items()): self._deadline() fences[str(user)] = journal.verify_poststop_journal(checkpoint, DIRECTORY, docker) - if set(os.listdir(fd)) != expected: - raise ValueError("original meter journal changed during fence audit") + _check_manifest(fd, entries) + self._check_lock() self._deadline() - return fences + return fences, entries def fence_all(self): """Only in the disposable harness, drain every independently signed user.""" @@ -289,29 +351,62 @@ def verify_exited(self): if self._prestop is None or self._pidfd is None or not _poll_exit(self._pidfd): raise ValueError("original meter pidfd has not exited after durable full-roster denial") docker = self._bound(False) - with _released_lifetime_lock(self._directory_fd, self._snapshot["instanceLock"]): - if self._ledger(docker) != self._prestop: - raise ValueError("durable deny or original WAL changed across process exit") - self._bound(False) - if not _poll_exit(self._pidfd): - raise ValueError("original meter pidfd exit could not be confirmed") - return { - "kind": "xmesh.quota-v2.nonfinal-first-meter-retirement", - "runtimeId": self._measured[3], "containerId": self._measured[0], - "startedAt": self._measured[1], - "signedWalReadbackSha256": self._witness_sha, - "inventorySha256": self._snapshot["sha256"], - "committedChargeHeadsSha256": self._snapshot["chargeHeadsSha256"], - "durableUserDenials": dict(self._prestop), - "originalMeterPidfdExited": True, - "lifetimeLockReleased": True, - "finalMeterVerified": False, - "settlementEligible": False, - "canResume": False, "refundableBytes": 0, - } + # Acquire the SAME already-open inode retained before the first + # authenticated readback, and retain it until this object closes. + # No new pathname open and no gap during publication. + self._check_lock() + try: + fcntl.flock(self._instance_fd, fcntl.LOCK_EX | fcntl.LOCK_NB) + except BlockingIOError as exc: + raise ValueError("original lifetime lock still held") from exc + self._check_lock() + if self._ledger(docker) != self._prestop: + raise ValueError("durable deny or original WAL changed across process exit") + self._bound(False) + if not _poll_exit(self._pidfd): + raise ValueError("original meter pidfd exit could not be confirmed") + return { + "kind": "xmesh.quota-v2.nonfinal-first-meter-retirement", + "runtimeId": self._measured[3], "containerId": self._measured[0], + "startedAt": self._measured[1], + "signedWalReadbackSha256": self._witness_sha, + "inventorySha256": self._snapshot["sha256"], + "committedChargeHeadsSha256": self._snapshot["chargeHeadsSha256"], + "durableUserDenials": dict(self._prestop[0]), + "originalMeterPidfdExited": True, + "lifetimeLockReleased": True, + "finalMeterVerified": False, + "settlementEligible": False, + "canResume": False, "refundableBytes": 0, + } + + def publish_exited(self): + """Optional private audit persistence; no terminal receipt or authority.""" + observation = self.verify_exited() + manifest = [{"filename": name, "sha256": digest} + for name, (_, digest) in sorted(self._prestop[1].items())] + payload = dict(observation, schemaVersion=1, nodeId=self._roster.node, + retiredLedgerSha256=hashlib.sha256( + wal.observed.canonical(manifest)).hexdigest(), + deliveredBytesVerified=False, nodeSignatureVerified=False, + canServePublic=False, canStart=False) + data = wal.observed.canonical({ + "observation": payload, + # Preserve the exact authenticated response bytes, NOT a + # re-encoded subset or a claim that the Node signed this record. + "nexusResponse": self._witness_raw.decode("utf-8"), + }) + b"\n" + RECORD_DIRECTORY.mkdir(mode=0o700, exist_ok=True) + + def before_link(): + if self.verify_exited() != observation: + raise ValueError("retirement observation changed before publication") + + _publish_record(RECORD_DIRECTORY, self._measured[3], data, before_link) + return payload def close(self): - for name in ("_directory_fd", "_pidfd"): + for name in ("_instance_fd", "_directory_fd", "_pidfd"): fd = getattr(self, name) if fd is not None: os.close(fd) diff --git a/experiments/quota-v2-physical-stop/public_tls_wal_watch.py b/experiments/quota-v2-physical-stop/public_tls_wal_watch.py index e0aeacab..96599c26 100644 --- a/experiments/quota-v2-physical-stop/public_tls_wal_watch.py +++ b/experiments/quota-v2-physical-stop/public_tls_wal_watch.py @@ -36,6 +36,13 @@ MAX_FDINFO = 8192 +def _file_identity(info): + """Stable bytes/inode/change identity (intentionally excludes access time).""" + return (info.st_dev, info.st_ino, info.st_mode, info.st_uid, + info.st_gid, info.st_nlink, info.st_size, info.st_mtime_ns, + info.st_ctime_ns) + + def _instance_lock(directory_fd, pid, deadline): """Read the measured Xray's real lifetime flock; never take it ourselves.""" fd = os.open(INSTANCE_LOCK, os.O_RDONLY | os.O_NOFOLLOW | os.O_CLOEXEC @@ -117,6 +124,10 @@ def _snapshot(directory, roster, deadline): # Bind the bytes persisted inside Xray, not only Agent's root copies. # Bound work before opening any file, and reject unsafe inodes. total = 0 + inodes = {INSTANCE_LOCK: _file_identity( + os.stat(INSTANCE_LOCK, dir_fd=fd, follow_symlinks=False))} + if inodes[INSTANCE_LOCK][:2] != instance[:2]: + raise ValueError("first-Genesis instance lock replaced before snapshot") for name in names - {INSTANCE_LOCK}: deadline() info = os.stat(name, dir_fd=fd, follow_symlinks=False) @@ -127,6 +138,7 @@ def _snapshot(directory, roster, deadline): or stat.S_IMODE(info.st_mode) != 0o600 or not 0 < info.st_size <= limit): raise ValueError("unsafe first-Genesis ledger file") + inodes[name] = _file_identity(info) total += info.st_size if total > MAX_SCAN: raise ValueError("first-Genesis WAL scan exceeds bounded budget") @@ -188,12 +200,17 @@ def read_meter(dfd, name): current = os.stat(directory, follow_symlinks=False) if (current.st_dev, current.st_ino) != (anchor.st_dev, anchor.st_ino): raise ValueError("first-Genesis journal directory was replaced") + if (set(os.listdir(fd)) != names + or any(_file_identity(os.stat(name, dir_fd=fd, follow_symlinks=False)) + != identity for name, identity in inodes.items())): + raise ValueError("first-Genesis ledger inode changed during snapshot") if _instance_lock(fd, roster._pid, deadline) != instance: raise ValueError("Xray instance lock was replaced during snapshot") deadline() return { "identity": (anchor.st_dev, anchor.st_ino), "instanceLock": instance, + "inodes": inodes, "sequence": len(entries), "sha256": hashlib.sha256(index).hexdigest(), "tail": next(reversed(entries.values()))["digest"] if entries else "0"*64, @@ -348,7 +365,7 @@ def _checked_evidence(roster, user, measured, directory, remeasure, deadline): raise ValueError("Nexus WAL witness expired or clock changed") # Private historical evidence for the disposable retirement verifier. # The bytes/digest do not establish terminality or grant any authority. - return before, hashlib.sha256(raw).hexdigest() + return before, raw def _check(roster, user, measured, directory, remeasure, deadline): diff --git a/tests/test_quota_v2_public_tls_meter_retirement.py b/tests/test_quota_v2_public_tls_meter_retirement.py index 5f20c3b5..20203c98 100644 --- a/tests/test_quota_v2_public_tls_meter_retirement.py +++ b/tests/test_quota_v2_public_tls_meter_retirement.py @@ -5,6 +5,8 @@ No positive issuer, terminal byte claim or service is exercised here. """ from contextlib import ExitStack +import fcntl +import json import hashlib import os from pathlib import Path @@ -187,7 +189,6 @@ def test_lifetime_lock_replacement_after_original_exit_rejected(self): proof.verify_exited() def test_foreign_writer_lock_after_original_exit_rejected_against_real_flock(self): - import fcntl proof = self.fenced() self.stop_child() with (self.directory / watch.INSTANCE_LOCK).open("rb") as lock: @@ -203,6 +204,83 @@ def test_changed_committed_wal_after_exit_never_settles(self): with self.assertRaisesRegex(ValueError, "committed original WAL bytes changed"): proof.verify_exited() + @staticmethod + def replace_identical(path): + raw = path.read_bytes() + replacement = path.with_name(".replacement") + replacement.write_bytes(raw) + replacement.chmod(0o600) + replacement.replace(path) + + def test_same_bytes_different_inode_before_fence_denies(self): + proof = self.capture() + self.replace_identical(next(self.directory.glob("meter-*.jsonl"))) + with self.assertRaisesRegex(ValueError, "changed before fencing"): + proof.fence_all() + self.fence.assert_not_called() + + def test_identical_wal_replacement_after_exit_denies(self): + proof = self.fenced() + self.stop_child() + self.replace_identical(next(self.directory.glob("meter-*.jsonl"))) + with self.assertRaisesRegex(ValueError, "WAL inode changed"): + proof.verify_exited() + + def test_identical_durable_fence_replacement_after_exit_denies(self): + proof = self.fenced() + self.stop_child() + self.replace_identical(next(self.directory.glob("fence-*.json"))) + with self.assertRaisesRegex(ValueError, "changed across process exit"): + proof.verify_exited() + + def test_original_lock_retained_across_verification_and_publication(self): + proof = self.fenced() + self.stop_child() + root = Path(self.stack.enter_context(tempfile.TemporaryDirectory( + prefix="xmesh-retire-record-"))) + with mock.patch.object(retirement, "RECORD_DIRECTORY", root): + payload = proof.publish_exited() + record = root / ("retired-" + self.runtime + ".json") + wire = record.read_bytes() + doc = json.loads(wire) + self.assertEqual(doc["observation"], payload) + self.assertEqual(hashlib.sha256(doc["nexusResponse"].encode()).hexdigest(), + payload["signedWalReadbackSha256"]) + self.assertEqual(doc["nexusResponse"].encode(), proof._witness_raw) + for flag in ("deliveredBytesVerified", "nodeSignatureVerified", "canStart", + "canServePublic", "canResume", "settlementEligible", "finalMeterVerified"): + self.assertIs(payload[flag], False) + self.assertEqual(payload["refundableBytes"], 0) + self.assertEqual(record.stat().st_mode & 0o777, 0o600) + self.assertEqual(record.stat().st_nlink, 1) + inode = record.stat().st_ino + self.assertEqual(proof.publish_exited(), payload) + self.assertEqual(record.stat().st_ino, inode) + self.assertEqual(record.read_bytes(), wire) + with (self.directory / watch.INSTANCE_LOCK).open("rb") as foreign: + with self.assertRaises(BlockingIOError): + fcntl.flock(foreign, fcntl.LOCK_EX | fcntl.LOCK_NB) + with self.assertRaisesRegex(ValueError, "conflicting immutable"): + retirement._publish_record(root, self.runtime, b"other", lambda: None) + proof.close() + with (self.directory / watch.INSTANCE_LOCK).open("rb") as foreign: + fcntl.flock(foreign, fcntl.LOCK_EX | fcntl.LOCK_NB) + + def test_pending_record_denies_recovery_without_original_observation(self): + root = Path(self.stack.enter_context(tempfile.TemporaryDirectory( + prefix="xmesh-retire-abort-"))) + + def abort(): + raise ValueError("ledger changed before publication") + + with self.assertRaisesRegex(ValueError, "ledger changed"): + retirement._publish_record(root, self.runtime, b"nonfinal", abort) + names = list(root.iterdir()) + self.assertEqual(len(names), 1) + self.assertTrue(names[0].name.startswith(".retirement-pending-")) + with self.assertRaisesRegex(ValueError, "interrupted retirement publication"): + retirement._publish_record(root, self.runtime, b"nonfinal", lambda: None) + def test_missing_deny_or_unknown_journal_after_exit_is_not_proof(self): proof = self.fenced() self.stop_child() diff --git a/tests/test_quota_v2_public_tls_wal_watch.py b/tests/test_quota_v2_public_tls_wal_watch.py index 95c4451b..b032701d 100644 --- a/tests/test_quota_v2_public_tls_wal_watch.py +++ b/tests/test_quota_v2_public_tls_wal_watch.py @@ -136,6 +136,20 @@ def test_empty_and_real_nonempty_index_have_no_authority(self): (self.directory / watch.wal.registry.NAME).read_bytes()).hexdigest()) self.assertIsNone(self.check()) + def test_same_bytes_different_inode_during_readback_denied(self): + def replace_cap(request): + snapshot = self.snapshot() + reply = self.reply(request, snapshot) + cap = self.directory / "positive-cap-u100.json" + replacement = self.directory / "untrusted-replacement" + replacement.write_bytes(cap.read_bytes()) + replacement.chmod(0o600) + replacement.replace(cap) + return reply + + with self.assertRaisesRegex(ValueError, "changed during readback"): + self.check(fetch=replace_cap) + def test_real_signature_is_not_authority_or_a_substitute_for_fresh_scope(self): request = watch._request(self.roster, 100, self.measured) snapshot = self.snapshot()