Access control starts as one line of code, if (user.isAdmin), and stays that way until the first enterprise customer asks for an accountant who can approve invoices but not see payroll. From then on, every shortcut taken in the first version becomes a migration, and every missed check becomes a potential data exposure across customers.
This is the reference our multi-tenant articles link to for authorisation. It follows the order in which a SaaS product's access model actually grows: from roles and permissions, to tenancy, to scopes and hierarchies, to the point where roles alone run out. Then it covers what decides whether any of it holds in production: where checks are enforced, how decisions are cached, what the admin screen must offer, and what the audit trail must be able to answer.
Code should ask what a user may do. Only customers should care what the user is called.
Who You Are, What You May Do, What You Paid For
Three different questions get blurred into "permissions", and keeping them apart is the first design decision:
| Question | Name | Answered by | Changes when |
|---|---|---|---|
| Who is this? | Authentication | Login, SSO, tokens, MFA | The user signs in or out |
| What may this person do here? | Authorisation | Roles, permissions, scopes, policies | An admin changes their access |
| What has this customer bought? | Entitlement | The subscription and plan | The customer upgrades, downgrades or stops paying |
A request passes all three. A user may be authenticated, hold the reports.export permission, and still be refused because the tenant's plan does not include exports. Mixing entitlement into roles ("Pro admin", "Basic admin") doubles the role catalogue with every plan and breaks on every plan change. Entitlements get their own treatment in our subscription and billing reference; the rest of this article is authorisation.
Permissions Are the Code's Vocabulary; Roles Are the Customer's
The rule that saves the most rework: code checks permissions, never roles. A permission is a fine-grained capability named by resource and action, such as invoices.view, invoices.approve or members.invite. A role is a named bundle of permissions that a customer assigns to people.
// Brittle: every new role means finding and editing every check.
if (user.role === 'admin' || user.role === 'finance_manager') { approve(invoice); }
// Durable: roles can be created, renamed and recombined without touching this line.
if (await authz.can(user, 'invoices.approve', invoice)) { approve(invoice); }Getting granularity right takes some judgement:
- Split permissions along lines customers will want to split. View, create, edit and delete are usually separate. Approve is almost always separate from edit, because the person who prepares something is often not allowed to sign it off.
- Do not split further than any customer will ever configure. Hundreds of permissions nobody understands produce admins who grant everything.
- Treat sensitive reads as their own permission. Viewing salaries, exporting data and seeing personal contact details deserve separate permissions from ordinary viewing.
- Own the catalogue in code. Permissions are declared alongside the features that check them and synced to the database on deploy. Customers compose roles; they never invent permissions.
The Tenant Is Part of Every Grant
In a multi-tenant product, "Priya is an admin" is never a complete statement. Priya is an admin of Acme, and perhaps a viewer of the consultancy workspace Acme's auditors invited her to. The grant attaches to a membership, not to the user:
create table permissions (
key text primary key, -- 'invoices.approve'
description text not null
);
create table roles (
id uuid primary key,
tenant_id uuid, -- null = system role template
name text not null,
is_system boolean not null default false
);
create table role_permissions (
role_id uuid references roles(id),
permission_key text references permissions(key),
primary key (role_id, permission_key)
);
create table memberships (
user_id uuid not null,
tenant_id uuid not null,
role_id uuid not null references roles(id),
scope jsonb, -- optional: team, branch, own records
primary key (user_id, tenant_id, role_id)
);Several decisions are embedded in that shape:
- System roles and custom roles coexist. Owner, Admin, Member and Viewer ship as templates; customers on higher plans create their own. Custom roles belong to one tenant and are invisible to others.
- New permissions need a grant policy. When you ship
invoices.void, system roles get it by migration. Custom roles do not, because you cannot know a customer's intent, so the release notes and the role editor should flag it. Deciding this per release, deliberately, prevents both silent privilege grants and features nobody can reach. - Your own staff are not tenant members. Support and operations access is a separate, platform-level model with its own permissions, time-limited impersonation, and its own audit trail. Adding staff as hidden admins inside customer tenants makes every customer's member list a lie.
Tenancy itself, meaning how a request is routed to the right tenant's data, is covered in our multi-tenant architecture article. Authorisation assumes that boundary holds, then works inside it.
Scopes: Every Record, Some Records, Own Records
A sales rep and a sales director may hold exactly the same permissions, deals.view and deals.edit, and still need different access: the rep sees their own deals, the regional manager sees their region's, the director sees all of them. That difference is scope, and it is a separate axis from permission.
| Scope | Meaning | Typical holder |
|---|---|---|
| Tenant | Every record in the workspace | Admins, directors, finance |
| Unit | Records belonging to a team, branch or region, and those below it | Managers |
| Own | Records the user created or is assigned to | Individual contributors |
| Shared | Specific records someone explicitly shared | Guests, external collaborators |
"And those below it" introduces the first hierarchy: an organisation tree of company, region, branch and team. Checking whether a record's branch sits under the manager's region is a tree query that runs constantly, so model the tree for reads. A closure table (one row per ancestor-descendant pair) or a materialised path column (/emea/uk/london) turns "everything under my unit" into an indexed lookup rather than a recursive walk.
Keep the two kinds of hierarchy apart, because mixing them in one mechanism produces rules nobody can predict:
- A role hierarchy says Manager includes everything Member can do. Resolve it when a role is saved, by flattening it into a plain permission set, so runtime checks never walk a role graph.
- A resource hierarchy says access to a folder implies access to its documents, or access to a region implies access to its branches. This one is evaluated at check time, against the tree described above.
When Roles Run Out: Conditions and Relationships
Eventually a requirement arrives that roles and scopes cannot express. "Managers can approve expenses under 5,000; above that it needs finance." "Anyone a document was shared with can comment." Two models extend RBAC rather than replace it:
| Model | What it adds | Example rule | You need it when |
|---|---|---|---|
| RBAC with scopes | Permissions bundled into roles, limited to a slice of records | Regional managers can edit deals in their region | Almost always; it is the baseline |
| Attribute conditions (ABAC) | Rules on attributes of the user, the record or the request | Approve only if amount < user.approval_limit and status = 'submitted' | Limits, record states, and segregation of duties ("cannot approve your own request") |
| Relationship-based (ReBAC) | Access derived from a graph of relationships between users and objects | Editors of a folder are editors of every document in it; anyone shared on a document can view it | Object-level sharing and nested containers are core product features, as in document, design or project tools |
Most B2B products are well served by RBAC with scopes plus a handful of attribute conditions written as policy functions. ReBAC is worth its cost when per-object sharing is the product. Then purpose-built systems inspired by Google's Zanzibar paper, such as OpenFGA and SpiceDB, store relationship tuples and answer checks quickly. Policy engines such as Open Policy Agent and Cedar keep rules as versioned code outside the application, which helps when many services must share one set of rules.
One Decision Point, Many Enforcement Points
Authorisation logic belongs in one place: a function that takes a subject, an action, a resource and the tenant, and returns allow or deny with a reason. It should deny by default. Enforcement, however, happens in many places, and this is where real systems leak. Broken access control sits at the top of the OWASP Top 10 for good reason.
| Enforcement point | What gets missed |
|---|---|
| API routes and actions | Checking the action but not the specific record: a valid user changes an id in the URL and reads someone else's invoice |
| Lists and search | Filtering after fetching. Scope must become a query condition, or pagination returns empty pages and counts reveal what the user cannot see |
| Search indexes | Indexing documents without their access fields, so search results ignore permissions |
| Background jobs | A job runs with system rights on behalf of a user who has since lost access |
| Reports and exports | Aggregates and CSV files built from unscoped queries, covered further in our reporting and analytics reference |
| Files | Permanent public URLs for uploaded documents; use short-lived signed URLs issued after a check |
| Real-time channels | Subscribing to a channel by guessing its name |
| AI assistants and integrations | A model with a service account answers questions the asking user could never have queried. We cover this in integrating LLMs with existing systems |
The list row matters most in day-to-day code. "Can this user see record 42?" and "which records can this user see?" are different questions, and the second must be answered by turning the user's scope into a where clause, not by checking records one by one after loading them.
Caching a Decision Without Caching a Mistake
Permission checks run on almost every request, so the effective permission set for a user in a tenant is worth caching. The hard part is invalidation, because the expectation is unforgiving: when an admin removes someone's access, it is gone now, not after a cache expires.
- Version the membership. Keep a counter per user and tenant that increments on any role or scope change, and include it in the cache key. A change makes the old cache entry unreachable instantly.
- Keep permissions out of long-lived tokens. A JWT carrying a list of permissions keeps granting them until it expires, whatever the admin does. Put identity and tenant in the token; resolve permissions on the server.
- Revoke sessions on removal. Removing a member from a tenant should end their sessions in that tenant and close their real-time connections.
The Admin Screen Is Half the Feature
An access model is only as good as the admins who configure it, and they configure it through a screen. Customers judge the whole capability by that screen, and security incidents often begin with an admin who could not tell what they were granting. What the admin experience needs:
- Permissions grouped by area and written in plain language. "Approve and reject invoices" rather than
invoices.approve. - An effective-access view per user, explaining each permission: granted through the Finance role, limited to the UK region.
- Clone-and-edit for roles, because customers almost always want "Admin, minus billing".
- No escalation through delegation. An admin cannot grant a permission they do not hold, or create a role more powerful than their own.
- A protected last owner. The system refuses to remove or demote the final owner of a tenant.
- Roles chosen at invitation, so new members never get default broad access while someone remembers to fix it.
- Clear marking of what the plan does not include, so admins see why a permission has no effect rather than filing a bug.
Audit: Who Could, Who Did, and Who Changed Who Could
Two logs answer different questions, and products need both:
- The access-change log records every grant, revocation, role edit and membership change: who changed what, for whom, from what to what, and when. It answers "who gave this contractor admin rights?"
- The sensitive-action log records exports, deletions, approvals, impersonation sessions, and denied attempts on sensitive actions. Repeated denials are often the earliest sign of a compromised account or a misconfigured role.
Both are append-only, include the tenant, and record both identities when staff act through impersonation. Enterprise customers, and auditors working to frameworks such as SOC 2 or ISO/IEC 27001, commonly ask for periodic access reviews. A report listing every member, their roles, scopes and last activity, exportable per tenant, turns that review from a project into a download.
Proving the Matrix Before Customers Do
Authorisation bugs rarely show up in normal testing, because developers test as admins. Three kinds of tests catch them:
- Table-driven policy tests: every role against every sensitive action, with the expected allow or deny written out as a matrix. When someone changes a role template, the diff in the test table is the review.
- Cross-tenant tests: a user of tenant A requests tenant B's records by id and receives a not-found response, for every resource type.
- Scope tests on lists: a rep's list, count and export contain only their records, including on the last page.
Access control done well is invisible to most users and obvious to the admins and auditors who depend on it. We build it into the foundation of our web application development projects rather than retrofitting it. If your product is outgrowing isAdmin, let's talk through the model your customers need.
Frequently Asked Questions
What is the difference between roles and permissions in RBAC?
A permission is a fine-grained capability named by resource and action, such as invoices.approve or members.invite. A role is a named bundle of permissions that a customer assigns to people. Code should check permissions, never roles, so customers can create, rename and recombine roles without anyone hunting down and editing every check. Permissions are the code's vocabulary; roles are the customer's.
How does RBAC work in a multi-tenant SaaS application?
The tenant is part of every grant. A role attaches to a membership, meaning a user in a specific tenant, rather than to the user globally, so the same person can be an admin of one workspace and a viewer in another. System roles ship as templates, custom roles belong to one tenant, and your own support staff use a separate platform-level model with time-limited impersonation and its own audit trail.
When is role-based access control not enough?
When a rule depends on attributes or relationships rather than job function. A rule such as managers approving expenses under a limit, or nobody approving their own request, needs attribute conditions (ABAC). Access granted to anyone a document was shared with needs relationship-based access (ReBAC). Most B2B products are well served by RBAC with scopes plus a few attribute conditions; ReBAC earns its cost when per-object sharing is the product.
Should user permissions be stored in a JWT?
No. A JWT carrying a list of permissions keeps granting them until it expires, whatever an admin does in the meantime. Put identity and tenant in the token and resolve permissions on the server, caching the effective permission set under a key that includes a membership version counter. Any role or scope change increments that counter, so access an admin removes is gone immediately rather than after a cache expires.
How do you test role-based access control?
Developers usually test as admins, so authorization bugs slip through normal testing. Three kinds of tests catch them: table-driven policy tests listing every role against every sensitive action with the expected allow or deny; cross-tenant tests in which a user of tenant A requests tenant B's records by id and gets a not-found response; and scope tests confirming a rep's lists, counts and exports contain only their records.
