import { dbSearchPath, getSettings } from "@opengeni/config"; import { assertRuntimeDatabasePosture, createDb, databasePasswordFileOptions, FORCE_RLS_TABLES, PROTECTED_NO_DIRECT_DML_TABLES, RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES, RUNTIME_FULL_DML_TABLES, RUNTIME_READ_INSERT_TABLES, RUNTIME_READ_INSERT_UPDATE_TABLES, RUNTIME_READ_ONLY_TABLES, RUNTIME_READ_UPDATE_TABLES, } from "./index"; const settings = getSettings(); const searchPath = dbSearchPath(settings); const client = createDb(settings.databaseUrl, { ...(searchPath ? { searchPath } : {}), rlsStrategy: settings.rlsStrategy, max: 1, ...databasePasswordFileOptions(settings), }); try { const posture = await assertRuntimeDatabasePosture(client.db, { rlsStrategy: settings.rlsStrategy, expectedRole: settings.runtimeDatabaseRole, targetSchema: settings.dbSchema.trim() || "public", }); // Structural evidence only: never print a connection string, secret, GUC, or // tenant row. The command is intended for release Jobs and audit artifacts. console.log( JSON.stringify({ ok: true, rlsStrategy: settings.rlsStrategy, currentUser: posture.identity.currentUser, sessionUser: posture.identity.sessionUser, memberships: posture.memberships.length, ownedSchemas: posture.ownedSchemas.length, ownedRelations: posture.ownedRelations.length, declaredProtectedTables: FORCE_RLS_TABLES.length, activeProtectedTables: posture.tables.filter((table) => table.rlsActive).length, declaredFullDmlTables: RUNTIME_FULL_DML_TABLES.length, privilegedFullDmlTables: posture.tables.filter( (table) => table.select && table.insert && table.update && table.delete && !table.truncate && !table.references && !table.trigger, ).length, declaredReadOnlyTables: RUNTIME_READ_ONLY_TABLES.length, declaredReadUpdateTables: RUNTIME_READ_UPDATE_TABLES.length, declaredReadInsertTables: RUNTIME_READ_INSERT_TABLES.length, declaredReadInsertUpdateTables: RUNTIME_READ_INSERT_UPDATE_TABLES.length, declaredProtectedNoDirectDmlTables: PROTECTED_NO_DIRECT_DML_TABLES.length, declaredTargetSchemaCapabilities: RUNTIME_TARGET_SCHEMA_CAPABILITY_ROUTINES.length, executableTargetSchemaCapabilities: posture.targetRoutines.filter( (routine) => routine.execute && !routine.publicExecute && routine.securityDefiner, ).length, }), ); } finally { await client.close(); }