gate: migration 0086, crm_migration BYPASSRLS, audit_log fix, CI test for app.tenant_id

- Migration 0086: Remove FORCE RLS from 5 global tables
- Migration 0085: crm_migration keeps BYPASSRLS for data migrations
- Migration 0085: Remove audit_log from crm_auth grants
- auth_service.py: Audit log via separate API session (crm_api with tenant context)
- tests/test_no_legacy_tenant_var.py: CI test for app.tenant_id in policies
This commit is contained in:
Agent Zero
2026-07-31 09:02:40 +02:00
parent 94318aaa4d
commit 1a980ba9d8
4 changed files with 153 additions and 17 deletions
+3 -3
View File
@@ -78,7 +78,6 @@ AUTH_TABLES = {
"tenants": ["SELECT"],
"password_reset_tokens": ["SELECT", "INSERT", "UPDATE", "DELETE"],
"sessions": ["SELECT", "INSERT", "UPDATE", "DELETE"],
"audit_log": ["SELECT", "INSERT"],
}
WORKER_GLOBAL_TABLES = {
@@ -98,8 +97,9 @@ def upgrade() -> None:
# Step 1: Create crm_platform_admin role
_exec("DO $$ BEGIN IF NOT EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'crm_platform_admin') THEN CREATE ROLE crm_platform_admin NOSUPERUSER NOBYPASSRLS NOLOGIN; END IF; END $$;")
# Step 2: Fix crm_migration role — remove BYPASSRLS
_exec("ALTER ROLE crm_migration NOBYPASSRLS")
# Step 2: crm_migration keeps BYPASSRLS for data migrations (NOSUPERUSER)
# crm_migration is the table owner and needs to run tenant-wide data migrations
_exec("ALTER ROLE crm_migration NOSUPERUSER BYPASSRLS")
# Step 3: Transfer ALL table ownership to crm_migration
for table in ALL_TABLES: