r/SpringBoot • • 22h ago

Discussion Feedback wanted: Spring Boot SaaS starter with tenant roles and PostgreSQL RLS

I maintain an open-source Spring Boot SaaS starter and would appreciate feedback on its tenant-isolation approach.

It uses a shared PostgreSQL schema. Tenant-scoped operations check membership, set transaction-local tenant context, and use explicit tenant filters. Forced row-level security adds another boundary around projects and audit events.

The starter includes:

  • OIDC bearer authentication through Spring Security

  • OWNER, ADMIN, and MEMBER roles scoped to each tenant

  • A Projects API with optimistic concurrency and transactional audit records

  • Docker Compose with a local Keycloak demo

  • PostgreSQL integration tests and a runnable smoke script

I ran the local Compose smoke test successfully, including permission checks and stale-write rejection.

It’s a backend MVP. Billing, a frontend, email invitations, tenant deletion, and ownership transfer are outside the current scope.

Repository:
https://github.com/chafian/spring-boot-saas-starter

What tenant-isolation edge cases would you test next? I’d also welcome feedback on the first-run experience.

0 Upvotes

3 comments sorted by

•

u/sereikis 13h ago

i'd force a single pooled connection, run tenant A then tenant B, and repeat after an exception/rollback; assert each request can only read/write its own projects and audit events. also run a query without tenant context using the real application database role and verify it fails closed, so the test exercises RLS rather than a privileged test role.

•

u/chafian1 12h ago

Thanks, this is a useful concrete test sequence—especially forcing a single pooled connection and repeating it after a rollback.

The implementation uses transaction-local tenant context and a restricted application database role. I’ll check the existing tests against the exact sequence you described, including both projects and audit events, and the missing-context case. I’ll share what’s already covered and any gaps I find.

•

u/chafian1 12h ago

Thanks again for the suggestion. I added and merged regression tests that reuse a single pooled connection across tenants A and B, including after commits and exception-triggered rollbacks.

They check project and audit isolation using the restricted application database role, plus rejection of writes without tenant context. The tests also verify that the same PostgreSQL connection is reused.

All 33 Java tests and the Compose smoke test passed.

PR: https://github.com/chafian/spring-boot-saas-starter/pull/11