fix: retain sync anchors and verify bound APT partial postconditions
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-13 17:20:50 +01:00
parent 435c4453fe
commit 998f16fde4
13 changed files with 1469 additions and 16 deletions
+157
View File
@@ -1232,6 +1232,161 @@ def verify_after(transaction, baseline):
return evidence
def partial_installed_snapshot():
"""Readonly original-job verification, never a general planning baseline.
Only this exact script/trigger/dependency-free fixture may be unpacked.
Normal inventory/planning/execution keep rejecting inconsistent dpkg state.
"""
data = run_read(['/usr/bin/dpkg-query', '--show',
'--showformat=${Package}\t${Architecture}\t${Version}\t${Status}\n'],
limit=32 * MAX_INPUT)
snapshot = {}
for line in data.decode('utf-8', 'strict').splitlines():
fields = line.split('\t')
require(len(fields) == 4, 'DPKG_QUERY_FORMAT')
name, arch, version, status = fields
key = name + ':' + arch
require(key not in snapshot, 'DPKG_QUERY_DUPLICATE')
ordinary = status in ('install ok installed', 'deinstall ok config-files',
'purge ok not-installed', 'unknown ok not-installed')
partial = key == 'rmm-mvp-test:all' and version == '1.0' and status == 'install ok unpacked'
require(ordinary or partial, 'PARTIAL_OTHER_INCONSISTENT_PACKAGE')
snapshot[key] = {'version': version, 'status': status}
return snapshot
def verify_partial(request):
"""Recheck ONLY the fixed original job's postcondition, with no mutation.
RootHelper independently verifies its historical signed Request and the
unresolved consumed row first. These caller bindings are not authority to
execute: this mode has no APT/dpkg effect call or writable metadata path.
Current code/config/runtime need not equal the historical execution runtime;
original signed bytes and original apt.conf remain immutable evidence.
"""
require(os.geteuid() == 0, 'ROOT_REQUIRED')
fields = ('transaction_sha256 job_payload_sha256 effect_armed_ledger_id grant_id '
'job_id attempt_id authorization_id plan_sha256')
exact(request, fields)
for key in ('transaction_sha256', 'job_payload_sha256', 'plan_sha256'):
token(request[key], HASH, 'PARTIAL_REQUEST_HASH')
token(request['effect_armed_ledger_id'], IDENT, 'PARTIAL_REQUEST_LEDGER')
for key in ('grant_id', 'job_id', 'attempt_id', 'authorization_id'):
value = request[key]
require(type(value) is str and str(uuid.UUID(value)) == value and
uuid.UUID(value).int != 0, 'PARTIAL_REQUEST_ID')
secure_path(BASE, directory=True, private=True)
secure_path(ACTIVE, directory=True, private=True)
names = ('context.json', 'signed-action.json', 'expectation.json', 'baseline.json',
'launch.json', 'native-prechecks.json', 'sandbox-ready.json',
'sandbox-result.json', 'hook-armed.json')
raw = {name: sealed_read(ACTIVE / name) for name in names}
ctx = VerifiedHelperContext.parse(json_bytes(raw['context.json']))
require(ctx.action == 'apt-native-acceptance' and ctx.execution_profile == 'dev-test' and
all(getattr(ctx, key) == request[key] for key in fields.split()), 'PARTIAL_CONTEXT_BINDING')
require(Path('/proc/sys/kernel/random/boot_id').read_text().strip() == ctx.boot_id,
'PARTIAL_BOOT_CHANGED')
require(digest(raw['signed-action.json']) == ctx.job_payload_sha256 and
digest(raw['expectation.json']) == ctx.transaction_sha256, 'PARTIAL_SIGNED_BYTES')
tx = ResolvedAptTransaction.parse(json_bytes(raw['expectation.json']))
fixture_scope(tx)
require(tx.recipe_id == 'rmm-apt-fixture-install-1.0', 'PARTIAL_FIXED_INSTALL_ONLY')
baseline = json_bytes(raw['baseline.json'])
require(type(baseline) is dict and raw['baseline.json'] == canonical(baseline) and
digest(raw['baseline.json']) == tx.baseline_sha256 and
'rmm-mvp-test:all' not in baseline, 'PARTIAL_ORIGINAL_BASELINE')
job = json_bytes(raw['signed-action.json'])
exact(job, 'schema_version tenant_id asset_id agent_id enrollment_generation assignment_version '
'job_id attempt_id action execution_identity not_before start_before max_runtime_seconds max_output_bytes')
require(type(job['schema_version']) is int and job['schema_version'] == 1 and
job['job_id'] == ctx.job_id and job['attempt_id'] == ctx.attempt_id and
job['execution_identity'] == 'root', 'PARTIAL_ORIGINAL_JOB')
outer = job['action']
exact(outer, 'action recipe_id recipe_version apt_manifest')
require(outer['action'] == 'apt_native_acceptance' and outer['recipe_id'] == tx.recipe_id and
outer['recipe_version'] == tx.recipe_version, 'PARTIAL_ORIGINAL_ACTION')
action = outer['apt_manifest']
exact(action, 'type schema_version action execution_profile transaction_sha256 '
'resolved_apt_transaction provider_sha256 hook_sha256 apt_config_sha256 '
'runtime_sha256 test_result_id transaction_bytes native_retry')
require(action['type'] == 'rmm.apt.helper-action' and type(action['schema_version']) is int and
action['schema_version'] == 3 and action['action'] == ctx.action and
action['execution_profile'] == ctx.execution_profile and
action['transaction_sha256'] == ctx.transaction_sha256 and
canonical(action['resolved_apt_transaction']) == canonical(json_bytes(raw['expectation.json'])) and
type(action['transaction_bytes']) is list and
all(type(n) is int and 0 <= n <= 255 for n in action['transaction_bytes']) and
bytes(action['transaction_bytes']) == raw['expectation.json'], 'PARTIAL_ORIGINAL_MANIFEST')
for key in ('provider_sha256', 'hook_sha256', 'apt_config_sha256', 'runtime_sha256'):
token(action[key], HASH, 'PARTIAL_ORIGINAL_RUNTIME_HASH')
token(action['test_result_id'], IDENT, 'PARTIAL_ORIGINAL_TEST_ID')
require(digest(sealed_read(ACTIVE / 'apt.conf')) == action['apt_config_sha256'],
'PARTIAL_ORIGINAL_CONFIG')
# This reuses only immutable historical binding checks, never the current
# executable gate or an acceptance publication. It also verifies both once
# markers and the original failed no-handoff history referenced by retry.
check_bootstrap_attempt(tx, ctx, action)
for prefix in ('bootstrap-attempt-', 'bootstrap-retry-'):
name = prefix + tx.recipe_id + '.json'
raw[name] = sealed_read(BASE / name)
for prefix in ('acceptance-', 'pending-acceptance-'):
require(not os.path.lexists(BASE / (prefix + tx.recipe_id + '.json')),
'PARTIAL_ACCEPTANCE_ALREADY_EXISTS')
require(canonical(json_bytes(raw['launch.json'])) == canonical({
'transaction_sha256': ctx.transaction_sha256,
'effect_armed_ledger_id': ctx.effect_armed_ledger_id}), 'PARTIAL_LAUNCH_BINDING')
prechecks = {'schema_version': 1, 'transaction_sha256': ctx.transaction_sha256,
'job_payload_sha256': ctx.job_payload_sha256, 'boot_id': ctx.boot_id,
'checks': {'namespaces_caps_nnp_seccomp': True, 'readonly_controlpaths': True,
'private_tmpfs_sockets': True,
'control_syscalls': {'invalid_reboot_magic': 'EPERM',
'invalid_kexec_load_flags': 'EPERM',
'invalid_kexec_file_fds_flags': 'EPERM'},
'frontend_lock': 'native-apt-check-conflict'}}
require(canonical(json_bytes(raw['native-prechecks.json'])) == canonical(prechecks) and
canonical(json_bytes(raw['sandbox-ready.json'])) == canonical({
'sandbox_version': 1, 'transaction_sha256': ctx.transaction_sha256}) and
canonical(json_bytes(raw['sandbox-result.json'])) == canonical({
'transaction_sha256': ctx.transaction_sha256, 'apt_exit_code': 0,
'reboot_required': False}), 'PARTIAL_NATIVE_COMPLETION_REQUIRED')
marker = json_bytes(raw['hook-armed.json'])
exact(marker, 'armed_at_ms effect_armed_ledger_id grant_id protocol_sha256 transaction_sha256')
require(marker['effect_armed_ledger_id'] == ctx.effect_armed_ledger_id and
marker['grant_id'] == ctx.grant_id and marker['transaction_sha256'] == ctx.transaction_sha256 and
type(marker['armed_at_ms']) is int and
ctx.not_before_ms <= marker['armed_at_ms'] < ctx.start_before_ms, 'PARTIAL_HOOK_BINDING')
token(marker['protocol_sha256'], HASH, 'PARTIAL_HOOK_PROTOCOL_HASH')
require(not observe_host_frontend_lock() and
not observe_host_frontend_lock(Path('/var/lib/dpkg/lock')), 'FOREIGN_PACKAGE_LOCK')
fingerprint = status_fingerprint()
observed = partial_installed_snapshot()
expected = dict(baseline)
expected['rmm-mvp-test:all'] = {'version': '1.0', 'status': 'install ok unpacked'}
require(observed == expected, 'PARTIAL_UNEXPECTED_PACKAGE_CHANGE')
verify_archive(tx.packages[0])
payload = sealed_read(Path('/usr/share/rmm-mvp-test/version'), limit=32)
require(payload == b'1.0\n', 'PARTIAL_FIXTURE_PAYLOAD')
require(status_fingerprint() == fingerprint and partial_installed_snapshot() == observed and
not observe_host_frontend_lock() and
not observe_host_frontend_lock(Path('/var/lib/dpkg/lock')), 'PARTIAL_STATE_CHANGED')
# Re-read the historical witnesses too: a stable live package projection
# cannot compensate for changed/tampered original evidence.
for name, data in raw.items():
path = ACTIVE / name if name in names else BASE / name
require(sealed_read(path) == data, 'PARTIAL_HISTORICAL_EVIDENCE_CHANGED')
proof = dict(schema_version=1, type='rmm.apt.partial-reconciliation', **request,
original_evidence_sha256=digest(canonical({name: digest(data) for name, data in raw.items()})),
original_baseline_sha256=tx.baseline_sha256,
observed_snapshot_sha256=digest(canonical(observed)), status_fingerprint=fingerprint,
fixture_payload_sha256=digest(payload), snapshot=observed,
checked_at_ms=time.time_ns() // 1000000, partial_effect=True,
postconditions_passed=False, reboot_required=False)
result = dict(effect_state='known_failed', code='APT_PARTIAL_UNCONFIGURED_VERIFIED', proof=proof)
require(len(canonical(result)) <= MAX_INPUT, 'PARTIAL_PROOF_LIMIT')
return result
def verified_no_change(transaction, baseline, context):
"""Independently verify the full selected postcondition, never run APT."""
fixture_scope(transaction) # Cannot promote unknown catalog recipes.
@@ -1690,6 +1845,8 @@ def main():
probe_worker()
elif mode == 'readiness-status':
sys.stdout.buffer.write(canonical(readiness_status()) + b'\n')
elif mode == 'verify-partial':
sys.stdout.buffer.write(canonical(verify_partial(json_bytes(sys.stdin.buffer.read(MAX_INPUT + 1)))) + b'\n')
elif mode == 'verify-controller':
verify_controller_profile()
elif mode == 'inspect-sandbox':