Skip to main content
Definable implements a robust Role-Based Access Control (RBAC) system that provides fine-grained authorization for all resources within the platform. This page explains how permissions work, how they’re assigned to roles, and how to implement permission checks in your code.

Permission Structure

Permissions in Definable follow a simple resource:action pattern that makes them intuitive and flexible:
Where:
  • resource: The entity being accessed (e.g., kb, conversation, organization)
  • action: The operation being performed (e.g., read, write, delete, admin)

Examples

Wildcard Support

Permissions support wildcards to enable broader access control:

Role Hierarchy

Roles are organized in a hierarchical system with numeric levels:
  • Owner (Level 100): Full system access, can perform all operations
  • Admin (Level 80): Administrative capabilities, can manage most resources
  • Member (Level 20): Standard user access, can use but not administer
  • Guest (Level 10): Limited access, typically read-only permissions

Database Structure

The permission system is implemented through these key database models:

Key Models

Role Model

Permission Model

Permissions are stored as simple string entries with the resource:action format.

Permission Checks

Middleware-Based Checks

The RBAC system uses FastAPI dependencies to check permissions for every protected endpoint:

Using RBAC in Endpoints

To protect an endpoint with RBAC, add the permission dependency:

Default Roles and Permissions

When a new organization is created, the system automatically creates these default roles:
  1. Owner
    • Level: 100
    • Permissions: *:* (full access to everything)
  2. Admin
    • Level: 80
    • Permissions: Various administrative permissions like kb:admin, conversation:admin
  3. Member
    • Level: 20
    • Permissions: Basic usage permissions like kb:read, kb:write, conversation:read, conversation:write
  4. Guest
    • Level: 10
    • Permissions: Limited access permissions like kb:read, conversation:read

Creating Custom Roles

Organization owners and admins can create custom roles with specific permission sets:

Best Practices

Permission Naming

  • Use clear, descriptive names for resources and actions
  • Keep permission names lowercase
  • Use singular form for resources (e.g., kb not kbs)
  • Use verb form for actions (e.g., read not reader)

Permission Checking

  • Always check permissions at the API level using the RBAC dependency
  • For complex business logic, you may need to check permissions within your service methods
  • Remember to check for wildcard permissions as well as specific ones

Role Management

  • Avoid creating too many roles, which can be hard to manage
  • Place roles at appropriate levels in the hierarchy
  • Define clear boundaries between role capabilities

Debugging RBAC Issues

If users report access problems:
  1. Check which role the user has in the organization
  2. Verify the permissions assigned to that role
  3. Examine the specific resource and action being requested
  4. Look for potential wildcard permissions that should grant access
  5. Check if the user’s token is valid and not expired

Next Steps

Migrations with Alembic

The RBAC system uses Alembic migrations to manage database schema changes and seed default data:
When adding new resources or modifying permission schemes, create a new Alembic migration to:
  1. Add new permission entries
  2. Assign default permissions to existing roles
  3. Update any permission dependencies
This ensures that all environments (development, staging, production) maintain consistent permission structures.