fix: permit verified local APT acquisition with native network denial checks
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-13 14:59:23 +01:00
parent e18fae0e8a
commit a5c2dce4fb
9 changed files with 210 additions and 13 deletions
+42 -7
View File
@@ -7,6 +7,7 @@ APT endpoint remains absent from the agent configuration and is stopped after
the probe. General helper resumes with the existing binding/shared ledger.
"""
import base64
import argparse
import hashlib
import json
import os
@@ -42,9 +43,10 @@ def upgrade(payload):
def ledger_guard():
with sqlite3.connect(ledger.as_uri()+'?mode=ro',uri=True) as db:
require(db.execute('PRAGMA integrity_check').fetchone()[0]=='ok','ledger integrity')
require(db.execute('SELECT count(*) FROM consumed').fetchone()[0]==5 and
actual={r[0] for r in db.execute('SELECT grant_id FROM consumed')}
require(actual==set(payload['expected_grants']) and
db.execute('SELECT count(*) FROM consumed WHERE result IS NULL').fetchone()[0]==0 and
db.execute('SELECT count(*) FROM helper_sync_meta WHERE fault IS NOT NULL').fetchone()[0]==0,'five known closed root attempts required')
db.execute('SELECT count(*) FROM helper_sync_meta WHERE fault IS NOT NULL').fetchone()[0]==0,'exact known closed root attempts required')
ledger_guard()
require(json.loads((state/'identity.json').read_text())['agent_id']==payload['agent_id'],'cloud identity drift')
with sqlite3.connect((state/'journal.sqlite').as_uri()+'?mode=ro',uri=True) as db:
@@ -85,7 +87,9 @@ def upgrade(payload):
cmd=['/usr/bin/python3','-I',str(provider)]
runtime=json.loads(run(cmd+['inspect-runtime']));runtime_sha=sha(json.dumps(runtime,sort_keys=True,separators=(',',':'),ensure_ascii=True).encode())
old_config['apt_provider']['runtime_sha256']=runtime_sha
require(old_config['apt_provider']['apt_config_sha256']==sha(run(cmd+['print-config'])),'unchanged APT config required')
config_sha=sha(run(cmd+['print-config']))
require(config_sha==payload['reviewed_config_sha256'],'reviewed APT config required')
old_config['apt_provider']['apt_config_sha256']=config_sha
create(config,json.dumps(old_config).encode())
pin=json.loads(run([str(binary),'--inspect-apt-profile'],env=dict(os.environ,RMM_HELPER_CONFIG=str(config))))
require(pin['identity']==old_general['identity'],'helper identity changed')
@@ -94,7 +98,7 @@ def upgrade(payload):
require(general==old_general,'general policy changed')
require(all(manifest(Path(p))==v for p,v in preserved.items()) and markers[0].read_bytes()==marker and
(ledger.stat().st_dev,ledger.stat().st_ino)==inode,'preserved identity/attempt/ledger changed')
report.update(stage='installed_preserved',preserved_state=True,runtime_sha256=runtime_sha,apt_pin=pin,general_pin=general);save()
report.update(stage='installed_preserved',preserved_state=True,runtime_sha256=runtime_sha,apt_config_sha256=config_sha,apt_pin=pin,general_pin=general);save()
fcntl.flock(lockfd,fcntl.LOCK_UN);os.close(lockfd);lockfd=None
run(['systemd-analyze','verify','/etc/systemd/system/rmm-apt-helper.service'])
run(['systemctl','daemon-reload'])
@@ -120,16 +124,47 @@ def upgrade(payload):
return dict(report,backup=str(backup))
def installed_metadata(payload):
paths=('/usr/local/libexec/rmm-privileged-helper','/usr/lib/rmm-apt-transaction/apt_transaction.py',
'/etc/systemd/system/rmm-apt-helper.service','/etc/rmm/apt-helper.json','/etc/rmm-remote/apt-helper-proof.json')
values={name:hashlib.sha256(Path(name).read_bytes()).hexdigest() for name in paths}
require(values[paths[0]]==payload['helper_sha256'] and values[paths[1]]==payload['provider_sha256'],'previous reviewed artifacts drifted')
require(json.loads(Path(paths[3]).read_text())['apt_provider']['runtime_sha256']==payload['runtime_sha256'] and
json.loads(Path(paths[4]).read_text())==payload['apt_pin'],'previous independent runtime/proof drifted')
return dict(files=values)
def main():
parser=argparse.ArgumentParser();parser.add_argument('--local-file-fix',action='store_true');args=parser.parse_args()
os.umask(0o077);m=cloud.contract
require(followup.evidence('gate')['unresolved']==0,'unresolved central job')
diagnosis=m.protected_json(followup.STATE/'diagnosis/checkpoint.json');require(diagnosis.get('verified') is True,'diagnostic evidence required')
preflights=list(followup.STATE.glob('preflight-*.json'));require(len(preflights)==1,'one reviewed installed baseline')
old=m.protected_json(preflights[0]);artifact=(followup.STATE/'helper-sandbox-fixed').read_bytes()
reports=list(followup.STATE.glob('sandbox-*.json'))
if args.local_file_fix:
require(len(reports)==1,'exact prior successful sandbox upgrade required; never repeat migration')
prior=m.protected_json(reports[0]);require(prior['completed'] is True,'previous migration incomplete')
pins=m.protected_json(followup.STATE/'provider-before-local-file-fix.json')
old=cloud.bootstrap.rpc('linux-vm.conf',installed_metadata,dict(pins,runtime_sha256=prior['runtime_sha256'],apt_pin=prior['apt_pin']))
artifact=(followup.STATE/'helper-local-file-fixed').read_bytes()
folders=[cloud.ROOT/'devstate/cloud-root/cases'/name for name in ('service_setup','service_start','service_stop','apt_native_install')]
folders += [followup.STATE/name for name in ('diagnosis','diagnosis-acquisition','diagnosis-hook','diagnosis-local-hook')]
expected=[str(uuid.UUID(m.protected_json(p/'checkpoint.json')['result']['result']['grant_id'])) for p in folders]
require(len(set(expected))==8,'eight actual completed root attempts required')
else:
require(not reports,'existing sandbox upgrade retained; no implicit repeat')
preflights=list(followup.STATE.glob('preflight-*.json'));require(len(preflights)==1,'one reviewed installed baseline')
old=m.protected_json(preflights[0]);artifact=(followup.STATE/'helper-sandbox-fixed').read_bytes()
folders=[cloud.ROOT/'devstate/cloud-root/cases'/name for name in ('service_setup','service_start','service_stop','apt_native_install')]+[followup.STATE/'diagnosis']
expected=[str(uuid.UUID(m.protected_json(p/'checkpoint.json')['result']['result']['grant_id'])) for p in folders]
code=(cloud.ROOT/'tools/apt-transaction/apt_transaction.py').read_bytes()
import importlib.util
import sys
spec=importlib.util.spec_from_file_location('reviewed_apt_provider',cloud.ROOT/'tools/apt-transaction/apt_transaction.py')
module=importlib.util.module_from_spec(spec);sys.modules[spec.name]=module;spec.loader.exec_module(module)
payload=dict(id=str(uuid.uuid4()),agent_id=followup.identity()['agent_id'],old_files=old['files'],
binary=base64.b64encode(artifact).decode(),helper_sha256=hashlib.sha256(artifact).hexdigest(),
provider=base64.b64encode(code).decode(),provider_sha256=hashlib.sha256(code).hexdigest(),unit=(cloud.ROOT/'deploy/linux/rmm-apt-helper.service').read_text())
provider=base64.b64encode(code).decode(),provider_sha256=hashlib.sha256(code).hexdigest(),unit=(cloud.ROOT/'deploy/linux/rmm-apt-helper.service').read_text(),
expected_grants=expected,reviewed_config_sha256=hashlib.sha256(module.apt_config()).hexdigest())
result=cloud.bootstrap.rpc('linux-vm.conf',upgrade,payload)
m.write_private(followup.STATE/('sandbox-'+payload['id']+'.json'),result)
print({k:result.get(k) for k in ('completed','stage','error_class','frames','preserved_state','runtime_sha256','readiness_only')})