tracecat_owner: Tracecat treats it as its own role setup.
<db> is the Tracecat database, owned by <admin>. Quote names that contain hyphens, for example "tracecat-app". On PostgreSQL 15 and earlier, drop WITH INHERIT TRUE, SET TRUE from the grants below.
Create the roles
Run these as<admin> in <db> before the first deploy.
1
Install the extensions
Run as a role that can create them:
rds_superuser on Amazon RDS, or azure_pg_admin on Azure with vector and pg_trgm allowlisted. See pgvector.2
Lock down public
Run as the owner of
public: azure_pg_admin on Azure, the bootstrap superuser on self-managed PostgreSQL 14 and earlier, and <admin> otherwise. Run as anyone else, it only warns.3
Create the owner and the migrator
Every migrator session acts as
<owner>, so the tables migrations create belong to <owner>.4
Create the app and the dynamic owner
<app> hands new workspace schemas to <dynamic-owner>, and <owner> can still alter them in later migrations. Create <dynamic-owner> before the API first boots.5
Grant the app access
Default privileges cover the tables future migrations create. Never make
<app> a member of <owner>, or the owner of <db> or public.Check the setup
As<migrator>, this must return <owner>:
<admin>, on PostgreSQL 16 or later, this must return the values in the comments:
If a check fails
If a check fails
current_userreturns<migrator>:<owner>was granted withSET FALSE. Regrant it.- First value
t: rerun theREVOKEas the owner ofpublic, or remove<app>from<owner>. USAGEorSETisf: grant<dynamic-owner>to<app>WITH INHERIT TRUE, SET TRUE.- Last value
t: remove<app>from the role that owns<db>.
Configure Tracecat
If<dynamic-owner> isn’t named app_owner, set TRACECAT__DB_DYNAMIC_OWNER_ROLE on every service and the migrations. The Helm chart sets it from tracecat.dynamicOwnerRole. With Docker Compose, add it to each service’s environment and leave TRACECAT__DB_ROLE_LOGIN and TRACECAT__DB_ADMIN_URI empty, so Compose skips role setup. Fargate doesn’t support separate database roles yet.
-
Point the migrations at
<migrator>and every other service at<app>. To log in with IAM or Entra tokens, see Database IAM login. -
Deploy. The migrations log
No Tracecat role setup in this database. -
When the migrations finish, as
<migrator>, let<dynamic-owner>reference cases (for custom fields) and stop<app>from writing the migration version table:This must returnf:
Before each release
Role and grant changes in a release don’t apply themselves here. When the release notes mention them, apply the matching SQL before you deploy. If a migration creates schemas or tables intables_* or custom_fields_*, re-own them with ALTER SCHEMA ... OWNER TO <dynamic-owner> and ALTER TABLE ... OWNER TO <dynamic-owner>.
Row-level security
Row-level security
Keep
TRACECAT__RLS_MODE at off or shadow unless a superuser can install the dynamic-table RLS guard. To install it, run MANUAL_INSTALL_SQL from alembic/versions/4ea30f9ea491_exempt_dynamic_rls_guard_function_owner.py as a superuser after the first migration. See Tenant isolation.