fix: reconcile configured APT effect without retroactive acceptance and retain host reboot evidence
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-13 20:00:20 +01:00
parent 34d695a778
commit b08734065a
26 changed files with 2006 additions and 36 deletions
@@ -57,8 +57,14 @@ def signed_job(ctx, manifest):
'apt_manifest': manifest}}
def prechecks(ctx):
return {'schema_version': 1, 'transaction_sha256': ctx.transaction_sha256,
def host_before(ctx, pending=False):
return {'schema_version':1,'transaction_sha256':ctx.transaction_sha256,'job_payload_sha256':ctx.job_payload_sha256,
'effect_armed_ledger_id':ctx.effect_armed_ledger_id,'grant_id':ctx.grant_id,'boot_id':ctx.boot_id,
'host_reboot_required':pending,'observed_at_ms':2000}
def prechecks(ctx, before=None):
result = {'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,
@@ -66,6 +72,10 @@ def prechecks(ctx):
'invalid_kexec_load_flags': 'EPERM',
'invalid_kexec_file_fds_flags': 'EPERM'},
'frontend_lock': 'native-apt-check-conflict'}}
if before is not None:
result.update(schema_version=2,host_reboot_before_sha256=apt.digest(apt.canonical(before)),
host_reboot_required_before=before['host_reboot_required'])
return result
class BindingTests(TestCase):
@@ -201,8 +211,9 @@ class NativeProbeTests(TestCase):
patch.object(apt, 'invalid_control_syscall_probes', return_value=prechecks(context())['checks']['control_syscalls']), \
patch.object(apt, 'frontend_lock_probe', return_value='native-apt-check-conflict'), \
patch.object(apt.socket, 'socket', side_effect=OSError(apt.errno.EAFNOSUPPORT, 'mocked kernel denial')), \
patch.object(apt,'load_host_reboot_before',return_value=(host_before(context()),apt.digest(apt.canonical(host_before(context()))))), \
patch.object(apt.VerifiedHelperContext, 'check_deadline'):
self.assertEqual(apt.native_prechecks(context()), prechecks(context()))
self.assertEqual(apt.native_prechecks(context()), prechecks(context(),host_before(context())))
def test_safe_invalid_syscall_probes_in_unprivileged_filtered_child(self):
code = '''import importlib.util,sys,json
@@ -235,7 +246,10 @@ class CompletionTests(TestCase):
def setup_files(self, base, ctx):
active = base / 'active'
active.mkdir()
(active / 'native-prechecks.json').write_bytes(apt.canonical(prechecks(ctx)))
before=host_before(ctx)
(active / 'host-reboot-before.json').write_bytes(apt.canonical(before))
(active / 'native-prechecks.json').write_bytes(apt.canonical(prechecks(ctx,before)))
(active / 'sandbox-result.json').write_bytes(apt.canonical({'transaction_sha256':ctx.transaction_sha256,'apt_exit_code':0,'reboot_required':False}))
(active / 'hook-armed.json').write_bytes(apt.canonical({'grant_id': ctx.grant_id}))
(base / 'bootstrap-attempt-rmm-apt-fixture-install-1.0.json').write_bytes(apt.canonical({
'transaction_sha256': ctx.transaction_sha256, 'job_payload_sha256': ctx.job_payload_sha256,
@@ -250,6 +264,7 @@ class CompletionTests(TestCase):
with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \
patch.object(apt, 'secure_path'), patch.object(apt, 'sealed_read', side_effect=lambda p, *a: p.read_bytes()), \
patch.object(apt, 'runtime_identity', return_value={}), \
patch.object(Path,'read_text',return_value=ctx.boot_id), \
patch.object(apt.os, 'fsync', wraps=os.fsync) as sync:
obj = fixture_transaction()
tx = apt.ResolvedAptTransaction.parse(obj)
@@ -281,7 +296,7 @@ class CompletionTests(TestCase):
elif variation == 'partial':
checkfile.write_bytes(b'{')
elif variation in ('negative', 'binding'):
obj = prechecks(ctx)
obj = prechecks(ctx,host_before(ctx))
if variation == 'negative':
obj['checks']['namespaces_caps_nnp_seccomp'] = False
else:
@@ -289,7 +304,8 @@ class CompletionTests(TestCase):
checkfile.write_bytes(apt.canonical(obj))
with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \
patch.object(apt, 'secure_path'), patch.object(apt, 'sealed_read', side_effect=lambda p, *a: p.read_bytes()), \
patch.object(apt, 'runtime_identity', return_value={'changed': True} if variation == 'runtime' else {}):
patch.object(apt, 'runtime_identity', return_value={'changed': True} if variation == 'runtime' else {}), \
patch.object(Path,'read_text',return_value=ctx.boot_id):
obj = fixture_transaction()
tx = apt.ResolvedAptTransaction.parse(obj)
with self.subTest(variation=variation), self.assertRaises((apt.Veto, OSError)):
@@ -305,6 +321,7 @@ class CompletionTests(TestCase):
with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \
patch.object(apt, 'sealed_read', side_effect=lambda p, *a: p.read_bytes()), \
patch.object(apt, 'runtime_identity', return_value={}), \
patch.object(Path,'read_text',return_value=ctx.boot_id), \
patch.object(apt, 'durable_once', side_effect=OSError('fsync failure')):
obj = fixture_transaction()
tx = apt.ResolvedAptTransaction.parse(obj)
@@ -350,7 +367,7 @@ class DriverTests(TestCase):
'transaction_sha256': ctx.transaction_sha256, 'apt_exit_code': native_code,
'reboot_required': False}))
if scenario != 'missing-prechecks':
(active / 'native-prechecks.json').write_bytes(apt.canonical(prechecks(ctx)))
(active / 'native-prechecks.json').write_bytes(apt.canonical(prechecks(ctx,json.loads((active/'host-reboot-before.json').read_bytes()))))
return type('MockNativeChild', (), {'wait': lambda _: native_code})()
with patch.object(apt, 'BASE', base), patch.object(apt, 'ACTIVE', active), \
@@ -358,6 +375,7 @@ class DriverTests(TestCase):
patch.object(apt, 'sealed_read', side_effect=read), patch.object(apt, 'runtime_identity', return_value={}), \
patch.object(apt, 'check_current_baseline'), patch.object(apt, 'check_preconditions'), patch.object(apt, 'verify_archive'), \
patch.object(apt, 'run_read', return_value=b''), patch.object(apt, 'installed_snapshot', return_value={}), \
patch.object(Path,'read_text',return_value=ctx.boot_id), patch.object(apt.time,'time_ns',return_value=2000000000), \
patch.object(apt.VerifiedHelperContext, 'check_deadline',
side_effect=apt.Veto('START_DEADLINE') if scenario == 'stale' else None), \
patch.object(apt.subprocess, 'Popen', side_effect=child) as spawn: