After adding additionnel configuration for validations2
This commit is contained in:
parent
fd5bac3cc8
commit
fddcdaeb35
@ -36,6 +36,8 @@
|
||||
"verify-deposit-addresses:prod": "node dist/scripts/verifyDepositAddresses.js",
|
||||
"smoke-approval-policies": "ts-node --transpile-only src/scripts/smokeApprovalPolicies.ts",
|
||||
"smoke-approval-policies:prod": "node dist/scripts/smokeApprovalPolicies.js",
|
||||
"set-forbid-self-approve": "ts-node --transpile-only src/scripts/setForbidSelfApprove.ts",
|
||||
"set-forbid-self-approve:prod": "node dist/scripts/setForbidSelfApprove.js",
|
||||
"verify-smtp": "ts-node --transpile-only src/scripts/verifySmtp.ts",
|
||||
"verify-smtp:prod": "node dist/scripts/verifySmtp.js",
|
||||
"rotate-encryption-key": "ts-node --transpile-only src/scripts/rotateEncryptionKey.ts",
|
||||
|
||||
92
backend/src/scripts/setForbidSelfApprove.ts
Normal file
92
backend/src/scripts/setForbidSelfApprove.ts
Normal file
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Break-glass: set forbid_self_approve on all (or matched) approval_policies.
|
||||
* No on-chain activity. Use when a solo Super Admin cannot approve their own policy change.
|
||||
*
|
||||
* VPS:
|
||||
* sudo docker compose run --rm --no-deps --build backend \
|
||||
* node dist/scripts/setForbidSelfApprove.js --allow=true --confirm=YES
|
||||
*
|
||||
* Optional: --operation-type=treasury_hot_to_cold (only that op; default = all policies)
|
||||
*/
|
||||
|
||||
import './loadEnv';
|
||||
import { query } from '../db/connection';
|
||||
|
||||
function arg(name: string): string | undefined {
|
||||
const prefix = `--${name}=`;
|
||||
const hit = process.argv.find((a) => a.startsWith(prefix));
|
||||
return hit ? hit.slice(prefix.length) : undefined;
|
||||
}
|
||||
|
||||
function hasFlag(name: string): boolean {
|
||||
return process.argv.includes(`--${name}`);
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const allowRaw = (arg('allow') ?? '').toLowerCase();
|
||||
const allow = allowRaw === 'true' || allowRaw === '1' || allowRaw === 'yes';
|
||||
const deny = allowRaw === 'false' || allowRaw === '0' || allowRaw === 'no';
|
||||
if (!allow && !deny) {
|
||||
console.error('Usage: --allow=true|false --confirm=YES [--operation-type=...]');
|
||||
process.exit(1);
|
||||
}
|
||||
const forbidSelf = deny; // allow=true → forbid_self_approve=false
|
||||
if (arg('confirm') !== 'YES' && !hasFlag('confirm=YES')) {
|
||||
console.error('Refusing to run without --confirm=YES');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const opType = arg('operation-type') || null;
|
||||
|
||||
const existing = await query<{ id: string; name: string; operation_type: string | null; decision: unknown }[]>(
|
||||
opType
|
||||
? `SELECT id, name, operation_type, decision FROM approval_policies WHERE operation_type = $1 OR ($1 IS NULL AND operation_type IS NULL)`
|
||||
: `SELECT id, name, operation_type, decision FROM approval_policies`,
|
||||
opType ? [opType] : []
|
||||
);
|
||||
|
||||
if (!existing.length) {
|
||||
console.error('No approval_policies rows found. Run migrations / smokeApprovalPolicies first.');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Updating ${existing.length} polic(y/ies): forbid_self_approve → ${forbidSelf}`);
|
||||
for (const row of existing) {
|
||||
const decision =
|
||||
row.decision && typeof row.decision === 'object'
|
||||
? { ...(row.decision as Record<string, unknown>) }
|
||||
: {};
|
||||
decision.forbid_self_approve = forbidSelf;
|
||||
if (!Array.isArray(decision.quorum)) {
|
||||
decision.quorum = [{ role: 'super_admin', count: 1 }];
|
||||
}
|
||||
if (!decision.mode) decision.mode = 'require_approvals';
|
||||
|
||||
await query(
|
||||
`UPDATE approval_policies
|
||||
SET decision = $2::jsonb, version = version + 1, updated_at = NOW()
|
||||
WHERE id = $1`,
|
||||
[row.id, JSON.stringify(decision)]
|
||||
);
|
||||
console.log(
|
||||
` OK ${row.name} (${row.operation_type ?? 'any'}) forbid_self_approve=${forbidSelf}`
|
||||
);
|
||||
}
|
||||
|
||||
await query(
|
||||
`INSERT INTO approval_policy_revisions (actor_id, before_snapshot, after_snapshot, note)
|
||||
VALUES (NULL, '[]'::jsonb, $1::jsonb, $2)`,
|
||||
[
|
||||
JSON.stringify({ action: 'setForbidSelfApprove', forbid_self_approve: forbidSelf, count: existing.length }),
|
||||
`CLI setForbidSelfApprove forbid_self_approve=${forbidSelf}`,
|
||||
]
|
||||
);
|
||||
|
||||
console.log('\nDone. Reload /admin/approval-policies (hard refresh). No on-chain txs.');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e instanceof Error ? e.message : e);
|
||||
process.exit(1);
|
||||
});
|
||||
@ -28,6 +28,8 @@
|
||||
"phase-b:break-glass-reset-2fa": "docker compose run --rm --no-deps --build backend node dist/scripts/breakGlassResetAdmin2fa.js",
|
||||
"phase-b:rotate-deposit-addresses": "docker compose run --rm --no-deps --build backend node dist/scripts/rotateDepositAddresses.js",
|
||||
"phase-b:verify-deposit-addresses": "docker compose run --rm --no-deps --build backend node dist/scripts/verifyDepositAddresses.js",
|
||||
"phase-b:smoke-approval-policies": "docker compose run --rm --no-deps --build backend node dist/scripts/smokeApprovalPolicies.js",
|
||||
"phase-b:set-forbid-self-approve": "docker compose run --rm --no-deps --build backend node dist/scripts/setForbidSelfApprove.js",
|
||||
"docker:local:grant-super-admin": "docker compose --env-file .env.docker run --rm --no-deps --build backend node dist/scripts/grantSuperAdminToAdmins.js",
|
||||
"docker:local:reset-password": "docker compose --env-file .env.docker run --rm --no-deps --build backend node dist/scripts/resetDevPassword.js",
|
||||
"docker:local:disable-admin-2fa": "docker compose --env-file .env.docker run --rm --no-deps --build backend node dist/scripts/disableAdmin2faRequirement.js",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user