Skip to main content

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 the zopio 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:
  1. Imports rules from both @repo/auth-rbac and @repo/auth-abac
  2. Combines them into a single array of rules
  3. Uses the evaluation engine from @repo/auth-rbac to process these rules

Benefits of Using Auth Runner

  1. Simplified API: No need to manually combine rules or specify them with each evaluation
  2. Consistent Authorization: Ensures all parts of your application use the same combined rule set
  3. Reduced Boilerplate: Eliminates repetitive code for rule combination
  4. Maintainability: Changes to rules in either system are automatically reflected

Best Practices

  1. Use auth-runner consistently: Replace direct usage of auth-rbac or auth-abac with auth-runner throughout your application
  2. Keep rule definitions separate: Continue defining RBAC rules in auth-rbac and ABAC rules in auth-abac
  3. Consider rule precedence: Rules are evaluated in order, so be mindful of how they’re combined
  4. 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 typical zopio application:
  1. Define your RBAC rules in auth-rbac (role-based permissions)
  2. Define your ABAC rules in auth-abac (attribute-based conditions)
  3. Use auth-runner to evaluate permissions throughout your application
  4. The auth-runner package automatically combines and evaluates all rules
This approach provides a clean, unified way to implement complex authorization logic that combines both role-based and attribute-based access control.