Skip to content
Back to CurriculumLesson 21 of 30
authz-rbacBeginner

Role-Based Access Control (RBAC): Hierarchies, Permissions & Preventing Role Explosion

Role-Based Access Control (RBAC) groups granular permissions into administrative roles (e.g. Viewer, Editor, Admin, Owner) and assigns roles to users. Production systems enforce role hierarchies, map operations to discrete permission strings ('doc:read', 'doc:edit') rather than role names, and defend against 'role explosion'.

Interactive Visual Concept ExplainerStep-by-Step Educational Simulation
Visual Step-by-Step Concept Explainerauthz-rbac
Role-Based Access Control (RBAC): Hierarchies, Permissions & Preventing Role Explosion
Steps:
Select Role:
read
ALLOWED ✅
create
ALLOWED ✅
edit
ALLOWED ✅
delete
DENIED ❌
billing
DENIED ❌
Step 1 of 6
Auto-stepping (1x)

Step 1: Application defines discrete permission strings for every operation (e.g. 'project:create', 'project:delete').

Security Guarantee: Check granular permissions in application code, never hardcoded role names.
Why This Architectural Concept Exists

Assigning permissions directly to individual users across thousands of corporate employees is an operational nightmare. When an employee switches departments or changes jobs, updating hundreds of individual access flags manually inevitably causes privilege accumulation and security breaches.

Intuitive Mental Model

The Hospital Keycard Badges: Nurses get Blue Badges (access to patient rooms and basic medical charts). Surgeons get Red Badges (patient rooms + operating rooms + pharmacy). Hospital Directors get Gold Badges (all facilities + financial records). Nobody programs individual door access for each nurse.

Architectural System TopologyProtocol Diagram
[ User ] ──(Assigned)──► [ Role: 'Editor' ] ──(Inherits)──► [ Role: 'Viewer' ]
                              │                                  │
                              ├─► Permission: 'document:create'  ├─► Permission: 'document:read'
                              └─► Permission: 'document:update'  └─► Permission: 'comment:create'
                                                                 │
                                  ┌──────────────────────────────┘
                                  ▼
[ Enforcement Point ] ── checks: hasPermission('document:read') ──► ALLOWED!
CosmosApp Production Milestone

CosmosApp organizes corporate team spaces using RBAC. Rather than hardcoding 'if (user.role === "admin")' in backend code, CosmosApp maps roles to fine-grained permissions (documents:write, billing:manage). When CosmosApp introduces a new 'BillingManager' role, developers don't have to touch document editing code.

Step-by-Step Execution Sequence
01

Step 1: Application defines discrete permission strings for every operation (e.g. 'project:create', 'project:delete').

02

Step 2: Administrative roles are established, each grouping a collection of specific permissions.

03

Step 3: Role hierarchies are configured where higher roles inherit all permissions of lower roles (Owner > Admin > Member > Viewer).

04

Step 4: Users are assigned one or more roles within a tenant or organization context.

05

Step 5: Incoming requests hit API route guards that evaluate hasPermission(requiredPermission).

06

Step 6: Policy engine resolves user's assigned roles, expands inherited permissions, and grants or denies access (403 Forbidden).

Production Architecture Blueprint
// CosmosApp Permission-Based RBAC Architecture:
const ROLE_PERMISSIONS: Record<string, string[]> = {
  viewer: ['doc:read', 'comment:create'],
  editor: ['doc:read', 'comment:create', 'doc:create', 'doc:update'],
  admin:  ['doc:read', 'comment:create', 'doc:create', 'doc:update', 'doc:delete', 'user:invite'],
};

export function hasPermission(userRoles: string[], requiredPermission: string): boolean {
  // Aggregate all permissions across assigned roles:
  const permissions = new Set<string>();
  for (const role of userRoles) {
    (ROLE_PERMISSIONS[role] || []).forEach((p) => permissions.add(p));
  }

  return permissions.has(requiredPermission);
}
Common Architectural Misconceptions
  • ✕Checking role names directly in controllers is fine (Checking 'if role == admin' creates rigid code; always check specific permissions like 'canDeleteDocument').
  • ✕Creating a new role for every edge case is scalable (Creating 'BillingEditorWithReadOnlyReports' leads to role explosion; use ABAC for contextual modifiers).

Key Architectural Takeaways

  • ✓Check granular permissions in application code, never hardcoded role names.
  • ✓Implement role hierarchies to keep role definitions clean and maintainable.
  • ✓Guard against role explosion by combining RBAC with ABAC for contextual parameters.
Common Architectural Pitfall

Writing 'if (user.role === "admin")' throughout the codebase. Introducing a new 'Manager' role requires modifying dozens of files.

Production Best Practice Fix

Check permissions (e.g. 'can_delete_project') and define which roles possess that permission in a central mapping.

Interactive Knowledge Check

What architectural problem is referred to as 'Role Explosion' in RBAC systems?