Skip to content

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

TypeScript

fix: align password tables with deployment access contract

Josué5cf3d68f32db
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index e82848a8b..d83e45462 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.734",
+ "version": "0.1.735",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.734",
+ "version": "0.1.735",
"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 f674910c0..ea2474f28 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.734",
+ "version": "0.1.735",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/db.realPostgresMigration.integration.test.ts b/control-api/test/db.realPostgresMigration.integration.test.ts
index be4d9bb61..a084e4dc1 100644
--- a/control-api/test/db.realPostgresMigration.integration.test.ts
+++ b/control-api/test/db.realPostgresMigration.integration.test.ts
@@ -1,6 +1,9 @@
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import express, { type Request as ExpressRequest } from 'express'
+import { execFileSync } from 'node:child_process'
import { randomBytes, randomUUID } from 'node:crypto'
+import { readFileSync } from 'node:fs'
+import { fileURLToPath } from 'node:url'
import { Pool, type PoolClient } from 'pg'
import request from 'supertest'
import { config } from '../src/config.js'
@@ -57,6 +60,46 @@ function expectPrivileges(actual: string[], expected: string[]): void {
expect([...actual].sort()).toEqual([...expected].sort())
}
+function deploymentRuntimeAccessQueries(): string[] {
+ const script = readFileSync(
+ new URL('../../deploy/scripts/run-control-api-db-migration.sh', import.meta.url),
+ 'utf8'
+ )
+ const start = script.indexOf('\nruntime_access_contract_values() {')
+ const end = script.indexOf('\nverify_trace_maintenance_access_contract() {', start)
+ if (start < 0 || end < 0) throw new Error('Deployment runtime access verifier is missing')
+
+ // Execute the real profile parser and verifier to capture their SQL, without
+ // entering the migration script's Kubernetes operations or copying its policy.
+ const output = execFileSync(
+ 'bash',
+ [
+ '-c',
+ `set -euo pipefail
+RUNTIME_ACCESS_PROFILES_FILE="$1"
+RUNTIME_SEQUENCE_ACCESS_PROFILES_FILE="$2"
+die() { printf '%s\\n' "$*" >&2; exit 1; }
+assert_db_query_equals() { printf '%s\\0' "$3"; }
+${script.slice(start, end)}
+verify_runtime_access_contract`,
+ 'deployment-runtime-access',
+ fileURLToPath(
+ new URL('../../deploy/scripts/control-api-runtime-access-profiles.tsv', import.meta.url)
+ ),
+ fileURLToPath(
+ new URL(
+ '../../deploy/scripts/control-api-runtime-sequence-access-profiles.tsv',
+ import.meta.url
+ )
+ ),
+ ],
+ { encoding: 'utf8', timeout: 10_000 }
+ )
+ const queries = output.split('\0').filter(Boolean)
+ expect(queries).toHaveLength(2)
+ return queries
+}
+
async function relationPrivileges(pool: Pool, roleName: string): Promise<PrivilegeExpectation> {
const result = await pool.query<{
relation_name: string
@@ -157,6 +200,42 @@ describeRealPostgres('control-api real Postgres migrations', () => {
}
})
+ it('verifies the deployment access contract against migrated schema and rejects drift', async () => {
+ const { initDb } = await import('../src/db.js')
+ await initDb({ connect: () => dbPool.connect() })
+ const [relationQuery, sequenceQuery] = deploymentRuntimeAccessQueries()
+ const violations = async (sql: string) =>
+ Number((await dbPool.query({ text: sql, rowMode: 'array' })).rows[0][0])
+
+ expect(await violations(relationQuery)).toBe(0)
+ expect(await violations(sequenceQuery)).toBe(0)
+ const privileges = await relationPrivileges(dbPool, 'control_api_runtime')
+ for (const relation of ['password_identifier_state', 'password_verification_pace']) {
+ expectPrivileges([...privileges[relation]], ['SELECT', 'INSERT', 'UPDATE', 'DELETE'])
+ }
+ expectPrivileges([...privileges.password_verification_work], ['SELECT', 'INSERT', 'DELETE'])
+
+ try {
+ await dbPool.query('GRANT UPDATE ON password_verification_work TO control_api_runtime')
+ expect(await violations(relationQuery)).toBe(1)
+ } finally {
+ await dbPool.query('REVOKE UPDATE ON password_verification_work FROM control_api_runtime')
+ }
+ try {
+ await dbPool.query('REVOKE DELETE ON password_verification_work FROM control_api_runtime')
+ expect(await violations(relationQuery)).toBe(1)
+ } finally {
+ await dbPool.query('GRANT DELETE ON password_verification_work TO control_api_runtime')
+ }
+ try {
+ await dbPool.query('CREATE TABLE runtime_access_contract_probe (id INTEGER)')
+ expect(await violations(relationQuery)).toBe(1)
+ } finally {
+ await dbPool.query('DROP TABLE IF EXISTS runtime_access_contract_probe')
+ }
+ expect(await violations(relationQuery)).toBe(0)
+ }, 60_000)
+
it('applies initDb twice and leaves the exact runtime privilege envelopes', async () => {
const { initDb } = await import('../src/db.js')
const connector = { connect: () => dbPool.connect() }
diff --git a/deploy/scripts/control-api-runtime-access-profiles.tsv b/deploy/scripts/control-api-runtime-access-profiles.tsv
index 57020cdfd..7b3291d2a 100644
--- a/deploy/scripts/control-api-runtime-access-profiles.tsv
+++ b/deploy/scripts/control-api-runtime-access-profiles.tsv
@@ -49,6 +49,9 @@ mcp_secret_rollback_permits legacy_dml
notification_deliveries legacy_dml
dynamic_clients legacy_dml
oauth_grants legacy_dml
+password_identifier_state legacy_dml
+password_verification_pace legacy_dml
+password_verification_work insert_delete
plugin_workload_sdk_credential_ticket_jtis legacy_dml
plugin_workload_sdk_invocation_attempts legacy_dml
plugin_workload_sdk_grants legacy_dml
diff --git a/deploy/scripts/run-control-api-db-migration.sh b/deploy/scripts/run-control-api-db-migration.sh
index a8019687d..6e73f1dfc 100755
--- a/deploy/scripts/run-control-api-db-migration.sh
+++ b/deploy/scripts/run-control-api-db-migration.sh
@@ -443,7 +443,7 @@ runtime_access_contract_values() {
/^[[:space:]]*#/ || /^[[:space:]]*$/ { next }
NF != 2 { exit 2 }
$1 !~ /^[a-z][a-z0-9_]*$/ { exit 3 }
- $2 !~ /^(legacy_dml|upsert|append|read|link_lifecycle|none)$/ { exit 4 }
+ $2 !~ /^(legacy_dml|upsert|append|read|link_lifecycle|insert_delete|none)$/ { exit 4 }
seen[$1]++ { exit 5 }
{
count++
@@ -586,11 +586,13 @@ verify_runtime_access_contract() {
-- link_lifecycle deliberately permits create plus governed tombstone
-- transitions. Physical DELETE remains denied so history cannot be
-- erased by the runtime role.
+ -- insert_delete permits immutable reservation creation and release,
+ -- while UPDATE and privileged table operations remain denied.
VALUES
('SELECT', expected.access_profile != 'none'),
- ('INSERT', expected.access_profile IN ('legacy_dml', 'upsert', 'append', 'link_lifecycle')),
+ ('INSERT', expected.access_profile IN ('legacy_dml', 'upsert', 'append', 'link_lifecycle', 'insert_delete')),
('UPDATE', expected.access_profile IN ('legacy_dml', 'upsert', 'link_lifecycle')),
- ('DELETE', expected.access_profile IN ('legacy_dml')),
+ ('DELETE', expected.access_profile IN ('legacy_dml', 'insert_delete')),
('TRUNCATE', false),
('REFERENCES', false),
('TRIGGER', false)
diff --git a/scripts/tests/test-control-api-runtime-access-contract.sh b/scripts/tests/test-control-api-runtime-access-contract.sh
index bbf5f836e..b68808c06 100755
--- a/scripts/tests/test-control-api-runtime-access-contract.sh
+++ b/scripts/tests/test-control-api-runtime-access-contract.sh
@@ -7,9 +7,9 @@ MIGRATION_SCRIPT="$ROOT_DIR/deploy/scripts/run-control-api-db-migration.sh"
relation_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ { count++ } END { print count + 0 }' "$PROFILE_FILE")"
duplicate_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ { seen[$1]++ } END { for (name in seen) if (seen[name] > 1) count++ } END { print count + 0 }' "$PROFILE_FILE")"
-invalid_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ && (NF != 2 || $1 !~ /^[a-z][a-z0-9_]*$/ || $2 !~ /^(legacy_dml|upsert|append|read|link_lifecycle|none)$/) { count++ } END { print count + 0 }' "$PROFILE_FILE")"
+invalid_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ && (NF != 2 || $1 !~ /^[a-z][a-z0-9_]*$/ || $2 !~ /^(legacy_dml|upsert|append|read|link_lifecycle|insert_delete|none)$/) { count++ } END { print count + 0 }' "$PROFILE_FILE")"
-if [[ "$relation_count" != "97" || "$duplicate_count" != "0" || "$invalid_count" != "0" ]] || \
+if [[ "$relation_count" != "100" || "$duplicate_count" != "0" || "$invalid_count" != "0" ]] || \
! grep -qx $'dynamic_clients\tlegacy_dml' "$PROFILE_FILE" || \
! grep -qx $'entity_change_feed\tnone' "$PROFILE_FILE" || \
! grep -qx $'entity_change_outbox\tnone' "$PROFILE_FILE" || \
@@ -17,10 +17,13 @@ if [[ "$relation_count" != "97" || "$duplicate_count" != "0" || "$invalid_count"
! grep -qx $'mcp_secret_rollback_permits\tlegacy_dml' "$PROFILE_FILE" || \
! grep -qx $'gfs_desktop_operator_links\tlink_lifecycle' "$PROFILE_FILE" || \
! grep -qx $'desktop_user_retirement_operations\tlink_lifecycle' "$PROFILE_FILE" || \
- ! grep -Fq '$2 !~ /^(legacy_dml|upsert|append|read|link_lifecycle|none)$/' "$MIGRATION_SCRIPT" || \
- ! grep -Fq "('INSERT', expected.access_profile IN ('legacy_dml', 'upsert', 'append', 'link_lifecycle'))" "$MIGRATION_SCRIPT" || \
+ ! grep -qx $'password_identifier_state\tlegacy_dml' "$PROFILE_FILE" || \
+ ! grep -qx $'password_verification_pace\tlegacy_dml' "$PROFILE_FILE" || \
+ ! grep -qx $'password_verification_work\tinsert_delete' "$PROFILE_FILE" || \
+ ! grep -Fq '$2 !~ /^(legacy_dml|upsert|append|read|link_lifecycle|insert_delete|none)$/' "$MIGRATION_SCRIPT" || \
+ ! grep -Fq "('INSERT', expected.access_profile IN ('legacy_dml', 'upsert', 'append', 'link_lifecycle', 'insert_delete'))" "$MIGRATION_SCRIPT" || \
! grep -Fq "('UPDATE', expected.access_profile IN ('legacy_dml', 'upsert', 'link_lifecycle'))" "$MIGRATION_SCRIPT" || \
- ! grep -Fq "('DELETE', expected.access_profile IN ('legacy_dml'))" "$MIGRATION_SCRIPT" || \
+ ! grep -Fq "('DELETE', expected.access_profile IN ('legacy_dml', 'insert_delete'))" "$MIGRATION_SCRIPT" || \
! grep -Fq "('TRUNCATE', false)" "$MIGRATION_SCRIPT" || \
! grep -Fq "('REFERENCES', false)" "$MIGRATION_SCRIPT" || \
! grep -Fq "('TRIGGER', false)" "$MIGRATION_SCRIPT"; then
@@ -28,4 +31,4 @@ if [[ "$relation_count" != "97" || "$duplicate_count" != "0" || "$invalid_count"
exit 1
fi
-printf 'PASS: control-api runtime link_lifecycle contract is explicit and least privilege\n'
+printf 'PASS: control-api runtime access contract is explicit and least privilege\n'
diff --git a/scripts/tests/test-gcp-scripts.sh b/scripts/tests/test-gcp-scripts.sh
index 74ccfd33c..c924e6e96 100755
--- a/scripts/tests/test-gcp-scripts.sh
+++ b/scripts/tests/test-gcp-scripts.sh
@@ -1461,12 +1461,12 @@ assert_control_api_runtime_access_contract_is_exact() {
relation_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ { count++ } END { print count + 0 }' "$profile_file")"
duplicate_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ { seen[$1]++ } END { for (name in seen) if (seen[name] > 1) count++ } END { print count + 0 }' "$profile_file")"
- invalid_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ && (NF != 2 || $1 !~ /^[a-z][a-z0-9_]*$/ || $2 !~ /^(legacy_dml|upsert|append|read|link_lifecycle|none)$/) { count++ } END { print count + 0 }' "$profile_file")"
+ invalid_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ && (NF != 2 || $1 !~ /^[a-z][a-z0-9_]*$/ || $2 !~ /^(legacy_dml|upsert|append|read|link_lifecycle|insert_delete|none)$/) { count++ } END { print count + 0 }' "$profile_file")"
sequence_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ { count++ } END { print count + 0 }' "$sequence_profile_file")"
sequence_duplicate_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ { seen[$1]++ } END { for (name in seen) if (seen[name] > 1) count++ } END { print count + 0 }' "$sequence_profile_file")"
sequence_invalid_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ && (NF != 2 || $1 !~ /^[a-z][a-z0-9_]*$/ || $2 !~ /^(legacy_rw|consume|none)$/) { count++ } END { print count + 0 }' "$sequence_profile_file")"
- if [[ "$relation_count" == "97" && "$duplicate_count" == "0" && "$invalid_count" == "0" ]] && \
+ if [[ "$relation_count" == "100" && "$duplicate_count" == "0" && "$invalid_count" == "0" ]] && \
grep -qx $'dynamic_clients\tlegacy_dml' "$profile_file" && \
grep -qx $'entity_change_feed\tnone' "$profile_file" && \
grep -qx $'entity_change_outbox\tnone' "$profile_file" && \
@@ -1481,6 +1481,9 @@ assert_control_api_runtime_access_contract_is_exact() {
grep -qx $'plugin_workload_sdk_spend_outcomes\tappend' "$profile_file" && \
grep -qx $'gfs_desktop_operator_links\tlink_lifecycle' "$profile_file" && \
grep -qx $'desktop_user_retirement_operations\tlink_lifecycle' "$profile_file" && \
+ grep -qx $'password_identifier_state\tlegacy_dml' "$profile_file" && \
+ grep -qx $'password_verification_pace\tlegacy_dml' "$profile_file" && \
+ grep -qx $'password_verification_work\tinsert_delete' "$profile_file" && \
[[ "$sequence_count" == "9" && "$sequence_duplicate_count" == "0" && "$sequence_invalid_count" == "0" ]] && \
grep -qx $'dynamic_clients_id_seq\tlegacy_rw' "$sequence_profile_file" && \
grep -qx $'entity_change_outbox_id_seq\tnone' "$sequence_profile_file" && \
@@ -1491,9 +1494,9 @@ assert_control_api_runtime_access_contract_is_exact() {
[[ "$migration_script" == *'IS DISTINCT FROM required.allowed'* ]] && \
[[ "$migration_script" == *'has_sequence_privilege('* ]] && \
[[ "$migration_script" == *"('SELECT', expected.access_profile != 'none')"* ]] && \
- [[ "$migration_script" == *"expected.access_profile IN ('legacy_dml', 'upsert', 'append', 'link_lifecycle')"* ]] && \
+ [[ "$migration_script" == *"expected.access_profile IN ('legacy_dml', 'upsert', 'append', 'link_lifecycle', 'insert_delete')"* ]] && \
[[ "$migration_script" == *"('UPDATE', expected.access_profile IN ('legacy_dml', 'upsert', 'link_lifecycle'))"* ]] && \
- [[ "$migration_script" == *"('DELETE', expected.access_profile IN ('legacy_dml'))"* ]] && \
+ [[ "$migration_script" == *"('DELETE', expected.access_profile IN ('legacy_dml', 'insert_delete'))"* ]] && \
[[ "$migration_script" == *"('TRUNCATE', false)"* ]] && \
[[ "$migration_script" == *"('REFERENCES', false)"* ]] && \
[[ "$migration_script" == *"('TRIGGER', false)"* ]]; then