Skip to content

๐Ÿ›ก๏ธ Authorization - RBAC, ABAC, & Policies

Donโ€™t sprinkle if (user.isAdmin) checks throughout your business logic. Authorization should be a decoupled layer or a dedicated service. A Programmer designs for the Principle of Least Privilege, ensuring users only have access to the specific data they need to perform their job.


The most common model. Permissions are grouped into Roles, and Roles are assigned to Users.

  • Structure: User โฎ• Role โฎ• Permission.
  • Example: A โ€œEditorโ€ role has the update_post and delete_post permissions.
  • Pros: Very easy to understand and audit. Excellent for 80% of application needs.
  • Cons: Can lead to โ€œRole Explosionโ€ (e.g., creating Manager_Region_A, Manager_Region_B) when permissions need to be more granular.

A more dynamic model that uses Attributes (properties) of the user, the resource, and the environment to make a decision.

  • Structure: IF (Subject.Attribute AND Resource.Attribute AND Environment.Attribute) THEN Allow.
  • Example: โ€œAllow Engineers to Access Servers only if Server.Project == User.Project and Time is during working hours.โ€
  • Pros: Extremely flexible; avoids role explosion.
  • Cons: High complexity; can be difficult to reason about and can impact performance if rules are too complex.

Taking authorization out of the code and into a configuration or policy engine.

  • Opa (Open Policy Agent): A popular industry standard. You write policies in a language called Rego.
  • How it works: Your API sends a โ€œqueryโ€ to the policy engine (e.g., โ€œCan User X do Action Y on Resource Z?โ€), and the engine returns a simple true/false.
  • Programmerโ€™s Move: This allows security teams to update permissions across multiple microservices without redeploying code.

๐Ÿ›๏ธ 4. ReBAC (Relationship-Based Access Control)

Section titled โ€œ๐Ÿ›๏ธ 4. ReBAC (Relationship-Based Access Control)โ€

Popularized by Googleโ€™s Zanzibar paper. It defines access based on relationships between entities.

  • Logic: โ€œUser A can edit Document B because User A is a member of Folder C, and Folder C contains Document B.โ€
  • Best for: Complex hierarchical structures (like Google Drive, Notion, or Slack).

  • Centralized: One โ€œAuthorization Serviceโ€ handles all checks. Great for consistency, but creates a single point of failure and adds network latency.
  • Decentralized: Each microservice handles its own authorization. Faster, but harder to ensure uniform security policies across the company.

Authorization isnโ€™t just about Allow/Deny. Itโ€™s often about filtering what comes back from the database.

  • Junior approach: Fetch all records, then loop through them in the API and remove the ones the user shouldnโ€™t see. (Slow and memory-intensive).
  • Senior approach: Inject authorization constraints into the Database Query itself (e.g., SELECT * FROM orders WHERE user_id = ?).
  • Scopes (OAuth2): High-level โ€œbucketsโ€ of access (e.g., read:profile, write:orders). These are usually what the application is allowed to do.
  • Permissions: Granular internal checks (e.g., can_refund_over_500). These are what the user is allowed to do.

๐Ÿ’ก Note: Always audit your authorization. Implement Access Logging so you can answer the question: โ€œWho accessed this sensitive record and when?โ€ In highly regulated industries, being able to prove that your authorization works is just as important as the authorization itself.