Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(control-api): wire dynamic_clients into the control_api_runtime access contract

Diego Zacariasa58abd6c25d9
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 7c2a1ed14..46b5a4117 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.612",
+ "version": "0.1.613",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.612",
+ "version": "0.1.613",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",
diff --git a/control-api/package.json b/control-api/package.json
index 7480cba97..65faa571e 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.612",
+ "version": "0.1.613",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/db.ts b/control-api/src/db.ts
index 98a991cfb..396bbdaf9 100644
--- a/control-api/src/db.ts
+++ b/control-api/src/db.ts
@@ -6107,6 +6107,10 @@ export const CONTROL_API_MIGRATIONS: DbMigration[] = [
version: '0116_dynamic_clients_table',
apply: applyDynamicClientsTable,
},
+ {
+ version: '0117_dynamic_clients_runtime_access',
+ apply: applyDynamicClientsRuntimeAccess,
+ },
]
async function consolidateWorkflowAllowedUsersToTriggers(db: DbClient): Promise<void> {
@@ -6321,6 +6325,23 @@ async function applyDynamicClientsTable(db: DbClient): Promise<void> {
`)
}
+async function applyDynamicClientsRuntimeAccess(db: DbClient): Promise<void> {
+ // `dynamic_clients` was created (0116) after the base migration's
+ // `GRANT ... ON ALL TABLES IN SCHEMA public`, which only reaches tables that
+ // existed when it ran. Without this the runtime role has f/f/f/f on the table
+ // and no USAGE/SELECT/UPDATE on its identity sequence, so dynamicClientStore's
+ // upsert/select/delete fail and the deploy access-contract verifier aborts on
+ // a coverage violation. dynamicClientStore runs INSERT ... ON CONFLICT DO
+ // UPDATE, SELECT and DELETE → the legacy_dml (S/I/U/D) relation profile and
+ // the legacy_rw (USAGE/SELECT/UPDATE) sequence profile, matching oauth_grants.
+ // Plain GRANTs are idempotent; the table is freshly created with no PUBLIC
+ // grant, so no REVOKE is needed to keep the least-privilege envelope exact.
+ await db.query(`
+ GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE dynamic_clients TO control_api_runtime;
+ GRANT USAGE, SELECT, UPDATE ON SEQUENCE dynamic_clients_id_seq TO control_api_runtime;
+ `)
+}
+
async function ensureSchemaMigrationsTable(db: DbClient): Promise<void> {
await db.query(`
CREATE TABLE IF NOT EXISTS schema_migrations (
diff --git a/control-api/test/db.dynamicClientsTableMigration.test.ts b/control-api/test/db.dynamicClientsTableMigration.test.ts
index 8360e306f..361c940da 100644
--- a/control-api/test/db.dynamicClientsTableMigration.test.ts
+++ b/control-api/test/db.dynamicClientsTableMigration.test.ts
@@ -17,14 +17,17 @@ describe('0116_dynamic_clients_table migration', () => {
clientQuery.mockResolvedValue({ rows: [], rowCount: 0 })
})
- it('is registered LAST (the next free version after 0115)', async () => {
+ it('is registered right after 0115, immediately before its runtime-access grant', async () => {
const { CONTROL_API_MIGRATIONS } = await import('../src/db.js')
const versions = CONTROL_API_MIGRATIONS.map(m => m.version)
expect(versions).toContain('0116_dynamic_clients_table')
- expect(versions.at(-1)).toBe('0116_dynamic_clients_table')
expect(versions.indexOf('0115_llm_allowed_models_image_input')).toBeLessThan(
versions.indexOf('0116_dynamic_clients_table')
)
+ // The runtime-access grant for the table must run after the table exists.
+ expect(versions.indexOf('0116_dynamic_clients_table')).toBeLessThan(
+ versions.indexOf('0117_dynamic_clients_runtime_access')
+ )
})
it('creates the dynamic_clients table with the encrypted columns, owner-unique constraint and issuer index', async () => {
diff --git a/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts b/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
index dfe092c13..83c56a4dc 100644
--- a/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
+++ b/control-api/test/db.oauthGrantsOwnerGeneralization.test.ts
@@ -21,7 +21,7 @@ describe('0101 oauth_grants owner generalization migration', () => {
const { CONTROL_API_MIGRATIONS } = await import('../src/db.js')
const versions = CONTROL_API_MIGRATIONS.map(m => m.version)
expect(versions).toContain('0106_oauth_grants_owner_generalization')
- expect(versions.at(-1)).toBe('0116_dynamic_clients_table')
+ expect(versions.at(-1)).toBe('0117_dynamic_clients_runtime_access')
expect(versions.indexOf('0100_seed_minimax_allowed_model')).toBeLessThan(
versions.indexOf('0106_oauth_grants_owner_generalization')
)
diff --git a/control-api/test/db.realPostgresMigration.integration.test.ts b/control-api/test/db.realPostgresMigration.integration.test.ts
index 3ee3b2c85..99c70df25 100644
--- a/control-api/test/db.realPostgresMigration.integration.test.ts
+++ b/control-api/test/db.realPostgresMigration.integration.test.ts
@@ -458,6 +458,7 @@ describeRealPostgres('control-api real Postgres migrations', () => {
'codex_subscription_oauth_states',
'gfs_desktop_operator_links',
'desktop_user_retirement_operations',
+ 'dynamic_clients',
] as const
const controlApiRelations = await relationPrivileges(dbPool, 'control_api_runtime')
const expectedControlApiRelations: Record<string, string[]> = {
@@ -480,6 +481,9 @@ describeRealPostgres('control-api real Postgres migrations', () => {
codex_subscription_oauth_states: ['INSERT', 'SELECT', 'UPDATE'],
gfs_desktop_operator_links: ['INSERT', 'SELECT', 'UPDATE'],
desktop_user_retirement_operations: ['INSERT', 'SELECT', 'UPDATE'],
+ // dynamicClientStore does INSERT ... ON CONFLICT DO UPDATE, SELECT and
+ // DELETE, so the runtime role needs the full legacy_dml envelope.
+ dynamic_clients: ['DELETE', 'INSERT', 'SELECT', 'UPDATE'],
}
for (const relation of exactControlApiRelations) {
expectPrivileges(
@@ -491,6 +495,14 @@ describeRealPostgres('control-api real Postgres migrations', () => {
expectPrivileges([...(controlApiRelations.gfs_upload_parts ?? new Set())], [])
expectPrivileges([...(controlApiRelations.gfs_upload_sessions ?? new Set())], [])
+ // The identity sequence must carry the legacy_rw (USAGE/SELECT/UPDATE)
+ // envelope; without it BIGSERIAL default fails on INSERT under the role.
+ const controlApiSequences = await sequencePrivileges(dbPool, 'control_api_runtime')
+ expectPrivileges(
+ [...(controlApiSequences.dynamic_clients_id_seq ?? new Set())],
+ ['SELECT', 'UPDATE', 'USAGE']
+ )
+
const linkUserId = randomUUID()
const linkAdminId = randomUUID()
const linkRuntimeClient = await dbPool.connect()
diff --git a/control-api/test/db.runtimeAccessMigrations.test.ts b/control-api/test/db.runtimeAccessMigrations.test.ts
index a702f8766..3b9a2bac5 100644
--- a/control-api/test/db.runtimeAccessMigrations.test.ts
+++ b/control-api/test/db.runtimeAccessMigrations.test.ts
@@ -54,4 +54,28 @@ describe('runtime access migrations', () => {
expect(deleteRevocation).toContain('FROM control_api_runtime')
expect(recordedVersions).toContain('0070_member_registration_runtime_delete_revoke')
})
+
+ it('0117 grants the control-api runtime S/I/U/D on dynamic_clients and USAGE/SELECT/UPDATE on its sequence', async () => {
+ const { initDb } = await import('../src/db.js')
+ await initDb()
+
+ const sqls = clientQuery.mock.calls.map(([sql]) => String(sql))
+ const grant = sqls.find(sql => sql.includes('ON TABLE dynamic_clients TO control_api_runtime'))
+
+ // The DML store (dynamicClientStore) does INSERT ... ON CONFLICT DO UPDATE,
+ // SELECT and DELETE, so the runtime role needs the full legacy_dml envelope
+ // on the table and legacy_rw (USAGE/SELECT/UPDATE) on its identity sequence.
+ expect(grant, 'the dynamic_clients runtime-access grant was applied').toBeDefined()
+ expect(grant).toContain(
+ 'GRANT SELECT, INSERT, UPDATE, DELETE ON TABLE dynamic_clients TO control_api_runtime'
+ )
+ expect(grant).toContain(
+ 'GRANT USAGE, SELECT, UPDATE ON SEQUENCE dynamic_clients_id_seq TO control_api_runtime'
+ )
+
+ 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('0117_dynamic_clients_runtime_access')
+ })
})
diff --git a/deploy/scripts/control-api-runtime-access-profiles.tsv b/deploy/scripts/control-api-runtime-access-profiles.tsv
index 6cbb1641b..087ca6c95 100644
--- a/deploy/scripts/control-api-runtime-access-profiles.tsv
+++ b/deploy/scripts/control-api-runtime-access-profiles.tsv
@@ -43,6 +43,7 @@ llm_provider_attempt_tickets upsert
llm_provider_attempts upsert
member_registration_credentials upsert
notification_deliveries legacy_dml
+dynamic_clients legacy_dml
oauth_grants legacy_dml
plugin_workload_sdk_credential_ticket_jtis legacy_dml
plugin_workload_sdk_invocation_attempts legacy_dml
diff --git a/deploy/scripts/control-api-runtime-sequence-access-profiles.tsv b/deploy/scripts/control-api-runtime-sequence-access-profiles.tsv
index f3ed6db69..1bb0a48fc 100644
--- a/deploy/scripts/control-api-runtime-sequence-access-profiles.tsv
+++ b/deploy/scripts/control-api-runtime-sequence-access-profiles.tsv
@@ -1,6 +1,7 @@
# public sequence<TAB>control_api_runtime access profile
administrative_events_ingest_sequence_seq consume
agent_run_events_ingest_sequence_seq consume
+dynamic_clients_id_seq legacy_rw
gfs_audit_sequence_no_seq legacy_rw
governed_event_stream_stream_sequence_seq consume
infrastructure_telemetry_events_ingest_sequence_seq consume