mcpField
O
openfga

openfga

github.com/openfgaSecurity5401 installsUpdated 9w ago
Repository

About openfga

A skill for designing and reviewing OpenFGA authorization models, from relations and tuples to permissions and tests. It guides model validation and CLI checks, with SDK references reserved for integration tasks.

Key features

  1. 01Define types, relations, and tuples
  2. 02Derive can_* permissions
  3. 03Apply usersets and inheritance patterns
  4. 04Write .fga.yaml behavior tests
  5. 05Validate models with OpenFGA CLI

Use cases

  1. 01Design an authorization model for a resource graph
  2. 02Test expected access with tuples and assertions
  3. 03Review or simplify an existing OpenFGA model

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/openfga/agent-skills --skill openfga

After installing, type/openfgain Claude Code to confirm it loaded.

Bundled files

References and scripts installed along with SKILL.md.

AGENTS.md
references/
core-relations.md
core-schema-version.md
core-separation.md
core-tuples.md
core-types.md
design-create-on-parent.md
design-hierarchy.md
design-modules.md
design-naming.md
design-organization.md
design-permissions.md
optimize-simplify.md
optimize-tuples.md
optimize-type-restrictions.md
relation-concentric.md
relation-conditions.md
relation-direct.md
relation-indirect.md
relation-usersets.md
relation-wildcards-as-booleans.md
relation-wildcards.md
roles-assignments.md
roles-simple.md
roles-static-combo.md
roles-when-to-use.md
sdk-dotnet.md
sdk-go.md
sdk-java.md
sdk-javascript.md

Details

From the project README

OpenFGA Best Practices

Use this skill to design and review OpenFGA models end to end: define types and relations, write tuples, derive can_* permissions, choose usersets and inheritance patterns, and validate behavior with .fga.yaml tests and CLI checks.

Quick Start Example

Minimal model:

model
  schema 1.1

type user

type organization
  relations
    define admin: [user]
    define member: [user] or admin

type document
  relations
    define organization: [organization]
    define owner: [user]
    define can_edit: owner or admin from organization
    define can_view: can_edit or member from organization

Example tuples:

organization:acme#admin@user:alice
document:roadmap#organization@organization:acme
document:roadmap#owner@user:bob

Example test targets:

  • check that user:alice can view and edit document:roadmap
  • check that user:bob can edit their own document
  • list_users for document:roadmap#can_view
  • list_objects for documents user:alice can edit

How to Use

When a workflow step points to a rule ID, open the matching file in references/ for detailed guidance and examples.

Note: SDK references (sdk-*.md) are only needed for integration tasks — skip them during pure model authoring and testing.

Rule Index

Core
FileDescription
references/core-types.mdDefine types for entity classes
references/core-relations.mdRelations belong on object types
references/core-tuples.mdRelationship tuples as facts
references/core-separation.mdModel vs data separation
references/core-schema-version.mdSchema version
Relations
FileDescription
references/relation-direct.mdDirect relationships
references/relation-indirect.mdIndirect relationships with X from Y
references/relation-concentric.mdConcentric relationships
references/relation-usersets.mdUsersets for group-based access
references/relation-conditions.mdConditional relationships
references/relation-wildcards.mdWildcards for public access
references/relation-wildcards-as-booleans.mdWildcards for boolean attributes
Design
FileDescription
references/design-permissions.mdDefine permissions with can_ relations
references/design-hierarchy.mdHierarchical structures
references/design-organization.mdOrganization-level access
references/design-create-on-parent.mdCheck create permissions on parent objects
references/design-naming.mdNaming conventions
references/design-modules.mdModularize models (only when asked)
Roles
FileDescription
references/roles-simple.mdSimple static roles
references/roles-static-combo.mdCombining static and custom roles
references/roles-assignments.mdRole assignments for resource-specific roles
references/roles-when-to-use.mdWhen to use each role pattern
Optimization
FileDescription
references/optimize-simplify.mdSimplify models
references/optimize-tuples.mdMinimize tuple count
references/optimize-type-restrictions.mdType restrictions
Testing
FileDescription
references/test-fga-yaml.mdStructure tests in .fga.yaml
references/test-check-assertions.mdCheck assertions
references/test-list-objects.mdList objects tests
references/test-list-users.mdList users tests
references/test-conditions.mdTesting conditions
references/test-cli.mdOpenFGA CLI usage
references/workflow-validate.mdAlways validate models
SDKs (for integration tasks only)
FileDescription
references/sdk-javascript.mdJavaScript/TypeScript SDK
references/sdk-go.mdGo SDK
references/sdk-python.mdPython SDK
references/sdk-java.mdJava SDK
references/sdk-dotnet.md.NET SDK

Recommended Workflow

  1. Model the resource graph. Define types, direct relations, inheritance edges, and can_* permissions. Rules to check first: core-*, relation-*, design-permissions, design-hierarchy.

  2. Add tuples and test intent. Add representative tuples and cover expected behavior with check, list_objects, and list_users tests. Rules to check next: core-tuples, test-fga-yaml, test-check-assertions, test-list-objects, test-list-users.

  3. Review parent-child creation and deletion paths. Verify each parent -> child edge has create permissions on the parent and that no child permission is directly grantable unless intended. Rules to check: design-create-on-parent, relation-direct, design-permissions.

  4. Simplify before removing schema. Before deleting any type or relation, confirm it is not referenced by permissions, tuples, or tests. If a simplification breaks a reference: restore the relation or update the model/tests, then re-run this step. Rules to check: optimize-simplify, optimize-tuples, optimize-type-restrictions.

  5. Validate the model. Run:

fga model validate --file stores/<store>/model.fga

If validation fails: read the reported relation or type errors, fix the model, and re-run validation before continuing.

  1. Run the store tests. Run:
fga model test --tests stores/<store>/store.fga.yaml

If tests fail: update tuples, assertions, or permission definitions, then re-run tests until all checks and list queries pass.

  1. Only then finalize delivery. For touched stores, finish only after validation and tests are green. Final rule to check: workflow-validate.

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md

Comments

Markdown supported