The designing rbac section of a postmortem is easy to skim past, right up until it's the section that matters. This works through the problem properly, from cause to fix. Production gives you neither a clean environment nor a patient timeline.
Role-based access control and attribute-based access control are usually framed as a maturity ladder: start with RBAC, grow into ABAC. That framing is wrong for most service teams. The two models fail in opposite directions, and the right choice depends less on how many roles you have and more on how badly a wrong allow hurts.
RBAC encodes permissions as roles. A principal holds roles; a role carries permissions; the policy engine checks membership. The decision is coarse and cheap: a lookup, maybe a cache hit. ABAC encodes permissions as attributes and rules. A principal has attributes (department, clearance, tenant, region, device posture); a resource has attributes (owner, classification, environment); the environment has attributes (time, network path, request origin). The engine evaluates a policy expression over those attributes. The decision is fine-grained and expensive: attribute resolution, policy evaluation, and a much larger test surface.
The real problem this post solves is the one teams hit six months in: they picked RBAC because it was simple, then bolted on exceptions until the role graph became an attribute system written in the worst possible notation — role names. Or they picked ABAC because it sounded more secure, then discovered that no one could explain why a given request was allowed.
Where the two models actually diverge
The comparison that matters is not "simple vs complex." It is "where does the decision logic live, and what happens when it is wrong."
| Dimension | RBAC | ABAC |
|---|---|---|
| Decision input | Role membership | Attributes of principal, resource, environment |
| Typical latency | One lookup, cache-friendly | Multiple attribute fetches, policy evaluation |
| Failure mode | Role explosion; accidental privilege via broad role | Policy bug silently grants or denies; hard to reproduce |
| Auditability | "User is in role X" is easy to explain | "Why was this allowed?" requires tracing attribute values at decision time |
| Change cost | Adding a role is cheap; removing one is expensive | Changing a policy affects every request that matches it |
| Best fit | Stable job functions, coarse boundaries | Context-dependent access, multi-tenant, regulatory scoping |
RBAC's blast radius is a role. If billing-admin accidentally includes refund:any, every holder of that role can issue refunds until someone notices. ABAC's blast radius is a policy expression. If a rule says resource.tenant == principal.tenant and the attribute resolver returns an empty string for missing tenants, every request with a missing tenant attribute matches. The second failure is quieter and wider.
That asymmetry is the argument for a specific default: use RBAC for the coarse boundary (which service, which environment, which job function) and reserve ABAC for the narrow cases where context genuinely changes the answer. Do not build one system to do both jobs.
Prerequisites before you write a single policy
You cannot design either model without three things in place. Skipping them is the most common reason an access-control project stalls.
1. A stable principal identifier. Every request must carry a verifiable identity — a signed token (JWT, mTLS client cert, cloud IAM identity) with a subject claim that does not change when a user changes their email. If your services key permissions off usernames or email addresses, you have already lost; renames and aliases will silently break policy.
2. A resource model with typed attributes. You need to know, for each resource type, which fields are safe to use in a policy and which are user-controlled. A tenant_id that comes from a request body is not an attribute; it is an attacker-controlled string. Only attributes resolved server-side from a trusted store belong in a policy.
3. A decision point you can test in isolation. Whether you use a library (Casbin, OPA/Rego, Cedar, OpenFGA) or hand-rolled checks, the authorization decision must be a pure function you can call from a unit test with fabricated inputs. If the only way to test a policy is to deploy it, you will not test it.
A quick inventory before choosing: list every distinct (verb, resource) pair your services expose. For each, ask whether the answer depends only on who the caller is (RBAC candidate) or also on properties of the resource or the request context (ABAC candidate). A team that does this honestly usually finds that 70–80% of checks are role-shaped and the remainder are contextual. That ratio, not a vendor whitepaper, should drive the design.
Step 1: model the coarse boundary as roles
Start with roles that map to job functions, not to individual permissions. A role called support-agent is a job function. A role called can-read-orders-and-refund-under-50 is a policy in disguise, and it will multiply.
The implementation is deliberately boring. Here is a minimal, runnable RBAC check in Python that you can drop into a service and test today:
from dataclasses import dataclass, field
from typing import Dict, Set
@dataclass(frozen=True)
class Principal:
subject: str
roles: Set[str] = field(default_factory=set)
# role -> set of "verb:resource" permissions
ROLE_PERMISSIONS: Dict[str, Set[str]] = {
"support-agent": {"read:order", "read:customer"},
"billing-admin": {"read:invoice", "write:invoice", "refund:any"},
"auditor": {"read:order", "read:invoice", "read:audit_log"},
}
def allowed(principal: Principal, action: str, resource: str) -> bool:
needed = f"{action}:{resource}"
for role in principal.roles:
if needed in ROLE_PERMISSIONS.get(role, set()):
return True
return False
# --- tests ---
assert allowed(Principal("u1", {"support-agent"}), "read", "order")
assert not allowed(Principal("u1", {"support-agent"}), "refund", "any")
assert allowed(Principal("u2", {"billing-admin"}), "refund", "any")
The point is not the code; it is the shape. The decision is a set membership test with no I/O. Cache the role set per request (it usually arrives in the token), and the check costs nanoseconds. That cheapness is RBAC's real advantage and the reason it should carry the majority of your checks.
Gotcha — role explosion. This is the most documented RBAC failure in the community. It starts when a customer asks for a role that is "like editor but can't delete." You add editor-no-delete. Then editor-no-delete-eu. Within a year you have hundreds of roles whose names encode policy. The tell is when role names contain conjunctions (and, except, only) or environment suffixes. When you see that, stop adding roles and move the varying dimension into attributes — which is the next step.
Step 2: push contextual rules into ABAC, narrowly
ABAC earns its complexity when the decision depends on a property of the resource or the request that is not stable per user. Multi-tenant isolation is the clearest case: the same support-agent role should read orders in tenant A but not tenant B, and tenant membership is a property of the request, not of the role.
A common pattern is to keep RBAC for the verb and add one ABAC rule for the scope. Here is a self-contained evaluator that combines both, using only the standard library:
from dataclasses import dataclass
from typing import Any, Dict, Optional
@dataclass(frozen=True)
class RequestContext:
principal_attrs: Dict[str, Any]
resource_attrs: Dict[str, Any]
env_attrs: Dict[str, Any]
def evaluate(ctx: RequestContext, action: str, resource_type: str) -> bool:
# Coarse gate: role must grant the verb at all.
roles = ctx.principal_attrs.get("roles", set())
if f"{action}:{resource_type}" not in ROLE_PERMISSIONS.get("any", set()) \
and not any(f"{action}:{resource_type}" in ROLE_PERMISSIONS.get(r, set()) for r in roles):
return False
# Contextual gate: tenant isolation. Missing tenant attrs deny, never allow.
p_tenant = ctx.principal_attrs.get("tenant_id")
r_tenant = ctx.resource_attrs.get("tenant_id")
if p_tenant is None or r_tenant is None:
return False
if p_tenant != r_tenant:
return False
# Contextual gate: environment. Production writes require a known-good path.
if action == "write" and ctx.env_attrs.get("environment") == "prod":
if ctx.env_attrs.get("network_zone") not in {"internal", "vpn"}:
return False
return True
The critical detail is the is None check. An ABAC engine that treats a missing attribute as "no constraint" is a security hole, because the attacker's easiest move is to make the attribute disappear. Deny on missing, always.
Gotcha — attribute spoofing. If tenant_id is read from a request header, a query parameter, or a JSON body, the policy is decorative. Attributes used in policy must be resolved server-side: from the authenticated token's claims, from a lookup against a trusted store keyed by the verified subject, or from the resource record itself. A common failure mode is a service that trusts X-Tenant-Id because "the gateway sets it" — until someone reaches the service directly through a misconfigured load balancer.
Step 3: make the decision explainable
ABAC's reputation problem is that nobody can answer "why was this allowed?" after the fact. Fix this at design time, not during an incident.
Return a decision object, not a boolean, from your authorization function. At minimum, record: the policy or rule that matched, the attribute values that were used, and the engine version. This is cheap to add and expensive to retrofit.
from dataclasses import dataclass, field
from typing import List
@dataclass
class Decision:
allowed: bool
reason: str
matched_rule: Optional[str] = None
attributes_used: Dict[str, Any] = field(default_factory=dict)
def decide(ctx: RequestContext, action: str, resource_type: str) -> Decision:
if not evaluate(ctx, action, resource_type):
return Decision(False, "denied by policy", None, {
"principal_tenant": ctx.principal_attrs.get("tenant_id"),
"resource_tenant": ctx.resource_attrs.get("tenant_id"),
})
return Decision(True, "allowed", "tenant_isolation", {
"principal_tenant": ctx.principal_attrs.get("tenant_id"),
"resource_tenant": ctx.resource_attrs.get("tenant_id"),
})
Log the Decision on every denied request and sample it on allows. When a customer reports a 403, the log line tells you whether the role gate or the tenant gate fired. Without this, debugging ABAC becomes guesswork, and teams respond by loosening policies — the worst possible outcome.
Edge cases that break both models
The service-to-service caller. A background job or another service often has no human role. Teams commonly give it a service-admin role with broad permissions, which reintroduces the blast-radius problem at machine scale. Prefer a dedicated principal per service with the minimum permission set, and treat its credentials like any other secret.
The impersonation / support-access path. When support staff need to act as a customer, the principal is ambiguous: whose attributes apply? Decide explicitly. A workable rule is that the effective principal is the customer, with an additional actor attribute recording the support agent, and the policy requires actor.is_support == true for the action. Do not model impersonation as "support agent has all customer roles."
The deleted or disabled principal. Role membership cached in a token outlives the role revocation. If a token is valid for an hour and a role is removed, the user keeps the role for up to an hour. Either keep token lifetimes short, or check a revocation list at the decision point for high-impact actions. This is a documented trade-off in every stateless-token system, not a bug in RBAC.
The empty attribute set. Covered above, but worth repeating because it is the single most common ABAC vulnerability: a missing attribute must deny. Write a test for it. assert not evaluate(ctx_without_tenant, "read", "order").
Cross-tenant resource identifiers. If resource IDs are guessable (sequential integers), an ABAC tenant check is your only defense against enumeration. If they are unguessable UUIDs, the tenant check is still required — do not rely on obscurity. The check is one comparison; keep it.
Verifying the design before it ships
You cannot prove an access-control system correct by reading it. You need three kinds of tests, and they are cheap to write.
1. Decision table tests. For each (role, action, resource, context) tuple that matters, assert allow or deny. Derive the table from the inventory you built in the prerequisites. A service with 20 (verb, resource) pairs and 5 roles has a table you can write in an afternoon.
2. Negative tests for missing attributes. For every attribute referenced in a policy, write a test where it is absent and assert deny. This catches the empty-string bug that a happy-path test never will.
3. Property tests for the tenant invariant. If tenant isolation is a rule, assert that for randomly generated principals and resources, allowed implies principal.tenant == resource.tenant (or an explicit cross-tenant grant exists). A property test over a few thousand generated cases finds the policy branch you forgot.
A verification checklist you can apply to any decision function:
- Every check is a pure function of inputs you can fabricate in a test.
- Missing attribute ⇒ deny, with a test proving it.
- Every deny path emits a reason string that names the rule.
- Role changes take effect within a stated, documented window.
- Service-to-service principals have their own minimal roles, not a shared admin role.
If any of these is false, fix it before adding features. An access-control system that cannot be tested is a liability regardless of which model it claims to implement.
The next 30 minutes: inventory your checks
Open the authorization module of one service — the file where allowed or authorize is defined — and list every (verb, resource) pair it checks, marking each as role-shaped (depends only on who the caller is) or context-shaped (depends on the resource, tenant, or request environment). That list is your RBAC/ABAC boundary. If more than a handful of pairs are context-shaped, you have an ABAC problem hiding inside your role names, and the next step is to extract the varying dimension into a server-resolved attribute with a deny-on-missing test.