Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(gfs): declare least-privilege operator link access
Alfredo Lopezdb18ddf60ed7
diff --git a/control-api/test/db.realPostgresMigration.integration.test.ts b/control-api/test/db.realPostgresMigration.integration.test.tsindex 9746b6102..84f6d267f 100644--- a/control-api/test/db.realPostgresMigration.integration.test.ts+++ b/control-api/test/db.realPostgresMigration.integration.test.ts@@ -386,6 +386,7 @@ describeRealPostgres('control-api real Postgres migrations', () => {'llm_allowed_models','llm_allowed_models_audit','llm_catalog_sync_runs',+ 'gfs_desktop_operator_links',] as constconst controlApiRelations = await relationPrivileges(dbPool, 'control_api_runtime')const expectedControlApiRelations: Record<string, string[]> = {@@ -402,6 +403,7 @@ describeRealPostgres('control-api real Postgres migrations', () => {llm_allowed_models: ['DELETE', 'INSERT', 'SELECT', 'UPDATE'],llm_allowed_models_audit: ['INSERT', 'SELECT'],llm_catalog_sync_runs: ['INSERT', 'SELECT'],+ gfs_desktop_operator_links: ['DELETE', 'INSERT', 'SELECT'],}for (const relation of exactControlApiRelations) {expectPrivileges(@@ -411,6 +413,90 @@ describeRealPostgres('control-api real Postgres migrations', () => {}expectPrivileges([...(controlApiRelations.gfs_blob_manifests ?? new Set())], [])+ const linkUserId = randomUUID()+ const linkAdminId = randomUUID()+ const linkRuntimeClient = await dbPool.connect()+ try {+ await linkRuntimeClient.query('BEGIN')+ await linkRuntimeClient.query(+ `INSERT INTO users (id, email, name)+ VALUES ($1, $2, 'GFS desktop operator privilege test')`,+ [linkUserId, `gfs-link-${linkUserId}@example.test`]+ )+ await linkRuntimeClient.query(+ `INSERT INTO control_admin_users (+ id, username, password_hash, role, status+ ) VALUES ($1, $2, 'gfs-link-test-hash', 'admin', 'active')`,+ [linkAdminId, `gfs-link-${linkAdminId}`]+ )++ const privilegeState = await linkRuntimeClient.query<{+ privilege_name: string+ allowed: boolean+ }>(+ `SELECT privilege.privilege_name,+ has_table_privilege(+ 'control_api_runtime',+ 'public.gfs_desktop_operator_links',+ privilege.privilege_name+ ) AS allowed+ FROM (VALUES+ ('SELECT'), ('INSERT'), ('UPDATE'), ('DELETE'),+ ('TRUNCATE'), ('REFERENCES'), ('TRIGGER')+ ) privilege(privilege_name)+ ORDER BY privilege.privilege_name`+ )+ expect(privilegeState.rows).toEqual([+ { privilege_name: 'DELETE', allowed: true },+ { privilege_name: 'INSERT', allowed: true },+ { privilege_name: 'REFERENCES', allowed: false },+ { privilege_name: 'SELECT', allowed: true },+ { privilege_name: 'TRIGGER', allowed: false },+ { privilege_name: 'TRUNCATE', allowed: false },+ { privilege_name: 'UPDATE', allowed: false },+ ])++ await linkRuntimeClient.query('SET LOCAL ROLE control_api_runtime')+ await linkRuntimeClient.query(+ `INSERT INTO gfs_desktop_operator_links (user_id, control_admin_id, source)+ VALUES ($1, $2, 'initial_setup')`,+ [linkUserId, linkAdminId]+ )+ const linked = await linkRuntimeClient.query<{ user_id: string; control_admin_id: string }>(+ `SELECT user_id::text, control_admin_id::text+ FROM gfs_desktop_operator_links+ WHERE user_id = $1`,+ [linkUserId]+ )+ expect(linked.rows).toEqual([{ user_id: linkUserId, control_admin_id: linkAdminId }])++ await linkRuntimeClient.query('SAVEPOINT deny_link_update')+ await expect(+ linkRuntimeClient.query(+ `UPDATE gfs_desktop_operator_links+ SET source = 'initial_setup'+ WHERE user_id = $1`,+ [linkUserId]+ )+ ).rejects.toThrow(/permission denied/)+ await linkRuntimeClient.query('ROLLBACK TO SAVEPOINT deny_link_update')++ await linkRuntimeClient.query('SAVEPOINT deny_link_truncate')+ await expect(+ linkRuntimeClient.query('TRUNCATE TABLE gfs_desktop_operator_links')+ ).rejects.toThrow(/permission denied/)+ await linkRuntimeClient.query('ROLLBACK TO SAVEPOINT deny_link_truncate')++ await linkRuntimeClient.query(+ `DELETE FROM gfs_desktop_operator_links+ WHERE user_id = $1`,+ [linkUserId]+ )+ } finally {+ await linkRuntimeClient.query('ROLLBACK')+ linkRuntimeClient.release()+ }+const maintenanceRelations = await relationPrivileges(dbPool, 'trace_maintenance_runtime')const expectedMaintenanceRelations: Record<string, string[]> = {administrative_events: ['SELECT'],diff --git a/deploy/scripts/control-api-runtime-access-profiles.tsv b/deploy/scripts/control-api-runtime-access-profiles.tsvindex db3459be8..d9cbe399f 100644--- a/deploy/scripts/control-api-runtime-access-profiles.tsv+++ b/deploy/scripts/control-api-runtime-access-profiles.tsv@@ -10,6 +10,7 @@ control_admin_revoked_tokens legacy_dmlcontrol_admin_users legacy_dmlgfs_audit legacy_dmlgfs_blob_manifests none+gfs_desktop_operator_links link_lifecyclegfs_grants legacy_dmlgfs_resources legacy_dmlgfs_shares legacy_dmldiff --git a/deploy/scripts/run-control-api-db-migration.sh b/deploy/scripts/run-control-api-db-migration.shindex 6b80d77a8..52ded6871 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|none)$/ { exit 4 }+ $2 !~ /^(legacy_dml|upsert|append|read|link_lifecycle|none)$/ { exit 4 }seen[$1]++ { exit 5 }{count++@@ -583,11 +583,13 @@ verify_runtime_access_contract() {FROM expected_access expectedJOIN actual_relations actual USING (relation_name)CROSS JOIN LATERAL (+ -- link_lifecycle deliberately permits only the explicit create/revoke+ -- operations for current-state identity links; UPDATE stays denied.VALUES('SELECT', expected.access_profile != 'none'),- ('INSERT', expected.access_profile IN ('legacy_dml', 'upsert', 'append')),+ ('INSERT', expected.access_profile IN ('legacy_dml', 'upsert', 'append', 'link_lifecycle')),('UPDATE', expected.access_profile IN ('legacy_dml', 'upsert')),- ('DELETE', expected.access_profile = 'legacy_dml'),+ ('DELETE', expected.access_profile IN ('legacy_dml', 'link_lifecycle')),('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.shnew file mode 100755index 000000000..c579eaf33--- /dev/null+++ b/scripts/tests/test-control-api-runtime-access-contract.sh@@ -0,0 +1,25 @@+#!/usr/bin/env bash+set -euo pipefail++ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"+PROFILE_FILE="$ROOT_DIR/deploy/scripts/control-api-runtime-access-profiles.tsv"+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")"++[[ "$relation_count" == "81" ]]+[[ "$duplicate_count" == "0" ]]+[[ "$invalid_count" == "0" ]]+grep -qx $'gfs_desktop_operator_links\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 -Fq "('UPDATE', expected.access_profile IN ('legacy_dml', 'upsert'))" "$MIGRATION_SCRIPT"+grep -Fq "('DELETE', expected.access_profile IN ('legacy_dml', 'link_lifecycle'))" "$MIGRATION_SCRIPT"+grep -Fq "('TRUNCATE', false)" "$MIGRATION_SCRIPT"+grep -Fq "('REFERENCES', false)" "$MIGRATION_SCRIPT"+grep -Fq "('TRIGGER', false)" "$MIGRATION_SCRIPT"++printf 'PASS: control-api runtime link_lifecycle contract is explicit and least privilege\n'diff --git a/scripts/tests/test-gcp-scripts.sh b/scripts/tests/test-gcp-scripts.shindex 9f68f875a..1f834a1e4 100755--- a/scripts/tests/test-gcp-scripts.sh+++ b/scripts/tests/test-gcp-scripts.sh@@ -1461,17 +1461,18 @@ 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|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|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)$/) { count++ } END { print count + 0 }' "$sequence_profile_file")"- if [[ "$relation_count" == "80" && "$duplicate_count" == "0" && "$invalid_count" == "0" ]] && \+ if [[ "$relation_count" == "81" && "$duplicate_count" == "0" && "$invalid_count" == "0" ]] && \grep -qx $'llm_allowed_models\tlegacy_dml' "$profile_file" && \grep -qx $'member_registration_credentials\tupsert' "$profile_file" && \grep -qx $'llm_allowed_models_audit\tappend' "$profile_file" && \grep -qx $'llm_catalog_sync_runs\tappend' "$profile_file" && \grep -qx $'plugin_workload_sdk_spend_outcomes\tappend' "$profile_file" && \+ grep -qx $'gfs_desktop_operator_links\tlink_lifecycle' "$profile_file" && \[[ "$sequence_count" == "7" && "$sequence_duplicate_count" == "0" && "$sequence_invalid_count" == "0" ]] && \grep -qx $'member_registration_credentials_id_seq\tconsume' "$sequence_profile_file" && \[[ "$migration_script" != *'RUNTIME_ACCESS_PROFILES_FILE:-'* ]] && \@@ -1479,6 +1480,9 @@ assert_control_api_runtime_access_contract_is_exact() {[[ "$migration_script" == *'FULL OUTER JOIN actual_sequences'* ]] && \[[ "$migration_script" == *'IS DISTINCT FROM required.allowed'* ]] && \[[ "$migration_script" == *'has_sequence_privilege('* ]] && \+ [[ "$migration_script" == *"expected.access_profile IN ('legacy_dml', 'upsert', 'append', 'link_lifecycle')"* ]] && \+ [[ "$migration_script" == *"expected.access_profile IN ('legacy_dml', 'link_lifecycle')"* ]] && \+ [[ "$migration_script" == *"('UPDATE', expected.access_profile IN ('legacy_dml', 'upsert'))"* ]] && \[[ "$migration_script" == *"('TRUNCATE', false)"* ]] && \[[ "$migration_script" == *"('REFERENCES', false)"* ]] && \[[ "$migration_script" == *"('TRIGGER', false)"* ]]; then