fgalgo is a Node.js tool that automatically generates OpenFGA Authorization Models and Relationship Tuples. It reads user attributes and device information from Excel files and Matter specification XML files, then generates Authorization Models and Relationship Tuples compatible with OpenFGA.
-
Automatic Generation
- Automatic import of user and device information from Excel files
- Parsing Matter specification XML files to generate device types and command sets
- Automatic generation of Authorization Models (.fga)
- Automatic generation of Relationship Tuples
- Automatic deployment to OpenFGA server
- Interactive device permission configuration
-
Automatic Update
- Fetch and save Authorization Models and Relationship Tuples from OpenFGA server
- Statistical analysis and summary display of existing data (user count, device count, group count, permission relationships, etc.)
- Interactive CLI for managing users, devices, and groups
- Natural language-based permission changes using LLM (Gemini API)
- Automatic application of changes to OpenFGA
- Node.js (v18 or higher recommended)
- python3
- OpenFGA CLI (
fgacommand) - OpenFGA server
git clone <repository-url>
cd fgalgonpm installCopy .env.sample to create a .env file and configure OpenFGA connection settings:
cp .env.sample .envEdit the .env file:
FGA_API_URL=your-openfga-api-url
FGA_STORE_ID=your-store-id
FGA_API_TOKEN=your-api-token
GEMINI_API_KEY=your-gemini-api-keyPlace the following files in the appropriate directories:
matter_xml/- Matter specification XML files
user_groups.xlsx- User group definitionsuser_attributes.xlsx- User attributesdevice_attributes.xlsx- Device attributes
Examples of configuration file formats are shown below:
| No. | Field | Description | Type |
|---|---|---|---|
| 1 | id | ID | int |
| 2 | uid | Unique group ID | string |
| 3 | name | Human-readable name | string |
| 4 | parent | Parent hierarchy group name | string / null |
| id | uid | name | parent |
|---|---|---|---|
| 1 | teacher | Teacher Group | |
| 2 | doctor | PhD Student Group | teacher |
| No. | Field | Description | Type |
|---|---|---|---|
| 1 | id | ID | int |
| 2 | uid | Unique user ID | string |
| 3 | name | Human-readable name | string |
| 4 | group | Affiliated groups | array of string / null |
| 5 | room | Affiliated rooms | array of string / null |
| id | uid | name | group | room |
|---|---|---|---|---|
| 1 | tanaka | Taro Tanaka | teacher | room101, room102 |
| 2 | sato | Hanako Sato | doctor | room102 |
| No. | Field | Description | Type |
|---|---|---|---|
| 1 | id | ID | int |
| 2 | uid | Unique device ID | string |
| 3 | name | Human-readable name | string |
| 4 | type | Device type | string |
| 5 | room | Affiliated rooms | array of string / null |
| uid | name | type | room |
|---|---|---|---|
| light101 | Room 101 Light | onofflightswitch | room101 |
| lock102 | Room 102 Smart Lock | doorlock | room102 |
node main.jsSelect create (automatic generation) or update (automatic update) when prompted.
Create mode generates new Authorization Models and Relationship Tuples from Excel files and Matter specification XML files, then deploys them to OpenFGA.
Before running create mode, prepare the following files:
User-related (Excel files)
user_groups.xlsx- User group definitionsuser_attributes.xlsx- User attributes
Device-related
device_attributes.xlsx- Device attributesmatter_xml/- Matter specification XML filesfile/json/matter/devicetype.json- Device type definitions (generated by Python script)
-
User Information Processing
- Load user groups and user attributes from Excel files
- Generate Authorization Model for users
- Generate Relationship Tuples for users
-
Device Information Processing
- Load Matter device types from JSON
- Load device attributes from Excel
- Interactive device configuration (permissions, actions)
- Generate Authorization Model for devices
- Generate Relationship Tuples for devices
-
Deploy to OpenFGA
- Send integrated Authorization Model to OpenFGA server
- Upload all Relationship Tuples
Update mode allows you to fetch existing data from OpenFGA and interactively manage and update it.
-
Data Retrieval and Storage
- Fetch current Authorization Model from OpenFGA server
- Fetch current Relationship Tuples from OpenFGA server (with pagination support)
- Save retrieved data to
./file/update/model.fgaand./file/update/tuple.json
-
Statistical Analysis and Display
- Automatically analyze statistics for users, devices, groups, and rooms
- Display counts of each entity, permission relationships, and active relations
- Display aggregated information by device type
-
Interactive Mode
- Select the item to manage from the main menu (users/devices/groups)
- Enter permission change requests in natural language
- LLM analyzes the request and generates an execution plan
- Review and approve the generated plan
- Automatically apply changes to OpenFGA
Update mode uses Gemini API to execute permission changes from natural language.
Usage Examples
Natural language request examples:
- "Grant Tanaka access to the door lock in room 101"
- "Remove all device permissions for Sato"
- "Grant admin permissions to the doctor group for all devices in room102"
The LLM automatically performs the following:
- Parse and structure the request
- Verify consistency with current data
- Generate an execution plan for necessary changes
- Generate updated Authorization Model and Relationship Tuples
fgalgo/
├── main.js # Main entry point
├── package.json
├── .env # Environment variables
├── src/ # Source code
│ ├── create/ # Automatic generation features
│ │ ├── user/ # User-related processing
│ │ ├── device/ # Device-related processing
│ │ ├── export/ # FGA export processing
│ │ └── util/ # Utility functions
│ └── update/ # Automatic update features
│ ├── api/ # OpenFGA API client
│ ├── cli/ # Interactive CLI
│ └── llm/ # LLM integration (Gemini)
├── file/ # Input and template files
│ ├── template/ # EJS templates
│ ├── model/ # FGA model files (for auto-generation)
│ ├── update/ # Files for automatic update
│ │ ├── model.fga # Fetched Authorization Model
│ │ ├── tuple.json # Fetched Relationship Tuples
│ │ ├── update_model.fga # Updated Model (LLM-generated)
│ │ └── update_tuple.json # Updated Tuples (LLM-generated)
│ └── json/ # JSON data files
├── matter_xml/ # Matter specification XML files
└── python/ # Python auxiliary scripts
- @openfga/sdk - OpenFGA SDK
- exceljs - Excel file processing
- xml2js - XML parsing
- ejs - Template engine
- inquirer - Interactive CLI
- dotenv - Environment variable management
Generate device type JSON from Matter XML specification files:
cd python
python parse-matter-devices-xml-to-json.pySaved to file/json/matter