Publish password-TOTP WebUI and bearer MCP access with verified deployment

This commit is contained in:
2026-11-17 20:29:07 +01:00
parent 9fa0fb81ff
commit 5a93bc146f
18 changed files with 441 additions and 17 deletions
+13 -5
View File
@@ -91,6 +91,8 @@ def activate(payload):
with (work/'deployment.lock').open('a') as lock:
fcntl.flock(lock,fcntl.LOCK_EX)
active = inspect('api')
queried_public = subprocess.run(['docker','inspect','rust-discovery-server-public-api-1'], capture_output=True, text=True)
public_api = json.loads(queried_public.stdout)[0] if queried_public.returncode == 0 else None
dist = next(Path(m['Source']) for m in active['Mounts'] if m['Destination'] == '/web')
if dist != root / 'web/dist' or active['Config']['Labels']['com.docker.compose.project'] != 'rust-discovery-server':
raise RuntimeError('Unexpected development WebUI deployment')
@@ -111,13 +113,18 @@ def activate(payload):
raise RuntimeError('Server build digest mismatch')
if inspect('gateway')['Image'] != active['Image']:
raise RuntimeError('API and Gateway have different base images')
labels = active['Config']['Labels']
labels = (public_api or active)['Config']['Labels']
if labels['com.docker.compose.project'] != 'rust-discovery-server':
raise RuntimeError('Unexpected compose project')
files = [Path(x) for x in labels['com.docker.compose.project.config_files'].split(',')]
base_files = [f for f in files if not (f.parent.parent == work and f.name == 'image.compose.yaml')]
compose = ['docker','compose','--project-name','rust-discovery-server','--project-directory',str(root/'deploy'),
'--env-file',str(root/'devstate/.env')]
public_env = root / 'devstate/public-access/image.env'
if public_api is not None:
if not public_env.is_file():
raise ValueError('Missing public API image configuration')
compose.extend(['--env-file', str(public_env)])
for path in base_files:
if not path.is_file() or not path.resolve().is_relative_to(root):
raise ValueError('Missing deployment overlay')
@@ -139,7 +146,8 @@ def activate(payload):
if subprocess.run(['docker','image','inspect',tag],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL).returncode:
run('docker','build','--network=none','--pull=false','-t',tag,str(context))
overlay=role_dir/'image.compose.yaml'
write_atomic(overlay,('services:\n'+''.join(f' {r}:\n image: {tag}\n pull_policy: never\n' for r in ('migrate','api','gateway'))).encode())
deployed_roles = ['api', 'gateway'] + (['public-api'] if public_api is not None else [])
write_atomic(overlay,('services:\n'+''.join(f' {r}:\n image: {tag}\n pull_policy: never\n' for r in ['migrate', *deployed_roles])).encode())
for path, content in payload['overlays'].items():
file = (root / 'deploy') / path
if not re.fullmatch(r'server\.[\w.-]+\.compose\.yaml', path) or file.is_symlink():
@@ -149,7 +157,7 @@ def activate(payload):
compose.extend(['-f',str(file)])
compose.extend(['-f',str(overlay)])
config=json.loads(run(*compose,'config','--format','json'))['services']
for role,port in [('api','18443'),('gateway','18444')]:
for role,port in [('api','18443'),('gateway','18444')] + ([('public-api','18445')] if public_api is not None else []):
svc=config[role]
if (svc['ports'][0]['host_ip']!='127.0.0.1' or str(svc['ports'][0]['published'])!=port or len(svc['ports'])!=1
or svc['user']!='10001:10001' or not svc['read_only']):
@@ -161,8 +169,8 @@ def activate(payload):
recorded = dict(line.split('|') for line in run(*sql,"SELECT version,encode(checksum,'hex') FROM _sqlx_migrations WHERE success").splitlines())
if recorded != payload['migrations']:
raise RuntimeError('Applied migrations differ from the build revision')
run(*compose,'up','-d','--no-deps','--no-build','--pull','never','api','gateway')
for role,host,port,ca in [('api','localhost','18443','api-pki'),('gateway','discovery.ease-technologies.de','18444','pki')]:
run(*compose,'up','-d','--no-deps','--no-build','--pull','never',*deployed_roles)
for role,host,port,ca in [('api','localhost','18443','api-pki'),('gateway','discovery.ease-technologies.de','18444','pki')] + ([('public-api','localhost','18445','api-pki')] if public_api is not None else []):
for _ in range(25):
res=subprocess.run(['curl','--noproxy','*','--resolve',f'{host}:{port}:127.0.0.1','--cacert',str(root/f'devstate/{ca}/ca.pem'),
'--max-time','2','--silent','--fail',f'https://{host}:{port}/healthz'],capture_output=True)