SECURITY ENGINEERING · PART 8 · WRITING SECURE CODE · AUTH · 118 OF 229

RBAC vs ABAC vs ReBAC: Authorization Models

Authorization decides what an authenticated user may do, and broken authorization is the number one web risk. This episode covers the models: RBAC with roles, ABAC with attributes and policies, ReBAC with relationships (the Google Zanzibar approach), the broken-access-control bugs they prevent (IDOR, missing checks), and the rules that make authorization reliable: deny by default, check on the server, every time.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 11

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • RBAC by role, ABAC by attributes, ReBAC by relationship
  • deny by default
  • check ownership on the server
  • centralise

Notes

The question

Every authorization model answers the same question: may this subject perform this action on this resource? The subject is who, the action is what, the resource is the thing acted on, and the answer is allow or deny. The models differ only in how they decide. Role-based access control decides by the user's role. Attribute-based decides by attributes and rules. Relationship-based decides by relationships between the user and the resource. Whatever the model, it must be enforced on the server, on every request.

Authorization in one line
  • subject (who) + action (what) + resource (on what) -> allow or deny
  • the models differ in HOW they decide
  • RBAC: by the user's role
  • ABAC: by attributes and rules
  • ReBAC: by relationships
  • all must be enforced on the server, every request

RBAC

Role-based access control, RBAC, is the most common model. You group permissions into roles, such as admin, editor and viewer, and assign roles to users. The check is simply whether the user holds a role that permits the action. Simple, well understood and easy to audit, which is why most systems start here. Its weaknesses are role explosion, hundreds of fine-grained roles, and that it cannot naturally express rules like edit only your own records.

Role-based (RBAC)
  • permissions grouped into roles (admin, editor, viewer)
  • users are assigned roles
  • check: does the user have a role that permits this?
  • simple, well understood, easy to audit
  • weakness: role explosion, and it struggles with "only your own records"

ABAC

Attribute-based access control, ABAC, decides from attributes: of the user (department, clearance), the resource (owner, sensitivity), and the context (time, location, network). You write policies like allow if the user's department equals the resource's. It is flexible and fine-grained, expressing rules RBAC cannot. The cost is complexity: policies are harder to write, test and reason about, and you need tooling like Open Policy Agent with Rego, or Cedar.

Attribute-based (ABAC)
  • decide from attributes: user (dept, clearance), resource (owner, sensitivity), context (time, location)
  • policy: allow if user.dept == resource.dept
  • flexible, fine-grained
  • cost: complex to write, test and reason about
  • tools: OPA/Rego, Cedar

ReBAC

Relationship-based access control, ReBAC, decides from relationships: Alice owns this document, the document is in that folder, Bob is in that team. Permissions flow along the graph, so membership and nesting are inherited. This is how Google Docs sharing works, from Google's Zanzibar paper, and it is excellent for sharing, nested folders and teams. Implementations include SpiceDB, OpenFGA and Ory Keto. Many systems combine models: RBAC for coarse roles, ReBAC or ABAC for fine access.

Relationship-based (ReBAC)
  • decide from relationships: "Alice is owner of doc1", "doc1 is in folder X", "Bob is a member of team Y"
  • permissions flow along the graph (inheritance)
  • this is how Google Docs sharing works (Zanzibar)
  • great for sharing, nesting, teams; tools: SpiceDB, OpenFGA, Ory Keto

The bugs: IDOR

Now the bugs these models prevent, starting with the most common. An insecure direct object reference, IDOR: you change an order number in a URL from 123 to 124 and read someone else's order. The cause is code that checked you are logged in, not that the record is yours. Related is a missing function-level check, such as an admin endpoint with no role check. And hiding a button in the interface is not access control, because an attacker calls the API directly.

Broken access control
  • IDOR: /orders/123 -> /124 reads someone else's order
  • cause: code checks you are logged in, not that the record is yours
  • missing function-level check: an admin API, no role check
  • a hidden button is not a control: attackers call the API directly

The rules

The rules apply to every model. Deny by default and allow explicitly, so a forgotten check fails closed. Enforce on the server, every request and every object, never trusting the client. Check ownership, not just role, which stops IDOR. Centralise the logic rather than scattering checks through controllers. Apply least privilege to roles and service accounts. Log decisions. And test with negative cases: confirm that forbidden actions are actually forbidden.

Get authorization right
  • deny by default; allow explicitly
  • enforce server-side, every request, every object
  • check ownership, not just role (stops IDOR)
  • centralise the logic
  • least privilege for roles and service accounts
  • log decisions; test negatives

Where to enforce it

Where you enforce authorization matters as much as the model. The mature pattern is a policy decision point: one place that answers allow or deny, so rules are not copy-pasted across services where they drift. Enforce at the API, and for defence in depth at the data layer too, such as row-level security so even a missed check cannot return another tenant's rows. In microservices, use a shared authz service or an Open Policy Agent sidecar, not rules reimplemented per service.

Architecture
  • a policy decision point: one place that answers allow/deny
  • enforce at the API and, for defence in depth, at the data layer (row-level security)
  • in microservices: a shared authz service or sidecar (OPA), not copy-pasted rules
  • make the default path the safe one

Common mistakes

Mistakes. Checking that a user is authenticated but never that they are authorized for this object. A role check with no ownership check, the classic IDOR. Authorization enforced only in the interface. Checks scattered and inconsistent, so some paths are missed. Allowing by default, so a forgotten check fails open. Trusting a role or user id sent by the client instead of the session. And no negative tests, so nobody confirms the forbidden stays forbidden.

Avoid these
  • checking authentication but not authorization
  • role check without ownership check (IDOR)
  • authorization only in the UI
  • scattered, inconsistent checks
  • allow by default; fail open
  • trusting a client-sent role or user ID
  • no negative tests

Say it like this

In the interview: RBAC for coarse roles because it is simple and auditable, ABAC when decisions depend on attributes and context, ReBAC for sharing, teams and nested resources, the Google Docs style. Real systems combine them. To avoid broken access control, especially IDOR, I check ownership of the specific object, not just the role, deny by default, and enforce on the server for every request and object. I centralise the logic in a policy decision point, apply least privilege, and write negative tests.

In the interview
  • "RBAC for coarse roles, ABAC
  • for attribute and context
  • rules, ReBAC for sharing and nesting like Google Docs.
  • Many systems combine them. To avoid IDOR I check ownership, not just role, deny by default, enforce server-side
  • on every object, centralise
  • the logic, write negative tests."

Interview questions

Q1What is the difference between authentication and authorization?

Authentication verifies who a user is. Authorization determines what an authenticated user is permitted to do. Authorization must be enforced on the server for every request and every object, not assumed from authentication.

Q2What is RBAC?

Role-based access control: permissions are grouped into roles such as admin, editor and viewer, and users are assigned roles. Access is granted if the user has a role that permits the action. It is simple and auditable but can suffer role explosion and struggles with per-record ownership rules.

Q3What is ABAC?

Attribute-based access control: decisions are made by evaluating policies over attributes of the user, the resource and the context (such as time or location). It is highly flexible and fine-grained but more complex to write, test and reason about, often using tools like Open Policy Agent or Cedar.

Q4What is ReBAC?

Relationship-based access control: access is determined by relationships between subjects and resources, such as ownership, folder membership or team membership, with permissions inherited along the graph. It underpins Google Docs-style sharing and the Zanzibar model, implemented by SpiceDB, OpenFGA and Ory Keto.

Q5What is an IDOR vulnerability?

An insecure direct object reference: a user accesses another user's data by changing an identifier, such as a record ID in a URL, because the application checks that the user is authenticated but not that the object belongs to them. The fix is per-object ownership checks on the server.

Q6Why is hiding a UI element not sufficient for authorization?

Because attackers can call the underlying API directly, bypassing the interface entirely. Authorization must be enforced on the server for every request; UI-level hiding is a usability feature, not a security control.

Q7What does "deny by default" mean in authorization?

Access is refused unless a rule explicitly allows it, so that any forgotten or missing check results in denial rather than unintended access. It makes authorization fail closed, which is the safe failure mode.

Q8How should authorization be enforced in a microservices architecture?

Through a centralised policy decision point or a shared authorization service or sidecar, such as Open Policy Agent, rather than duplicating rules in each service. Enforcement should happen at the API and, for defence in depth, at the data layer, for example with row-level security.