Role-based access control (RBAC) in Cybersecurity - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When managing who can do what in a system, it is important to understand how the time to check permissions grows as the system gets bigger.
We want to know how long it takes to verify access rights when many users and roles exist.
Analyze the time complexity of the following code snippet.
// Check if a user has permission to perform an action
function hasAccess(user, action) {
for (const role of user.roles) {
if (role.permissions.includes(action)) {
return true;
}
}
return false;
}
This code checks each role assigned to a user to see if any role grants the requested permission.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through the user's roles and checking permissions in each role.
- How many times: The loop runs once for each role the user has; inside it, checking permissions may scan multiple permissions.
As the number of roles and permissions grows, the time to check access grows roughly by multiplying these counts.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 roles, 5 permissions each | About 50 checks |
| 100 roles, 10 permissions each | About 1,000 checks |
| 1000 roles, 20 permissions each | About 20,000 checks |
Pattern observation: The time grows roughly with the number of roles times the number of permissions checked.
Time Complexity: O(r * p)
This means the time to check access grows with the number of roles (r) a user has and the number of permissions (p) each role contains.
[X] Wrong: "Checking access is always fast and does not depend on how many roles or permissions exist."
[OK] Correct: The code must look through each role and its permissions, so more roles or permissions mean more work and longer checking time.
Understanding how access checks scale helps you design systems that stay quick and secure as they grow, a skill valued in real-world cybersecurity roles.
"What if permissions were stored in a fast lookup structure like a set instead of a list? How would the time complexity change?"
Practice
Solution
Step 1: Understand RBAC concept
RBAC assigns permissions to users based on their roles, not individually.Step 2: Compare with other options
Encryption, monitoring, and password creation are different security tasks unrelated to RBAC.Final Answer:
To assign permissions to users based on their roles -> Option CQuick Check:
RBAC = Assign permissions by role [OK]
- Confusing RBAC with encryption methods
- Thinking RBAC manages passwords
- Assuming RBAC monitors network traffic
Solution
Step 1: Define role in RBAC
A role is a collection of permissions grouped for users with similar job functions.Step 2: Eliminate unrelated options
Users, password policies, and network protocols are not roles themselves.Final Answer:
A set of permissions assigned to users -> Option DQuick Check:
Role = Set of permissions [OK]
- Confusing roles with individual users
- Mixing roles with password policies
- Thinking roles are network protocols
Solution
Step 1: Identify Alice's role permissions
Alice has the 'User' role, which allows only reading files.Step 2: Match permissions to actions
Since 'User' role lacks write and delete permissions, Alice cannot perform those actions.Final Answer:
Only read files -> Option AQuick Check:
User role = Read only [OK]
- Assuming users have admin permissions
- Confusing role capabilities
- Ignoring role assignment
Solution
Step 1: Identify the incorrect role assignment
The user should only have 'Guest' permissions, but has both 'Guest' and 'Admin'.Step 2: Correct the role assignment
Removing the 'Admin' role from the user ensures they only have 'Guest' permissions.Final Answer:
Remove the 'Admin' role from the user -> Option BQuick Check:
Fix RBAC by removing wrong roles [OK]
- Adding permissions to wrong roles
- Creating unnecessary combined roles
- Deleting user instead of fixing roles
Solution
Step 1: Understand the goal of RBAC
RBAC limits access by assigning roles with specific permissions matching job needs.Step 2: Apply roles based on job duties
Assigning employees to roles that fit their job ensures they access only necessary files.Final Answer:
Assign each employee to one or more roles matching their job duties -> Option AQuick Check:
RBAC = Roles match job duties [OK]
- Giving all employees full access
- Using one role for all permissions
- Assigning roles without considering job function
