Prompt
What's the best way to structure authorization in a multi-tenant SaaS platform with both customer admins and end users?
Latest observation
A good multi-tenant SaaS authorization model usually has three layers:
- Tenant isolation — who can access which customer/org data at all
- Role-based permissions — what a user can do within a tenant
- Resource-level rules — what specific records they can see or modify
The best practical approach is usually:
1) Model tenants first
Treat every customer as a tenant with a strict boundary.
- Every user belongs to one or more tenants
- Every business record carries a
tenant_id - Every query is scoped by
tenant_idby default - Never rely on UI filtering alone; enforce it in the backend and database
This prevents cross-customer data leaks.
2) Use roles, but keep them tenant-scoped
Have roles assigned within a tenant, not globally.
Typical roles:
- Tenant Admin: manage users, billing, settings, integrations
- Manager/Supervisor: manage team data, approve actions
- End User: use the product, edit their own objects, limited visibility
- Read-only/Auditor: view-only access
Store something like:
userstenantstenant_memberships(user_id,tenant_id,role, status)
This lets the same user be:
- an admin in one tenant
- a normal user in another
3) Separate “role” from “permission”
Don’t hard-code business logic directly into roles.
Instead:
- Define permissions like:
user.createuser.inviteinvoice.readinvoice.approveproject.update
- Map roles to permissions
This gives you flexibility when customers want custom access patterns.
Example:
- Tenant Admin → all permissions
- Manager → read/write team resources, no billing
- End User → read/write own items only
4) Add resource ownership and scope rules
Roles alone usually aren’t enough.
Common rules:
- User can edit only resources they own
- Manager can edit resources in their team
- Admin can access all tenant resources
- Some actions depend on status, org unit, or assignment
This is where ABAC-style rules help:
resource.tenant_id == user.tenant_idresource.owner_id == user.idresource.team_id in user.team_idsuser.role == admin
A very common pattern is:
- RBAC for coarse access
- ABAC/resource rules for fine-grained access
5) Enforce authorization centrally
Put authorization in a single shared layer, not spread across controllers and UI.
Good places to enforce:
- API middleware / service layer
- Policy engine
- Database row-level security if available
Avoid:
- checking permissions only in frontend
- repeating ad hoc
if (admin)logic everywhere
A policy layer makes behavior consistent and testable.
6) Consider row-level security for strong tenant isolation
If you use Postgres or similar, row-level security (RLS) is excellent for SaaS tenant isolation.
Benefits:
- protects against accidental query bugs
- enforces tenant boundaries at the DB level
- useful as a defense-in-depth layer
Typical approach:
- app sets current
tenant_id/ session context - DB policies restrict rows by tenant and permission context
This is especially valuable for high-trust data.
7) Design for customer-admin and end-user separation
A clean split is:
Customer admins
Can:
- manage tenant users
- assign roles
- configure tenant settings
- see all tenant data
- manage billing/integrations
End users
Can:
- access only assigned resources
- create/update limited objects
- view only their own or team-owned data
- no tenant-wide admin controls
This makes the UX and policy model much clearer.
8) Use invitation and membership state
In SaaS, users often aren’t immediately active.
Track membership states like:
- invited
- active
- suspended
- removed
Authorization should consider membership status, not just role.
Example:
- active membership required to access tenant
- suspended users cannot log in, even if they still exist in the database
9) Keep “super admin” separate from tenant admins
If you have internal staff, create a separate global admin model.
Internal admins should:
- be clearly distinguished from customer tenant admins
- require extra audit logging
- ideally use impersonation with explicit controls
Do not mix internal support access with customer roles.
10) Audit everything important
Log:
- role changes
- permission changes
- tenant membership changes
- destructive actions
- admin impersonation
- cross-resource access denials
This is especially important in multi-tenant systems.
Recommended practical pattern
For most SaaS products, the best default is:
- Tenant-scoped RBAC
- plus resource ownership/team-based ABAC
- enforced in a central policy layer
- with tenant_id enforced everywhere
- and optionally DB row-level security for defense in depth
Simple data model example
tenants(id, name, ...)users(id, email, ...)tenant_memberships(id, tenant_id, user_id, role, status)permissions(id, key)role_permissions(role, permission_id)- business tables include
tenant_id, plus optionalowner_id,team_id
Rule of thumb
If you’re asking “should this user be allowed to do X on Y?” the answer should come from:
- Is the user a member of this tenant?
- What role do they have in this tenant?
- Do resource-specific rules allow this action?
- Is their membership active?
If you want, I can also give you:
- a reference authorization schema
- a policy design example
- or a Postgres RLS pattern for multi-tenant SaaS.