Role-based Access Control (RBAC)
Role-based access control (RBAC) in RedwoodJS aims to be a simple, manageable approach to access management. It adds control over who can access routes, see features, or invoke services or functions to the existing useAuth()
hook on the web side and requireAuth()
helper on the api side.
A role is a collection of permissions applied to a set of users based on the part they play in an organization or setting. Using roles makes it easier to add, remove, and adjust these permissions as your user base increases in scale and functionality increases in complexity.
This how to examines how RBAC is implemented in RedwoodJS and how to protect areas of your app's sides -- web, api, or custom.
Quick Links
- Authentication vs Authorization
- House and Blog Role-access Examples
- Identity as a Service
- How To Code Examples
- Additional Resources
Authentication vs Authorization
How is Authorization different from Authentication?
- Authentication is the act of validating that users are who they claim to be.
- Authorization is the process of giving the user permission to access a specific resource or function.
In even more simpler terms authentication is the process of verifying oneself, while authorization is the process of verifying what you have access to.
House and Blog Role-access Examples
When thinking about security, it helps to think in terms of familiar examples.
Let's consider one from the physical world -- access to the various rooms of a 🏠 house -- and compare it to a digital example of a Blog.
RBAC Example: House
Consider a 🏠 while you are away on vacation.
You are the owner and have given out 🔑 keys to your neighbor and a plumber that unlock the 🏠 🚪 door.
You've assigned them passcodes to turn off the 🚨 alarm that identifies them as either a neighbor or plumber.
Your neighbor can enter the kitchen to get food to feed your 😸 and the your office to water your 🌵 and also use the 🚽.
The plumber can access the basement to get at the pipes, use the 🚽, access the laundry or 🍴 kitchen to fix the sink, but not your office.
Neither of them should be allowed into your 🛏 bedroom.
The owner knows who they claim to be and has given them keys.
The passcodes inform what access they have because it says if they are a neighbor or plumber.
If your 🏠 could enforce RBAC, it needs to know the rules.
Role Matrix for House RBAC
Role | Kitchen | Basement | Office | Bathroom | Laundry | Bedroom |
---|---|---|---|---|---|---|
Neighbor | ✅ | ✅ | ✅ | |||
Plumber | ✅ | ✅ | ✅ | ✅ | ||
Owner | ✅ | ✅ | ✅ | ✅ | ✅ |