fix: identify APT local-file handoff failure and verify Windows admin tunnel
Rust development slice / linux (push) Failing after 6s
Rust development slice / linux (push) Failing after 6s
This commit is contained in:
@@ -111,8 +111,29 @@ def add_expiry_cleanup(payload):
|
||||
return dict(expiry_cleanup_armed=True,expires_at=config['expires_at'])
|
||||
|
||||
|
||||
def add_repair(payload):
|
||||
script=Path('/usr/local/libexec/rmm-bootstrap-public.py');config_path=Path('/etc/rmm-bootstrap-download.json')
|
||||
require(not script.is_symlink() and script.stat().st_uid==0 and hashlib.sha256(script.read_bytes()).hexdigest()==payload['previous_code_sha256'],'public server code drift')
|
||||
config=json.loads(config_path.read_text());require('public_files' not in config,'existing additional publication retained')
|
||||
raw=base64.b64decode(payload['bundle'],validate=True)
|
||||
require(len(raw)<262144 and hashlib.sha256(raw).hexdigest()==payload['sha256'],'repair bundle mismatch')
|
||||
root=Path('/opt/rmm-bootstrap-download')
|
||||
def create(p,data,mode):
|
||||
fd=os.open(p,os.O_CREAT|os.O_EXCL|os.O_WRONLY|os.O_NOFOLLOW,mode)
|
||||
with os.fdopen(fd,'wb') as f:f.write(data);f.flush();os.fsync(f.fileno());os.fchmod(f.fileno(),mode)
|
||||
create(root/'public-server-before-repair.py',script.read_bytes(),0o600)
|
||||
create(root/'public-config-before-repair.json',config_path.read_bytes(),0o600)
|
||||
create(Path('/srv/rmm-bootstrap-download/windows-dev-repair.zip'),raw,0o644)
|
||||
url_path=config['url_path'].rsplit('/',1)[0]+'/windows-dev-repair.zip'
|
||||
config['public_files']={config['url_path']:'windows-dev-access.zip',url_path:'windows-dev-repair.zip'}
|
||||
next_config=config_path.with_suffix('.repair-next');create(next_config,json.dumps(config).encode(),0o644);os.replace(next_config,config_path)
|
||||
next_script=script.with_suffix('.repair-next');create(next_script,base64.b64decode(payload['code'],validate=True),0o755);os.replace(next_script,script)
|
||||
subprocess.run(['systemctl','restart','rmm-bootstrap-download.service'],capture_output=True,check=True)
|
||||
return dict(url='https://discovery.ease-technologies.de:8443'+url_path,sha256=payload['sha256'],expires_at=config['expires_at'])
|
||||
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser();parser.add_argument('action',choices=('install','status','finish','cleanup-timer'));args=parser.parse_args();os.umask(0o077)
|
||||
parser=argparse.ArgumentParser();parser.add_argument('action',choices=('install','status','finish','cleanup-timer','repair'));args=parser.parse_args();os.umask(0o077)
|
||||
if args.action=='install':
|
||||
with __import__('zipfile').ZipFile(STATE/'windows-dev-access.zip') as archive:
|
||||
config=json.loads(archive.read('bootstrap-public.json'))
|
||||
@@ -126,6 +147,14 @@ def main():
|
||||
elif args.action=='cleanup-timer':
|
||||
result=cloud.bootstrap.rpc('server.conf',add_expiry_cleanup,{})
|
||||
cloud.contract.write_private(STATE/'publication-expiry.json',result);print(result)
|
||||
elif args.action=='repair':
|
||||
bundle=(STATE/'windows-dev-repair.zip').read_bytes()
|
||||
result=cloud.bootstrap.rpc('server.conf',add_repair,dict(bundle=base64.b64encode(bundle).decode(),sha256=hashlib.sha256(bundle).hexdigest(),
|
||||
previous_code_sha256=(STATE/'download-service-before-repair.sha256').read_text(),
|
||||
code=base64.b64encode((cloud.ROOT/'deploy/windows/download_service.py').read_bytes()).decode()))
|
||||
with urllib.request.urlopen(result['url'],context=ssl.create_default_context(),timeout=15) as response:raw=response.read(262145)
|
||||
require(hashlib.sha256(raw).hexdigest()==result['sha256'],'downloaded repair mismatch')
|
||||
cloud.contract.write_private(STATE/'repair-published.json',result);print(result)
|
||||
else:
|
||||
r=cloud.bootstrap.rpc('server.conf',finish,{})
|
||||
published=cloud.contract.protected_json(STATE/'publication.json')
|
||||
|
||||
Reference in New Issue
Block a user