TL;DR
- Start with role-based access control (RBAC) when a tenant can explain permission grants with a short set of job roles. Roles such as billing viewer and billing approver can name stable capabilities. Scope role assignments to the tenant where the user actually holds them.
- Add attribute-based access control (ABAC) when the same role should produce different decisions according to the resource, the caller or the context. Evaluate the attributes at their source of truth. Invoice amount, workflow state, verified step-up authentication and data region are common examples.
- Consider a policy-based implementation when multiple services need the same rules, policy changes have their own approval process or customers need governed variations. Policy-based access control (PBAC) describes how rules are expressed and managed here. A policy can combine both roles and attributes. Whichever model you choose, test denials, apply the decision at the service boundary, and tie sensitive mutations to the state that was evaluated.
Where simple SaaS roles stop answering the question
A B2B payments portal has viewers and approvers. One enterprise customer asks that approvers see invoices only for their region, approve amounts under a threshold and avoid approving invoices they created. Another customer needs machine identities to ingest invoices but never approve them. The application adds approver_eu, then approver_eu_limited and separate combinations for each region and threshold. Identity administrators can assign the roles but are less certain which permission an assignment effectively grants after a policy or region changes.
Role count alone is a poor signal. A system with dozens of stable roles may still be explainable. A system with six roles can be difficult to review if several permissions actually depend on undocumented customer-specific logic. Look for repeated dimensions, frequent reassignments driven by changes to data, and decisions where two users with identical roles should see different outcomes on different resources.
Define the expected answer for one concrete operation first. Who can approve invoice 481? A clear answer names the tenant membership, permission, invoice state, ownership rule, regional eligibility and evidence of recent step-up authentication. Decide which facts are required for invoice list results as well as direct object reads. A single-object check is insufficient when an export should contain only permitted objects.
Authentication establishes identity and relevant session evidence. Authorisation uses that identity and additional facts to decide an action. A tenant membership claim from an identity provider may help bootstrap application state. The eventual decision still needs a current scope of authority, including what happens when that membership is revoked during an active session.
How RBAC, ABAC and PBAC fit together
RBAC grants permissions through roles. Separate the role assignment from the capabilities it grants. A tenant-scoped assignment answers whether a principal serves as a billing approver in that organisation. A role definition can then grant invoice.approve consistently. This gives administrators an understandable assignment workflow and makes the effects of a role change testable. NIST’s role-based access control project
ABAC includes subject, object, requested action and contextual attributes in deciding whether an action is allowed. Region is an invoice attribute. The user’s permitted regions come from an authoritative grant. Current authentication evidence can be a context attribute. ABAC makes it possible to say that an approver may approve one invoice and must be denied for another. It also makes attribute freshness, provenance and defaults part of the security design. NIST SP 800-162 on attribute-based access control
PBAC can mean different things across products. Here it means explicitly evaluating a versioned policy at a defined decision point and enforcing that result where the operation runs. The same policy may use roles, attributes or relationships. A version-controlled policy that maps tenant roles to actions still expresses RBAC semantics. Moving it to a policy engine does not fix ambiguous requirements or missing tenant checks.
Specify decision composition once. Default to deny. Treat hard boundaries such as inactive membership or a tenant mismatch as non-overridable. Let a grant enable consideration of a known action, then apply the conditions the action requires. If tenant administrators can supply a policy, constrain which inputs and actions they can affect. Do not let tenant-authored rules bypass provider controls like tenant isolation, separation of duties or the allowed currency of a transaction.
Request arrives with verified identity
→ load tenant membership and requested resource
→ check action grant
→ evaluate trusted subject, object and contextual attributes
→ enforce allow or deny at the operation
→ record the outcome and policy revision
Implement and test a layered authorisation decision
Define policy inputs and who owns them
Build one input contract per decision family. In this example, the invoice’s tenant, creator, currency, amount, lifecycle state and row version come from the database. Tenant-scoped user roles and an active membership flag come from the membership service or its authoritative table. The region grant comes from identity-specific entitlements. The step-up flag is computed by verifying authentication evidence and a freshness rule on the server. None of those facts are accepted from the client’s JSON body.
Represent actions with a closed vocabulary shared by endpoint declarations, capabilities and policy tests. Keeping a single invoice approval action makes approval rules easier to trace than scattering checks across controllers. The configuration below is a small, versioned policy document that the service loads from a trusted deployment artefact after runtime schema validation. It defines USD minor units for the approval limit, using an illustrative cap rather than a business recommendation.
{
"revision": "invoice-review-v1",
"grants": {
"billing_viewer": ["invoice.read"],
"billing_approver": ["invoice.read", "invoice.approve"]
},
"approval_amount_limit_minor": 1000000
}
A production loader should reject unknown keys and actions, malformed role definitions and negative approval amounts. Convert the configured action list to a set when constructing the policy. Close the loop by recording the active revision at service startup and during policy evaluation. An invalid update should leave a deliberate, observable state such as a previously approved last-known version or fail closed, especially for sensitive mutations. Define the maximum acceptable age of any cached policy.
Evaluate roles and trusted attributes together
The Python 3.12 example is intentionally a pure decision function. Typed objects show how the code receives validated facts. A production service still needs to authenticate the caller, build those objects, scope retrieval to the tenant, and enforce the result before writing. The return value contains an internal reason for diagnosis. Public responses should follow your application’s resource visibility policy.
from dataclasses import dataclass
@dataclass(frozen=True)
class Subject:
id: str
tenant_id: str
roles: frozenset[str]
active: bool
@dataclass(frozen=True)
class Invoice:
tenant_id: str
creator_id: str
region: str
currency: str
amount_minor: int
state: str
version: int
@dataclass(frozen=True)
class Context:
allowed_regions: frozenset[str]
step_up_valid: bool
@dataclass(frozen=True)
class Policy:
revision: str
grants: dict[str, frozenset[str]]
approval_amount_limit_minor: int
def decide(
subject: Subject, invoice: Invoice,
action: str, context: Context, policy: Policy,
) -> tuple[bool, str]:
if not subject.active or subject.tenant_id != invoice.tenant_id:
return False, "tenant_membership"
if not any(action in policy.grants.get(role, ()) for role in subject.roles):
return False, "missing_capability"
if invoice.region not in context.allowed_regions:
return False, "region_restricted"
if action == "invoice.read":
return True, "role_and_region"
if action == "invoice.approve":
# Restrict the example policy to one currency and known lifecycle state.
if (invoice.creator_id == subject.id
or invoice.currency != "USD"
or not 0 <= invoice.amount_minor <= policy.approval_amount_limit_minor
or invoice.state != "pending"
or not context.step_up_valid):
return False, "approval_requirements"
return True, "approval_policy"
return False, "unknown_action"
Start a unit-test table with an active viewer reading a permitted region, an approver authorising a pending USD invoice, and the same approver requesting their own invoice. Include an incorrect tenant, unsupported currency, stale step-up evidence and an unknown action. Mirror those tests at the API boundary with actual membership and data fixtures. Exercise list and export paths separately because they need a filter, a tested batch evaluation or another trustworthy way to resolve many decisions.
If the policy grows across services, separate the point that decides from the point that enforces. Central policy management does not have to add a network request to each call. An engine can evaluate locally from a distributed, versioned bundle. Document what happens when the policy is absent, unhealthy or too old. An outage policy for reads may differ from one for invoice approvals. Open Policy Agent policy bundles
Tie mutations to the facts evaluated
Between decision and update, another worker might change the amount or approve the invoice. Fetch the decision facts from the primary, then check their version when applying the mutation. The database should increment the version whenever an attribute relevant to this decision changes. The sample below is PostgreSQL with application-bound parameters. Decide what should happen when a membership entitlement changes concurrently, because an invoice row version alone does not cover that separate authority.
-- Same primary database transaction as the policy read for this invoice.
UPDATE invoice
SET status = 'approved', version = version + 1, approved_by = :principal
WHERE tenant_id = :authorised_tenant
AND id = :invoice_id
AND version = :expected_version
AND status = 'pending'
RETURNING id, version;
A zero-row result means the pending invoice or checked version is gone. Reload and evaluate again, or return a conflict that asks the client to refresh. Locking the row while evaluating and applying a change is an alternative when the workflow needs a stricter state boundary. Keep external network calls out of such transactions when possible. Audit the policy revision, action, outcome and an internal correlation ID. Avoid storing full identity tokens or raw attributes merely because your engine offers decision logging. Open Policy Agent decision logs and masking
Failures to rehearse before launch
A long-lived token keeps an expired grant alive
Membership changes in the identity store while a session still has old claims. Choose a freshness budget for each action. Read authoritative membership for high-risk actions, or use an entitlement version and invalidate the cache when it changes. Test a revoked approver with a valid session token. Make sure revocation works on service-to-service paths too.
A new grant defeats a tenant isolation rule
An administrator adds an allow rule that is evaluated before a hard boundary. The system grants access in a different tenant because the first match ended evaluation. Put tenant scope in resource retrieval and in the mandatory decision path. Test combinations of permissions and multiple tenant assignments, including a user with administrator rights in only one tenant.
An approved decision no longer describes the invoice being updated
The invoice is edited after approval is evaluated. A version-checked mutation or transaction lock can force the operation to use the evaluated state. Do not retry a stale approval against new values without running the policy again. Add a test that changes the amount between the read and write.
A list or export applies weaker rules than the detail endpoint
The detail policy is correct, but an export uses a broad database role and returns rows the caller could never open directly. Treat listing as a distinct decision with known scope and matching predicates. Row-level database policies can protect tenant scope while the application enforces region, action and workflow restrictions. Run the same prohibited-resource fixtures through reads, exports and asynchronous jobs.
Choose the smallest model that meets the constraints
| Observed constraint | Starting model | Evidence to collect |
|---|---|---|
| Stable permissions attached to job functions | Tenant-scoped RBAC | Role definitions and effective permissions are easy to explain. |
| One role needs different decisions per resource or request | RBAC plus ABAC checks | Decision attributes have a known owner, type and freshness. |
| Rules cross services or have an independent approval lifecycle | Versioned central policy with local or remote evaluation | Every enforcement point reports its active policy revision and has tests. |
| Access depends on nested team and folder relationships | Relationship-oriented permissions | Objects and relationship edges have a model for updates and consistency. |
Use the table as a review aid. If you want a scoring worksheet, rate the importance of dynamic context, multi-service consistency, independent policy review and relationship traversal as zero, one or two. Explain each score using a named requirement, then select the simplest model that can satisfy every high-priority requirement. Avoid adding scores into a universal cutoff. A single contractual boundary can outweigh several convenience factors.
Measure the form of complexity your team is adding
An illustrative role catalogue with four regions, three approval thresholds and two approval modes can create 24 approval-role variants before accounting for workflow state. A reusable approver role and three attributes can express those dimensions more directly. That does not mean the operational cost disappears. The team now has to source and verify those attributes. Track distinct role grants, documented exceptions, stale decisions, policy revision adoption and evaluation latency. Compare the burden of explaining access before and after changing models.
Frequently asked questions
What is the difference between RBAC, ABAC and PBAC?
RBAC grants access through roles and their permissions. ABAC evaluates facts about the caller, resource, action and context. PBAC commonly describes a versioned policy approach to expressing and applying access rules. Policies can combine both roles and attributes, so the models often work together in an enterprise SaaS application.
When should a SaaS product move beyond RBAC?
Add attribute checks when authorised users in the same role need different access for different resources or circumstances. Common signals include roles named for combinations of regions, data classifications or thresholds. Keep stable actions in roles and move variable conditions to trusted attributes with an explicit update and evaluation path.
Should an application fail closed when policy evaluation is unavailable?
For sensitive operations, deny the action when a trustworthy decision is unavailable. If using a local cached policy, set a maximum approved age and define which operations can continue with it. Document and test the difference between a permission denial, an evaluator outage and a valid decision made from cached policy.
How do I test tenant-scoped permission rules?
Test the same endpoint with an authorised resource, another tenant’s resource, an inactive membership and insufficient capability. Cover list queries, exports and asynchronous workers as separate enforcement paths. For mutations, update the relevant resource facts between evaluation and write in an integration test and verify the original decision cannot be applied to changed state.
Further reading
- Use PostgreSQL row-level security for tenant isolation
- Compare Keycloak and Auth0 for enterprise SSO
- NIST’s ABAC guide
- Open Policy Agent policy testing
Choosing between RBAC, ABAC and a versioned policy system? Contact Dumb Potato to map your real permission decisions and agree the tests that should protect them.
