feat: deploy platform inventory and signed APT retry client compatibility
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -25,6 +25,39 @@ STATE = cloud.ROOT / 'devstate/cloud-apt-retry'
|
||||
CASES = ('apt_install_retry', 'apt_native_update', 'ensure_package', 'apply_updates')
|
||||
|
||||
|
||||
def upgrade_agent(payload):
|
||||
"""Parser compatibility upgrade only; same identity/journal, no execution."""
|
||||
import sqlite3
|
||||
os.umask(0o077)
|
||||
state = Path('/var/lib/rmm-agent-remote'); binary = Path('/usr/local/libexec/rmm-agent-remote')
|
||||
require(not binary.is_symlink() and binary.stat().st_uid == 0 and binary.stat().st_mode&0o022 == 0 and
|
||||
hashlib.sha256(binary.read_bytes()).hexdigest() == payload['previous_sha256'], 'reviewed prior agent required')
|
||||
require(json.loads((state/'identity.json').read_text())['agent_id'] == payload['agent_id'], 'fixed identity required')
|
||||
with sqlite3.connect((state/'journal.sqlite').as_uri()+'?mode=ro', uri=True) as db:
|
||||
require(db.execute('PRAGMA integrity_check').fetchone()[0] == 'ok' and
|
||||
db.execute("SELECT count(*) FROM job_attempts WHERE state NOT IN ('succeeded','failed','cancelled','expired')").fetchone()[0] == 0,
|
||||
'unresolved native job')
|
||||
backup = Path('/var/lib/rmm-bootstrap-history')/('cloud-agent-schema3-'+payload['id']); backup.mkdir(mode=0o700)
|
||||
raw = base64.b64decode(payload['binary'], validate=True)
|
||||
require(hashlib.sha256(raw).hexdigest() == payload['sha256'] and raw[:6] == b'\x7fELF\x02\x01' and raw[18:20] == b'\x3e\x00', 'reviewed x64 artifact')
|
||||
staged = backup/'agent-next'
|
||||
with staged.open('xb') as f: f.write(raw); f.flush(); os.fsync(f.fileno()); os.fchmod(f.fileno(), 0o755)
|
||||
subprocess.run(['/lib64/ld-linux-x86-64.so.2','--list',str(staged)], capture_output=True, check=True, timeout=15)
|
||||
subprocess.run(['systemctl','stop','rmm-agent-remote.service'], capture_output=True, check=True, timeout=20)
|
||||
def manifest():
|
||||
result = {}
|
||||
for p in state.rglob('*'):
|
||||
require(not p.is_symlink(), 'agent state symlink')
|
||||
if p.is_file(): result[str(p.relative_to(state))] = hashlib.sha256(p.read_bytes()).hexdigest()
|
||||
return result
|
||||
before = manifest()
|
||||
require(binary.stat().st_dev == backup.stat().st_dev, 'same-filesystem preserved binary')
|
||||
os.rename(binary, backup/'previous-agent'); os.rename(staged, binary)
|
||||
require(before == manifest(), 'identity/journal bytes changed during upgrade')
|
||||
subprocess.run(['systemctl','start','rmm-agent-remote.service'], capture_output=True, check=True, timeout=20)
|
||||
return dict(binary_sha256=payload['sha256'], state_preserved_before_start=True, package_effects=False, backup=str(backup))
|
||||
|
||||
|
||||
def switch_endpoint(payload):
|
||||
import sqlite3
|
||||
os.umask(0o077)
|
||||
|
||||
Reference in New Issue
Block a user