Permission Inheritance and Hierarchies
What you'll learn: How to model nested resources so child entities automatically inherit permissions from their parents, drastically reducing authorization complexity.
The Core Idea
In real systems, resources often form natural hierarchies—organizations contain projects, projects contain repositories, repositories contain files. Instead of assigning permissions to every single resource individually, permission inheritance lets you grant access at a parent level and automatically apply it to all children.
Think of it like apartment building security: if you have a master key for the entire building (parent), you don't need separate keys for each apartment (children). The building-level permission flows downward.
How It Works
When a user requests access to a resource, the authorization system walks up the hierarchy checking permissions at each level:
- Check the resource itself
- If no explicit permission exists, check its parent
- Continue up the chain until you find a grant or reach the root
Example hierarchy:
Organization (Alice: Admin)
└─ Project (Bob: Contributor)
└─ Repository
└─ File
Alice can access the file because her Admin role at the Organization level inherits down through all children. Bob can access it too via his Project-level access.
Implementation Patterns
- Path-based models: Store resource paths like
/org/proj/repoand match prefixes - Recursive queries: Database queries that traverse parent relationships
- Cached inheritance maps: Pre-compute effective permissions for performance
- Explicit overrides: Allow child resources to override inherited permissions when needed
Watch Out For
Deep hierarchies can slow down permission checks. Cache aggressively and consider pre-computing effective permissions for frequently-accessed resources.
Key Takeaway: Permission inheritance through resource hierarchies transforms O(n) permission assignments into O(1) by letting parent-level grants cascade automatically to children, making large-scale authorization manageable.