Overview
Create custom authorization models in OpenFGA to match your application’s permission requirements. This guide covers model design, testing, and best practices.Authorization Model Language
OpenFGA models are defined in a simple DSL:Key Concepts
Types
Objects in your system (user, organization, document)
Relations
Relationships between objects (admin, member, viewer)
Conditions
Context-based permissions (time, IP, attributes)
Default Model
The MCP Server includes this model:- Hierarchical roles (admin → member → viewer)
- Organization-based access (organization#member)
- Resource ownership
- Delegated permissions
Custom Models
Example: Project Management
Example: Multi-Tenant SaaS
Example: Content Management
Relation Operators
Direct Assignment
Union (OR)
Intersection (AND)
Exclusion (BUT NOT)
Computed Relations
Conditional Permissions
Add context-based rules:Testing Models
Model Validation
Test Assertions
Deploying Models
Via Setup Script
Updatescripts/setup/setup_openfga.py:
Via API
Best Practices
Start Simple
Start Simple
Begin with basic types and relations. Add complexity as needed.Good:Too Complex:
Use Hierarchies
Use Hierarchies
Define role hierarchies to reduce tuple count.
Limit Indirection
Limit Indirection
Too many hops slow down checks.Good (2 hops):Bad (5+ hops):
Name Consistently
Name Consistently
Use consistent naming across your model.
- Types: Singular (user, document, not users)
- Relations: Lowercase (admin, not Admin)
- IDs: Prefixed (user:123, not 123)
Version Models
Version Models
Track model changes and test migrations.
Performance Optimization
Reduce Tuple Count
Use group/organization relations instead of per-user tuples: Bad (100 tuples for 100 users):Add Indexes
For PostgreSQL backend, add indexes on frequently queried fields.Enable Caching
Migration Guide
Adding New Types
- Create new model with added type
- Write new model to OpenFGA
- No data migration needed
Modifying Relations
- Create new model
- Write new model
- Migrate existing tuples if needed
Next Steps
OpenFGA Setup
Deploy OpenFGA
Relationship Tuples
Manage tuples
Authorization Guide
Learn authorization
Keycloak Integration
Sync roles
Flexible Authorization: Custom permission models support any access control pattern!