Add rls-safe-mode module: Hibernate 8.0.0.CR2 HQL safe mode and PostgreSQL row-level security for @TenantId

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017ic4b6ZEVHGaYy15HAxRzy
This commit is contained in:
Ankur Mhatre
2026-12-01 08:08:31 +05:30
co-authored by Claude Sonnet 5.5
parent 54c6d606ff
commit 1c9d9423c0
20 changed files with 817 additions and 1 deletions
+20
View File
@@ -0,0 +1,20 @@
rls_enabled=true. Rows: tenantA=2, tenantB=1
tenantA HQL select count(i) from Invoice i -> 2
tenantA native select count(*) from invoice -> 2
SQL that reached PostgreSQL for the native query:
select set_config('hibernate.tenant_id', ?, true), set_config('hibernate.tenant_id_root', ?, true) [tenantA, false]
select set_config('hibernate.tenant_id', ?, true), set_config('hibernate.tenant_id_root', ?, true) [tenantA, false]
select count(*) from invoice []
tenantA native insert for tenantB -> rejected: PSQLException: ERROR: new row violates row-level security policy for table "invoice"
admin (root) HQL count -> 3 native count -> 3
no tenant set -> rejected: HibernateException: SessionFactory configured for multi-tenancy, but no tenant identifier specified
Outside Hibernate, on plain JDBC connections:
role app, no tenant variable set select count(*) -> 0
role app, after set_config('...','tenantB') select count(*) -> 1
role postgres (superuser) select count(*) -> 3
role app superuser=false bypassrls=false
role postgres superuser=true bypassrls=true
rls_enabled=false. Same data.
tenantA HQL count -> 2 native count -> 3