Skip to content

Commit 9ee5518

Browse files
authored
Merge pull request #4 from linuxfoundation/bramwelt/fga-operator-support
Update code and chart to support fga-operator
2 parents 7c1b842 + 84c7961 commit 9ee5518

File tree

7 files changed

+66
-28
lines changed

7 files changed

+66
-28
lines changed

CLAUDE.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ make gosec # Run security scanner
5858
### Required Environment Variables
5959

6060
- `NATS_URL`: NATS server connection URL (e.g., `nats://localhost:4222`)
61-
- `FGA_API_URL`: OpenFGA API endpoint (e.g., `http://localhost:8080`)
62-
- `FGA_STORE_ID`: OpenFGA store ID
63-
- `FGA_MODEL_ID`: OpenFGA authorization model ID
61+
- `OPENFGA_API_URL`: OpenFGA API endpoint (e.g., `http://localhost:8080`)
62+
- `OPENFGA_STORE_ID`: OpenFGA store ID
63+
- `OPENFGA_AUTH_MODEL_ID`: OpenFGA authorization model ID
6464

6565
### Optional Environment Variables
6666

@@ -169,9 +169,9 @@ Each message type has a dedicated handler function:
169169
```bash
170170
# Set environment variables
171171
export NATS_URL="nats://localhost:4222"
172-
export FGA_API_URL="http://localhost:8080"
173-
export FGA_STORE_ID="01K1GTJZW163H839J3YZHD8ZRY"
174-
export FGA_MODEL_ID="01K1H4TFHDSBCZVZ5EP6HHDWE6"
172+
export OPENFGA_API_URL="http://localhost:8080"
173+
export OPENFGA_STORE_ID="01K1GTJZW163H839J3YZHD8ZRY"
174+
export OPENFGA_AUTH_MODEL_ID="01K1H4TFHDSBCZVZ5EP6HHDWE6"
175175

176176
# Run the service
177177
make run
@@ -194,7 +194,7 @@ helm install fga-sync ./charts/lfx-v2-fga-sync \
194194

195195
- **Build failures**: Ensure Go 1.24+ and run `go mod tidy`
196196
- **NATS connection**: Verify NATS_URL and network connectivity
197-
- **OpenFGA errors**: Check FGA_API_URL and ensure OpenFGA is healthy
197+
- **OpenFGA errors**: Check OPENFGA_API_URL and ensure OpenFGA is healthy
198198
- **Cache issues**: Monitor cache hit rates via `/debug/vars`
199199

200200
### Debugging

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ Dependencies you need but should get from [lfx-v2-helm](https://github.com/linux
9494
# This assumes you have the lfx-platform chart running
9595
# from https://github.com/linuxfoundation/lfx-v2-helm/tree/main
9696
export NATS_URL="nats://lfx-platform-nats.lfx.svc.cluster.local:4222"
97-
export FGA_API_URL="http://lfx-platform-openfga.lfx.svc.cluster.local:8080"
98-
export FGA_STORE_ID="01K1GTJZW163H839J3YZHD8ZRY" # Use your actual store ID if you aren't using the lfx-platform chart
99-
export FGA_MODEL_ID="01K1H4TFHDSBCZVZ5EP6HHDWE6" # Use your actual model ID if you aren't using the lfx-platform chart
97+
export OPENFGA_API_URL="http://lfx-platform-openfga.lfx.svc.cluster.local:8080"
98+
export OPENFGA_STORE_ID="01K1GTJZW163H839J3YZHD8ZRY" # Use your actual store ID if you aren't using the lfx-platform chart
99+
export OPENFGA_AUTH_MODEL_ID="01K1H4TFHDSBCZVZ5EP6HHDWE6" # Use your actual model ID if you aren't using the lfx-platform chart
100100
export CACHE_BUCKET="fga-sync-cache"
101101
export USE_CACHE=true
102102
export DEBUG=false
@@ -130,9 +130,9 @@ make docker-build
130130
# Run the container
131131
docker run -d \
132132
-e NATS_URL=nats://lfx-platform-nats.lfx.svc.cluster.local:4222 \
133-
-e FGA_API_URL=http://lfx-platform-openfga.lfx.svc.cluster.local:8080 \
134-
-e FGA_STORE_ID=01K1GTJZW163H839J3YZHD8ZRY \
135-
-e FGA_MODEL_ID=01K1H4TFHDSBCZVZ5EP6HHDWE6 \
133+
-e OPENFGA_API_URL=http://lfx-platform-openfga.lfx.svc.cluster.local:8080 \
134+
-e OPENFGA_STORE_ID=01K1GTJZW163H839J3YZHD8ZRY \
135+
-e OPENFGA_AUTH_MODEL_ID=01K1H4TFHDSBCZVZ5EP6HHDWE6 \
136136
-e CACHE_BUCKET=fga-sync-cache \
137137
-p 8080:8080 \
138138
linuxfoundation/lfx-v2-fga-sync:latest
@@ -159,9 +159,9 @@ make helm-install
159159
| Variable | Description | Default | Required |
160160
|----------|-------------|---------|----------|
161161
| `NATS_URL` | NATS server connection URL | `nats://localhost:4222` | Yes |
162-
| `FGA_API_URL` | OpenFGA API endpoint | - | Yes |
163-
| `FGA_STORE_ID` | OpenFGA store ID | - | Yes |
164-
| `FGA_MODEL_ID` | OpenFGA authorization model ID | - | Yes |
162+
| `OPENFGA_API_URL` | OpenFGA API endpoint | - | Yes |
163+
| `OPENFGA_STORE_ID` | OpenFGA store ID | - | Yes |
164+
| `OPENFGA_AUTH_MODEL_ID` | OpenFGA authorization model ID | - | Yes |
165165
| `CACHE_BUCKET` | JetStream KeyValue bucket name | `fga-sync-cache` | No |
166166
| `USE_CACHE` | Whether to try to use cache for access checks | `false` | No |
167167
| `PORT` | HTTP server port | `8080` | No |

charts/lfx-v2-fga-sync/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ apiVersion: v2
55
name: lfx-v2-fga-sync
66
description: LFX Platform V2 FGA Sync chart
77
type: application
8-
version: 0.1.0
8+
version: 0.2.0
99
appVersion: "latest"

charts/lfx-v2-fga-sync/templates/deployment.yaml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ kind: Deployment
66
metadata:
77
name: {{ .Chart.Name }}
88
namespace: {{ .Release.Namespace }}
9+
{{- with .Values.deployment.labels }}
10+
labels:
11+
{{- toYaml . | nindent 4 }}
12+
{{- end }}
913
spec:
1014
replicas: {{ .Values.application.replicas }}
1115
selector:
@@ -15,6 +19,9 @@ spec:
1519
metadata:
1620
labels:
1721
app: {{ .Chart.Name }}
22+
{{- with .Values.deployment.podLabels }}
23+
{{- toYaml . | nindent 8 }}
24+
{{- end }}
1825
spec:
1926
containers:
2027
- name: app
@@ -25,12 +32,15 @@ spec:
2532
env:
2633
- name: NATS_URL
2734
value: "{{ .Values.nats.url }}"
28-
- name: FGA_API_URL
35+
- name: OPENFGA_API_URL
2936
value: "{{ .Values.fga.apiUrl }}"
30-
- name: FGA_STORE_ID
37+
{{- $labels := default (dict) .Values.deployment.labels }}
38+
{{- if not (hasKey $labels "openfga-store") }}
39+
- name: OPENFGA_STORE_ID
3140
value: "{{ .Values.fga.storeId }}"
32-
- name: FGA_MODEL_ID
41+
- name: OPENFGA_AUTH_MODEL_ID
3342
value: "{{ .Values.fga.modelId }}"
43+
{{- end }}
3444
- name: CACHE_BUCKET
3545
value: "{{ .Values.nats.cacheFgaKvBucket.name }}"
3646
- name: DEBUG

charts/lfx-v2-fga-sync/values.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ image:
1111
# pullPolicy is the image pull policy
1212
pullPolicy: "IfNotPresent"
1313

14+
# deployment is the configuration for the deployment
15+
deployment:
16+
# labels are additional labels to add to the deployment
17+
# When fga-operator is running in the cluster, adding the label
18+
# 'openfga-store: <store-name>' will automatically populate the
19+
# OPENFGA_STORE_ID and OPENFGA_AUTH_MODEL_ID environment variables
20+
# on the pod, overriding fga.storeId and fga.modelId
21+
labels:
22+
openfga-store: "lfx-core"
23+
# podLabels are additional labels to add to the pods
24+
podLabels: {}
25+
1426
# nats is the configuration for the NATS server
1527
nats:
1628
# url is the URL of the NATS server
@@ -43,10 +55,14 @@ nats:
4355
fga:
4456
# apiUrl is the URL of the OpenFGA API server
4557
apiUrl: http://lfx-platform-openfga.lfx.svc.cluster.local:8080
46-
# storeId is the ID of the OpenFGA store
47-
storeId: 01K1GTJZW163H839J3YZHD8ZRY
48-
# modelId is the ID of the OpenFGA model
49-
modelId: 01K1H4TFHDSBCZVZ5EP6HHDWE6
58+
# storeId is the ID of the OpenFGA store, ignored if
59+
# deployment.labels.openfga-store is set and the fga-operator is
60+
# running
61+
storeId: ""
62+
# modelId is the ID of the OpenFGA model, ignored if
63+
# deployment.labels.openfga-store is set and the fga-operator is
64+
# running
65+
modelId: ""
5066

5167
# application is the configuration for the application
5268
application:

fga.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,22 @@ type FgaService struct {
5555
// does not use or support authentication.
5656
func connectFga() (IFgaClient, error) {
5757
var err error
58+
fgaURL := os.Getenv("OPENFGA_API_URL")
59+
fgaStoreID := os.Getenv("OPENFGA_STORE_ID")
60+
fgaAuthModelID := os.Getenv("OPENFGA_AUTH_MODEL_ID")
61+
if fgaURL == "" {
62+
return nil, fmt.Errorf("OPENFGA_API_URL must be set")
63+
}
64+
if fgaStoreID == "" {
65+
return nil, fmt.Errorf("OPENFGA_STORE_ID must be set")
66+
}
67+
if fgaAuthModelID == "" {
68+
return nil, fmt.Errorf("OPENFGA_AUTH_MODEL_ID must be set")
69+
}
5870
fgaClient, err := NewSdkClient(&ClientConfiguration{
59-
ApiUrl: os.Getenv("FGA_API_URL"),
60-
StoreId: os.Getenv("FGA_STORE_ID"),
61-
AuthorizationModelId: os.Getenv("FGA_MODEL_ID"),
71+
ApiUrl: fgaURL,
72+
StoreId: fgaStoreID,
73+
AuthorizationModelId: fgaAuthModelID,
6274
})
6375
if err != nil {
6476
return nil, err

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func main() {
9393
os.Exit(1)
9494
}
9595

96-
logger.With("url", os.Getenv("FGA_API_URL")).Info("OpenFGA client created")
96+
logger.With("url", os.Getenv("OPENFGA_API_URL")).Info("OpenFGA client created")
9797

9898
// Create HTTP handlers for health checks.
9999
createHTTPHandlers()

0 commit comments

Comments
 (0)