From a596b604d936fb5a9f3a7ccf250f3eb8bc978b3e Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 25 Nov 2026 02:31:19 +0100 Subject: [PATCH] Publish minimal Guild report and court calendar storage grants --- website/scripts/political-service-grants.mjs | 13 +++++++++++++ website/tests/political-service-grants.test.mjs | 6 ++++++ 2 files changed, 19 insertions(+) create mode 100644 website/scripts/political-service-grants.mjs create mode 100644 website/tests/political-service-grants.test.mjs diff --git a/website/scripts/political-service-grants.mjs b/website/scripts/political-service-grants.mjs new file mode 100644 index 00000000..d7078166 --- /dev/null +++ b/website/scripts/political-service-grants.mjs @@ -0,0 +1,13 @@ +import {fileURLToPath} from 'node:url';import {resolve} from 'node:path';import {execFileSync} from 'node:child_process'; +import {openDatabase} from '../node/mysql.mjs';import {openPostbankDatabase} from '../node/postbank-db.mjs'; +export async function politicalServiceGrantPlan(db,bank){ + const sql='SELECT DATABASE() db,@@hostname host,@@port port,@@server_id server_id',a=(await db.query(sql))[0],b=await bank?.first(sql); + if(!a||!b||['host','port','server_id'].some(k=>String(a[k])!==String(b[k]))||!/^[a-z][a-z0-9_]{2,63}$/.test(b.db||''))throw Error('One transactional MySQL server required'); + const identity=(await db.query('SELECT CURRENT_USER() identity'))[0]?.identity?.split('@');if(identity?.length!==2||!identity.every(v=>/^[a-zA-Z0-9_.%:-]+$/.test(v)))throw Error('Unexpected central identity'); + const target="'"+identity[0]+"'@'"+identity[1]+"'"; + return [['SELECT','pb_guild_passages'],['SELECT,INSERT','jarvis_events'],['SELECT,INSERT','jarvis_event_history']].map(([rights,table])=>'GRANT '+rights+' ON `'+b.db+'`.`'+table+'` TO '+target+';\n').join(''); +} +if(process.argv[1]&&resolve(process.argv[1])===fileURLToPath(import.meta.url)){ + const apply=process.argv.slice(2).join(' ')==='--apply';if(process.argv.length>2&&!apply)throw Error('Use no arguments to review, or --apply'); + const db=await openDatabase(process.env),bank=await openPostbankDatabase(process.env);try{const sql=await politicalServiceGrantPlan(db,bank);if(apply){if(process.getuid?.()!==0)throw Error('Apply through the privileged deployment operator');execFileSync('mysql',['--batch'],{input:sql,stdio:['pipe','pipe','pipe']});console.log('Applied three scoped political service grants. No business records or balances changed.');}else process.stdout.write(sql);}finally{await Promise.allSettled([db.close(),bank?.close()]);} +} diff --git a/website/tests/political-service-grants.test.mjs b/website/tests/political-service-grants.test.mjs new file mode 100644 index 00000000..eb9bf4a8 --- /dev/null +++ b/website/tests/political-service-grants.test.mjs @@ -0,0 +1,6 @@ +import test from 'node:test';import assert from 'node:assert/strict';import{politicalServiceGrantPlan}from'../scripts/political-service-grants.mjs'; +test('political services request only Guild read and calendar read/insert on the verified bank server',async()=>{ + const identity={db:'dune_site',host:'central',port:3306,server_id:1},db={query:async sql=>[sql.includes('CURRENT_USER')?{identity:'dune_app@localhost'}:identity]},bank={first:async()=>({...identity,db:'dune_bank'})}; + const plan=await politicalServiceGrantPlan(db,bank);assert.equal(plan,"GRANT SELECT ON `dune_bank`.`pb_guild_passages` TO 'dune_app'@'localhost';\nGRANT SELECT,INSERT ON `dune_bank`.`jarvis_events` TO 'dune_app'@'localhost';\nGRANT SELECT,INSERT ON `dune_bank`.`jarvis_event_history` TO 'dune_app'@'localhost';\n");assert.doesNotMatch(plan,/UPDATE|DELETE|DROP|ALL PRIVILEGES|pb_accounts/); + await assert.rejects(politicalServiceGrantPlan(db,{first:async()=>({...identity,host:'foreign',db:'dune_bank'})}),/One transactional/);await assert.rejects(politicalServiceGrantPlan(db,{first:async()=>({...identity,db:'bank`;DROP'})}),/One transactional/);await assert.rejects(politicalServiceGrantPlan({query:async sql=>[sql.includes('CURRENT_USER')?{identity:"app'@localhost"}:identity]},bank),/identity/); +});