Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenFGA Integration #673

Open
wants to merge 54 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
2008c54
Draft
daveads Sep 30, 2024
81f9fa1
test
daveads Oct 4, 2024
59b2f89
init test**
daveads Oct 20, 2024
b84bd88
inital test
daveads Oct 20, 2024
0778841
configs
daveads Oct 21, 2024
2c30962
fix...
daveads Oct 21, 2024
646a244
packages/opal-common/opal_common/engine/paths.py
daveads Oct 21, 2024
d29c71e
test...
daveads Oct 21, 2024
f802eb2
implemented using api calls drop openfga_sdk
daveads Oct 25, 2024
fa9df9d
openfga test
daveads Oct 26, 2024
2a89c34
test
daveads Oct 26, 2024
7c98c35
docker test
daveads Oct 28, 2024
c450108
..
daveads Oct 28, 2024
f19b265
support for .yaml policy file
daveads Oct 29, 2024
832d903
bug free
daveads Oct 30, 2024
e9b013b
docker
daveads Nov 4, 2024
42374cc
Done
daveads Nov 5, 2024
bebad51
based off review
daveads Nov 13, 2024
0862044
fix improper indentation
daveads Nov 13, 2024
150edd9
review
daveads Nov 13, 2024
773bea4
..
daveads Nov 17, 2024
3ecba01
Merge branch 'master' into feat/openfga-policy-engine
daveads Nov 17, 2024
b7f27e9
formatted
daveads Nov 17, 2024
96a55db
Merge branch 'master' into feat/openfga-policy-engine
daveads Nov 20, 2024
e1bacf0
added INLINE_OPENFGA_EXEC_PATH
daveads Nov 20, 2024
d4ecc3c
formatter
daveads Nov 20, 2024
73d31da
test
daveads Nov 20, 2024
d602c0b
..
daveads Nov 20, 2024
4d57122
..
daveads Nov 20, 2024
4900a9e
openfga app-test
daveads Nov 20, 2024
fe7da70
...
daveads Nov 20, 2024
96c54b4
EXEC_PATH openfga
daveads Nov 20, 2024
9451b04
doc
daveads Nov 21, 2024
2f093c9
openfga docs
daveads Nov 22, 2024
a8b147f
formatted
daveads Nov 22, 2024
71ee7d0
..
daveads Nov 22, 2024
d417531
format
daveads Nov 22, 2024
f45f366
docker
daveads Nov 27, 2024
f8c3eea
..
daveads Nov 27, 2024
93b853c
Merge branch 'master' into feat/openfga-policy-engine
danyi1212 Dec 2, 2024
31c0204
Merge branch 'master' into feat/openfga-policy-engine
danyi1212 Dec 2, 2024
2c22639
format
daveads Dec 8, 2024
3550ea9
merge master
daveads Dec 9, 2024
4880a02
test
daveads Dec 9, 2024
5d567ee
formatt
daveads Dec 9, 2024
3eaa392
Merge branch 'master' into feat/openfga-policy-engine
daveads Dec 11, 2024
5ee38c3
merged master
daveads Dec 11, 2024
c4d16c2
docs
daveads Dec 16, 2024
c05b885
format
daveads Dec 16, 2024
dd19cfc
Update documentation/docs/tutorials/openfga.mdx
gemanor Dec 17, 2024
a17ee8e
Update documentation/docs/tutorials/openfga.mdx
gemanor Dec 17, 2024
3c5adb2
Update documentation/docs/tutorials/openfga.mdx
gemanor Dec 17, 2024
088f9bc
Merge branch 'master' into feat/openfga-policy-engine
daveads Dec 30, 2024
d1421cc
Merge branch 'master' into feat/openfga-policy-engine
daveads Feb 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions docker/docker-compose-example-openfga.yml
daveads marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
version: '3'
name: opal-openfga-example

services:
# When scaling the opal-server to multiple nodes and/or multiple workers, we use
# a *broadcast* channel to sync between all the instances of opal-server.
# Under the hood, this channel is implemented by encode/broadcaster.
# At the moment, the broadcast channel can be either: postgresdb, redis or kafka.
broadcast_channel:
image: postgres:alpine
environment:
Expand All @@ -9,48 +14,65 @@ services:
networks:
- opal-network

# OPAL server configuration
# Handles policy updates and coordinates with the broadcast channel
opal_server:
image: permitio/opal-server:latest
environment:
# the broadcast backbone uri used by opal server workers
- OPAL_BROADCAST_URI=postgres://postgres:postgres@broadcast_channel:5432/postgres
# number of uvicorn workers to run inside the opal-server container
- UVICORN_NUM_WORKERS=4
# the git repo hosting our OpenFGA policy
- OPAL_POLICY_REPO_URL=https://github.com/daveads/opal-example-policy-openfga
# polling interval of 30 seconds to check for policy updates
daveads marked this conversation as resolved.
Show resolved Hide resolved
- OPAL_POLICY_REPO_POLLING_INTERVAL=30
# configures initial data sources for the opal client
- OPAL_DATA_CONFIG_SOURCES={"config":{"entries":[{"url":"http://opal_server:7002/policy-data","topics":["policy_data"],"dst_path":"/static"}]}}
- OPAL_LOG_FORMAT_INCLUDE_PID=true
ports:
# exposes opal server on the host machine at: http://localhost:7002
- "7002:7002"
depends_on:
- broadcast_channel
networks:
- opal-network

# OPAL client configured specifically for OpenFGA integration
opal_client_openfga:
image: permitio/opal-client-openfga:latest
environment:
- OPAL_SERVER_URL=http://opal_server:7002
- OPAL_LOG_FORMAT_INCLUDE_PID=true
# Configure OpenFGA as the policy engine
- OPAL_POLICY_STORE_TYPE=OPENFGA
- OPAL_POLICY_STORE_URL=http://0.0.0.0:8080
- OPAL_OPENFGA_STORE_ID=01JAT34GM6T5WRVMXXDYWGSYKN
# Enable inline OpenFGA mode
- OPAL_INLINE_OPENFGA_ENABLED=true
#- OPAL_LOG_LEVEL=DEBUG

ports:
# exposes opal client API at: http://localhost:7766
- "7766:7000"
# exposes OpenFGA API at: http://localhost:8080
- "8080:8080"
# Additional port exposure
- "3000:3000"
networks:
- opal-network
depends_on:
- opal_server
# Ensures opal-server is ready before starting the client
command: sh -c "exec ./wait-for.sh opal_server:7002 --timeout=20 -- ./start.sh"
volumes:
- openfga_backup:/opal/backup:rw

# Network configuration for service communication
networks:
opal-network:
driver: bridge

# Volume for persisting OpenFGA data
volumes:
openfga_backup:
105 changes: 105 additions & 0 deletions documentation/docs/tutorials/openfga.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# OpenFGA and OPAL
gemanor marked this conversation as resolved.
Show resolved Hide resolved

[OpenFGA](https://openfga.dev) is an open-source authorization engine implementing the Zanzibar authorization model created by Google. OPAL provides realtime synchronization and management capabilities for OpenFGA, allowing you to keep your authorization data and relationships up-to-date across distributed OpenFGA instances.

## Quick Start

OPAL can run OpenFGA as a policy engine instead of OPA. To launch an example configuration with Docker-Compose:
gemanor marked this conversation as resolved.
Show resolved Hide resolved

```bash
git clone https://github.com/permitio/opal.git
cd opal
docker-compose -f docker/docker-compose-example-openfga.yml up -d
```

## Interacting with OpenFGA

The OpenFGA API will be available at [http://localhost:8080](http://localhost:8080). Here are some key endpoints and operations:
gemanor marked this conversation as resolved.
Show resolved Hide resolved

### Check Current State
- View relationship tuples: `GET /stores/{store_id}/read`
- List authorization models: `GET /stores/{store_id}/authorization-models`

### Authorization Checks
To check permissions, send a POST request to `/stores/{store_id}/check`:
```json
{
"tuple_key": {
"user": "user:anne",
"relation": "reader",
"object": "document:budget"
}
}
```

### Setting Up Authorization Models
Create or update an authorization model with PUT to `/stores/{store_id}/authorization-models`:
```json
{
"schema_version": "1.1",
"type_definitions": [
{
"type": "user"
},
{
"type": "document",
"relations": {
"reader": {
"this": {}
},
"writer": {
"this": {}
}
}
}
]
}
```

### Writing Relationship Tuples
Add new relationships with a POST to `/stores/{store_id}/write`:
gemanor marked this conversation as resolved.
Show resolved Hide resolved
```json
{
"writes": {
"tuple_keys": [
{
"user": "user:anne",
"relation": "reader",
"object": "document:budget"
}
]
}
}
```

## Git Integration
Instead of manually configuring authorization models and relationships, you can set the `OPAL_POLICY_REPO_URL` in your Docker compose configuration to automatically load configuration from a Git repository.

## Key Features
The OpenFGA integration with OPAL provides:
- Automatic synchronization of authorization models across OpenFGA instances
- Real-time updates to relationship tuples
- Centralized management of authorization rules
- Support for complex relationship-based authorization patterns
- Version control integration for authorization configuration
- Distributed deployment support with synchronization

## Monitoring
To view OPAL logs:
```bash
# Server logs
docker-compose -f docker/docker-compose-example-openfga.yml logs opal_server

# Client logs
docker-compose -f docker/docker-compose-example-openfga.yml logs opal_client_openfga
```

Alternatively, you can also change the Docker-compose config and set your own policy git repo (the **OPAL_POLICY_REPO_URL** variable) to automatically load authorization models and relationship tuples from version control.

For the server and client, respectively.

The OpenFGA integration provides:
gemanor marked this conversation as resolved.
Show resolved Hide resolved
- Automatic synchronization of authorization models across OpenFGA instances
- Real-time updates to relationship tuples
- Centralized management of authorization rules
- Support for complex relationship-based authorization patterns
Loading