SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
  • SSL/TLS
  • Encryption at Rest
  • Secrets Management
  • Password Management
  • RBAC
  • SAML
  • OWASP Top 10 and Common Attacks
  • DDoS Attacks and Defenses
  • Web Application Firewall (WAF)
  • Certificates and PKI
  • Multi-Factor Authentication (MFA)
  • Zero Trust
  • Key Management (KMS)
  • Data Privacy and GDPR Basics
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Operations and Security/Advanced Security

RBAC

Give permissions to roles, then give roles to people.

⏱ 12 min readIntermediateMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

RBAC (Role-Based Access Control) gives permissions to roles, and then gives roles to people. Nobody gets permissions one by one.

  • A permission is one allowed action, such as "approve a payment".
  • A role is a bundle of permissions that matches a job, such as "Accountant".
  • To change what a person can do, you change their roles, not a long list of single rights.

02Concept: What is it?

Every system must answer one question many times a day: is this person allowed to do this action? This is authorization. Without a plan, teams give rights to each person directly. That works for 5 people, but with 500 people nobody can say who can do what.

RBAC adds one layer in the middle. The model has three parts: users, roles and permissions. A user holds one or more roles. A role holds a set of permissions. When a user does something, the system collects the permissions of all their roles and checks if the action is in that set.

Users, roles and permissions
👩Alice
👨Bob
🧑Carol
→↓have
🎭Editor
🎭Approver
→↓grant
🔑edit report
🔑approve payment
🔑read report
The role sits in the middle. Change the role once, and everyone who holds it is updated.

Two ideas keep RBAC healthy. Least privilege means a person gets only the permissions needed for the job, nothing extra. Deny by default means that if no role allows an action, the answer is no.

🧠Roles describe jobs, not people
Name roles after what someone does ("Support agent", "Payroll approver"), not after who they are. People change jobs. The roles stay.

03Real-Life Example

🍵The Key Cards in an Office Building
An office has many doors: the front door, the server room, the finance office and the cleaning cupboard. Giving each person a list of single doors is slow and easy to get wrong. Instead the building makes a few card types: Visitor, Employee, Finance and IT. Each card type opens a fixed set of doors. When Dana joins finance, security gives her a Finance card. When she moves to IT, they swap the card. Nobody has to remember 12 separate doors for her. And nobody who works in finance can open the server room, unless IT gives them that card too.
Office building
RBAC
A person
A user
A card type (Finance, IT)
A role
A door that can be opened
A permission
Giving Dana a Finance card
Assigning a role to a user
Swapping the card when she changes jobs
Removing one role and adding another
A door nobody has a card for stays locked
Deny by default
A person with every card
Too much privilege, a risk
Checking one action
🙋User asksapprove payment
→↓
🎭Find rolesApprover
→↓
🔑Collect permissionsall roles together
→↓
✅Allow or denyin the set?

04Why Do We Need It?

🧮Fewer things to manage
10 roles are easier to review than 10,000 single grants spread over 500 people.
🔒Least privilege
Each person gets only what the job needs, so a stolen account can do less damage.
🚀Fast onboarding
A new joiner gets the role of their team, and is ready on day one.
🔍Easy audits
Auditors can ask 'who holds the Approver role?' and get a clear answer.
✋Separation of duties
Roles make it possible to forbid risky combinations, such as creating and approving the same payment.
🧾Compliance
Many rules (finance, health, privacy) ask for controlled, reviewable access. RBAC is the common way to show it.
Do not give rights to people. Give rights to roles, and roles to people.

05Where Do We Use It?

☁️Cloud platforms
AWS IAM, Azure and Google Cloud all let you attach permissions to roles and groups.
☸️Kubernetes
Kubernetes has built-in Roles, ClusterRoles and RoleBindings.
🗄️Databases
PostgreSQL and MySQL have roles, so you can give 'read only' to a reporting tool.
🏢Business apps
Admin panels, CRMs and HR systems use roles like Manager, Agent and Admin.
🔌APIs and gateways
An API gateway or service checks a role claim in a token before it lets the call pass.
🐙Developer tools
GitHub and GitLab use roles such as Read, Write and Maintain on a repository.

06Types / Parts / How It Works

RBAC building blocks

PartWhat it isExample
User / subjectThe person or service asking to do somethingalice@company.com, a billing service
RoleA named set of permissions for a jobEditor, Approver, Admin
PermissionOne allowed action on one kind of thingpayment:approve, report:read
AssignmentThe link between a user and a roleAlice has Editor
SessionThe roles that are active right now for a loginAlice logged in as Editor

Role hierarchy

In a hierarchy, a senior role inherits everything from a junior role. If Editor inherits Viewer, then an Editor can also read. This saves repeating permissions, but a long chain can give more than you meant, so keep it short.

A short role hierarchy
👑Adminmanage users, delete
↓includes
✏️Editoredit
↓includes
👁️Viewerread
Arrows point from the senior role to the role it includes.

RBAC compared with other models

ModelDecides byGood forWeak point
ACL (access control list)A list on each item: who may touch itA few items with different owners (files)Hard to see the whole picture across many items
RBACThe roles of the userJobs that are the same for many peopleRole explosion when rules get detailed
ABAC (attribute-based)Rules over attributes: user, item, time, placeFine rules such as 'managers see only their own region'Rules are harder to read and test
ReBAC (relationship-based)Relationships: 'owner of', 'member of'Sharing, folders, social appsNeeds a graph of relations
Many systems mix them
🎭RBACthe broad job
📐ABAC rulenarrow it by region
✅Decision
VisualizerGive roles to people and test what they can doPick a person and click roles to give or remove them. Click a permission to test it. Switch on the role hierarchy, then try giving Bob the Approver role while he is a Clerk. Turn on separation of duties and try again.
Pick a person
Role model
Separation of duties

Flat: each role gives only its own permissions, nothing more.

Roles of Alice (click to give or take away)
What Alice can do (green = allowed, dark = denied). Click one to test it.
Denied: none of Alice's roles gives the permission to approve payment. Least privilege means we add a role only if the job really needs it.
Roles held
1
by Alice
Permissions
1
in effect
Add one permission for all
40 vs 1
edits: per person vs one role
Onboard everyone
40 vs 40
grants: direct vs role

A small teaching model with made-up roles and permissions. Real systems have many more, and the counts above are illustrative: with direct grants each person needs every permission one by one, with roles each person needs one assignment.

07How to Use It / Steps / Implementation

Designing roles that stay clean

  1. 1
    List the real jobs
    Start from what people do (support agent, accountant, on-call engineer), not from the list of system features.
  2. 2
    List the permissions
    Write each permission as 'action on thing', for example invoice:read or invoice:approve. Keep them small and clear.
  3. 3
    Group them into roles
    Make one role per job. Give each role only what that job needs (least privilege).
  4. 4
    Start from nothing
    Deny by default. A new user has no roles until someone gives them one.
  5. 5
    Add rules for risky pairs
    Mark combinations that no single person should hold (create and approve a payment), and have the system refuse them.
  6. 6
    Check on the server, every time
    Hiding a button in the page is not security. The server (or gateway) must check the permission on every request.
  7. 7
    Review often
    Every few months, check who holds powerful roles, remove old access and keep a log of every change.
💡Check permissions, not role names
In code, ask "does this user have invoice:approve?", not "is this user an Admin?". Then you can change which roles carry the permission without editing the code.
⚠️Time-limited power
For rare, risky jobs (production access), give the role for a short time and remove it automatically. This is often called just-in-time access.

08Key Terms to Know

TermMeaning in easy words
AuthorizationDeciding what an already known user is allowed to do
RoleA named bundle of permissions that matches a job
PermissionOne allowed action on one kind of resource
AssignmentGiving a role to a user
Least privilegeGive only the permissions the job needs, and no more
Deny by defaultIf nothing allows an action, the answer is no
Role hierarchyA senior role inherits the permissions of a junior role
Separation of dutiesNo single person can finish a risky task alone (for example create and approve a payment)
Role explosionSo many narrow roles that nobody can manage them
ABACAttribute-based access control: rules over user, item and context attributes
ACLAccess control list: a list on a resource saying who may use it

09Pros, Cons and Trade-offs

✅ Pros
  • Simple to explain and to audit
  • Matches how companies are organised
  • Easy onboarding and offboarding
  • Supports least privilege and separation of duties
  • Supported by almost every cloud and database
⚠️ Cons
  • Role explosion when you need fine rules
  • Cannot express 'only your own records' by itself
  • Roles slowly collect extra permissions over time (role creep)
  • A deep hierarchy hides what a role really allows
  • Needs regular review to stay correct

Trade-offs

ChoiceWe gainWe lose
Few broad rolesSimple to managePeople get more than they need
Many narrow rolesTight least privilegeHard to manage, role explosion
Role hierarchyLess repeating of permissionsHarder to see the full set, easy to over-grant
Roles plus attribute rulesFine control on top of simple rolesMore rules to write and test
Check at one gatewayOne place to enforceServices trust the gateway, deeper checks can be missed
Check inside every serviceDefence in depthRules can drift between services

10Common Problems and Mistakes

Common mistakes

  1. One giant Admin role. Everyone who needs a little extra gets full power.
  2. Role explosion. A new role for every small difference ("Editor-Europe-ReadOnly-Weekends"). Use an attribute rule instead.
  3. Role creep. People change teams and keep old roles. Remove access when the job changes.
  4. Checking only in the user interface. A hidden button does not stop a direct API call.
  5. Checking role names in code. Scattered if role == "admin" checks are hard to change and easy to miss.
  6. No separation of duties. The person who creates a payment can also approve it.
  7. No review or log. Nobody knows who gave a powerful role, or when.

Things to watch

🕸️Stale roles in tokens
If roles are copied into a token, a removed role still works until the token expires.
🧍Shared accounts
A shared login hides who did what. Give each person and each service its own identity.
🌱Roles for services
Services need roles too. Give a service only the calls it needs.
🚪Break-glass access
Plan an emergency path, but log it loudly and review it afterwards.

11Real-World Examples

☁️AWS IAM
Roles hold policies that list allowed actions. People and services assume a role to get its rights.
☸️Kubernetes
A Role lists allowed actions in a namespace. A RoleBinding links it to users or service accounts.
🐙GitHub
Repository roles such as Read, Write and Admin decide who can push or change settings.
🏦Banks
A teller, a manager and an auditor see and approve different things, and some pairs of duties are kept apart.
🏥Hospitals
Nurses, doctors and billing staff see different parts of a patient record. Rules often add context on top of roles.
📊Analytics tools
Viewer, Editor and Owner roles control who can look at, change or share dashboards.
📝Note
The exact role and permission names differ in each product. Read the documentation of the platform you use.
Mini case: RBAC plus a rule
🧑‍💼Managerrole
→↓can view orders
📐Ruleonly own region
→↓allowed
📦Orders in Europe
Role Attribute rule Result
Roles give the broad right. A small rule narrows it.

12Related Topics to Read Next

Authentication vs Authorization→

RBAC is a way to do authorization, after the user is known.

JWT→

Tokens often carry the user's roles to the service.

OAuth / OAuth2→

Scopes are a close cousin of permissions.

Single Sign-On (SSO)→

SSO logs the user in. Roles then say what they can do.

API Gateway Pattern→

A gateway is a common place to check roles for every call.

Secrets Management→

Services need tightly limited access to their secrets too.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: permissions go to roles, roles go to users.
  • ✔Parts: user, role, permission, assignment.
  • ✔Rules: least privilege and deny by default.
  • ✔Hierarchy: a senior role inherits a junior role. Keep chains short.
  • ✔Separation of duties: one person cannot create and approve.
  • ✔Danger: role explosion, role creep, one giant Admin role.
  • ✔Compare: ACL per item, ABAC by attributes, ReBAC by relationships. Mix RBAC with ABAC rules.
  • ✔One line: “Give rights to jobs, give jobs to people, and check on the server every time.”
← Previous
Password Management
Next →
SAML