Prompt
multi-tenant authorization patterns
Latest observation
Multi-tenant authorization patterns are the ways you control who can access what when one application serves multiple customers/organizations/tenants.
Here are the main patterns, with tradeoffs:
1) Tenant-isolated authorization
Idea: Every request is scoped to a single tenant, and users can only access resources within that tenant.
-
How it works
- User authenticates
- Token/session includes
tenant_id - All queries and permission checks filter by
tenant_id
-
Pros
- Simple to reason about
- Strong isolation
- Easier audits and compliance
-
Cons
- Cross-tenant access is hard
- Admin/support workflows need explicit exceptions
-
Best for
- Most SaaS apps
- Strong data separation requirements
2) Role-Based Access Control (RBAC) per tenant
Idea: Users have roles within a tenant, like admin, member, viewer.
-
Example
- Alice is
adminin Tenant A - Alice is
viewerin Tenant B
- Alice is
-
Pros
- Easy to understand
- Good for common business permissions
- Works well with tenant isolation
-
Cons
- Role explosion if permissions become fine-grained
- Harder to model exceptions
-
Best for
- Standard SaaS permissioning
3) Attribute-Based Access Control (ABAC)
Idea: Authorization decisions use attributes of:
- user
- resource
- action
- environment
Example rule:
-
Allow if
user.department == resource.department -
And
user.tenant_id == resource.tenant_id -
And
resource.confidentiality != "high"unless user issecurity_admin -
Pros
- Flexible
- Handles complex business rules
- Good for dynamic policies
-
Cons
- Harder to implement and debug
- Policies can become opaque
-
Best for
- Complex enterprise systems
- Fine-grained access needs
4) Relationship-Based Access Control (ReBAC)
Idea: Authorization depends on relationships in a graph.
Example:
- user
belongs_toteam - team
ownsproject - project
containsdocument
User can access document if there’s a valid path in the relationship graph.
-
Pros
- Great for collaboration models
- Natural fit for shared resources
- Powerful for nested permissions
-
Cons
- More complex infrastructure
- Need graph traversal or specialized auth engine
-
Best for
- Collaborative apps, document sharing, org hierarchies
5) Tenant admin + delegated administration
Idea: Tenant admins manage users and permissions inside their tenant, while platform admins can act across tenants.
-
Use cases
- Customer admin invites users
- Support staff can impersonate or access tenant data with approval
-
Pros
- Scales operationally
- Matches enterprise expectations
-
Cons
- Requires careful audit logging
- Support access must be tightly controlled
6) Scoped tokens / claims-based authorization
Idea: Put tenant and permission scopes into the auth token.
Example JWT claims:
{
"sub": "user-123",
"tenant_id": "tenant-a",
"roles": ["member"],
"scopes": ["read:invoices", "write:projects"]
}
-
Pros
- Fast authorization checks
- Easy to propagate identity across services
-
Cons
- Token staleness if permissions change
- Can get large and hard to manage
-
Best for
- Microservices and APIs
Common design rules
Always enforce tenant boundaries server-side
Never rely only on the UI to hide data.
Include tenant context in every authorization decision
- request path
- session/token
- database query filters
Separate:
- Authentication = who the user is
- Tenant membership = which tenant(s) they belong to
- Authorization = what they can do in that tenant
Audit sensitive actions
Especially for:
- cross-tenant access
- impersonation
- admin overrides
- permission changes
Practical recommendation
For most SaaS products:
- Use tenant isolation
- Add RBAC within each tenant
- Introduce ABAC/ReBAC only if needed for more complex sharing
- Use scoped tokens for API efficiency
- Add audited platform-admin overrides for support
If you want, I can also provide:
- a reference architecture
- database schema patterns
- JWT/claims examples
- or a policy design for a specific stack (e.g. PostgreSQL, Node, Django, AWS, etc.).