Skip to content

Commit e8542c0

Browse files
authored
Merge pull request #14 from linuxfoundation/bramwelt/openfga
[LFXV2-13] OpenFGA Initial Setup
2 parents acb82af + f1b3270 commit e8542c0

File tree

7 files changed

+298
-3
lines changed

7 files changed

+298
-3
lines changed

charts/lfx-platform/Chart.lock

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ dependencies:
2323
- name: nack
2424
repository: https://nats-io.github.io/k8s/helm/charts/
2525
version: 0.29.0
26-
digest: sha256:4c4959d3be948ca6f92601403c6ad8a14513fb57878b19152a4a402fc4ecdaab
27-
generated: "2025-07-22T10:45:48.174955-07:00"
26+
- name: fga-operator
27+
repository: https://3schwartz.github.io/fga-operator/
28+
version: 1.0.0
29+
digest: sha256:a826405ffe32fac17de8a7b9a93e580cdd2be07d0f950bcaa41e0b3b176a5ebc
30+
generated: "2025-07-24T13:06:18.443902223-07:00"

charts/lfx-platform/Chart.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apiVersion: v2
55
name: lfx-platform
66
description: LFX Platform v2 Helm chart
77
type: application
8-
version: 0.1.1
8+
version: 0.1.2
99
icon: https://github.com/linuxfoundation/lfx-v2-helm/raw/main/img/lfx-logo-color.svg
1010
dependencies:
1111
- name: traefik
@@ -40,3 +40,7 @@ dependencies:
4040
repository: https://nats-io.github.io/k8s/helm/charts/
4141
version: ~0.29.0
4242
condition: nack.enabled
43+
- name: fga-operator
44+
repository: https://3schwartz.github.io/fga-operator/
45+
version: ~1.0.0
46+
condition: fga-operator.enabled

charts/lfx-platform/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ For more Traefik configuration options, see the [Traefik Helm Chart documentatio
8686

8787
For more OpenFGA configuration options, see the [OpenFGA Helm Chart documentation](https://github.com/openfga/helm-charts).
8888

89+
For information on managing OpenFGA see the [OpenFGA Documentation](../../docs/openfga.md).
90+
8991
#### Heimdall
9092

9193
| Parameter | Description | Default |
@@ -153,3 +155,5 @@ openfga:
153155
datastore:
154156
existingSecret: openfga-postgresql-client
155157
```
158+
159+
## Documentation
File renamed without changes.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright The Linux Foundation and each contributor to LFX.
2+
# SPDX-License-Identifier: MIT
3+
---
4+
{{- if and .Values.openfga.enabled (index .Values "fga-operator" "enabled") }}
5+
apiVersion: extensions.fga-operator/v1
6+
kind: AuthorizationModelRequest
7+
metadata:
8+
name: {{ index .Values "fga-operator" "store" }}
9+
labels:
10+
{{- include "lfx-platform.labels" . | nindent 4 }}
11+
app.kubernetes.io/component: openfga
12+
spec:
13+
instances:
14+
- version:
15+
major: 1
16+
minor: 1
17+
patch: 1
18+
authorizationModel: |
19+
model
20+
schema 1.1
21+
22+
type user
23+
24+
type team
25+
relations
26+
define member: [user]
27+
28+
type project
29+
relations
30+
define parent: [project]
31+
define owner: [team#member] or owner from parent
32+
define writer: [user] or owner or writer from parent
33+
define auditor: [user, team#member] or writer or auditor from parent
34+
define viewer: [user:*] or auditor or auditor from parent
35+
36+
type committee
37+
relations
38+
define member: [user]
39+
define project: [project]
40+
define writer: writer from project
41+
define auditor: auditor from project
42+
define viewer: [user:*] or auditor from project
43+
44+
type meeting
45+
relations
46+
define project: [project]
47+
define committee: [committee]
48+
define organizer: [user]
49+
define participant: [user, committee#member]
50+
define viewer: [user:*, committee#member] or participant or auditor from project
51+
{{- end }}

charts/lfx-platform/values.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ lfx:
1111
registry: linuxfoundation
1212
pullPolicy: IfNotPresent
1313

14+
fga-operator:
15+
enabled: true
16+
# Non-chart value
17+
store: "lfx-core"
18+
controllerManager:
19+
openFgaUrlEnvVar: 'http://lfx-platform-openfga:8080'
20+
# This value needs to be set in order for the operator to start, but
21+
# because no auth is required for the openfga API this value will be
22+
# ignored by openfga
23+
openFgaApiTokenEnvVar: "fake"
24+
1425
# Traefik configuration
1526
traefik:
1627
enabled: true

docs/openfga.md

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
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

Comments
 (0)