Ship verified private Lobby configuration in the canonical operations artifact
All checks were successful
DuneRealms Web CI / web (push) Successful in 3m20s
All checks were successful
DuneRealms Web CI / web (push) Successful in 3m20s
This commit is contained in:
parent
d88d96e87c
commit
33507e7be7
5 changed files with 30 additions and 6 deletions
|
|
@ -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 <commit>`
|
||||
to inspect, then add `--apply` to prepare private server configuration. It changes
|
||||
Run `configure-lobby-account.py --source <commit>` 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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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)){
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff