# RBAC, ABAC or ReBAC: how should you model permissions?

By Vishal Kumar · Published 2026-08-21 · Updated 2026-11-13
Source: https://fungyaan.com/p/rbac-abac-rebac
Tags: security, authorization, rbac, abac, rebac, multi-tenancy

**The verdict, which the scenes below earn:** start with **roles per tenant**, add **attribute rules** where conditions matter, and use **relationships** when users share individual items with each other.
- **RBAC (role-based):** users get roles (`owner`, `editor`, `viewer`); roles grant permissions. Simple to explain and audit.
- **ABAC (attribute-based):** rules over attributes of the user, the resource and the context ("managers can approve expenses under ₹50,000 in their own department, during business hours").
- **ReBAC (relationship-based):** permissions follow a graph ("Asha can edit this doc because she's in the team that owns the folder that contains it"). This is Google's Zanzibar model, used by tools like OpenFGA and SpiceDB.
- **Enforce in one place in the code, and again in the database** for tenant isolation, so a forgotten check can't leak another customer's data.

> **Case file**
>
> | | |
> |---|---|
> | **The case** | Someone opened a document they shouldn't have, or couldn't open one they should |
> | **Suspects** | RBAC, ABAC, ReBAC |
> | **Culprit** | A permission model that doesn't fit the product, enforced in scattered checks |
> | **The fix** | Tenant-scoped roles, attribute rules for conditions, relationships for sharing, RLS underneath |

## The case

Someone opened a document they shouldn't have. Or someone who should have could not. Either way, the question on the table is the detective's favourite: "why was this allowed?" Permissions look like a dull corner of an app until you notice that each model is a different way of answering it. Roles, conditions and relationships are three different explanations, and each fits a different kind of product.

## The three suspects

Here they are side by side:

| | RBAC | ABAC | ReBAC |
|---|---|---|---|
| **Question it answers** | What can this role do? | Is this allowed under these conditions? | Is this user connected to this object? |
| **Example** | Editors can publish posts | Approvers can approve invoices below their limit, in their region | Viewers of a folder can view every doc in it |
| **Data needed** | User → roles | Attributes of user, resource, environment | A graph of relationships |
| **Strengths** | Easy to understand, audit and build UIs for | Expressive; fewer roles | Natural for sharing and nested structures |
| **Weaknesses** | Role explosion ("editor-EU-readonly-finance") | Harder to audit ("who can see X?" is hard to answer) | Needs a relationship store; consistency is subtle |
| **Tools** | Any framework; a `role` column | OPA/Rego, Cedar, policy code | OpenFGA, SpiceDB, Permify, Ory Keto |

```mermaid
flowchart LR
  subgraph RBAC
    U1[User] -->|has role| R1[Editor] -->|grants| P1[posts:publish]
  end
  subgraph ReBAC
    U2[Asha] -->|member of| T[Team Ops] -->|owner of| F[Folder Q3] -->|parent of| D[Doc budget.xlsx]
  end
```

## Use case 1: multi-tenant SaaS

**The scene:** each customer (tenant) has users with different rights inside their own workspace.

**What I'd use:** RBAC scoped by tenant, plus tenant isolation in the database. Its charm is its plainness: anyone can read the role table and see who can do what.
- A membership table: `(tenant_id, user_id, role)`. A user can be an admin in one tenant and a viewer in another.
- Permissions per role in code: `{"admin": [...], "editor": ["posts:write", "posts:publish"], "viewer": ["posts:read"]}`.
- **Every query is scoped to the tenant**, enforced by PostgreSQL row-level security as well as application code, so a bug in a handler returns nothing rather than another customer's data. The [tenant isolation case](/p/postgres-rls-tenant-isolation) shows the policies.

## Use case 2: document sharing

**The scene:** users share folders and documents with people and groups, and permissions inherit down the folder tree.

**What I'd use:** ReBAC. This is where Zanzibar's insight shines, and it's a beautiful one: if permissions are edges in a graph, sharing and inheritance stop being special cases.
- Store relationships as tuples: `doc:budget#parent@folder:q3`, `folder:q3#owner@team:ops#member`, `team:ops#member@user:asha`.
- A check walks the graph: can `user:asha` `edit` `doc:budget`?
- Listing ("which docs can Asha see?") needs the system's list API or a precomputed index; it's the hard part, and the reason to use a dedicated service rather than recursive SQL. Recursive SQL is the tempting false lead here.

## Use case 3: regulated data and approval limits

**The scene:** finance approvals with amount limits, region restrictions and separation of duties (you can't approve your own expense).

**What I'd use:** RBAC for the coarse structure plus ABAC policies for the conditions.
- Roles decide who may approve at all; attributes handle the nuance.
- Policies check attributes: `amount <= user.limit`, `invoice.region in user.regions`, `invoice.submitted_by != user.id`.
- Keep policies as code (OPA/Rego, Cedar, or plain functions), versioned and tested with tables of allow/deny cases, and log every decision for auditors.

```mermaid
flowchart TD
  Q1{"Do users share individual items, with inheritance?"}
  Q1 -->|yes| RE["ReBAC: OpenFGA, SpiceDB"]
  Q1 -->|no| Q2{"Do conditions matter: limits, regions, own items?"}
  Q2 -->|yes| AB["RBAC + ABAC policy code"]
  Q2 -->|no| RB["Tenant-scoped RBAC"]
  RE --> DB["Row-level security underneath"]
  AB --> DB
  RB --> DB
```

## Where the guards stand

1. **At the edge:** authentication (the [OAuth and OIDC case](/p/oauth-oidc-flows) covers the flows), coarse checks (is this a staff-only route?).
2. **In the application, in one place:** a single `authorize(user, action, resource)` function or middleware, never ad-hoc `if user.role == ...` scattered through handlers.
3. **In the database** for tenant isolation (RLS) and anything where a leak would be catastrophic.
4. **In the UI** only for hiding buttons; the UI is never the enforcement, and treating it as one is a classic red herring.

> **Remember this**
> - Roles answer "what can this role do", attributes "under what conditions", relationships "how is this user connected".
> - One `authorize(user, action, resource)` function, never scattered role checks.
> - The UI hides buttons, the database holds the line.

## What I'd do on Monday

1. **Tenant-scoped RBAC** with a small, fixed set of roles.
2. **Attribute rules** as tested policy code for conditions and limits.
3. **ReBAC (OpenFGA or SpiceDB)** when sharing and inheritance arrive.
4. **One authorisation function**, plus row-level security as the safety net.
5. **Log decisions** and review roles regularly; remove access when people change jobs.

In the end, nobody is the culprit: these models layer rather than compete. Start with roles, let conditions and relationships join when the product asks for them, and keep the database holding the line underneath.
