Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 60

RBAC vs. ABAC: Understanding Access Control Patterns

Recommended resources

Hello!

In our last lesson, we took a deep dive into OAuth 2.0, an authorization framework designed to let a third-party application act on a user's behalf. We covered how an application like diagrams.net can get limited, revocable access to your Google Drive files without ever learning your Google password. This is known as delegated authorization.

Now, let's shift our focus inward. Once a user has authenticated with our own application, how do we determine what they are allowed to do? Verifying a user's identity (authentication) is only the first step. The second, equally critical step is deciding what actions they can perform and what data they can access. This is authorization.

This lesson directly addresses the learning outcome: Explain Role-Based Access Control (RBAC) and Attribute-Based Access Control (ABAC) patterns. We will explore the two dominant models for managing permissions within a backend system, starting with the most common and moving to the most powerful and flexible.

We'll cover:

  • The fundamental principles of Role-Based Access Control (RBAC).
  • The limitations of RBAC and where it falls short.
  • The concepts behind Attribute-Based Access Control (ABAC) as a more granular solution.
  • A comparison of the two models and how they can work together.
  • The architectural components that implement these authorization decisions.

Distinguishing Authentication from Authorization

Before we dive in, let's firmly establish the difference between the two concepts.

Role-based access control (RBAC) vs. Attribute-based access control (ABAC)

This short introduction from IBM Technology clearly distinguishes authentication from authorization, setting the stage for our discussion on the authorization models, RBAC and ABAC.

Watch the first 50 seconds of the video.

  • Authentication: Who are you? This is about proving identity. We've covered this with sessions and JWTs.
  • Authorization: What are you allowed to do? This is about granting permissions. This is our focus today.

Role-Based Access Control (RBAC)

Imagine a system where you assign permissions directly to each user. User Alice can read_document and edit_document. User Bob can read_document. User Charlie can read_document, edit_document, and delete_document. Now imagine you have thousands of users and hundreds of permissions. Managing this web of individual assignments becomes impossible.

RBAC simplifies this by introducing an abstraction: the role.

Role-based access control (RBAC) vs. Attribute-based access control (ABAC)

To understand how RBAC solves this management nightmare, let's watch the next segment of the IBM video, which uses a clear hospital analogy.

Watch from 00:50 to 03:29. Pay close attention to how introducing roles like 'Doctor' and 'Nurse' simplifies permission management compared to assigning permissions to individuals.

The core idea of RBAC is simple but powerful:

  1. Permissions are assigned to roles. (e.g., The 'Editor' role has create_post, edit_post, and delete_post permissions).
  2. Users are assigned to roles. (e.g., Alice is an 'Editor').

By this association, Alice inherits all permissions of the 'Editor' role. When a new editor, David, joins, you simply assign him the 'Editor' role, and he instantly gets the correct set of permissions.

The Formal RBAC Model

The National Institute of Standards and Technology (NIST) formalized the RBAC model. Understanding its components gives us a precise vocabulary.

NIST RBAC Model Diagram
This diagram from a presentation on the NIST RBAC Model illustrates the core entities: Users, Roles, and Permissions, and their relationships (UA, PA). It also shows advanced concepts like Role Hierarchies (RH) and Separation of Duty (SSD, DSD), which we'll touch on.

Let's break down the core components, as formally defined in the foundational NIST paper on RBAC.

[PDF] Role-Based Access Control Models - NIST CSRC

For a rigorous definition of the base RBAC model, we can turn to the original NIST paper. This will give you the precise, technical understanding you're looking for.

Read section 4.1, 'BASE MODEL (RBAC0)'. Focus on the definitions of Users (U), Roles (R), Permissions (P), and Sessions (S), as well as the User Assignment (UA) and Permission Assignment (PA) relationships.

Key takeaways from the NIST model:

  • Users, Roles, Permissions: The fundamental sets of entities.
  • User Assignment (UA): A many-to-many relationship linking users to roles.
  • Permission Assignment (PA): A many-to-many relationship linking permissions to roles.
  • Session: A user activates a subset of their assigned roles for a specific session. This supports the Principle of Least Privilege. For example, a user who is both a project-member and a billing-admin can start a session with only the project-member role active to do their development work, reducing the risk of accidental changes to billing data.

Advanced RBAC: Hierarchies and Constraints

The NIST model also defines more advanced features that are common in real-world systems:

  • Role Hierarchies (RBAC1): Roles can inherit permissions from other roles. For example, a Moderator role might inherit all permissions from the User role, plus add its own delete_comment permission. An Admin role could then inherit from Moderator. This reflects organizational structure.
  • Constraints (RBAC2): Rules that enforce policies. The most common is Separation of Duty (SoD), which ensures a user cannot be assigned to mutually exclusive roles. For instance, a user cannot be both a purchasing_agent and an accounts_payable_clerk to prevent fraud.

These concepts are detailed in sections 4.2 and 4.3 of the same NIST paper (LINK) if you wish to explore them further.


The Limits of RBAC: When Roles Aren't Enough

RBAC is the foundation of authorization in most applications. However, it starts to break down when authorization logic becomes more contextual.

Consider these requirements:

  • A user can edit a blog post, but only if they are the author.
  • A manager can approve an expense report, but only if the amount is less than $5,000.
  • A user can access sensitive documents, but only during business hours and from an office IP address.

With a pure RBAC model, you'd be forced to either hardcode this logic directly in your application code (mixing authorization and business logic) or create an explosion of highly specific roles (PostAuthor, LowValueExpenseApprover), which defeats the purpose of RBAC's simplicity.

This problem is sometimes called permission leakage.

What is attribute-based access control (ABAC)

This blog post from Stytch clearly illustrates the problem of 'permission leakage' in RBAC using the familiar example of GitHub's permission model.

Read the section 'Permission leakage in RBAC'. Notice how granting a 'Member' the ability to manage repositories could accidentally give them the same power as an 'Owner' if not for more granular controls.

The need for this more granular, contextual control leads us to our next model: ABAC.


Attribute-Based Access Control (ABAC)

ABAC moves beyond static roles and defines authorization in terms of dynamic policies that evaluate attributes. An access decision can be based on any characteristic you can think of.

In ABAC, policies are typically expressed using four categories of attributes:

What is attribute-based access control (ABAC)

The same Stytch article provides an excellent, detailed breakdown of the four core attribute types in an ABAC system. This is the fundamental grammar of ABAC.

Read the subsection 'How do attributes work within ABAC architectures?' down to the end of the 'Environment' description. Focus on understanding the four categories: Subject, Object, Action, and Environment.

  1. Subject Attributes: Properties of the user requesting access.
    • Examples: user.role = 'manager', user.department = 'finance', user.security_clearance = 'level_3'.
  2. Resource (Object) Attributes: Properties of the resource being accessed.
    • Examples: document.owner = 'alice', document.status = 'draft', transaction.amount < 100.
  3. Action Attributes: The specific action being performed.
    • Examples: action = 'read', action = 'edit', action = 'approve'.
  4. Environmental Attributes: The context of the access request.
    • Examples: time_of_day is between 9-5, request.ip_address is in a specific range, device.security_compliant = true.

A policy in ABAC looks like this:
"PERMIT action='edit' on a resource of type blog_post IF subject.id == resource.author_id."

This is far more powerful and expressive than RBAC alone.

How To Handle Permissions Like A Senior Dev

Let's watch a practical demonstration of how a flexible ABAC system can be implemented in code. This video shows how complex rules, like checking if a user is blocked or has been invited to a resource, can be elegantly handled.

Watch from 19:18 to 21:03 for a conceptual introduction to ABAC's components. Then, watch the detailed code walkthrough from 24:17 to 33:02. You don't need to absorb every line of TypeScript, but focus on how the hasPermission function can now accept the resource object itself and evaluate rules based on its attributes (like isCompleted, authorId, or if the user is in the invited_users array).


RBAC vs. ABAC: It's Not a Competition

A common misconception is that ABAC replaces RBAC. This is incorrect. In practice, they work together. A user's role is often one of the most important subject attributes in an ABAC policy.

  • RBAC provides coarse-grained access control based on static job functions. It's simple and easy to manage for broad permissions.
  • ABAC provides fine-grained access control by layering on dynamic, context-aware rules.

You can think of it as a hybrid approach: RBAC defines the baseline permissions, and ABAC policies refine them for specific situations.

Role-based access control (RBAC) vs. Attribute-based access control (ABAC)

This segment of the IBM video provides a concise summary of when each approach is suitable and emphasizes that a hybrid model is often the best solution.

Watch from 04:58 to 05:56.


A Look at the Architecture: PEP and PDP

To implement these authorization models cleanly, it's best to separate the authorization logic from your business logic. A standard architectural pattern for this involves two key components: the Policy Enforcement Point (PEP) and the Policy Decision Point (PDP).

Attribute-Based Access Control (ABAC) System Architecture
This diagram shows the flow in a standard ABAC architecture. The PEP intercepts a request and asks the PDP for a decision, which is made by consulting policies and attributes.

What is attribute-based access control (ABAC)

For a deeper look at this architecture, the Stytch article explains not just the PEP and PDP, but the entire system defined by the XACML standard, including points for retrieving policies (PRP) and attributes (PIP).

Read the section 'Standard ABAC architecture'. Focus on understanding the responsibilities of the five components, especially the PEP and PDP.

  • Policy Enforcement Point (PEP): This is the gatekeeper. It sits in your application's request path (e.g., as a middleware in Django) and intercepts incoming requests. It doesn't make decisions itself; it simply asks, "Should this be allowed?"
  • Policy Decision Point (PDP): This is the brain. It takes the attributes from the PEP (subject, resource, action, environment), evaluates them against the configured policies (which could be RBAC, ABAC, or a mix), and returns a simple Permit or Deny decision.

This separation is powerful. Your business logic can be written cleanly, assuming permissions have already been checked, while your entire authorization logic is centralized and managed by the PDP.


Conclusion

You have now explored the two primary patterns for managing application-level authorization. You understand their principles, their trade-offs, and the architectural patterns used to implement them.

Key Takeaways:

  • RBAC is a coarse-grained model that simplifies permission management by assigning permissions to roles and users to roles. It's ideal for static permissions based on job function.
  • ABAC is a fine-grained, powerful model where access is determined by policies that evaluate attributes of the subject, resource, action, and environment. It handles dynamic, context-sensitive rules that RBAC cannot.
  • RBAC and ABAC are complementary. A user's role is often a key attribute in an ABAC policy, allowing for a hybrid system that combines broad-stroke roles with fine-grained rules.
  • The PEP/PDP architecture provides a clean separation of concerns, decoupling your business logic from the authorization decision-making process.

Preview of the Next Lesson

We've now established a strong theoretical foundation for both authentication and authorization. Our next step is to put these concepts into practice. In the next lesson, "Implement JWT authentication in a Django application, including token generation and validation middleware," we will build the first piece of our secure backend: a robust system for identifying the 'subject' whose attributes we'll need for our authorization checks. This will be the practical foundation upon which we can later build our RBAC or ABAC logic.