From f80521a61d4b7c54177fb33f236e4e5162133710 Mon Sep 17 00:00:00 2001 From: Kevin Janssen Date: Mon, 16 Nov 2026 16:02:29 +0100 Subject: [PATCH] Record preserved Linux helper followup and explicit journal capacity blocker --- deploy/linux_updater_compatible_apply.py | 110 +++++++-- deploy/updater_server_signing_bootstrap.py | 2 +- .../linux-updater-helper-followup-final.json | 212 ++++++++++++++++++ docs/linux-updater-compatible-controllers.md | 65 ++++++ 4 files changed, 372 insertions(+), 17 deletions(-) create mode 100644 docs/evidence/linux-updater-helper-followup-final.json diff --git a/deploy/linux_updater_compatible_apply.py b/deploy/linux_updater_compatible_apply.py index 7c80f3a..5454b59 100644 --- a/deploy/linux_updater_compatible_apply.py +++ b/deploy/linux_updater_compatible_apply.py @@ -19,8 +19,8 @@ import uuid import linux_updater_bootstrap as prerequisite import remote_client_bootstrap as transport ROOT=Path(__file__).resolve().parents[1] -BASE=ROOT/'devstate/linux-updater-capability-build/9923a97f-4c8c-4e0a-bbad-4f1d88f0d43a/manifest.json' -BASE_SHA='a41ad700b4b7527bf911bf00f2745914188760c631af0c3255364c05f1ef4fbc' +BASE=ROOT/'devstate/linux-updater-helper-start-build/d674db1c-ebca-48ed-b04c-8f7ec9e45ca1/manifest.json' +BASE_SHA='3520d0cfdda856b2c9c075197059047e47a24dab42270f4676416dd1ec5871cf' BOOT='45aba743-be1d-4ae5-ba00-139fb9363bfe' def sha(raw):return hashlib.sha256(raw).hexdigest() @@ -127,6 +127,13 @@ def pair(payload): def status(unit): fields={k:v for k,v in(line.split('=',1)for line in run(['systemctl','show','--all','--property=Id,ActiveState,SubState,MainPID,ControlPID,InvocationID,Job,ControlGroup,UnitFileState','--',unit]).splitlines())};require(fields['Id']==unit,'exact service');return fields units=['rmm-agent-remote.service','rmm-helper-cloud.service','rmm-full-maintenance-helper.service'] + def closed_service(unit,row): + empty=row['MainPID']=='0'and row['ControlPID']=='0'and not row['Job']and not row['ControlGroup'] + if row['ActiveState']=='inactive':return empty + if row['ActiveState']!='failed'or unit!=units[2]or manifest.get('followup_of_case_id')!='ac6cf439-e0a6-4323-82e1-c55df96b2441':return False + original=json.loads((Path('/var/lib/rmm-updater-bootstrap/ac6cf439-e0a6-4323-82e1-c55df96b2441')/'pair-started.json').read_text())['status'][unit] + failure=dict(line.split('=',1)for line in run(['systemctl','show','--property=Result,ExecMainCode,ExecMainStatus,NRestarts,Restart','--',unit]).splitlines()) + return empty and row['InvocationID']==original['InvocationID']and failure=={'Result':'exit-code','ExecMainCode':'1','ExecMainStatus':'1','NRestarts':'0','Restart':'no'} def databases(): result={} for path in ('/var/lib/rmm-agent-remote/journal.sqlite','/var/lib/rmm-agent-remote/consumption.sqlite','/var/lib/rmm-helper/consumption.sqlite'): @@ -155,29 +162,56 @@ def pair(payload): for name,entry in manifest['files'].items():require(sha((folder/name).read_bytes())==entry['sha256'],'staged artifact changed') for unit in ('rmm-apt-helper.service','rmm-agent.service','rmm-helper-dev-test.service'): s=status(unit);require(s['ActiveState']=='inactive'and s['MainPID']in('','0')and s['ControlPID']in('','0')and s['Job']==''and s['UnitFileState']in('','disabled'),'APT and legacy remain closed') - if payload['action']=='install': - require(not(folder/'pair-install-intent.json').exists(),'existing intent means readback, never repeat') + transitions=[('agent.bin','/usr/local/libexec/rmm-agent-remote',manifest['old_agent_sha256']),('helper.bin','/usr/local/libexec/rmm-privileged-helper',manifest['old_helper_sha256']),('full-config.json','/etc/rmm-remote/helper-full-maintenance.json',manifest['old_config_sha256']),('full-pin.json','/etc/rmm-remote/full-maintenance-helper-proof.json',manifest['old_pin_sha256'])] + followup=payload['action']in('install-followup','install-stopped-followup');continuing=payload['action']=='install-stopped-followup' + if payload['action']=='validate-staged': + result=subprocess.check_output([str(folder/'helper.bin'),'--inspect-full-maintenance-profile'],env={'RMM_HELPER_CONFIG':str(folder/'full-config.json'),'PATH':'/usr/bin:/bin'},stderr=subprocess.DEVNULL,timeout=20);pin=json.loads(result) + require(pin==json.loads((folder/'full-pin.json').read_text())and pin['helper_binary_sha256']==manifest['files']['helper.bin']['sha256'],'actual staged helper independently reproduces exact Full pin') + record('staged-profile-qualified.json',{'actual_helper_sha256':pin['helper_binary_sha256'],'actual_full_policy_sha256':pin['policy_sha256'],'profile_matches':True,'services_changed':False,'job_authority':False}) + return {'case_id':ident,'actual_native_staged_profile_matches':True,'full_policy_sha256':pin['policy_sha256'],'services_changed':False,'job_authority':False} + elif payload['action']in('install','install-followup','install-stopped-followup'): + if continuing:require(ident=='8fa5c0bd-b0ae-45ec-8cde-3d766d0576d4'and(folder/'pair-install-intent.json').is_file()and not(folder/'pair-followup-continue-intent.json').exists(),'exact known stopped pre-swap followup only') + else:require(not(folder/'pair-install-intent.json').exists(),'existing intent means readback, never repeat') fence=payload['central_fence'];require(fence['operation']=='linux_compatible_closed_scope_v1'and fence['open_jobs']==0 and not fence['job_authority']and fence['tenant_id']==manifest['tenant_id']and fence['agent_id']==manifest['agent_id'],'closed central scope') at=datetime.datetime.fromisoformat(fence['observed_at']);require(0<=(datetime.datetime.now(datetime.timezone.utc)-at).total_seconds()<30,'fresh closed-scope readback') before={u:status(u)for u in units};pids=[] + if followup: + require((folder/'staged-profile-qualified.json').is_file(),'actual native staged Full profile qualification required') + require(manifest.get('followup_of_case_id')=='ac6cf439-e0a6-4323-82e1-c55df96b2441'and manifest['files']['agent.bin']['sha256']==manifest['old_agent_sha256']=='7fef8d0f1e2bcf5cd6c373e567a0c17bfb08d8c780cd4d1925b6c1355e572547'and manifest['old_helper_sha256']=='8fdc6ded02278eb18e64003d0bc7bf45d452cd48ded0450e6e900ca66e44d449','exact known failed baseline followup only') + failure=dict(line.split('=',1)for line in run(['systemctl','show','--property=Result,ExecMainCode,ExecMainStatus,NRestarts,Restart','--',units[2]]).splitlines());require(failure=={'Result':'exit-code','ExecMainCode':'1','ExecMainStatus':'1','NRestarts':'0','Restart':'no'},'known original failed no-restart Full startup') + require(before[units[2]]['ActiveState']=='failed'and before[units[2]]['MainPID']=='0'and before[units[2]]['ControlPID']=='0'and not before[units[2]]['Job'],'closed original failed Full') + require(not Path('/etc/rmm-agent-updater/policy.json').exists()and not Path('/var/lib/rmm-agent-updater/installed-record.json').exists()and status('rmm-agent-updater.service')['ActiveState']=='inactive','no trust or update activity before compatible followup') + require(sha(Path('/usr/local/libexec/rmm-agent-remote').read_bytes())==manifest['old_agent_sha256'],'unchanged exact V2Agent');transitions=transitions[1:] for u,s in before.items(): + if continuing: + require(closed_service(u,s),'known fully closed original stop');continue + if followup and u==units[2]:continue require(s['ActiveState']=='active'and int(s['MainPID'])>1 and s['ControlPID']=='0'and s['Job']=='','exact active original pair') pid=int(s['MainPID']);fd=os.pidfd_open(pid);pids.append(fd) - original=databases();retained=retained_metadata() - for source,target,oldsha in [('agent.bin','/usr/local/libexec/rmm-agent-remote',manifest['old_agent_sha256']),('helper.bin','/usr/local/libexec/rmm-privileged-helper',manifest['old_helper_sha256']),('full-config.json','/etc/rmm-remote/helper-full-maintenance.json',manifest['old_config_sha256']),('full-pin.json','/etc/rmm-remote/full-maintenance-helper-proof.json',manifest['old_pin_sha256'])]: + if continuing: + original_intent=json.loads((folder/'pair-install-intent.json').read_text());require(original_intent['files']==manifest['files']and original_intent['known_full_failure']==failure,'exact original admission and known failure') + for u,s in before.items(): + old=original_intent['before'][u];require(old['InvocationID']==s['InvocationID']and(old['MainPID']=='0'or not Path('/proc/'+old['MainPID']).exists()),'original service invocation retained and original PID exited') + original=original_intent['databases'];retained=original_intent['retained'];require(retained_metadata()==retained,'original pre-stop identity PKI General metadata retained') + for source,target,oldsha in transitions: + path=Path(target);require(not(folder/(source+'-save-intent.json')).exists()and not(folder/(source+'-publish-intent.json')).exists()and not path.with_name(path.name+'.bootstrap-'+ident+'.previous').exists()and not path.with_name(path.name+'.bootstrap-'+ident+'.candidate').exists(),'zero original swap intents or renames, never resume ambiguous effects') + else:original=databases();retained=retained_metadata() + for source,target,oldsha in transitions: raw,_=public(target,256*1024*1024);require(sha(raw)==oldsha,'original target CAS') - record('pair-install-intent.json',{'before':before,'databases':original,'retained':retained,'central_fence':fence,'files':manifest['files']}) - run(['systemctl','stop','--',units[0],units[2],units[1]],30) + if continuing:record('pair-followup-continue-intent.json',{'before':before,'original_stop_sha256':sha((folder/'pair-install-intent.json').read_bytes()),'central_fence':fence,'stop_repeated':False,'job_authority':False}) + else: + record('pair-install-intent.json',{'before':before,'databases':original,'retained':retained,'central_fence':fence,'files':manifest['files'],'known_full_failure':failure if followup else None}) + run(['systemctl','stop','--',units[0],units[2],units[1]],30) for fd in pids: poll=select.poll();poll.register(fd,select.POLLIN);require(poll.poll(1000),'original process not exited');os.close(fd) for u in units: - s=status(u);require(s['ActiveState']=='inactive'and s['MainPID']=='0'and s['ControlPID']=='0'and not s['Job']and not s['ControlGroup'],'all original processes stopped') + s=status(u);require(closed_service(u,s),'all original processes stopped or exact preserved original Full failure') with contextlib.ExitStack()as held: for path in ('/var/lib/rmm-agent-remote/agent.lock','/var/lib/rmm-helper/executor.lock'): f=held.enter_context(open(path,'rb'));fcntl.flock(f,fcntl.LOCK_EX|fcntl.LOCK_NB) closed=databases() require(all(closed[p]['file_id']==v['file_id']and closed[p]['evidence_sha256']==v['evidence_sha256']for p,v in original.items()),'original effect history changed during stop') - for source,target,oldsha in [('agent.bin','/usr/local/libexec/rmm-agent-remote',manifest['old_agent_sha256']),('helper.bin','/usr/local/libexec/rmm-privileged-helper',manifest['old_helper_sha256']),('full-config.json','/etc/rmm-remote/helper-full-maintenance.json',manifest['old_config_sha256']),('full-pin.json','/etc/rmm-remote/full-maintenance-helper-proof.json',manifest['old_pin_sha256'])]: + for source,target,oldsha in transitions: target=Path(target);old,meta=public(target,256*1024*1024);require(sha(old)==oldsha,'stopped target CAS') previous=target.with_name(target.name+'.bootstrap-'+ident+'.previous');candidate=target.with_name(target.name+'.bootstrap-'+ident+'.candidate');require(not previous.exists()and not candidate.exists(),'create-once bootstrap names') fd=os.open(candidate,os.O_WRONLY|os.O_CREAT|os.O_EXCL|os.O_NOFOLLOW,stat.S_IMODE(meta.st_mode)) @@ -216,14 +250,54 @@ def pair(payload): updater=status('rmm-agent-updater.service');require(updater['ActiveState']=='inactive'and updater['MainPID']=='0'and updater['ControlPID']=='0'and not updater['Job']and updater['UnitFileState']=='disabled','updater remains stopped and disabled') record('units-installed.json',{'updater':updater,'restart_override_sha256':sha(override.read_bytes()),'namespace_provisioned':True,'updater_started':False}) return {'case_id':ident,'updater_unit_installed_not_started':True,'full_restart_no_bound':True,'job_authority':False} + elif payload['action']=='adopt-units': + require(manifest.get('followup_of_case_id')=='ac6cf439-e0a6-4323-82e1-c55df96b2441'and(folder/'pair-installed.json').is_file(),'exact known baseline followup') + require(not(folder/'units-installed.json').exists(),'create-only adopted unit receipt') + require(sha(Path('/usr/local/libexec/rmm-agent-updater').read_bytes())==manifest['files']['updater.bin']['sha256']and Path('/etc/systemd/system/rmm-agent-updater.service').read_bytes()==(folder/'updater.service').read_bytes(),'exact previously installed stable updater unit and bytes') + require(Path('/etc/systemd/system/rmm-full-maintenance-helper.service.d/99-rmm-update-closed-start.conf').read_bytes()==b'[Service]\nRestart=no\n'and run(['systemctl','show','--value','--property=Restart','--',units[2]])=='no','original closed restart override') + for u in units+['rmm-agent-updater.service']: + s=status(u);require(closed_service(u,s),'all project roles remain closed before followup start') + record('units-installed.json',{'adopted_unchanged_from':manifest['followup_of_case_id'],'updater_started':False,'job_authority':False}) + return {'case_id':ident,'existing_units_adopted_unchanged':True,'updater_started':False,'job_authority':False} elif payload['action']=='start': installed=json.loads((folder/'pair-installed.json').read_text());require((folder/'units-installed.json').is_file(),'separate reviewed unit setup required');require(not(folder/'pair-start-intent.json').exists(),'existing start means readback only') require(retained_metadata()==installed['retained'],'original metadata changed') for u in units: - s=status(u);require(s['ActiveState']=='inactive'and s['MainPID']=='0'and s['ControlPID']=='0'and not s['Job'],'pair remains stopped') + s=status(u);require(closed_service(u,s),'pair remains stopped or original known Full failure preserved') record('pair-start-intent.json',{'units':[units[1],units[2],units[0]],'only_once':True}) for u in (units[1],units[2],units[0]): record(u+'-start-intent.json',{'unit':u});run(['systemctl','start','--',u],20);s=status(u);require(s['ActiveState']=='active'and int(s['MainPID'])>1,'single compatible start') + if u==units[1]: + # A real nonmutating Policy nonce as the provisioned UID proves General + # finished initialization before Full is started. No snapshot/apply/job. + import socket,struct + pin=json.loads(Path('/etc/rmm-remote/general-helper-proof.json').read_text());challenge=str(uuid.uuid4());request={'operation':'general_policy_v1','challenge':challenge,'identity':pin['identity']};wire=json.dumps(request,separators=(',',':')).encode();expected_pid=int(s['MainPID']);ledger_id=identity('/var/lib/rmm-helper/consumption.sqlite');lock_id=identity('/var/lib/rmm-helper/executor.lock') + read_fd,write_fd=os.pipe();child=os.fork() + if child==0: + os.close(read_fd) + try: + os.setgroups([]);os.setgid(984);os.setuid(993);deadline=time.monotonic()+10;answer=None + while time.monotonic()