Skip to content

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

TypeScript

fix: reject forbidden runtime column ACLs

Josuéd02e291edc14
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index d83e45462..7b29f65cb 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.735",
+ "version": "0.1.736",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.735",
+ "version": "0.1.736",
"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 ea2474f28..e793ae989 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.735",
+ "version": "0.1.736",
"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 a084e4dc1..b11e72086 100644
--- a/control-api/test/db.realPostgresMigration.integration.test.ts
+++ b/control-api/test/db.realPostgresMigration.integration.test.ts
@@ -100,6 +100,19 @@ verify_runtime_access_contract`,
return queries
}
+const deniedRuntimeColumnPrivileges = [
+ { privilege: 'SELECT', relation: 'gfs_blob_manifests', column: 'blob_key' },
+ { privilege: 'INSERT', relation: 'gfs_blob_manifests', column: 'blob_key' },
+ { privilege: 'UPDATE', relation: 'password_verification_work', column: 'owner_instance' },
+ { privilege: 'REFERENCES', relation: 'gfs_blob_manifests', column: 'blob_key' },
+] as const
+
+const columnPrivilegeFixtures = deniedRuntimeColumnPrivileges.flatMap(grant => [
+ { ...grant, principal: 'direct' as const },
+ { ...grant, principal: 'public' as const },
+ { ...grant, principal: 'inherited' as const },
+])
+
async function relationPrivileges(pool: Pool, roleName: string): Promise<PrivilegeExpectation> {
const result = await pool.query<{
relation_name: string
@@ -236,6 +249,59 @@ describeRealPostgres('control-api real Postgres migrations', () => {
expect(await violations(relationQuery)).toBe(0)
}, 60_000)
+ it.each(columnPrivilegeFixtures)(
+ 'rejects $principal column-level $privilege on $relation',
+ async ({ privilege, relation, column, principal }) => {
+ const { initDb } = await import('../src/db.js')
+ await initDb({ connect: () => dbPool.connect() })
+ const [relationQuery] = deploymentRuntimeAccessQueries()
+ const relationName = quoteIdent(relation)
+ const columnName = quoteIdent(column)
+ const inheritedRole = `runtime_column_acl_probe_${randomBytes(6).toString('hex')}`
+ const grantee = principal === 'public' ? 'PUBLIC' : quoteIdent('control_api_runtime')
+ const inherited = principal === 'inherited'
+ const assertClean = async () => {
+ const result = await dbPool.query<{ table_access: boolean; column_access: boolean }>(
+ `SELECT has_table_privilege('control_api_runtime', $1, $2) AS table_access,
+ has_any_column_privilege('control_api_runtime', $1, $2) AS column_access`,
+ [relation, privilege]
+ )
+ expect(result.rows[0]).toEqual({ table_access: false, column_access: true })
+ const violationCount = Number(
+ (await dbPool.query({ text: relationQuery, rowMode: 'array' })).rows[0][0]
+ )
+ expect(violationCount).toBe(1)
+ }
+
+ try {
+ if (inherited) {
+ await dbPool.query(`CREATE ROLE ${quoteIdent(inheritedRole)} NOLOGIN INHERIT`)
+ }
+ const grantTarget = inherited ? quoteIdent(inheritedRole) : grantee
+ await dbPool.query(
+ `GRANT ${privilege} (${columnName}) ON TABLE ${relationName} TO ${grantTarget}`
+ )
+ if (inherited) {
+ await dbPool.query(`GRANT ${quoteIdent(inheritedRole)} TO control_api_runtime`)
+ }
+
+ await assertClean()
+ } finally {
+ if (inherited) {
+ await dbPool.query(`REVOKE ${quoteIdent(inheritedRole)} FROM control_api_runtime`)
+ await dbPool.query(
+ `REVOKE ${privilege} (${columnName}) ON TABLE ${relationName} FROM ${quoteIdent(inheritedRole)}`
+ )
+ await dbPool.query(`DROP ROLE IF EXISTS ${quoteIdent(inheritedRole)}`)
+ } else {
+ await dbPool.query(
+ `REVOKE ${privilege} (${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 6e73f1dfc..c2cda8a60 100755
--- a/deploy/scripts/run-control-api-db-migration.sh
+++ b/deploy/scripts/run-control-api-db-migration.sh
@@ -602,6 +602,15 @@ verify_runtime_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(
+ 'control_api_runtime',
+ actual.oid,
+ required.privilege_name
+ )
+ )
)
SELECT
(SELECT COUNT(*) FROM relation_coverage_violations)
diff --git a/scripts/tests/test-control-api-runtime-access-contract.sh b/scripts/tests/test-control-api-runtime-access-contract.sh
index b68808c06..f38d98c05 100755
--- a/scripts/tests/test-control-api-runtime-access-contract.sh
+++ b/scripts/tests/test-control-api-runtime-access-contract.sh
@@ -21,6 +21,7 @@ if [[ "$relation_count" != "100" || "$duplicate_count" != "0" || "$invalid_count
! 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 'has_any_column_privilege(' "$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', 'insert_delete'))" "$MIGRATION_SCRIPT" || \