fix: disable stopped historical helper autostart before final VM reboot
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -227,3 +227,64 @@ def enable_general_autostart(payload):
|
||||
and retained() == original, 'enable only: same PIDs, boot, database inodes and Root consumption rows')
|
||||
return dict(report,applied=True,preflight=False,services_after=after,general_autostart_enabled=True,
|
||||
link_target=str(unit),state_preserved=True)
|
||||
|
||||
|
||||
def legacy_helper_unit_metadata(payload):
|
||||
import stat
|
||||
p=Path('/etc/systemd/system/rmm-helper-dev-test.service');s=p.lstat()
|
||||
require(stat.S_ISREG(s.st_mode) and s.st_uid==0 and not s.st_mode&0o022 and s.st_size<=16384,'owned historical unit')
|
||||
raw=p.read_bytes();lines=[line.strip() for line in raw.decode().splitlines()]
|
||||
commands=[line for line in lines if line.startswith('ExecStart=')]
|
||||
shared='StateDirectory=rmm-helper' in lines
|
||||
exact=commands==['ExecStart=/usr/local/libexec/rmm-privileged-helper']
|
||||
require(exact and shared,'known historical helper sharing current Root state')
|
||||
return dict(unit_sha256=hashlib.sha256(raw).hexdigest(),root_owned=True,
|
||||
fixed_helper_binary=exact,shared_root_state=shared,
|
||||
clock_query_filters=[line for line in lines if line in ('SystemCallFilter=adjtimex clock_adjtime','SystemCallFilter=adjtimex')])
|
||||
|
||||
|
||||
def disable_legacy_helper_autostart(payload):
|
||||
"""Disable only the stopped historical dev helper; never stop/start a unit."""
|
||||
import contextlib
|
||||
import sqlite3
|
||||
import stat
|
||||
require(os.geteuid()==0,'root bootstrap required')
|
||||
unit=Path('/etc/systemd/system/rmm-helper-dev-test.service')
|
||||
s=unit.lstat()
|
||||
require(stat.S_ISREG(s.st_mode) and s.st_uid==0 and not s.st_mode&0o022
|
||||
and hashlib.sha256(unit.read_bytes()).hexdigest()==payload['unit_sha256'],
|
||||
'exact owned historical helper unit')
|
||||
state=Path('/var/lib/rmm-agent-remote')
|
||||
require(json.loads((state/'identity.json').read_text())['agent_id']==payload['agent_id'],
|
||||
'permanent Cloud identity')
|
||||
def inspect():
|
||||
services={}
|
||||
for name in ('rmm-helper-dev-test.service','rmm-agent-remote.service','rmm-helper-cloud.service','rmm-apt-helper.service'):
|
||||
raw=subprocess.run(['systemctl','show',name,'-p','ActiveState','-p','MainPID','-p','UnitFileState'],capture_output=True,check=True,timeout=10).stdout.decode()
|
||||
services[name]=dict(line.split('=',1) for line in raw.splitlines())
|
||||
result=dict(services=services,boot_id=Path('/proc/sys/kernel/random/boot_id').read_text().strip(),inodes={})
|
||||
for path in (state/'journal.sqlite',state/'consumption.sqlite',Path('/var/lib/rmm-helper/consumption.sqlite')):
|
||||
m=path.stat();result['inodes'][str(path)]=[m.st_dev,m.st_ino]
|
||||
with contextlib.closing(sqlite3.connect(path.as_uri()+'?mode=ro',uri=True)) as db:
|
||||
require(db.execute('PRAGMA integrity_check').fetchone()[0]=='ok','preserved journal integrity')
|
||||
if path==state/'journal.sqlite':
|
||||
require(db.execute("SELECT count(*) FROM job_attempts WHERE state NOT IN ('succeeded','failed','cancelled','expired')").fetchone()[0]==0,'no active job during bootstrap')
|
||||
else:require(db.execute('SELECT count(*) FROM consumed WHERE result IS NULL').fetchone()[0]==0,'no unresolved consumption')
|
||||
if path.parent==Path('/var/lib/rmm-helper'):
|
||||
rows=db.execute('SELECT c.grant_id,c.result,e.start,e.outcome FROM consumed c JOIN execution_evidence e USING(grant_id) ORDER BY c.grant_id').fetchall()
|
||||
result['root_rows_sha256']=hashlib.sha256(json.dumps([[hashlib.sha256(v).hexdigest() if isinstance(v,bytes) else v for v in row] for row in rows],separators=(',',':')).encode()).hexdigest()
|
||||
return result
|
||||
before=inspect();old=before['services']['rmm-helper-dev-test.service']
|
||||
require(old['ActiveState']=='inactive' and old['MainPID']=='0' and old['UnitFileState']=='enabled','only stopped enabled legacy helper')
|
||||
require(all(before['services'][n]['ActiveState']=='active' and before['services'][n]['UnitFileState']=='enabled'
|
||||
for n in ('rmm-agent-remote.service','rmm-helper-cloud.service'))
|
||||
and before['services']['rmm-apt-helper.service']['ActiveState']=='inactive','current services already correct')
|
||||
subprocess.run(['systemctl','disable','rmm-helper-dev-test.service'],capture_output=True,check=True,timeout=15)
|
||||
after=inspect()
|
||||
require(after['services']['rmm-helper-dev-test.service']['UnitFileState']=='disabled'
|
||||
and all(after['services'][n]['MainPID']==v['MainPID'] and after['services'][n]['ActiveState']==v['ActiveState']
|
||||
for n,v in before['services'].items())
|
||||
and all(after[k]==before[k] for k in ('boot_id','inodes','root_rows_sha256'))
|
||||
and hashlib.sha256(unit.read_bytes()).hexdigest()==payload['unit_sha256'],'disable only, original state preserved')
|
||||
return dict(verified=True,before=before,after=after,jobs_created=False,service_restarted=False,
|
||||
reboot_requested=False,legacy_autostart_disabled=True)
|
||||
|
||||
@@ -32,7 +32,8 @@ def vm_state(payload):
|
||||
require(not path.is_symlink() and hashlib.sha256(path.read_bytes()).hexdigest()==payload[key],'qualified current binaries')
|
||||
require(hashlib.sha256(Path('/etc/systemd/system/rmm-helper-cloud.service').read_bytes()).hexdigest()==payload['general_unit_sha256'],'reviewed General D-Bus service profile with direct reboot syscalls denied')
|
||||
services={}
|
||||
for unit in ('rmm-agent-remote.service','rmm-helper-cloud.service','rmm-apt-helper.service'):
|
||||
for unit in ('rmm-agent-remote.service','rmm-helper-cloud.service','rmm-apt-helper.service',
|
||||
'rmm-agent.service','rmm-helper-dev-test.service'):
|
||||
raw=subprocess.run(['systemctl','show',unit,'-p','ActiveState','-p','MainPID','-p','UnitFileState'],capture_output=True,check=True,timeout=10).stdout.decode()
|
||||
services[unit]=dict(line.split('=',1) for line in raw.splitlines())
|
||||
dropin=Path('/etc/systemd/system/rmm-agent-remote.service.d/30-cloud-root.conf')
|
||||
|
||||
Reference in New Issue
Block a user