Hardened systemd deployment contract for read-only Monero observer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
export const CUSTODY_DB_ACTION_ARGUMENT_COUNTS = {
|
||||
migrate: 0,
|
||||
'migrate-mainnet-schema': 0,
|
||||
'grant-runtime': 1,
|
||||
'grant-monero-observer-runtime': 1,
|
||||
'grant-monero-credit-runtime': 1,
|
||||
@@ -19,11 +20,20 @@ export type CustodyDbAction = keyof typeof CUSTODY_DB_ACTION_ARGUMENT_COUNTS;
|
||||
export type CustodyDbArguments = { action: CustodyDbAction; argument?: string; extraArgument?: string };
|
||||
|
||||
export function assertCustodyDbActionAllowedOnNetwork(action: CustodyDbAction, isMainnet: boolean): void {
|
||||
if (isMainnet && action !== 'grant-monero-observer-runtime') {
|
||||
if (action === 'migrate-mainnet-schema' && !isMainnet) {
|
||||
throw new Error('Mainnet schema migration action requires the mainnet profile');
|
||||
}
|
||||
if (isMainnet && action !== 'grant-monero-observer-runtime' && action !== 'migrate-mainnet-schema') {
|
||||
throw new Error('Only the separately scoped Monero observation-role grant is allowed on mainnet');
|
||||
}
|
||||
}
|
||||
|
||||
export function assertMainnetSchemaMigrationAcknowledged(action: CustodyDbAction, acknowledgement: string | undefined): void {
|
||||
if (action === 'migrate-mainnet-schema' && acknowledgement !== 'explicit-schema-migration-only') {
|
||||
throw new Error('Mainnet schema migration requires explicit schema-migration acknowledgement');
|
||||
}
|
||||
}
|
||||
|
||||
export function parseCustodyDbArguments(args: readonly string[]): CustodyDbArguments {
|
||||
const [action, ...values] = args;
|
||||
if (!action || !Object.hasOwn(CUSTODY_DB_ACTION_ARGUMENT_COUNTS, action)) {
|
||||
|
||||
Reference in New Issue
Block a user