Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-api): member_registration_credentials store schema (0055)
Jose Ramirez4ab4428a2285
diff --git a/control-api/src/db.ts b/control-api/src/db.tsindex ea09b8b33..6b42014ca 100644--- a/control-api/src/db.ts+++ b/control-api/src/db.ts@@ -5,6 +5,7 @@ import {dropPluginWorkloadSdkSuperAdminApprovedColumn,} from './services/pluginWorkloadSdkSchema.js'import { applyRegistryConnectionSchema } from './services/registryConnectionSchema.js'+import { applyMemberRegistrationCredentialsSchema } from './services/memberRegistrationCredentialsSchema.js'export type DbClient = {query: (text: string, values?: unknown[]) => Promise<{ rows: unknown[]; rowCount: number | null }>@@ -2650,6 +2651,10 @@ const CONTROL_API_MIGRATIONS: DbMigration[] = [version: '0054_workflow_run_completed_notification_download_detection',apply: applyWorkflowRunCompletedNotificationTrigger,},+ {+ version: '0055_member_registration_credentials',+ apply: applyMemberRegistrationCredentialsSchema,+ },]async function consolidateWorkflowAllowedUsersToTriggers(db: DbClient): Promise<void> {diff --git a/control-api/src/services/memberRegistrationCredentialsSchema.ts b/control-api/src/services/memberRegistrationCredentialsSchema.tsnew file mode 100644index 000000000..c096e4812--- /dev/null+++ b/control-api/src/services/memberRegistrationCredentialsSchema.ts@@ -0,0 +1,31 @@+import type { DbClient } from '../db.js'++// ─── Hosted member-registration credentials — schema (migration 0055) ──+// One row per (bound_domain, mint). The hub binds each credential to exactly one+// destination hostname; hosted mode mints one per configured UI host (spec §8.2).+// `secret_encrypted` is AES-256-GCM via src/oauth/encryption.ts — never plaintext.+// Rotation is ops-level: UPDATE ... SET revoked_at = now(), secret_encrypted = ''+// frees the partial-unique slot; the next send/boot re-mints.+//+// Type-only dependency on db.js so db.ts can import it without a runtime cycle —+// mirrors registryConnectionSchema.ts.+export async function applyMemberRegistrationCredentialsSchema(db: DbClient): Promise<void> {+ await db.query(`+ CREATE TABLE IF NOT EXISTS member_registration_credentials (+ id BIGSERIAL PRIMARY KEY,+ bound_domain TEXT NOT NULL,+ tenant_id TEXT NOT NULL,+ kid TEXT NOT NULL,+ secret_encrypted TEXT NOT NULL,+ created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),+ revoked_at TIMESTAMPTZ+ );++ -- At most one ACTIVE credential per bound domain; revoked rows stay as audit+ -- trail (with secret_encrypted blanked). The re-mint path relies on the+ -- WHERE clause: a revoked row must not block a fresh INSERT.+ CREATE UNIQUE INDEX IF NOT EXISTS member_registration_credentials_active_domain_idx+ ON member_registration_credentials (bound_domain)+ WHERE revoked_at IS NULL;+ `)+}diff --git a/control-api/test/db.memberRegistrationCredentialsMigration.test.ts b/control-api/test/db.memberRegistrationCredentialsMigration.test.tsnew file mode 100644index 000000000..64c664738--- /dev/null+++ b/control-api/test/db.memberRegistrationCredentialsMigration.test.ts@@ -0,0 +1,43 @@+import { beforeEach, describe, expect, it, vi } from 'vitest'++const clientQuery = vi.fn()+const clientRelease = vi.fn()+const mockConnect = vi.fn()+const mockPoolCtor = vi.fn(function MockPool() {+ return { connect: mockConnect, query: vi.fn() }+})+vi.mock('pg', () => ({ Pool: mockPoolCtor }))++describe('0055_member_registration_credentials migration', () => {+ beforeEach(() => {+ vi.resetModules()+ vi.clearAllMocks()+ mockConnect.mockResolvedValue({ query: clientQuery, release: clientRelease })+ clientQuery.mockResolvedValue({ rows: [], rowCount: 0 })+ })++ it('creates the table with an active-domain partial unique index and encrypted secret column', async () => {+ const { initDb } = await import('../src/db.js')+ await initDb()+ const sqls = clientQuery.mock.calls.map(([sql]) => String(sql))+ expect(sqls).toContainEqual(+ expect.stringContaining('CREATE TABLE IF NOT EXISTS member_registration_credentials')+ )+ // The rotation re-mint path depends on the LITERAL partial-index predicate (spec §8.8).+ expect(+ sqls.some(+ sql =>+ /CREATE UNIQUE INDEX IF NOT EXISTS member_registration_credentials_active_domain_idx/.test(+ sql+ ) &&+ /ON member_registration_credentials \(bound_domain\)/.test(sql) &&+ /WHERE revoked_at IS NULL/.test(sql)+ )+ ).toBe(true)+ expect(sqls.some(sql => /secret_encrypted/.test(sql))).toBe(true)+ const recordedVersions = clientQuery.mock.calls+ .filter(([sql]) => String(sql).includes('INSERT INTO schema_migrations'))+ .map(([, params]) => (Array.isArray(params) ? params[0] : undefined))+ expect(recordedVersions).toContain('0055_member_registration_credentials')+ })+})