OpenFGA Compatibility
Melange supports every OpenFGA Schema 1.1 feature except conditions, running entirely in PostgreSQL. It is tested against the official OpenFGA test suite. Schemas that use conditions are rejected at compile time.
Test Suite Compliance
Melange is validated against the official OpenFGA compatibility test suite. This ensures that authorization behavior matches the OpenFGA specification for all supported features. The test suite covers:
- Direct assignments and userset references
- Union, intersection, and exclusion operators
- Tuple-to-userset (parent inheritance)
- Wildcards and contextual tuples
- Complex nested permission patterns
All tests for supported features pass.
Feature Support
| Feature | Melange | Level | Notes |
|---|---|---|---|
Direct assignment [user] | ✅ | Full | Subjects explicitly granted via tuples |
Userset references [type#relation] | ✅ | Full | Full runtime evaluation |
Wildcards [user:*] | ✅ | Full | Public access, subject_id = '*' in tuples |
| Union (OR) | ✅ | Full | Any rule matches |
| Intersection (AND) | ✅ | Full | All rules must match |
| Exclusion (BUT NOT) | ✅ | Full | Recursive with parent inheritance |
| Computed relations | ✅ | Full | implied_by with transitive closure |
| Tuple-to-userset (FROM) | ✅ | Full | Parent inheritance |
| Contextual tuples | ✅ | Full | Temporary tuples passed with check request |
Grouping () | ✅ | Full | Complex nested expressions |
| Schema 1.0 | ⚠️ | Untested | Parser potentially works, but untested |
| Schema 1.1 | ✅ | Full | All features except conditions |
| Conditions | ❌ | None | CEL expressions not supported |
| Modular models | ✅ | Full | fga.mod manifests, module, extend type |
| Schema 1.2 | ✅ | Full | Modules supported |
Supported Features
Direct Assignment
Subjects can be directly assigned to relations:
type document
relations
define owner: [user]
define editor: [user, team]
Union (OR)
Multiple conditions combined with OR:
define admin: [user] or owner
define reader: [user] or writer or can_read from org
Tuple-to-Userset (FROM)
Inherit permissions from parent objects:
type repository
relations
define org: [organization]
define can_read: can_read from org
Role Hierarchy (Implied-By)
Transitive closure is computed at schema load time:
define owner: [user]
define admin: [user] or owner # owner implies admin
define member: [user] or admin # owner and admin imply member
Exclusion (BUT NOT)
Deny permission based on another relation:
define can_review: can_read from repo but not author
Wildcards
Public access using wildcard subjects:
define public: [user:*]
define can_read: public or member
Intersection (AND)
Require multiple conditions to all be satisfied:
define viewer: editor and can_read from org
define can_delete: owner and active
Contextual Tuples
Pass temporary tuples with a check request without storing them in the database. Useful for evaluating hypothetical permissions or time-limited access:
// Check with contextual tuples
allowed, err := checker.CheckWithContextualTuples(ctx, user, "can_read", doc, []melange.ContextualTuple{
{Subject: user, Relation: "temp_access", Object: doc},
})Modular Models (Schema 1.2)
Split authorization schemas across multiple files using fga.mod manifests:
# fga.mod
schema: '1.2'
contents:
- core.fga
- issue-tracker/projects.fga
- wiki/spaces.fgaEach file declares a module and can extend types from other modules:
module wiki
extend type organization
relations
define can_create_space: admin or member
type space
relations
define organization: [organization]
define viewer: member from organization
Pass the manifest path instead of a single .fga file:
err := migrator.Migrate(ctx, db, "schemas/fga.mod")At compile time, all modules are merged into a unified schema. The generated SQL is identical whether you use a single file or modular models.
Unsupported Features
Conditions
CEL expressions for conditional authorization are not supported:
# NOT SUPPORTED
condition ip_allowed(user_ip: ipaddress) {
user_ip.in_cidr("10.0.0.0/8")
}
define viewer: [user with ip_allowed]
Melange rejects these schemas rather than dropping the condition, since a dropped condition would silently widen access:
$ melange validate --schema schema.fga
Error: parsing schema: melange: invalid schema: conditions are not supported
and would be silently dropped: document#viewer allows [user with ip_allowed].Most conditions can be expressed another way: a WHERE clause in the tuples
view for conditions on stored data (expiry, status), and contextual tuples or
session settings for conditions on request data (client IP, time). See
Replacing Conditions.
Excluding a Parent Relation Inside a Compound Expression
Melange rewrites each relation into a union of intersections before
compiling it. A but not whose subtract is a tuple-to-userset (x from parent) can be compiled at the top of a relation, but not when it ends up
inside an intersection:
# Supported
define can_view: viewer but not blocked from parent
# NOT SUPPORTED
define can_view: (viewer but not blocked from parent) and active
Melange rejects these schemas rather than compiling them approximately. Move the sub-expression into its own named relation:
define viewer_not_blocked: viewer but not blocked from parent
define can_view: viewer_not_blocked and active
Moving from OpenFGA to Melange
If you run OpenFGA today, most of your model carries over unchanged.
Reuse your
.fgafiles. Schema 1.1 models and modular models (fga.mod) compile as-is. Check that no relation uses a condition (see Replacing Conditions) or excludes a parent relation inside a compound expression, both of which Melange rejects.Replace tuple writes with a view. Instead of writing tuples to a store, define a
melange_tuplesview over the tables that already hold the relationships (memberships, ownership, parent links). See Creating Your Tuples View. If some relationships only exist in OpenFGA, export them withfga tuple readinto a table and include it in the view.Swap the client. Replace OpenFGA SDK calls with the Go Checker, the TypeScript client, or plain SQL (
check_permission). Contextual tuples,ListObjects, andListUsersequivalents are supported.
What you gain: checks run in your database transaction, see uncommitted writes, and need no separate service or tuple sync. What you give up: CEL conditions (most can be replaced with SQL), and the option to scale authorization separately from PostgreSQL.
To try it, start with Installation and the Quick Start.
Migration Path to OpenFGA
Melange is designed to be a stepping stone. If you outgrow its capabilities, you can migrate to the full OpenFGA service.
Planned: Support for the official OpenFGA client SDK is on the roadmap, which will make migration even simpler by allowing you to use the same client code with both Melange and OpenFGA.
When to Consider Migrating
- You need CEL conditions that cannot be expressed in the tuples view or contextual tuples
- You need a dedicated authorization service for horizontal scaling
- Your tuple volume exceeds what PostgreSQL can handle efficiently
Migration Steps
Schema compatibility: Your
.fgaschema files work with both Melange and OpenFGA.Export tuples: Query your
melange_tuplesview to export tuples:SELECT subject_type, subject_id, relation, object_type, object_id FROM melange_tuples;Import to OpenFGA: Use the OpenFGA API to write tuples:
fga tuple write --store-id $STORE_ID \ user:alice owner repository:123Update application code: Replace Melange Checker with OpenFGA SDK:
// Before (Melange) allowed, err := checker.Check(ctx, user, "can_read", repo) // After (OpenFGA) resp, err := client.Check(ctx).Body(openfga.CheckRequest{ TupleKey: openfga.TupleKey{ User: "user:alice", Relation: "can_read", Object: "repository:123", }, }).Execute() allowed := resp.GetAllowed()Sync tuples ongoing: Replace the
melange_tuplesview with tuple writes to OpenFGA on data changes.
What Changes
| Aspect | Melange | OpenFGA |
|---|---|---|
| Deployment | Embedded in PostgreSQL | Separate service |
| Tuple storage | View over existing tables | Dedicated tuple store |
| Transaction visibility | Yes (uncommitted changes) | No (eventual consistency) |
| Latency | Single database query | Network round-trip |
| Scaling | PostgreSQL limits | Horizontal scaling |
What Stays the Same
- Schema files (
.fga) are compatible - Relation names and semantics
- Subject/object/relation model
- Basic permission patterns
Testing Compatibility
Melange includes the official OpenFGA test suite to validate Schema 1.1 compliance. Run the full suite:
# Run the complete OpenFGA compatibility test suite
just test-openfga
# Run specific feature categories
just test-openfga-feature DirectAssignment
just test-openfga-feature ComputedUserset
just test-openfga-feature TupleToUserset
just test-openfga-feature Intersection
just test-openfga-feature Exclusion
just test-openfga-feature WildcardsThe test suite validates behavior against the official OpenFGA specification, ensuring that permission checks return identical results to the OpenFGA server for all supported patterns.
See Contributing - Testing for details on running the compatibility test suite.