Publish independently verified bootstrap workers and record native Windows update recovery

This commit is contained in:
2026-11-17 16:47:31 +01:00
parent ee1ae24d0c
commit beb3485838
7 changed files with 228 additions and 32 deletions
+24 -12
View File
@@ -67,7 +67,7 @@ def verify_native_image(path, target, size):
'Windows x86-64 PE32+ image required: ' + path.name)
def binaries(folder, receipt):
def binaries(folder, receipt, worker_only=False):
record = json.loads(receipt.read_text(encoding='utf-8-sig'))
if 'target' in record and 'sha256' in record:
target, hashes = record['target'], record['sha256']
@@ -75,11 +75,12 @@ def binaries(folder, receipt):
check(record.get('completed') is True and record['stage'] == 'built_not_deployed', 'completed MSVC receipt required')
target = WINDOWS
entries = record['artifacts']
check(all(entries[name[:-4]]['build_target'] == target for name in FILES[target]), 'incorrect build target')
hashes = {name: entries[name[:-4]]['sha256'] for name in FILES[target]}
names = FILES[target][2:] if worker_only else FILES[target]
check(all(entries[name[:-4]]['build_target'] == target for name in names), 'incorrect build target')
hashes = {name: entries[name[:-4]]['sha256'] for name in names}
check(target in FILES, 'unknown release target')
result = []
for name in FILES[target]:
for name in FILES[target][2:] if worker_only else FILES[target]:
path = folder / name
digest, size = fingerprint(path)
verify_native_image(path, target, size)
@@ -274,11 +275,16 @@ def rotate_pin(state, label, tenant, expected, new_pin):
def publish(args):
platform, blobs = binaries(args.artifacts, args.build_receipt)
env = json.loads(args.envelope.read_bytes())
manifest = json.loads(base64.urlsafe_b64decode(env['payload_bytes'] + '==='))
check(manifest['platform'] == platform and manifest['artifacts'] == [dict(role=role, **blob)
for role, blob in zip(('agent', 'helper'), blobs[:2])], 'input files differ from release envelope')
worker_only = args.rotate_worker_only
platform, blobs = binaries(args.artifacts, args.build_receipt, worker_only)
if worker_only:
check(args.envelope is None and args.rotate_bootstrap_from, 'worker rotation requires a predecessor and no release envelope')
else:
check(args.envelope is not None, 'a release envelope is required')
env = json.loads(args.envelope.read_bytes())
manifest = json.loads(base64.urlsafe_b64decode(env['payload_bytes'] + '==='))
check(manifest['platform'] == platform and manifest['artifacts'] == [dict(role=role, **blob)
for role, blob in zip(('agent', 'helper'), blobs[:2])], 'input files differ from release envelope')
check(bool(args.rotate_bootstrap_from) == bool(args.bootstrap_state), 'rotation needs previous SHA and local signing state')
check(not (args.rotate_bootstrap_from and args.bootstrap_worker), 'a rotation uses the new receipt-bound stable worker')
client = Publisher(args.origin, args.ca)
@@ -296,7 +302,8 @@ def publish(args):
tenant = str(uuid.UUID(args.tenant))
check(session['tenant_id'] == tenant and 'catalog:write' in session['permissions'], 'tenant catalog write permission required')
path = '/api/v1/tenants/' + tenant
paths = [args.artifacts / name for name in FILES[platform]]
names = FILES[platform][2:] if worker_only else FILES[platform]
paths = [args.artifacts / name for name in names]
if args.bootstrap_worker:
paths[2] = args.bootstrap_worker
sha, size = fingerprint(paths[2])
@@ -311,10 +318,14 @@ def publish(args):
{'Content-Type': 'application/octet-stream', 'Content-Length': str(blob['bytes'])})
check(result['sha256'] == blob['sha256'] and result['size_bytes'] == blob['bytes'], 'artifact receipt differs')
if args.rotate_bootstrap_from:
stable = blobs[2]
stable = blobs[-1]
label = {LINUX:'linux', WINDOWS:'windows', WINDOWS_GNU:'windows-gnu'}[platform]
rotate_pin(args.bootstrap_state,label,tenant,args.rotate_bootstrap_from,
{'sha256':stable['sha256'],'bytes':stable['bytes']})
if worker_only:
print(json.dumps({'tenant_id':tenant,'platform':platform,'updater_sha256':stable['sha256'],
'updater_bytes':stable['bytes']}))
return
result = client.request('POST', path + '/agent-releases', encoded(env), {'Content-Type': 'application/json'})
check(result['release_envelope'] == env, 'published envelope changed')
print(json.dumps({'release_id': result['release_id'], 'version': manifest['version'], 'platform': platform,
@@ -346,7 +357,8 @@ def main():
cmd.add_argument('--bootstrap-worker', type=Path, help='Pinned initial stable updater when publishing subsequent code pairs')
cmd.add_argument('--ca', type=Path)
cmd.add_argument('--tenant', required=True)
cmd.add_argument('--envelope', type=Path, required=True)
cmd.add_argument('--envelope', type=Path, help='Prepared agent and helper release')
cmd.add_argument('--rotate-worker-only', action='store_true', help='Rotate the stable worker independently of a code-pair release')
auth = cmd.add_mutually_exclusive_group(required=True)
auth.add_argument('--dev-username')
auth.add_argument('--dev-login-file', type=Path)
+30 -13
View File
@@ -29,7 +29,10 @@ def on_server(options):
tool = stage / options['tool'] / 'agent_release.py'
if hashlib.sha256(tool.read_bytes()).hexdigest() != options['tool']:
raise ValueError('staged release tool differs')
build = state / 'builds' / options['label'] / str(options['sequence'])
if options['worker_only']:
build = state / 'worker-builds' / options['label'] / options['worker_sha']
else:
build = state / 'builds' / options['label'] / str(options['sequence'])
build.mkdir(parents=True, exist_ok=True)
for name, digest in options['files'].items():
source = stage / digest / name
@@ -47,11 +50,12 @@ def on_server(options):
finally:
os.unlink(tmp.name)
if hashlib.sha256(dest.read_bytes()).hexdigest() != digest:
raise ValueError('sequence already contains different build: ' + name)
raise ValueError('staged slot already contains different build: ' + name)
inputs = ['--artifacts', str(build), '--build-receipt', str(build / options['receipt'])]
subprocess.run(['python3', '-I', str(tool), 'prepare', *inputs, '--state', str(state), '--gateway', options['gateway'],
'--service-uid','10001','--minimum-updater-version',str(options['minimum']),'--sequence',str(options['sequence']),'--version',options['version']],check=True)
if options['label'].startswith('windows'):
if not options['worker_only']:
subprocess.run(['python3', '-I', str(tool), 'prepare', *inputs, '--state', str(state), '--gateway', options['gateway'],
'--service-uid','10001','--minimum-updater-version',str(options['minimum']),'--sequence',str(options['sequence']),'--version',options['version']],check=True)
if not options['worker_only'] and options['label'].startswith('windows'):
import re
import uuid
public = Path('/etc/rmm-time-source/time-public-key.json')
@@ -98,12 +102,17 @@ def on_server(options):
if options['rotate']:
selection=['--rotate-bootstrap-from',options['rotate'],'--bootstrap-state',str(state)]
elif pin.is_file():
sha=json.loads(pin.read_bytes())['current']['sha256']
selection=['--bootstrap-worker',str(state/'objects'/tenant/sha)]
current=json.loads(pin.read_bytes())['current']
sha=current['sha256']
active_worker=state/'objects'/tenant/sha
if active_worker.stat().st_size != current['bytes'] or hashlib.sha256(active_worker.read_bytes()).hexdigest() != sha:
raise ValueError('current tenant bootstrap worker differs from protected pin')
selection=['--bootstrap-worker',str(active_worker)]
else:
selection=['--bootstrap-worker',str(state/'bootstrap-workers'/label)]
subprocess.run(['python3','-I',str(tool),'publish',*inputs,'--tenant',options['tenant'],
'--envelope',str(state/'prepared'/options['label']/str(options['sequence'])/'envelope.json'),
operation = ['--rotate-worker-only'] if options['worker_only'] else [
'--envelope',str(state/'prepared'/options['label']/str(options['sequence'])/'envelope.json')]
subprocess.run(['python3','-I',str(tool),'publish',*inputs,'--tenant',options['tenant'],*operation,
'--origin','https://localhost:18443','--ca','/opt/rust-discovery/devstate/api-pki/ca.pem',
'--dev-login-file',auth.name,*selection],check=True)
@@ -112,21 +121,29 @@ def main():
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--artifacts',type=Path,required=True)
parser.add_argument('--build-receipt',type=Path,required=True)
parser.add_argument('--sequence',type=int,required=True)
parser.add_argument('--version',required=True)
parser.add_argument('--sequence',type=int)
parser.add_argument('--version')
parser.add_argument('--minimum-updater-version',type=int,default=1)
parser.add_argument('--rotate-bootstrap-from',help='Rotate only this tenant from the given previous worker SHA-256')
parser.add_argument('--rotate-worker-only',action='store_true',help='Publish just the stable worker from its build receipt and rotate its tenant pin')
parser.add_argument('--gateway',default='https://discovery.ease-technologies.de')
parser.add_argument('--tenant',default='11111111-1111-4111-8111-111111111111')
parser.add_argument('--prepare-only',action='store_true')
args=parser.parse_args()
platform, _ = agent_release.binaries(args.artifacts,args.build_receipt)
files=[*(args.artifacts/name for name in agent_release.FILES[platform]),args.build_receipt]
if args.rotate_worker_only:
if not args.rotate_bootstrap_from or args.prepare_only or args.sequence is not None or args.version is not None:
parser.error('worker-only requires --rotate-bootstrap-from and accepts no prepare, sequence, or version')
elif args.sequence is None or args.version is None:
parser.error('a release requires --sequence and --version')
platform, descriptors = agent_release.binaries(args.artifacts,args.build_receipt,args.rotate_worker_only)
names = agent_release.FILES[platform][2:] if args.rotate_worker_only else agent_release.FILES[platform]
files=[*(args.artifacts/name for name in names),args.build_receipt]
tool=Path(agent_release.__file__).resolve()
if args.build_receipt.name in agent_release.FILES[platform]:
raise ValueError('build receipt and binary names must differ')
params={'files':{f.name:hashlib.sha256(f.read_bytes()).hexdigest() for f in files},'tool':hashlib.sha256(tool.read_bytes()).hexdigest(),
'receipt':args.build_receipt.name,'sequence':args.sequence,'version':args.version,'tenant':args.tenant,
'worker_only':args.rotate_worker_only,'worker_sha':descriptors[-1]['sha256'],
'minimum':args.minimum_updater_version,'rotate':args.rotate_bootstrap_from,'gateway':args.gateway,'prepare_only':args.prepare_only,'label':{agent_release.LINUX:'linux',
agent_release.WINDOWS:'windows',agent_release.WINDOWS_GNU:'windows-gnu'}[platform]}
subprocess.run([sys.executable,str(ROOT/'tools/dev_stage.py'),'server',*map(str,files),str(tool)],check=True)