|
| 1 | +# OpenFGA Documentation |
| 2 | + |
| 3 | +This document provides comprehensive guidance on managing OpenFGA stores and authorization models in the LFX Platform, including how to create, update, and query stores and models using both the fga-operator and direct CLI commands. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +OpenFGA (Open Fine-Grained Authorization) is a modern authorization system that provides flexible, high-performance authorization for applications. The LFX Platform uses OpenFGA for managing authorization models and stores through the [fga-operator](https://github.com/3schwartz/fga-operator). |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +The fga-operator automates the synchronization between your Kubernetes deployments and OpenFGA authorization models. It provides: |
| 12 | + |
| 13 | +- **AuthorizationModelRequest**: Defines authorization models and creates stores |
| 14 | +- **Store**: Kubernetes resource representing an OpenFGA store |
| 15 | +- **AuthorizationModel**: Kubernetes resource representing an authorization model |
| 16 | +- **Automatic Deployment Updates**: Updates deployments with latest model IDs |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +### 1. Verify the Model Deployed |
| 21 | + |
| 22 | +The LFX Platform includes a pre-configured authorization model that's automatically deployed when you install the chart. The model can be found in `charts/lfx-platform/templates/openfga/model.yaml`. Check that it deployed successfully: |
| 23 | + |
| 24 | +```bash |
| 25 | +# Check AuthorizationModelRequest status |
| 26 | +kubectl get AuthorizationModelRequest -n lfx |
| 27 | + |
| 28 | +# Check Store resource |
| 29 | +kubectl get Store -n lfx |
| 30 | + |
| 31 | +# Check AuthorizationModel resource |
| 32 | +kubectl get AuthorizationModel -n lfx |
| 33 | +``` |
| 34 | + |
| 35 | +### 2. View the Authorization Model Details |
| 36 | + |
| 37 | +Get detailed information about the deployed authorization model: |
| 38 | + |
| 39 | +```bash |
| 40 | +# Get the store name from values (default is 'lfx-core') |
| 41 | +STORE_NAME=$(helm get values lfx-platform -n lfx -o json | jq -r '.["fga-operator"].store // "lfx-core"') |
| 42 | + |
| 43 | +# View the authorization model details |
| 44 | +kubectl get AuthorizationModel/$STORE_NAME -n lfx -o yaml |
| 45 | +``` |
| 46 | + |
| 47 | +This will show you the model ID, version, and the complete authorization model definition. |
| 48 | + |
| 49 | +## Managing Stores and Models |
| 50 | + |
| 51 | +### Listing Stores |
| 52 | + |
| 53 | +Use the fga-cli to list all stores: |
| 54 | + |
| 55 | +```bash |
| 56 | +kubectl run --rm -it fga-cli --namespace lfx --image=openfga/cli --env="FGA_API_URL=http://lfx-platform-openfga:8080" --restart=Never -- store list |
| 57 | +``` |
| 58 | + |
| 59 | +### Listing Models |
| 60 | + |
| 61 | +List all authorization models for a specific store: |
| 62 | + |
| 63 | +```bash |
| 64 | +# First, get the store ID |
| 65 | +STORE_ID="$(kubectl get Store lfx-core -n lfx -o jsonpath='{.spec.id}')" |
| 66 | + |
| 67 | +# Then list models |
| 68 | +kubectl run --rm -it fga-cli --namespace lfx --image=openfga/cli --env="FGA_STORE_ID=$STORE_ID" --env="FGA_API_URL=http://lfx-platform-openfga:8080" --restart=Never -- model list |
| 69 | +``` |
| 70 | + |
| 71 | +### Getting Model Details |
| 72 | + |
| 73 | +Get detailed information about a specific model: |
| 74 | + |
| 75 | +```bash |
| 76 | +# Get model details (replace MODEL_ID with actual ID) |
| 77 | +kubectl run --rm -it fga-cli --namespace lfx --image=openfga/cli --env="FGA_STORE_ID=$STORE_ID" --env="FGA_API_URL=http://lfx-platform-openfga:8080" --restart=Never -- model get --id MODEL_ID |
| 78 | +``` |
| 79 | + |
| 80 | +## Updating Authorization Models |
| 81 | + |
| 82 | +To update the authorization model, modify the version and model definition in `charts/lfx-platform/templates/openfga/model.yaml`: |
| 83 | + |
| 84 | +1. **Increment the version** in the `instances` section: |
| 85 | + ```yaml |
| 86 | + instances: |
| 87 | + - version: |
| 88 | + major: 1 |
| 89 | + minor: 1 |
| 90 | + patch: 3 # Bump this version number |
| 91 | + authorizationModel: | |
| 92 | + model |
| 93 | + schema 1.1 |
| 94 | +
|
| 95 | + type user |
| 96 | +
|
| 97 | + type team |
| 98 | + relations |
| 99 | + define member: [user] |
| 100 | +
|
| 101 | + type project |
| 102 | + relations |
| 103 | + define parent: [project] |
| 104 | + define owner: [team#member] or owner from parent |
| 105 | + define writer: owner or writer from parent |
| 106 | + define auditor: [user, team#member] or writer or auditor from parent |
| 107 | + define viewer: [user:*] or auditor or auditor from parent |
| 108 | + # Add new relations here as needed |
| 109 | + ``` |
| 110 | +
|
| 111 | +2. **Redeploy the chart** to apply the changes: |
| 112 | + ```bash |
| 113 | + helm upgrade lfx-platform ./charts/lfx-platform -n lfx |
| 114 | + ``` |
| 115 | + |
| 116 | +The fga-operator will automatically detect the version change and create a new authorization model in OpenFGA while keeping the existing model for backward compatibility. |
| 117 | + |
| 118 | +## Deployment Integration |
| 119 | + |
| 120 | +### Automatic Environment Variable Updates |
| 121 | + |
| 122 | +The fga-operator automatically updates deployments with the `openfga-store` label. When you create or update an authorization model, the operator will: |
| 123 | + |
| 124 | +1. Update the `OPENFGA_AUTH_MODEL_ID` environment variable |
| 125 | +2. Update the `OPENFGA_STORE_ID` environment variable |
| 126 | +3. Add annotations with timestamps and version information |
| 127 | + |
| 128 | +### Example Deployment |
| 129 | + |
| 130 | +```yaml |
| 131 | +apiVersion: apps/v1 |
| 132 | +kind: Deployment |
| 133 | +metadata: |
| 134 | + name: whoami |
| 135 | + namespace: lfx |
| 136 | + labels: |
| 137 | + openfga-store: lfx-core |
| 138 | + # Set a version to use a specific model |
| 139 | + # openfga-auth-model-version: 1.2.3 |
| 140 | +spec: |
| 141 | + replicas: 1 |
| 142 | + selector: |
| 143 | + matchLabels: |
| 144 | + app: whoami |
| 145 | + template: |
| 146 | + metadata: |
| 147 | + labels: |
| 148 | + app: whoami |
| 149 | + spec: |
| 150 | + containers: |
| 151 | + - name: api |
| 152 | + image: traefik/whoami:latest |
| 153 | + env: |
| 154 | + - name: OPENFGA_API_URL |
| 155 | + value: "http://lfx-platform-openfga:8080" |
| 156 | + # OPENFGA_AUTH_MODEL_ID and OPENFGA_STORE_ID will be automatically set |
| 157 | +``` |
| 158 | + |
| 159 | +### Checking Deployment Updates |
| 160 | + |
| 161 | +Verify that your deployment updated with the latest model information: |
| 162 | + |
| 163 | +```bash |
| 164 | +# Check environment variables |
| 165 | +kubectl get deployment whoami -n lfx -o jsonpath='{.spec.template.spec.containers[0].env}' |
| 166 | + |
| 167 | +# Check annotations |
| 168 | +kubectl get deployment whoami -n lfx -o jsonpath='{.metadata.annotations}' |
| 169 | +``` |
| 170 | + |
| 171 | +## Querying Authorization Data |
| 172 | + |
| 173 | +### Writing Tuples |
| 174 | + |
| 175 | +Add authorization relationships: |
| 176 | + |
| 177 | +```bash |
| 178 | +# Add a user as owner of a project |
| 179 | +kubectl run --rm -it fga-cli --namespace lfx --image=openfga/cli --env= "FGA_STORE_ID=$STORE_ID" --env= "FGA_API_URL=http://lfx-platform-openfga:8080" --restart=Never -- tuple write --tuple "user:[email protected]:owner:project:project1" |
| 180 | +``` |
| 181 | + |
| 182 | +### Reading Tuples |
| 183 | + |
| 184 | +Query existing relationships: |
| 185 | + |
| 186 | +```bash |
| 187 | +# List all tuples |
| 188 | +kubectl run --rm -it fga-cli --namespace lfx --image=openfga/cli --env="FGA_STORE_ID=$STORE_ID" --env="FGA_API_URL=http://lfx-platform-openfga:8080" --restart=Never -- tuple read |
| 189 | + |
| 190 | +# Query specific relationships |
| 191 | +kubectl run --rm -it fga-cli --namespace lfx --image=openfga/cli --env= "FGA_STORE_ID=$STORE_ID" --env= "FGA_API_URL=http://lfx-platform-openfga:8080" --restart=Never -- tuple read --tuple "user:[email protected]:owner:project:project1" |
| 192 | +``` |
| 193 | + |
| 194 | +### Checking Authorization |
| 195 | + |
| 196 | +Test authorization decisions: |
| 197 | + |
| 198 | +```bash |
| 199 | +# Check if a user can read a project |
| 200 | +kubectl run --rm -it fga-cli --namespace lfx --image=openfga/cli --env= "FGA_STORE_ID=$STORE_ID" --env= "FGA_API_URL=http://lfx-platform-openfga:8080" --restart=Never -- check --tuple "user:[email protected]:reader:project:project1" |
| 201 | +``` |
| 202 | + |
| 203 | +## Advanced Topics |
| 204 | + |
| 205 | +### Events and Monitoring |
| 206 | + |
| 207 | +Monitor operator events: |
| 208 | + |
| 209 | +```bash |
| 210 | +# Check events |
| 211 | +kubectl get events -n lfx --sort-by='.lastTimestamp' |
| 212 | + |
| 213 | +# Check specific resource events |
| 214 | +kubectl describe AuthorizationModelRequest lfx-core -n lfx |
| 215 | +``` |
| 216 | + |
| 217 | +## References |
| 218 | + |
| 219 | +- [OpenFGA Documentation](https://openfga.dev/) |
| 220 | +- [fga-operator GitHub Repository](https://github.com/3schwartz/fga-operator) |
| 221 | +- [OpenFGA CLI Documentation](https://openfga.dev/docs/getting-started/cli) |
| 222 | +- [OpenFGA Helm Chart](https://github.com/openfga/helm-charts) |
0 commit comments