From 6e27d69a0972e11b3d8c9ec7201f89849dcedacf Mon Sep 17 00:00:00 2001 From: unimatrixgit <95320811+unimatrixgit@users.noreply.github.com> Date: Thu, 3 Dec 2026 21:51:49 +0100 Subject: [PATCH] Register explicit DuneStaff permissions and audited staff policy activation --- website/node/managed-game-permissions.json | 18 +++++++ .../node/organisation-default-policies.mjs | 2 +- website/node/organisation-runtime.mjs | 2 +- website/node/permissions.mjs | 3 ++ website/ops/enable-staff-tools.mjs | 48 +++++++++++++++++++ website/tests/organisation-runtime.test.mjs | 2 +- .../tests/staff-tools-permissions.test.mjs | 24 ++++++++++ 7 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 website/ops/enable-staff-tools.mjs create mode 100644 website/tests/staff-tools-permissions.test.mjs diff --git a/website/node/managed-game-permissions.json b/website/node/managed-game-permissions.json index ab4aa282..a7ab3a91 100644 --- a/website/node/managed-game-permissions.json +++ b/website/node/managed-game-permissions.json @@ -348,6 +348,24 @@ "label": "Use voice chat groups", "source": "Simple Voice Chat 2.6.25 plugin.yml", "highRisk": false + }, + { + "node": "dunestaff.fly", + "label": "Staff self flight", + "source": "DuneStaff explicit command or visibility check", + "highRisk": true + }, + { + "node": "dunestaff.vanish", + "label": "Staff self vanish", + "source": "DuneStaff explicit command or visibility check", + "highRisk": true + }, + { + "node": "dunestaff.vanish.see", + "label": "See vanished staff", + "source": "DuneStaff explicit command or visibility check", + "highRisk": true } ], "networkAdministratorRoles": [ diff --git a/website/node/organisation-default-policies.mjs b/website/node/organisation-default-policies.mjs index eccab264..2bd4b044 100644 --- a/website/node/organisation-default-policies.mjs +++ b/website/node/organisation-default-policies.mjs @@ -1,7 +1,7 @@ import {NODES} from './permissions.mjs'; import {ORGANISATION} from './organisation-model.mjs'; import {validatePolicyNodes} from './organisation-management.mjs'; -const staff=['web.menu.staffmanual','web.mail.internal.view']; +const staff=['web.menu.staffmanual','web.mail.internal.view','dunestaff.fly','dunestaff.vanish','dunestaff.vanish.see']; const branchNodes={ customer_support:['web.tickets.support','web.tickets.staff','web.menu.tickets','web.accounts.view','dune.tickets.staff','dune.staff.open','dune.staff.history'], sales_accounts:['web.tickets.sales','web.tickets.staff','web.menu.tickets','web.shop.support','web.accounts.view','web.bank.staff.view','web.bank.staff.clients'], diff --git a/website/node/organisation-runtime.mjs b/website/node/organisation-runtime.mjs index b844bfae..8d5a4061 100644 --- a/website/node/organisation-runtime.mjs +++ b/website/node/organisation-runtime.mjs @@ -7,7 +7,7 @@ const privileged=value=>{ const node=value.startsWith('cp.')?'web.'+value.slice(3):value; return /^web\.(accounts\.|ranks\.|servers\.|luckperms\.|tickets\.|bank\.staff\.|payroll\.|posts\.(edit|publish)|items\.manage|bans\.|forum\.(moderate|admin)|git\.admin|community\.manage|quests\.manage)/.test(node) ||/^dune\.(admin|staff\.|moderation\.|ban\.|unban\.|items\.give|tickets\.staff)/.test(node) - ||node.startsWith('duneprotect.')||/^dunelobby\.(admin|build)$/.test(node) + ||node.startsWith('dunestaff.')||node.startsWith('duneprotect.')||/^dunelobby\.(admin|build)$/.test(node) ||/^web\.menu\.(?:administration|staffmanual|permissions|servers|luckperms|bans|forum|items|posts|tickets)$/.test(node) ||/^web\.(?:shop\.support|bank\.projects\.approve|mail\.staff\.)/.test(node); }; diff --git a/website/node/permissions.mjs b/website/node/permissions.mjs index 9251e730..e3507923 100644 --- a/website/node/permissions.mjs +++ b/website/node/permissions.mjs @@ -1,6 +1,9 @@ import {JARVIS_IDENTITY,isJarvisIdentity} from './jarvis-identity.mjs'; import {organisationRuntimeAccess} from './organisation-runtime.mjs'; export const NODES={ + 'dunestaff.fly':'Toggle your own staff flight', + 'dunestaff.vanish':'Toggle your own staff vanish', + 'dunestaff.vanish.see':'See vanished staff', 'web.jarvis.clans.reset':'Issue and redeem fixed protected-clan roster reset keys', 'web.jarvis.keys.view':'Browse JARVIS masterkey templates', 'web.jarvis.accounts.test-identity':'Issue and redeem synthetic test identities for unlinked accounts', diff --git a/website/ops/enable-staff-tools.mjs b/website/ops/enable-staff-tools.mjs new file mode 100644 index 00000000..86a7cd21 --- /dev/null +++ b/website/ops/enable-staff-tools.mjs @@ -0,0 +1,48 @@ +import {realpath} from 'node:fs/promises'; +import {fileURLToPath,pathToFileURL} from 'node:url'; +import {resolve} from 'node:path'; +import {createOrganisationManagement} from '../node/organisation-management.mjs'; +import {validStaffRole} from '../node/organisation-model.mjs'; +import {OFFICIAL_ACCOUNT} from '../node/official-account.mjs'; +import {openDatabase} from '../node/mysql.mjs'; + +export const STAFF_TOOL_NODES=Object.freeze(['dunestaff.fly','dunestaff.vanish','dunestaff.vanish.see']); +const same=(a,b)=>JSON.stringify([...a].sort())===JSON.stringify([...b].sort()); +export function staffToolPolicyPlan(policies){ + return policies.filter(p=>validStaffRole(p.scope_type,p.scope_key,p.role_key)).flatMap(p=>{ + if(!Array.isArray(p.nodes)||!Number.isSafeInteger(p.version)||p.version<1)throw Error('Invalid current staff policy'); + const nodes=[...new Set([...p.nodes,...STAFF_TOOL_NODES])].sort(); + return same(nodes,p.nodes)?[]:[{scopeType:p.scope_type,scopeKey:p.scope_key,role:p.role_key,version:p.version,before:[...p.nodes],nodes}]; + }); +} +export async function enableStaffTools(db,actor,{apply=false}={}){ + if(actor?.id!==OFFICIAL_ACCOUNT.ownerId||actor?.username!=='unimatrix999')throw Error('Existing verified Owner required'); + const origin='https://cp.dunerealms.com',url=origin+'/api/admin/organisation/policies'; + const route=createOrganisationManagement(db,{origin,authenticate:async()=>actor}); + const read=async()=>{const r=await route(new Request(url));if(r.status!==200)throw Error('Staff policy authority unavailable');const j=await r.json();if(j.canEdit!==true||j.enforcement!=='active')throw Error('Active central policy authority required');return j;}; + const plan=staffToolPolicyPlan((await read()).policies); + if(!apply)return {applied:0,planned:plan.length,nodes:STAFF_TOOL_NODES}; + let applied=0; + for(const p of plan){ + const current=await read(),row=current.policies.find(r=>r.scope_type===p.scopeType&&r.scope_key===p.scopeKey&&r.role_key===p.role); + if(!row||row.version!==p.version||!same(row.nodes,p.before))throw Error('Staff policy changed; review a fresh plan'); + const scope=current.versions.find(r=>r.scope_type===p.scopeType&&r.scope_key===p.scopeKey); + const r=await route(new Request(url,{method:'POST',headers:{origin,'Content-Type':'application/json'},body:JSON.stringify({scopeType:p.scopeType,scopeKey:p.scopeKey,role:p.role,nodes:p.nodes,scopeVersion:Number(scope?.version||1),reason:'Owner requested staff /fly and /vanish for The Wild Update'})})); + if(r.status!==200)throw Error('Original staff policy publisher rejected update: '+r.status); + applied++; + } + return {applied,planned:plan.length,nodes:STAFF_TOOL_NODES}; +} +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 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'); + process.loadEnvFile('/home/dunerealms/.config/dunerealms.env'); + const db=await openDatabase(process.env); + try{ + const actor=await db.prepare("SELECT id,username FROM site_accounts WHERE id=? AND username='unimatrix999' AND password_hash NOT LIKE '!%'").bind(OFFICIAL_ACCOUNT.ownerId).first(); + console.log(JSON.stringify({source,...await enableStaffTools(db,actor,{apply:args.includes('--apply')})})); + }finally{await db.close();} +} +if(process.argv[1]&&import.meta.url===pathToFileURL(await realpath(resolve(process.argv[1]))).href)await main(); diff --git a/website/tests/organisation-runtime.test.mjs b/website/tests/organisation-runtime.test.mjs index 2d235069..501c818a 100644 --- a/website/tests/organisation-runtime.test.mjs +++ b/website/tests/organisation-runtime.test.mjs @@ -46,7 +46,7 @@ test('Safe persisted citizen features survive while accidental staff grants on U assert(result.nodes.includes('web.mail.internal.view'));assert(result.nodes.includes('web.quests.view'));assert(result.nodes.includes('duneess.chat.colors'));assert(result.ranks.includes('vip'));assert(!result.nodes.includes('web.bank.staff.manage'));assert(!result.nodes.includes('web.accounts.assign')); }); test('Citizen ranks cannot retain staff powers through CP aliases, ticket scopes or native administration',async()=>{ - const unwanted=['cp.community.manage','web.tickets.dev','web.tickets.sales','web.forum.admin','dune.items.give','dunelobby.admin','dunelobby.build']; + const unwanted=['cp.community.manage','web.tickets.dev','web.tickets.sales','web.forum.admin','dune.items.give','dunelobby.admin','dunelobby.build','dunestaff.fly','dunestaff.vanish','dunestaff.vanish.see']; const base={...DEFAULT_RANKS[0],nodes:[...DEFAULT_RANKS[0].nodes,...unwanted]}; const result=await organisationRuntimeAccess(database({assignments:[]}),user,{registry:NODES,basicRank:base,legacyRanks:[],clock:()=>10}); for(const node of unwanted)assert(!result.nodes.includes(node),node); diff --git a/website/tests/staff-tools-permissions.test.mjs b/website/tests/staff-tools-permissions.test.mjs new file mode 100644 index 00000000..9468bec3 --- /dev/null +++ b/website/tests/staff-tools-permissions.test.mjs @@ -0,0 +1,24 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import {STAFF_TOOL_NODES,staffToolPolicyPlan,enableStaffTools} from '../ops/enable-staff-tools.mjs'; +import {defaultOrganisationPolicies} from '../node/organisation-default-policies.mjs'; +import {GAME_NODE_SET} from '../node/game-ranks.mjs'; + +test('staff-tool plan adds only the three explicit nodes to existing staff policies',()=>{ + const staff={scope_type:'branch',scope_key:'news_media',role_key:'officer',version:7,nodes:['web.posts.edit']}; + const civil={scope_type:'clan',scope_key:'test',role_key:'officer',version:1,nodes:['dune.clans.view']}; + const plan=staffToolPolicyPlan([staff,civil]); + assert.equal(plan.length,1);assert.equal(plan[0].version,7); + assert.deepEqual(plan[0].nodes,[...STAFF_TOOL_NODES,'web.posts.edit'].sort()); + assert.deepEqual(staff.nodes,['web.posts.edit']); + assert.deepEqual(staffToolPolicyPlan([{...staff,nodes:plan[0].nodes}]),[]); +}); + +test('staff utility defaults are registered for native sync and absent from ordinary membership',()=>{ + for(const node of STAFF_TOOL_NODES)assert(GAME_NODE_SET.has(node)); + for(const p of defaultOrganisationPolicies().filter(p=>p.role!=='branch_lead'))for(const node of STAFF_TOOL_NODES)assert(p.nodes.includes(node)); +}); + +test('the policy operator rejects a caller other than the verified Owner before any database access',async()=>{ + await assert.rejects(enableStaffTools({},{id:'other',username:'unimatrix999'},{apply:true}),/verified Owner/); +});