feat: accept native Windows passive client and tenant-safe inventory migration
Rust development slice / linux (push) Failing after 6s

This commit is contained in:
2026-11-13 16:18:04 +01:00
parent a430de7bf0
commit d38d93d284
13 changed files with 418 additions and 47 deletions
+33 -2
View File
@@ -84,6 +84,12 @@ def deploy(payload):
require(json.loads((backup/'build-result.json').read_text())['exit_code'] == 0, 'build must pass')
require(all(hashlib.sha256((root/name).read_bytes()).hexdigest() == sha for name,sha in record['files'].items()), 'source drift')
require(not (backup/'deploy-result.json').exists(), 'deployment already recorded')
if payload.get('closed_policy_sha256'):
import datetime as dt
policy = (root/'devstate/root-policy/policy.json').read_bytes()
require(hashlib.sha256(policy).hexdigest() == payload['closed_policy_sha256'] and
dt.datetime.fromisoformat(json.loads(policy)['expires_at']) < dt.datetime.now(dt.timezone.utc),
'known unknown requires closed root policy')
raw = base64.b64decode(payload['web_tar'], validate=True)
require(hashlib.sha256(raw).hexdigest() == payload['web_sha256'], 'reviewed web archive hash')
# Publish immutable hashed assets before index, keeping the bind-mounted
@@ -118,6 +124,7 @@ def deploy(payload):
def main():
parser = argparse.ArgumentParser(description=__doc__); parser.add_argument('action', choices=('stage','status','deploy')); parser.add_argument('--id')
parser.add_argument('--preserve-known-unknown', action='store_true', help='Windows inventory migration only; preserve exact fenced APT evidence')
args = parser.parse_args(); os.umask(0o077); STATE.mkdir(mode=0o700, parents=True, exist_ok=True)
if args.action == 'stage':
names = ['Cargo.toml','Cargo.lock','rust-toolchain.toml','deploy/Dockerfile','deploy/linux/rmm-apt-helper.service',
@@ -135,11 +142,26 @@ def main():
print(dict(id=ident, launched=result['launched'], deployed=False))
else:
ident = str(uuid.UUID(args.id)); cloud.contract.protected_json(STATE/(ident+'.json'))
before = None; payload = dict(id=ident)
if args.action == 'deploy':
target = cloud.contract.protected_json(cloud.ROOT/'devstate/remote-vm.json')['identity']
gate = cloud.bootstrap.rpc('server.conf', cloud.server, dict(kind='gate', tenant_id=cloud.TENANT, agent_id=target['agent_id']))
require(gate['unresolved'] == 0, 'unresolved cloud job; no server switch')
payload = dict(id=ident)
if args.preserve_known_unknown:
import cloud_apt_retry as apt
checkpoint = cloud.contract.protected_json(apt.STATE/'apt_install_retry/checkpoint.json')
job = checkpoint['plan']['jobs'][0]
require(checkpoint['stage'] == 'unknown' and checkpoint['audit']['simulation'] is True and
gate == dict(jobs=13, outbox=13, permits=12, unresolved=1), 'one exact known unknown required')
current = cloud.Backend().call('jobs.get', dict(tenant_id=cloud.TENANT, job_id=job['job_id']))
require(current['state'] == 'unknown' and current['attempt_id'] == job['attempt_id'], 'same unknown attempt required')
before = cloud.bootstrap.rpc('linux-vm.conf', apt.stored_attempt_evidence,
dict(job_id=job['job_id'], attempt_id=job['attempt_id']))
require(before['ledger']['unresolved'] == 1 and before['ledger']['consumed'] == 9 and
before['ledger']['result'] is None and before['ledger']['outcome']['error_code'] == 'DPKG_INCONSISTENT', 'preserve exact native unknown')
closed = cloud.contract.protected_json(apt.STATE/'policy-closed.json')
payload['closed_policy_sha256'] = closed['policy_sha256']
require((cloud.ROOT/'migrations/0013_windows_inventory_scope.sql').is_file(), 'additive Windows migration only')
else: require(gate['unresolved'] == 0, 'unresolved cloud job; no server switch')
if args.action == 'deploy':
stream = io.BytesIO()
with tarfile.open(fileobj=stream, mode='w:') as archive:
@@ -149,6 +171,15 @@ def main():
archive.add(p, arcname=str(p.relative_to(cloud.ROOT/'web/dist')), recursive=False)
data = stream.getvalue(); payload.update(web_tar=base64.b64encode(data).decode(), web_sha256=hashlib.sha256(data).hexdigest())
result = cloud.bootstrap.rpc('server.conf', status if args.action == 'status' else deploy, payload)
if before is not None:
after = cloud.bootstrap.rpc('linux-vm.conf', apt.stored_attempt_evidence,
dict(job_id=job['job_id'], attempt_id=job['attempt_id']))
gate_after = cloud.bootstrap.rpc('server.conf', cloud.server, dict(kind='gate', tenant_id=cloud.TENANT, agent_id=target['agent_id']))
current = cloud.Backend().call('jobs.get', dict(tenant_id=cloud.TENANT, job_id=job['job_id']))
require(before == after and gate_after == gate and current['state'] == 'unknown' and current['attempt_id'] == job['attempt_id'],
'unknown evidence or execution artifacts changed during Windows migration')
cloud.contract.write_private(STATE/(ident+'.unknown-preserved.json'), dict(evidence=after, gate=gate_after, result=current))
result['unknown_attempt_preserved'] = True
print(result)