Authorization models: RBAC, ABAC and OAuth
Who is allowed to do what, and how apps prove it without sharing passwords
A plain-words guide to authentication versus authorization, the main access control models (DAC, MAC, RBAC, ABAC), least privilege and separation of duties, how OAuth 2.0 and OpenID Connect work at a high level, and the common mistakes to avoid.
beginner level, 16 minutes, 18 slides.
Authorization models: RBAC, ABAC and OAuth
Welcome. A plain-words guide to authentication versus authorization, the main access control models (DAC, MAC, RBAC, ABAC), least privilege and separation of duties, how OAuth 2.0 and OpenID Connect work at a high level, and the common mistakes to avoid. This talk runs about 16 minutes.
Logged in is not the same as allowed
OWASP defines authorization as the process of verifying that a requested action or service is approved for a specific entity. It is distinct from authentication, which is the process of verifying an entity's identity.
Two questions that sound alike but are very different. Who are you? And what are you allowed to do? The OWASP Authorization Cheat Sheet quotes NIST in defining authorization as the process of verifying that a requested action or service is approved for a specific entity, and notes that it is distinct from authentication, which verifies identity. A user who has logged in is often not authorized to do everything. In this talk we meet the main ways systems decide, then OAuth and OpenID Connect, and finish with the most common mistakes.
Authentication versus authorization
Authentication
- Proves who you are
- Examples: password, passkey, one-time code
- Answers: who is this?
Authorization
- Decides what you may do
- Examples: roles, permissions, policies, scopes
- Answers: is this allowed?
Own analogy: At an airport your passport proves who you are. Your boarding pass decides which plane you may board.
Here is the difference in everyday terms. Authentication proves who you are, with a password, a passkey or a one-time code. Authorization decides what you may do once we know who you are, using roles, permissions, policies or scopes. Think of an airport. Your passport proves who you are, but only your boarding pass decides which plane you can board. You can have a perfectly valid passport and still be refused at the wrong gate. Most serious access bugs happen at the second step, where the system knows who you are but forgets to check what you may do.
Four ways to decide access
| Model | In plain words | Who decides |
|---|---|---|
| DAC (discretionary) | The owner of a resource chooses who else can use it | Resource owner |
| MAC (mandatory) | A central policy labels users and data, and owners cannot override it | System policy |
| RBAC (role-based) | Access follows the roles a person has | Administrators assign roles |
| ABAC (attribute-based) | Access depends on attributes of the user, the resource and the situation | Policy rules |
Define: access control model: A way of organising the rules that decide who may do what to which resource.
There are four classic models. In discretionary access control, or DAC, the owner of a file or resource decides who else can use it, like lending your own book. In mandatory access control, or MAC, a central policy labels people and data and owners cannot override it, like security clearances. In role-based access control, access follows the roles a person holds. In attribute-based access control, access depends on attributes of the user, the resource and the situation. The DAC and MAC lines are our own plain-word summaries. We look at the last two in detail next, because modern applications mostly use them.
RBAC: access through roles
OWASP: in RBAC, access is granted or denied based upon the roles assigned to a user. Permissions are not directly assigned to an entity; they are associated with a role and the entity inherits the permissions of any roles assigned to it.
Users get roles; roles carry permissions.
- User: Assigned one or more roles
- Role: A named bundle of permissions
- Permission: An allowed action on a resource
- NIST: RBAC was formalised in 1992 by David Ferraiolo and Rick Kuhn and has become the predominant model for advanced access control because it reduces administration cost.
- Relationships between roles and users can be many-to-many, and roles may be hierarchical (OWASP).
In role-based access control you do not hand out permissions to each person one by one. You define roles, such as support agent or billing admin, attach permissions to the roles, and then assign people to roles. OWASP describes it exactly that way, and adds that users and roles can be many-to-many and that roles may be hierarchical. NIST's RBAC project page says the model was formalised in 1992 by Ferraiolo and Kuhn and became the predominant model for advanced access control because it reduces the cost of security administration. Think of a job title that comes with a set of keys.
ABAC: access through attributes
NIST SP 800-162: ABAC is a logical access control methodology where authorization to perform a set of operations is determined by evaluating attributes associated with the subject, object, requested operations, and, in some cases, environment conditions against policy, rules, or relationships.
- OWASP: attributes are characteristics that can be represented as name-value pairs and assigned to a subject, object or environment.
- OWASP examples of attributes: job role, time of day, project name, creation date.
- OWASP example: a Sales Representative may need to access a customer database from the internal network during working hours, but not from home at midnight.
An invented policy in plain YAML to show the idea. Not a real product format.
rule: view-customer-record
allow_if:
user.department: sales
resource.region: user.region
context.network: internal
context.hour_between: [8, 18]Attribute-based access control asks a richer question. NIST SP 800-162 defines it as deciding by evaluating attributes of the subject, the object, the requested operation and sometimes the environment, against policy. An attribute is just a name and value, such as department equals sales. OWASP gives a clear example: a sales representative may access the customer database from the internal network in working hours, but not from home at midnight. The code block is an invented policy to show the idea, not a real product format. Notice that the rule reads like a sentence about context, not about a job title.
RBAC or ABAC?
RBAC is good for
- Clear job functions
- Simple to explain and audit
- Predictable permissions per role
ABAC is good for
- Context such as time, place and project
- Fine-grained rules without a role for every case
- Policies that reflect resource properties
What OWASP says: OWASP's cheat sheet recommends preferring attribute and relationship based access control over RBAC, and says the decision has significant implications for the whole software life cycle and should be made as early as possible.
Our own view: Many real systems mix them: roles for the broad strokes, attributes for the exceptions.
Which should you choose? The first two columns here are our own summary. RBAC is simple to explain and audit, and works well when jobs are clear. ABAC handles context, such as time, place or project, without inventing a new role for every special case. OWASP's cheat sheet actually recommends preferring attribute and relationship based control over RBAC, and says the decision has big consequences for the whole software life cycle, so it should be made early. In practice many systems blend them: roles for the broad strokes, attributes for the exceptions. The key is to decide deliberately, not by accident.
Least privilege and separation of duties
OWASP: least privileges refers to the principle of assigning users only the minimum privileges necessary to complete their job, applied both horizontally and vertically.
| Principle | Plain meaning | Example |
|---|---|---|
| Least privilege (horizontal) | Same level, different needs | An accountant should not read the customer database; a sales representative should not read payroll (OWASP) |
| Least privilege (vertical) | More senior roles may need more access, but only what they need | A head of sales needs more access than their team (OWASP) |
| Separation of duties | No single person can complete a risky action alone | One person requests a payment and another approves it (our own example) |
Try it: Mine least-privilege roles and catch toxic combinations (identity governance from scratch)
Least privilege means giving people only the minimum access they need for their job. OWASP says to apply it horizontally and vertically. Horizontally means two people at the same level with different needs: the accountant should not see the customer database, and the sales representative should not see payroll. Vertically means the head of sales may need more access than their team, but still only what they need. Separation of duties is a related idea that we add ourselves: no single person should be able to complete a risky action alone, like requesting and approving the same payment.
Deny by default, check every time
- OWASP: the application cannot remain neutral when an entity requests access. It must always decide to deny or permit.
- Configure the application to deny access by default.
- Permission should be validated on every request, regardless of whether it came from an AJAX script, server-side, or any other source.
- OWASP: an attacker only needs to find one way in. A single missed check is enough.
A simplified server-side check. Names are examples.
function canEdit(user, doc) {
if (!user || !doc) return false; // deny by default
if (doc.ownerId === user.id) return true;
if (user.roles.includes('editor') && doc.teamId === user.teamId) return true;
return false; // no rule matched: deny
}Two rules that prevent a huge number of bugs. First, deny by default. OWASP says an application cannot stay neutral when someone asks for access: it must always decide, and it should be set up to deny when no rule matches. Second, validate permission on every request, whatever its source, because an attacker only needs to find one way in, and a single missed check is enough. The code is a simplified example. Read it from the top: unknown user, deny. Owner, allow. Editor on the same team, allow. Everything else falls through to deny.
OAuth 2.0: access without sharing passwords
RFC 6749 explains the problem. Without OAuth, a resource owner shares credentials with a third-party app, which creates problems:
- Third-party apps must store the owner's credentials, typically a password in clear text.
- Third-party apps gain overly broad access, with no way to restrict duration or limit access to a subset of resources.
- Owners cannot revoke access to one third party without revoking all, and must do so by changing the password.
- Compromise of any third-party app compromises the password and all the data it protects.
OAuth's fix: The client obtains an access token instead of using the owner's credentials: a string denoting a specific scope, lifetime, and other access attributes.
Before OAuth, if a printing service wanted to fetch your photos from a photo site, you might hand it your photo-site password. RFC 6749, the OAuth 2.0 standard, lists why that is bad. The app has to store your password, often in clear text. It gets overly broad access with no limit on duration. You cannot revoke one app without changing the password for all. And if the app is compromised, so is your password. OAuth's answer is an access token, a string denoting a specific scope, lifetime and other access attributes. It is like a valet key: it opens the car, but not the glovebox.
The four roles and the token
The four roles defined in RFC 6749, section 1.1.
- Resource owner: You: can grant access
- Client: The app that wants access
- Authorization server: Issues access tokens
- Resource server: Holds the data, accepts tokens
An example authorization request. Hosts are examples; scope names are invented.
GET https://auth.example.com/authorize
?response_type=code
&client_id=EXAMPLE_CLIENT
&redirect_uri=https%3A%2F%2Fapp.example.org%2Fcallback
&scope=photos.read
&state=RANDOM_VALUE- Scope is how the app asks for limited access, such as read only.
- The client uses the access token to reach the protected resources hosted by the resource server.
Try it: Design least-privilege OAuth scopes for an API -- and enforce them per route with tests
OAuth names four roles. The resource owner is the person who can grant access. The client is the application that wants it. The authorization server checks the owner's approval and issues access tokens. The resource server holds the data and accepts tokens. In the example request, the client asks the authorization server for a code and names the scope it wants, photos dot read, which is an invented scope meaning read-only photo access. The hosts are examples. Notice the app never sees your password. It gets a token limited to what you approved, which it presents to the resource server.
OpenID Connect: who just signed in?
OpenID Connect 1.0 is a simple identity layer on top of the OAuth 2.0 protocol. It enables clients to verify the identity of the end user based on the authentication performed by an authorization server.
| OAuth 2.0 | OpenID Connect | |
|---|---|---|
| Main question | What may this app access? | Who is the user who signed in? |
| Key output | Access token | ID Token (a JSON Web Token with claims about the authentication event) |
| Used for | Authorization | Authentication, built on OAuth 2.0 |
Do not mix them up: An access token says what an app may do. It is not, by itself, proof of who the user is. Our own plain advice.
OAuth answers what an app may access. It was not designed to tell the app who the user is. OpenID Connect, or OIDC, adds that. Its core specification calls it a simple identity layer on top of OAuth 2.0, letting a client verify the end user's identity based on authentication done by the authorization server. The extra output is an ID Token, a JSON Web Token carrying claims about the sign-in event. The question rows in the table are our own summary. A common beginner mistake is to treat an access token as proof of who someone is. Remember: tokens for access, ID tokens for identity.
Common mistakes
| Mistake | Better habit |
|---|---|
| Over-broad roles, such as one admin role for everything | Narrow roles and least privilege; review for privilege creep (OWASP) |
| Checks only in the user interface | Validate permission on every request, on the server (OWASP) |
| Guessable identifiers give access to other people's records | Ensure lookup IDs cannot be used even when guessed (OWASP heading) |
| Long-lived tokens with wide scope | Short lifetime and narrow scope; RFC 6749 describes a token as having a specific scope and lifetime (our advice on how to use that) |
| No tests for who can do what | Create unit and integration tests for authorization logic (OWASP) |
Privilege creep: OWASP: after deployment, periodically review permissions so that users' privileges do not exceed what was defined in design. It is easier to grant than to take away.
Here are the mistakes we see most. One admin role for everything is too broad; prefer narrow roles and review regularly. OWASP calls the slow build-up of extra rights privilege creep, and warns it is easier to grant permissions than to take them away. Checking only in the user interface fails, because attackers do not use your interface, so validate on the server on every request. Guessable identifiers need protection too. Long-lived, wide-scope tokens are our own concern: RFC 6749 says tokens have a scope and lifetime, so use both. And test your authorization logic like any other code.
Test it like code
OWASP recommends creating tests that validate that the permissions mapped out in the design phase are being correctly enforced.
| Test case | Expected result |
|---|---|
| Support agent reads a ticket in their own team | Allowed |
| Support agent reads a ticket in another team | Denied |
| Anonymous user calls the delete endpoint | Denied |
| Editor edits a document owned by someone outside their team | Denied |
Try it: Write and unit-test an authorization policy with OPA and Rego
If you cannot test it, you do not really know it. OWASP recommends creating tests that check the permissions you designed are actually enforced. The table shows invented test cases for a ticketing app. Notice that most of them are denials. Testing that the right people get in is easy. Testing that the wrong people stay out is where bugs hide. Write each case before the code if you can, run them whenever the policy changes, and keep them in your build. The labs show how to do this with real policy languages such as OPA and Casbin.
Check your understanding
Check yourself: A user signs in successfully, then opens another customer's invoice by changing the ID in the address. Which control failed?
Answer: Authorization. The system knew who the user was but did not check what they were allowed to see. OWASP says authorization is distinct from authentication.
Check yourself: What is the main benefit of an OAuth access token over sharing your password with an app?
Answer: It denotes a specific scope and lifetime instead of full access. RFC 6749 describes an access token as a string denoting a specific scope, lifetime, and other access attributes, avoiding the need to hand over the owner's credentials.
Check yourself: Which model decides using the user's department, the resource's region and the time of day?
Answer: ABAC. NIST SP 800-162 describes ABAC as evaluating attributes of the subject, object, requested operation and environment against policy.
Three questions to test yourself. Pause before you reveal each answer. The first is a classic: someone changes an identifier and sees another person's data. Ask yourself whether the system failed to know who they were, or failed to check what they were allowed to do. The second compares OAuth tokens with sharing passwords. The third asks you to match rules about department, region and time of day to the right model. If any answer surprised you, revisit that slide, and then try the labs to practise designing scopes, policies and roles.
Recap
- Authentication proves who you are. Authorization decides what you may do.
- RBAC grants access through roles; ABAC through attributes and policy.
- Least privilege, separation of duties, deny by default, check every request.
- OAuth 2.0 gives apps scoped, time-limited tokens instead of your password.
- OpenID Connect adds a layer for knowing who signed in.
- Review permissions regularly and test them like code.
To recap. Authentication proves who you are, and authorization decides what you may do. RBAC gives access through roles, and ABAC through attributes and policy. Apply least privilege, separate duties for risky actions, deny by default and check every request on the server. OAuth 2.0 gives apps scoped, time-limited tokens instead of your password, and OpenID Connect adds a layer for knowing who signed in. Review permissions regularly to avoid privilege creep, and test your rules like code. Now try the labs: design scopes, write a policy, enforce roles, and hunt for toxic combinations.
Practise this
- Design least-privilege OAuth scopes for an API -- and enforce them per route with tests
- Write and unit-test an authorization policy with OPA and Rego
- Enforce multi-tenant RBAC with Casbin (RBAC with domains) -- and test it like code
- Mine least-privilege roles and catch toxic combinations (identity governance from scratch)
Slides only get you so far. Pick one of these hands-on labs and do it today while it is fresh. Every lab is free.
Sources
- OWASP Authorization Cheat Sheet
- NIST Role Based Access Control project
- NIST SP 800-162, Guide to Attribute Based Access Control (ABAC)
- RFC 6749, The OAuth 2.0 Authorization Framework
- OpenID Connect Core 1.0
Every claim in this deck came from these pages, fetched and checked for this release. Read the originals.
Hands-on labs for this deck
- Design least-privilege OAuth scopes for an API -- and enforce them per route with tests
- Write and unit-test an authorization policy with OPA and Rego
- Enforce multi-tenant RBAC with Casbin (RBAC with domains) -- and test it like code
- Mine least-privilege roles and catch toxic combinations (identity governance from scratch)
Open the interactive deck or see all slide decks.
Related
- Design least-privilege OAuth scopes for an API -- and enforce them per route with tests
- Write and unit-test an authorization policy with OPA and Rego
- Enforce multi-tenant RBAC with Casbin (RBAC with domains) -- and test it like code
- Mine least-privilege roles and catch toxic combinations (identity governance from scratch)
- All slide decks
- What is Least privilege?
- What is Compensating control?
- What is Role-based access control?
- What is Separation of duties?
- Free cyber labs