Provision scoped original-war access for the paid raid service
All checks were successful
DuneRealms Web CI / web (push) Successful in 3m14s

This commit is contained in:
unimatrixgit 2026-11-29 16:56:44 +01:00
commit 699c66f064
3 changed files with 63 additions and 0 deletions

View file

@ -45,6 +45,10 @@ Require transactional/replay/cancel-race tests, actor/deed/funding/Home Block ch
## Implemented integration and operation boundaries
Provision the existing website service's original-war table access with the BUILT `ops/pillager-war-access.mjs --source=<reviewed release SHA>` (plan first, then `--apply`) before activation. It verifies the actual current application identity and same MySQL server, privately backs up SHOW GRANTS, and adds only SELECT/INSERT/UPDATE on nine fixed existing war/calendar/event tables. No account creation, game-role change, administrative privilege, ledger permission expansion, schema creation or financial transaction is included. It preserves before/after grants privately and verifies the original atomic adapter through a read-only poll; it never weakens transactional-table validation or switches to separate commits. MySQL GRANT is not transactional: if setup fails part-way, preserve the backup and reconcile only its recorded additions; do not revoke pre-existing privileges or blanket-replace grants.
This prerequisite was discovered during actual491ad06 read-only canary: both databases contained the required InnoDB tables, but the website service could not see the bank's original-war tables. The route correctly returned503 and no paid test order was made. Lobby resource deployment and the Arrakis startup canary were already applied; the remaining four planets were held. This setup correction follows the existing CMS publication-access provisioning pattern and requires its own committed build before use.
Acceptance reserves native delivery capacity before posting: at most100 active paid orders per server and at most262144 bytes for the full UTF-8 poll response. Overflow refuses the next debit; existing orders are never silently truncated. The global500-order register guard remains a reconciliation boundary. Regression coverage also exercises the actual central MySQL root interface (`query/transaction`, without a root `first` convenience), including original-war storage qualification.
`imperial-raid-runtime.mjs` combines the existing banking/key adapter, durable order service and post-commit jobs. The existing central scheduler drains jobs every15 seconds; no second payment worker or native reward command is introduced. Feature activation requires `IMPERIAL_RAIDS_ENABLED=true`, `POSTBANK_ENABLED=true` and `WAR_BRIDGE_ENABLED=true`. `ops/configure-imperial-raids.mjs` is a plan-by-default built helper, restricted to the exact immutable reviewed release via `--source=<40-character commit>`. `--apply` privately backs up the environment and changes only its feature flag, preserving ownership/mode. It neither seeds balances nor runs a payment. Restart uses the existing release process. Do not run a draft/local script on the host.

View file

@ -0,0 +1,42 @@
import {readFile,writeFile,mkdir,realpath} from 'node:fs/promises';
import {execFileSync} from 'node:child_process';
import {pathToFileURL,fileURLToPath} from 'node:url';
import {resolve} from 'node:path';
import mysql from 'mysql2/promise';
export const RAID_WAR_TABLES=Object.freeze(['jarvis_war_calendar_guard','jarvis_war_proposals','jarvis_war_slots','jarvis_war_rosters','jarvis_war_history','jarvis_war_campaigns','jarvis_war_roster_keys','jarvis_events','jarvis_event_history']);
export function raidWarAccessPlan({bankSchema,centralIdentity}){
if(!/^[a-z][a-z0-9_]{2,63}$/.test(bankSchema||''))throw TypeError('Verified bank schema required');
const parts=String(centralIdentity).split('@');
if(parts.length!==2||parts.some(p=>! /^[a-zA-Z0-9_.%:-]+$/.test(p))||parts[0]==='root'||parts[0].startsWith('mysql.'))throw TypeError('Verified existing application identity required');
const principal=parts.map(p=>"'"+p+"'").join('@');
return RAID_WAR_TABLES.map(t=>`GRANT SELECT,INSERT,UPDATE ON \`${bankSchema}\`.\`${t}\` TO ${principal}`);
}
async function main(){
const args=process.argv.slice(2),source=args.find(a=>a.startsWith('--source='))?.slice(9);
if(!/^[a-f0-9]{40}$/.test(source||'')||args.some(a=>a!=='--apply'&&!a.startsWith('--source=')))throw Error('Exact reviewed --source commit required');
const release=await realpath(fileURLToPath(new URL('..',import.meta.url)));
if(!release.endsWith('/releases/ci-'+source))throw Error('Run only the exact immutable reviewed release helper');
process.loadEnvFile('/home/dunerealms/.config/dunerealms.env');const e=process.env,raw=JSON.parse(await readFile(e.POSTBANK_DB_CONFIG,'utf8'));
const site=await mysql.createConnection({host:e.DB_HOST||'127.0.0.1',port:Number(e.DB_PORT||3306),user:e.DB_USER,password:e.DB_PASSWORD,database:e.DB_NAME}),bank=await mysql.createConnection(raw);
try{
const [a]=await site.query('SELECT CURRENT_USER() identity,@@hostname host,@@port port,@@server_id server_id'),[b]=await bank.query('SELECT DATABASE() name,@@hostname host,@@port port,@@server_id server_id');
if(a[0].identity.split('@')[0]!==e.DB_USER||['host','port','server_id'].some(k=>String(a[0][k])!==String(b[0][k])))throw Error('The original service identity and same transaction server are required');
const plan=raidWarAccessPlan({bankSchema:b[0].name,centralIdentity:a[0].identity});
const [tables]=await bank.execute('SELECT TABLE_NAME name,ENGINE engine FROM information_schema.TABLES WHERE TABLE_SCHEMA=? AND TABLE_NAME IN ('+RAID_WAR_TABLES.map(()=>'?').join(',')+')',[b[0].name,...RAID_WAR_TABLES]);
if(RAID_WAR_TABLES.some(t=>!tables.some(r=>r.name===t&&String(r.engine).toLowerCase()==='innodb')))throw Error('Existing transactional war tables are required; this helper creates none');
if(!args.includes('--apply')){console.log(JSON.stringify({applied:false,source,tables:RAID_WAR_TABLES,privileges:['SELECT','INSERT','UPDATE'],financialTransactions:false}));return;}
const backup=resolve('/root/dunerealms-pillager-access-backups',new Date().toISOString().replace(/[:.]/g,'-'));await mkdir(backup,{recursive:true,mode:0o700});
const principal=a[0].identity.split('@').map(p=>"'"+p+"'").join('@');
const grants=execFileSync('mysql',['--batch','--raw','--skip-column-names','--execute','SHOW GRANTS FOR '+principal],{encoding:'utf8',stdio:['ignore','pipe','pipe']});
await writeFile(resolve(backup,'grants.before.sql'),grants,{mode:0o600,flag:'wx'});await writeFile(resolve(backup,'plan.json'),JSON.stringify({source,statements:plan}),{mode:0o600,flag:'wx'});
for(const sql of plan)execFileSync('mysql',['--execute',sql],{stdio:['ignore','pipe','pipe']});
const after=execFileSync('mysql',['--batch','--raw','--skip-column-names','--execute','SHOW GRANTS FOR '+principal],{encoding:'utf8',stdio:['ignore','pipe','pipe']});await writeFile(resolve(backup,'grants.after.sql'),after,{mode:0o600,flag:'wx'});
// Metadata checks and poll are read-only. A setup bug cannot execute a payment.
const adapt=c=>({query:async(sql,v=[])=>{if(!/^\s*SELECT\b/i.test(sql))throw Error('Read-only readiness required');return(await c.execute(sql,v))[0];},first:async(sql,v=[])=>{if(!/^\s*SELECT\b/i.test(sql))throw Error('Read-only readiness required');return(await c.execute(sql,v))[0][0]||null;},transaction:async()=>{throw Error('No financial transaction allowed during setup');}});
const {createImperialRaidRuntime}=await import('../node/imperial-raid-runtime.mjs');const result=await createImperialRaidRuntime(adapt(site),adapt(bank),null).execute({action:'poll',server:'arrakis'});
if(result.ok!==true||result.schema!==1||!Array.isArray(result.orders))throw Error('Original atomic raid readiness failed; preserve the private grant backup');
console.log(JSON.stringify({applied:true,source,tables:RAID_WAR_TABLES,privileges:['SELECT','INSERT','UPDATE'],backup,readOnlyReadiness:true,financialTransactions:false}));
}finally{await site.end();await bank.end();}
}
if(process.argv[1]&&import.meta.url===pathToFileURL(await realpath(resolve(process.argv[1]))).href)await main();

View file

@ -0,0 +1,17 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import {readFileSync} from 'node:fs';
import {raidWarAccessPlan,RAID_WAR_TABLES} from '../ops/pillager-war-access.mjs';
test('existing application service receives only named original-war SELECT/INSERT/UPDATE, never ledger/admin/player permissions',()=>{
const input={bankSchema:'synthetic_bank',centralIdentity:'synthetic_service@localhost'},plan=raidWarAccessPlan(input);
assert.equal(plan.length,9);assert.equal(new Set(plan).size,9);assert.deepEqual(raidWarAccessPlan(input),plan);
for(let i=0;i<plan.length;i++)assert.equal(plan[i],`GRANT SELECT,INSERT,UPDATE ON \`synthetic_bank\`.\`${RAID_WAR_TABLES[i]}\` TO 'synthetic_service'@'localhost'`);
assert.doesNotMatch(plan.join('\n'),/\*|GRANT OPTION|DELETE|CREATE|ALTER|DROP|pb_accounts|pb_entries|site_accounts|organisation_keys/);
for(const bad of [{bankSchema:'bank;DROP'},{centralIdentity:"app'@localhost"},{centralIdentity:'root@localhost'},{centralIdentity:'app@localhost@elsewhere'},{centralIdentity:'mysql.session@localhost'}])assert.throws(()=>raidWarAccessPlan({...input,...bad}));
});
test('built setup requires immutable source, same server/current identity and backups before grants; readiness cannot write',()=>{
const source=readFileSync(new URL('../ops/pillager-war-access.mjs',import.meta.url),'utf8');
assert.ok(source.indexOf("'grants.before.sql'")<source.indexOf('for(const sql of plan)'));
assert.match(source,/releases\/ci-/);assert.match(source,/same transaction server/);assert.match(source,/No financial transaction allowed during setup/);
assert.match(source,/mode:0o600,flag:'wx'/);assert.match(source,/information_schema.TABLES/);assert.doesNotMatch(source,/password.*--execute|--password/);
});