Authorization Runner For Advanced Scenarios
The@repo/auth-runner
package provides a simplified interface for using both role-based (RBAC) and attribute-based (ABAC) access control together in your application. It serves as an integration layer that combines the functionality of both authorization systems.
Overview
When implementing complex authorization systems, you often need to combine different authorization models. The@repo/auth-runner
package makes this easy by:
- Combining rules from both RBAC and ABAC systems
- Providing a simplified API for authorization checks
- Abstracting away the complexity of rule management
Installation
The package is included in thezopio
stack. If you need to install it separately:
Usage
Using the auth-runner package is straightforward:With API Routes
With React Components
How It Works
Under the hood, the auth-runner package:- Imports rules from both
@repo/auth-rbac
and@repo/auth-abac
- Combines them into a single array of rules
- Uses the evaluation engine from
@repo/auth-rbac
to process these rules
Benefits of Using Auth Runner
- Simplified API: No need to manually combine rules or specify them with each evaluation
- Consistent Authorization: Ensures all parts of your application use the same combined rule set
- Reduced Boilerplate: Eliminates repetitive code for rule combination
- Maintainability: Changes to rules in either system are automatically reflected
Best Practices
- Use auth-runner consistently: Replace direct usage of auth-rbac or auth-abac with auth-runner throughout your application
- Keep rule definitions separate: Continue defining RBAC rules in auth-rbac and ABAC rules in auth-abac
- Consider rule precedence: Rules are evaluated in order, so be mindful of how they’re combined
- Test thoroughly: Verify that the combined rules produce the expected authorization decisions
Example: Complete Authorization Flow
Here’s a complete example of how authorization works with auth-runner in a typicalzopio
application:
- Define your RBAC rules in auth-rbac (role-based permissions)
- Define your ABAC rules in auth-abac (attribute-based conditions)
- Use auth-runner to evaluate permissions throughout your application
- The auth-runner package automatically combines and evaluates all rules