Permission Structure
Permissions in Definable follow a simpleresource:action
pattern that makes them intuitive and flexible:
- 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 theresource: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:-
Owner
- Level: 100
- Permissions:
*:*
(full access to everything)
-
Admin
- Level: 80
- Permissions: Various administrative permissions like
kb:admin
,conversation:admin
-
Member
- Level: 20
- Permissions: Basic usage permissions like
kb:read
,kb:write
,conversation:read
,conversation:write
-
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
notkbs
) - Use verb form for actions (e.g.,
read
notreader
)
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:- Check which role the user has in the organization
- Verify the permissions assigned to that role
- Examine the specific resource and action being requested
- Look for potential wildcard permissions that should grant access
- Check if the userβs token is valid and not expired
Next Steps
- JWT Authentication: Learn about the JWT implementation
- Invitation Flow: How users are invited to organizations
- Authentication Overview: Broader view of the authentication system
Migrations with Alembic
The RBAC system uses Alembic migrations to manage database schema changes and seed default data:- Add new permission entries
- Assign default permissions to existing roles
- Update any permission dependencies