Skip to content

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

TypeScript

fix(deploy): rp1053-01 reject denied maintenance column grants

Josuéfe2703dc2bea
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 7b29f65cb..86e53095b 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.736",
+ "version": "0.1.737",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.736",
+ "version": "0.1.737",
"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 e793ae989..d584b970e 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.736",
+ "version": "0.1.737",
"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 b11e72086..01c8cc72d 100644
--- a/control-api/test/db.realPostgresMigration.integration.test.ts
+++ b/control-api/test/db.realPostgresMigration.integration.test.ts
@@ -100,6 +100,55 @@ verify_runtime_access_contract`,
return queries
}
+function traceMaintenanceRuntimeAccessQueries(): string[] {
+ const script = readFileSync(
+ new URL('../../deploy/scripts/run-control-api-db-migration.sh', import.meta.url),
+ 'utf8'
+ )
+ const start = script.indexOf('\nmaintenance_access_contract_values() {')
+ const end = script.indexOf('\nverify_workflow_recipes_runtime_boundary() {', start)
+ if (start < 0 || end < 0) throw new Error('Trace maintenance access verifier is missing')
+
+ // Capture SQL from the production profile parser and verifier without entering Kubernetes.
+ const output = execFileSync(
+ 'bash',
+ [
+ '-c',
+ `set -euo pipefail
+MAINTENANCE_ACCESS_PROFILES_FILE="$1"
+MAINTENANCE_SEQUENCE_ACCESS_PROFILES_FILE="$2"
+MAINTENANCE_FUNCTION_ACCESS_PROFILES_FILE="$3"
+die() { printf '%s\\n' "$*" >&2; exit 1; }
+assert_db_query_equals() { printf '%s\\0' "$3"; }
+${script.slice(start, end)}
+verify_trace_maintenance_access_contract`,
+ 'trace-maintenance-runtime-access',
+ fileURLToPath(
+ new URL(
+ '../../deploy/scripts/trace-maintenance-runtime-access-profiles.tsv',
+ import.meta.url
+ )
+ ),
+ fileURLToPath(
+ new URL(
+ '../../deploy/scripts/trace-maintenance-runtime-sequence-access-profiles.tsv',
+ import.meta.url
+ )
+ ),
+ fileURLToPath(
+ new URL(
+ '../../deploy/scripts/trace-maintenance-runtime-function-access-profiles.tsv',
+ import.meta.url
+ )
+ ),
+ ],
+ { encoding: 'utf8', timeout: 10_000 }
+ )
+ const queries = output.split('\0').filter(Boolean)
+ expect(queries).toHaveLength(3)
+ return queries
+}
+
const deniedRuntimeColumnPrivileges = [
{ privilege: 'SELECT', relation: 'gfs_blob_manifests', column: 'blob_key' },
{ privilege: 'INSERT', relation: 'gfs_blob_manifests', column: 'blob_key' },
@@ -302,6 +351,66 @@ describeRealPostgres('control-api real Postgres migrations', () => {
}
)
+ it.each(['direct', 'public', 'inherited'] as const)(
+ 'rejects %s column-level UPDATE on governed_event_stream for trace maintenance',
+ async principal => {
+ const { initDb } = await import('../src/db.js')
+ await initDb({ connect: () => dbPool.connect() })
+ const [relationQuery, sequenceQuery, functionQuery] = traceMaintenanceRuntimeAccessQueries()
+ const relation = 'governed_event_stream'
+ const column = 'event_id'
+ const relationName = quoteIdent(relation)
+ const columnName = quoteIdent(column)
+ const inheritedRole = `trace_maintenance_acl_probe_${randomBytes(6).toString('hex')}`
+ const grantee = principal === 'public' ? 'PUBLIC' : quoteIdent('trace_maintenance_runtime')
+ const inherited = principal === 'inherited'
+ const violationCount = async (query: string) =>
+ Number((await dbPool.query({ text: query, rowMode: 'array' })).rows[0][0])
+
+ expect(await violationCount(relationQuery)).toBe(0)
+ expect(await violationCount(sequenceQuery)).toBe(0)
+ expect(await violationCount(functionQuery)).toBe(0)
+
+ try {
+ if (inherited) {
+ await dbPool.query(`CREATE ROLE ${quoteIdent(inheritedRole)} NOLOGIN INHERIT`)
+ }
+ const grantTarget = inherited ? quoteIdent(inheritedRole) : grantee
+ await dbPool.query(
+ `GRANT UPDATE (${columnName}) ON TABLE ${relationName} TO ${grantTarget}`
+ )
+ if (inherited) {
+ await dbPool.query(`GRANT ${quoteIdent(inheritedRole)} TO trace_maintenance_runtime`)
+ }
+
+ const privileges = await dbPool.query<{
+ table_access: boolean
+ column_access: boolean
+ }>(
+ `SELECT has_table_privilege('trace_maintenance_runtime', $1, 'UPDATE') AS table_access,
+ has_any_column_privilege('trace_maintenance_runtime', $1, 'UPDATE') AS column_access`,
+ [relation]
+ )
+ expect(privileges.rows[0]).toEqual({ table_access: false, column_access: true })
+ expect(await violationCount(relationQuery)).toBe(1)
+ expect(await violationCount(sequenceQuery)).toBe(0)
+ expect(await violationCount(functionQuery)).toBe(0)
+ } finally {
+ if (inherited) {
+ await dbPool.query(`REVOKE ${quoteIdent(inheritedRole)} FROM trace_maintenance_runtime`)
+ await dbPool.query(
+ `REVOKE UPDATE (${columnName}) ON TABLE ${relationName} FROM ${quoteIdent(inheritedRole)}`
+ )
+ await dbPool.query(`DROP ROLE IF EXISTS ${quoteIdent(inheritedRole)}`)
+ } else {
+ await dbPool.query(
+ `REVOKE UPDATE (${columnName}) ON TABLE ${relationName} FROM ${grantee}`
+ )
+ }
+ }
+ }
+ )
+
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/run-control-api-db-migration.sh b/deploy/scripts/run-control-api-db-migration.sh
index c2cda8a60..51f705e0e 100755
--- a/deploy/scripts/run-control-api-db-migration.sh
+++ b/deploy/scripts/run-control-api-db-migration.sh
@@ -700,6 +700,15 @@ verify_trace_maintenance_access_contract() {
actual.oid,
required.privilege_name
) IS DISTINCT FROM required.allowed
+ OR (
+ NOT required.allowed
+ AND required.privilege_name IN ('SELECT', 'INSERT', 'UPDATE', 'REFERENCES')
+ AND has_any_column_privilege(
+ 'trace_maintenance_runtime',
+ actual.oid,
+ required.privilege_name
+ )
+ )
)
SELECT
(SELECT COUNT(*) FROM relation_coverage_violations)
diff --git a/scripts/tests/test-gcp-scripts.sh b/scripts/tests/test-gcp-scripts.sh
index 0a1e1dace..b73dadf99 100755
--- a/scripts/tests/test-gcp-scripts.sh
+++ b/scripts/tests/test-gcp-scripts.sh
@@ -1454,12 +1454,16 @@ assert_db_migration_context_fails_closed() {
}
assert_trace_maintenance_runtime_access_contract_is_exact() {
- local relation_file sequence_file function_file migration_script
+ local relation_file sequence_file function_file migration_script maintenance_contract
local relation_count sequence_count function_count
relation_file="deploy/scripts/trace-maintenance-runtime-access-profiles.tsv"
sequence_file="deploy/scripts/trace-maintenance-runtime-sequence-access-profiles.tsv"
function_file="deploy/scripts/trace-maintenance-runtime-function-access-profiles.tsv"
migration_script="$(cat deploy/scripts/run-control-api-db-migration.sh)"
+ maintenance_contract="$(
+ printf '%s\n' "$migration_script" |
+ sed -n '/^verify_trace_maintenance_access_contract() {/,/^verify_workflow_recipes_runtime_boundary() {/p'
+ )"
relation_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ { count++ } END { print count + 0 }' "$relation_file")"
sequence_count="$(awk -F '\t' '!/^[[:space:]]*(#|$)/ { count++ } END { print count + 0 }' "$sequence_file")"
@@ -1468,6 +1472,8 @@ assert_trace_maintenance_runtime_access_contract_is_exact() {
if [[ "$relation_count" == "8" && "$sequence_count" == "2" && "$function_count" == "11" ]] && \
[[ "$migration_script" == *'verify_trace_maintenance_access_contract'* ]] && \
[[ "$migration_script" == *'has_table_privilege('* ]] && \
+ [[ "$maintenance_contract" == *'has_any_column_privilege('* ]] && \
+ [[ "$maintenance_contract" == *'NOT required.allowed'* ]] && \
[[ "$migration_script" == *'has_sequence_privilege('* ]] && \
[[ "$migration_script" == *'has_function_privilege('* ]] && \
[[ "$migration_script" == *"'trace_maintenance_runtime'"* ]] && \