Skip to main content

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:
Supported Patterns:
  • Hierarchical roles (admin → member → viewer)
  • Organization-based access (organization#member)
  • Resource ownership
  • Delegated permissions

Custom Models

Example: Project Management

Usage:

Example: Multi-Tenant SaaS

Isolation:

Example: Content Management

Inheritance:

Relation Operators

Direct Assignment

Users directly assigned admin relation.

Union (OR)

User is member OR admin.

Intersection (AND)

User must be admin AND owner.

Exclusion (BUT NOT)

User is member but not suspended.

Computed Relations

User is viewer OR inherits from parent.

Conditional Permissions

Add context-based rules:
Usage:

Testing Models

Model Validation

Test Assertions

Deploying Models

Via Setup Script

Update scripts/setup/setup_openfga.py:

Via API

Best Practices

Begin with basic types and relations. Add complexity as needed.Good:
Too Complex:
Define role hierarchies to reduce tuple count.
Too many hops slow down checks.Good (2 hops):
Bad (5+ hops):
Use consistent naming across your model.
  • Types: Singular (user, document, not users)
  • Relations: Lowercase (admin, not Admin)
  • IDs: Prefixed (user:123, not 123)
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):
Good (1 tuple):

Add Indexes

For PostgreSQL backend, add indexes on frequently queried fields.

Enable Caching

Migration Guide

Adding New Types

  1. Create new model with added type
  2. Write new model to OpenFGA
  3. No data migration needed

Modifying Relations

  1. Create new model
  2. Write new model
  3. 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!