{}DSA Atlas

Authorization — RBAC, ABAC, ReBAC & Policies

Where authorization checks belong, object-level authorization and IDOR/BOLA, role-based, attribute-based and relationship-based access control (Google Zanzibar), scopes vs permissions, policy engines (OPA, Cedar), multi-tenant isolation, and filtering lists by permission.

Intermediate → Advanced5 interview questions

Authorization is checked on every request

Authentication tells you who; authorization decides whether this subject may perform this action on this resource, now.

Text
decision = authorize(subject, action, resource, context)
           e.g. (user:42, "refund", order:9, {ip, time, mfa_age})
Python
# ❌ vulnerable: any logged-in user can read any invoice by changing the ID
@app.get("/invoices/{invoice_id}")
def get_invoice(invoice_id: str, user=Depends(current_user)):
    return db.invoices.get(invoice_id)

# ✅ scope every lookup by the caller's tenant (and check object-level rules)
@app.get("/invoices/{invoice_id}")
def get_invoice(invoice_id: str, user=Depends(current_user)):
    invoice = db.invoices.find_one(id=invoice_id, tenant_id=user.tenant_id)
    if invoice is None or not policy.can(user, "invoice:read", invoice):
        raise HTTPException(404)          # don't reveal existence
    return invoice

Models

RBAC Asha editor post:createpost:updatepost:publish user → role → permissions ABAC allow if user.dept == doc.dept and lvl ≤ clearance and env.time in 09–18 and user.mfa_recent policies over attributes ReBAC Asha team:eng folder:Q4 doc:plan member→ editor ofparent of access from graph paths
Three ways to answer "can Asha edit this?"
RBACABACReBAC
Decision based onrole membershipattributes + policiesrelationships in a graph
Expressivenesslow–mediumvery highhigh (hierarchies, sharing)
"Who can access X?"easyhardpossible via reverse lookups
Typicalinternal admin tools, SaaS tenant rolescompliance, government, cloud IAM conditionsDrive/Docs sharing, GitHub, Notion, multi-level orgs
Toolsbuilt-in tables, CasbinOPA/Rego, Cedar, XACMLSpiceDB, OpenFGA, Ory Keto, Permify

RBAC schema

SQL
CREATE TABLE role (id SERIAL PRIMARY KEY, tenant_id BIGINT, name TEXT, UNIQUE (tenant_id, name));
CREATE TABLE permission (id SERIAL PRIMARY KEY, name TEXT UNIQUE);          -- 'invoice:approve'
CREATE TABLE role_permission (role_id INT REFERENCES role, permission_id INT REFERENCES permission,
                              PRIMARY KEY (role_id, permission_id));
CREATE TABLE user_role (user_id BIGINT, role_id INT REFERENCES role, PRIMARY KEY (user_id, role_id));

-- does user 42 have invoice:approve (in their tenant)?
SELECT EXISTS (
  SELECT 1 FROM user_role ur
  JOIN role_permission rp ON rp.role_id = ur.role_id
  JOIN permission p ON p.id = rp.permission_id
  WHERE ur.user_id = 42 AND p.name = 'invoice:approve'
);

ReBAC (Zanzibar-style) model

Text
// OpenFGA / SpiceDB-style schema
type user
type team
  relations
    define member: [user]
type folder
  relations
    define owner: [user]
    define editor: [user, team#member] or owner
    define viewer: [user, team#member] or editor
type document
  relations
    define parent: [folder]
    define editor: [user] or editor from parent
    define viewer: [user] or viewer from parent

// tuples (facts)
team:eng#member@user:asha
folder:q4#editor@team:eng#member
document:plan#parent@folder:q4

// check: document:plan#editor@user:asha → ALLOWED (via team → folder → document)

ABAC with a policy engine

Text
# OPA / Rego
package orders.authz

default allow := false

allow if {
  input.action == "refund"
  input.subject.roles[_] == "support_agent"
  input.resource.tenant_id == input.subject.tenant_id
  input.resource.amount_cents <= 50000          # agents may refund up to 500.00
  time.now_ns() - input.subject.mfa_at_ns < 15 * 60 * 1e9
}
Text
// AWS Cedar
permit (principal, action == Action::"refund", resource)
when { principal in Role::"support_agent"
       && resource.tenant == principal.tenant
       && resource.amount_cents <= 50000 };

Architecture: PEP and PDP

request Service (PEP)builds (subject, action,resource, context) Policy decision pointOPA · Cedar · SpiceDB · library Policy & relationship storeversioned, audited allow?allow/deny
Enforcement in the service; decisions centralised so every service applies the same rules.

Multi-tenant isolation

  • Resolve the tenant from the token (never from a client-supplied header alone).
  • Scope every query by tenant_id; enforce with Postgres Row-Level Security as a backstop.
  • Separate encryption keys per tenant for regulated customers.
  • Cross-tenant admin access only through audited, break-glass paths.
  • Test: automated "tenant A cannot see tenant B" suites.

Design rules

  1. Deny by default; explicit allows.
  2. Least privilege: narrow roles, short-lived elevated access (just-in-time).
  3. Check at the object level, on the server, every time.
  4. Keep authorization logic centralised (library/PDP), not copy-pasted.
  5. Re-check sensitive actions with step-up authentication (recent MFA).
  6. Audit every decision for sensitive resources.
  7. Separate scopes (what the app may do) from permissions (what the user may do).

Interview questions

0 / 5 marked confident

Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.