From 33507e7be7a69e382aab6126df200985e1853d7c Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Wed, 2 Dec 2026 11:43:02 +0100 Subject: [PATCH] Ship verified private Lobby configuration in the canonical operations artifact --- website/ops/LOBBY-ACCOUNT-FIRST-JOIN.md | 5 +++-- website/ops/configure-lobby-account.py | 17 +++++++++++++++-- website/ops/test_lobby_account_config.py | 10 ++++++++++ website/scripts/deployment-package.mjs | 2 +- website/tests/deployment-package.test.mjs | 2 +- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/website/ops/LOBBY-ACCOUNT-FIRST-JOIN.md b/website/ops/LOBBY-ACCOUNT-FIRST-JOIN.md index dfbca471..ab615240 100644 --- a/website/ops/LOBBY-ACCOUNT-FIRST-JOIN.md +++ b/website/ops/LOBBY-ACCOUNT-FIRST-JOIN.md @@ -35,8 +35,9 @@ records never log credentials. The player's client may retain its own received D ## Release Both web and plugin changes require their exact canonical CI and normal merge. -Run the immutable release's `ops/configure-lobby-account.py --source ` -to inspect, then add `--apply` to prepare private server configuration. It changes +Run `configure-lobby-account.py --source ` from the independently verified +CI operations artifact (or immutable release) to inspect, then add `--apply` to +prepare private server configuration before promotion. It changes only three Lobby-account environment settings. It does not restart the website. Use the existing staged website promotion so schema creation and readiness happen before the new plugin activates. Never put its generated private material in Git diff --git a/website/ops/configure-lobby-account.py b/website/ops/configure-lobby-account.py index 36e12c50..8cc3e70f 100644 --- a/website/ops/configure-lobby-account.py +++ b/website/ops/configure-lobby-account.py @@ -1,5 +1,6 @@ """Prepare private Lobby provisioning credentials for a reviewed website release.""" import argparse +import hashlib import json import os from pathlib import Path @@ -11,6 +12,18 @@ ENV=Path('/home/dunerealms/.config/dunerealms.env') STATE=Path('/var/lib/dunerealms-operations/lobby-account') KEYS={'LOBBY_ACCOUNT_ENABLED','LOBBY_ACCOUNT_TOKEN','LOBBY_ACCOUNT_ENCRYPTION_KEY'} +def reviewed_source(path,source): + if not re.fullmatch(r'[a-f0-9]{40}',source):return False + if path.resolve().parents[1]==Path('/home/dunerealms/apps/dunerealms/releases/ci-'+source):return True + manifest=path.parent/'manifest.json' + if not manifest.is_file():return False + m=json.loads(manifest.read_text()) + record=m.get('files',{}).get(path.name,{}) + return (m.get('sourceRepository')=='https://www.dunerealms.com/git/unimatrix/web.git' + and m.get('sourceCommit')==source + and record.get('sha256')==hashlib.sha256(path.read_bytes()).hexdigest() + and record.get('bytes')==path.stat().st_size) + def configured(text,token,key): if not re.fullmatch(r'[A-Za-z0-9_-]{43}',token) or not re.fullmatch(r'[a-f0-9]{64}',key): raise ValueError('Invalid private provisioning material') @@ -29,8 +42,8 @@ def atomic(path,data,uid,gid): def main(): p=argparse.ArgumentParser(description=__doc__);p.add_argument('--source',required=True);p.add_argument('--apply',action='store_true');a=p.parse_args() - if not re.fullmatch(r'[a-f0-9]{40}',a.source) or Path(__file__).resolve().parents[1]!=Path('/home/dunerealms/apps/dunerealms/releases/ci-'+a.source): - raise ValueError('Run the exact immutable website release helper') + if not reviewed_source(Path(__file__).resolve(),a.source): + raise ValueError('Run the exact immutable release or independently verified CI operations artifact') if ENV.resolve()!=ENV or not ENV.is_file() or ENV.stat().st_mode&0o077: raise ValueError('Existing private website environment required') if not a.apply: diff --git a/website/ops/test_lobby_account_config.py b/website/ops/test_lobby_account_config.py index cff109db..b0a74af6 100644 --- a/website/ops/test_lobby_account_config.py +++ b/website/ops/test_lobby_account_config.py @@ -1,6 +1,9 @@ import importlib.util from pathlib import Path import unittest +import tempfile +import json +import hashlib s=importlib.util.spec_from_file_location('lobby_config',Path(__file__).with_name('configure-lobby-account.py')) m=importlib.util.module_from_spec(s);s.loader.exec_module(m) @@ -14,5 +17,12 @@ class ConfigTests(unittest.TestCase): self.assertEqual(result.count('LOBBY_ACCOUNT_TOKEN='),1) def test_invalid_material_cannot_enter_environment(self): with self.assertRaises(ValueError):m.configured('',"x\nBAD=true",'b'*64) + def test_artifact_source_and_helper_bytes_must_match(self): + with tempfile.TemporaryDirectory() as folder: + p=Path(folder)/'configure-lobby-account.py';p.write_bytes(b'verified') + manifest={'sourceRepository':'https://www.dunerealms.com/git/unimatrix/web.git','sourceCommit':'a'*40,'files':{p.name:{'sha256':hashlib.sha256(p.read_bytes()).hexdigest(),'bytes':8}}} + (p.parent/'manifest.json').write_text(json.dumps(manifest)) + self.assertTrue(m.reviewed_source(p,'a'*40));self.assertFalse(m.reviewed_source(p,'b'*40)) + p.write_bytes(b'changed!');self.assertFalse(m.reviewed_source(p,'a'*40)) if __name__=='__main__':unittest.main() diff --git a/website/scripts/deployment-package.mjs b/website/scripts/deployment-package.mjs index c5d63cc4..187d0b6c 100644 --- a/website/scripts/deployment-package.mjs +++ b/website/scripts/deployment-package.mjs @@ -6,7 +6,7 @@ import {createHash} from 'node:crypto'; export function packageDeploymentScripts(output,sourceCommit=null,{sourceDirectory=fileURLToPath(new URL('../ops/',import.meta.url))}={}){ if(sourceCommit!==null&&!/^[a-f0-9]{40}$/.test(sourceCommit))throw Error('Invalid deployment source commit'); const files={}; - for(const name of ['dunerealms-ci-trigger','dunerealms-build-release']){ + for(const name of ['dunerealms-ci-trigger','dunerealms-build-release','configure-lobby-account.py']){ const bytes=Buffer.from(readFileSync(path.join(sourceDirectory,name),'utf8').replaceAll('\r\n','\n')); files[name]={sha256:createHash('sha256').update(bytes).digest('hex'),bytes:bytes.length}; mkdirSync(output,{recursive:true});writeFileSync(path.join(output,name),bytes); diff --git a/website/tests/deployment-package.test.mjs b/website/tests/deployment-package.test.mjs index 55bf510f..73be1648 100644 --- a/website/tests/deployment-package.test.mjs +++ b/website/tests/deployment-package.test.mjs @@ -8,7 +8,7 @@ import {packageDeploymentScripts} from '../scripts/deployment-package.mjs'; test('built operational scripts have deterministic bytes, exact hashes and recorded source identity',()=>{ const folder=mkdtempSync(path.join(tmpdir(),'dune-web-deployment-')),source=path.join(folder,'source'),output=path.join(folder,'output');mkdirSync(source); - for(const name of ['dunerealms-ci-trigger','dunerealms-build-release'])writeFileSync(path.join(source,name),'#!/bin/bash\r\necho verified\r\n'); + for(const name of ['dunerealms-ci-trigger','dunerealms-build-release','configure-lobby-account.py'])writeFileSync(path.join(source,name),'#!/bin/bash\r\necho verified\r\n'); const commit='a'.repeat(40),manifest=packageDeploymentScripts(output,commit,{sourceDirectory:source}); assert.equal(manifest.sourceCommit,commit);assert.equal(manifest.sourceRepository,'https://www.dunerealms.com/git/unimatrix/web.git'); for(const [name,record] of Object.entries(manifest.files)){