"""Preserved witnesses of the one already approved configure-only attempt.""" def maintenance_status(payload): root=Path('/var/lib/rmm-bootstrap-history') reports=[] for folder in sorted(root.glob('cloud-configured-reconcile-*')): require(not folder.is_symlink() and folder.stat().st_uid==0,'known private maintenance directory') path=folder/'report.json' if path.exists(): require(not path.is_symlink() and path.stat().st_size<=1024*1024,'bounded maintenance report') reports.append(dict(path=str(path),report=json.loads(path.read_text()))) require(len(reports)<=3,'bounded configured maintenance reports') states={} for unit in ('rmm-agent-remote.service','rmm-helper-cloud.service','rmm-apt-helper.service'): raw=subprocess.run(['systemctl','show',unit,'-p','ActiveState','-p','SubState','-p','MainPID'],capture_output=True,check=True,timeout=10).stdout.decode() states[unit]=dict(line.split('=',1) for line in raw.splitlines()) hashes={name:hashlib.sha256(Path(path).read_bytes()).hexdigest() for name,path in ( ('agent','/usr/local/libexec/rmm-agent-remote'),('helper','/usr/local/libexec/rmm-privileged-helper'), ('provider','/usr/lib/rmm-apt-transaction/apt_transaction.py'))} return dict(reports=reports,services=states,installed_sha256=hashes) def stored_configured(payload): import stat base=Path('/var/lib/rmm-apt-transaction');active=base/'active' context=json.loads((active/'context.json').read_text()) require(all(context[k]==str(uuid.UUID(payload[k])) for k in ('job_id','attempt_id','grant_id')),'same already approved configure attempt') require(context['grant_id']=='33775478-15b0-46ec-b059-44f500dbb0b6','one preserved configure attempt') def witness(path): require(not path.is_symlink(),'witness symlink') if not path.exists():return dict(exists=False) s=path.stat();require(stat.S_ISREG(s.st_mode) and s.st_uid==0 and s.st_size<=1024*1024,'bounded original root file') return dict(exists=True,sha256=hashlib.sha256(path.read_bytes()).hexdigest(),size=s.st_size, inode=s.st_ino,mtime_ns=s.st_mtime_ns,ctime_ns=s.st_ctime_ns) names=('context.json','signed-action.json','expectation.json','baseline.json','partial-proof.json', 'hook-armed.json','sandbox-result.json','native-prechecks.json','sandbox-ready.json','launch.json') files={name:witness(active/name) for name in names} original='31ef5e5e-5dbd-4428-a9a1-cbd15de2f5a0' for name in ('recovery-attempt-'+original+'.json','recovery-'+original+'.json','pending-recovery-'+original+'.json', 'bootstrap-attempt-rmm-apt-fixture-install-1.0.json','bootstrap-retry-rmm-apt-fixture-install-1.0.json'): files[name]=witness(base/name) return dict(files=files,marker_current=witness(Path('/run/reboot-required')), same_boot=Path('/proc/sys/kernel/random/boot_id').read_text().strip()==context['boot_id'], marker_observation_phase='after_original_effect_only',original_state_changed=False)