openfga binary in your PATH. If you have built openfga as a binary, but not in your path, you can refer to it directly (e.g. replace openfga in the instructions below with ./openfga or /path/to/openfga).
For a list of all the configuration options that the latest release of OpenFGA supports, see Configuration Options, or you can run openfga --help to see the ones specific to your version.
The instructions below are for configuring the standalone OpenFGA server. If you are using OpenFGA as a library, you can refer to the GoDoc for more information.
Configuring data storage
OpenFGA supports multiple storage engine options, including:memory- A memory storage engine, which is the default. Data is lost between server restarts.postgres- A Postgres storage engine.mysql- A MySQL storage engine.sqlite- A SQLite storage engine.
openfga migrate command. This will create the required database tables or perform the database migration required for a new version.
Postgres
PostgreSQL Read Replicas Configuration
OpenFGA supports configuring separate read and write datastores for PostgreSQL to improve performance and scalability. This feature allows you to distribute read operations across read replicas while directing write operations to the primary database.Setting Up Read Replicas
To use read replicas, you need to configure both a primary datastore (for writes) and a secondary datastore (for reads):- The
--datastore-uriparameter specifies the primary database (used for writes and high-consistency reads) - The
--datastore-secondary-uriparameter specifies the read replica (used for regular read operations) - Both databases must have the same schema and should be kept in sync through PostgreSQL replication
Synchronous vs Asynchronous Replication
The choice between synchronous and asynchronous replication affects data consistency and performance: Synchronous Replication:- Pros: Guarantees data consistency across primary and replica
- Cons: Higher latency for write operations
- Use case: When data consistency is critical and you can tolerate slower writes
- PostgreSQL config:
synchronous_commit = onandsynchronous_standby_names = 'replica_name'
- Pros: Better write performance, lower latency
- Cons: Potential for read-after-write inconsistencies (replica lag)
- Use case: When write performance is prioritized and slight delays in read consistency are acceptable
- PostgreSQL config:
synchronous_commit = off(default)
Consistency Preferences
OpenFGA provides consistency controls to handle read-after-write scenarios: Higher Consistency Mode: When usingHIGHER_CONSISTENCY preference in read operations, OpenFGA will automatically route the query to the primary database instead of the read replica, ensuring you get the most up-to-date data.
HIGHER_CONSISTENCY flag will be routed to the read replica for better performance.
Best Practices
- Monitor Replica Lag: Set up monitoring for replication lag between primary and replica
- Use Higher Consistency Sparingly: Only use
HIGHER_CONSISTENCYwhen you need immediate read-after-write consistency - Connection Pooling: Configure appropriate connection pools for both primary and replica connections
Example PostgreSQL Replication Setup
Here’s a basic example of setting up PostgreSQL streaming replication: Primary server configuration (postgresql.conf):This is a simplified example. For production setups, refer to the PostgreSQL documentation on replication for comprehensive configuration guidelines.
MySQL
The MySQL datastore has stricter limits for the max length of some fields for tuples compared to other datastore engines, in particular:- object type is at most 128 characters (down from 256)
- object id is at most 255 characters (down from 256)
- user is at most 256 characters (down from 512)
parseTime=true.
SQLite
Configuring authentication
You can configure authentication in three ways:- no authentication (default)
- pre-shared key authentication
- OIDC
Pre-shared key authentication
If using Pre-shared key authentication, you will configure OpenFGA with one or more secret keys and your application calling OpenFGA will have to set anAuthorization: Bearer <YOUR-KEY-HERE> header.
- Configuration File
- Environment Variables
Update the config.yaml file to
OIDC
To configure with OIDC authentication, you will first need to obtain the OIDC issuer and audience from your provider.- Configuration File
- Environment Variables
Update the config.yaml file to
Profiler (pprof)
Profiling throughpprof can be enabled on the OpenFGA server by providing the --profiler-enabled flag. For example:
3001, you can do so by specifying the --profiler-addr flag. For example:
Health check
OpenFGA is configured with an HTTP health check endpoint/healthz and a gRPC health check grpc.health.v1.Health/Check, which is wired to datastore testing. Possible response values are
- UNKNOWN
- SERVING
- NOT_SERVING
- SERVICE_UNKNOWN
- cURL
- gRPC
Experimental features
Various releases of OpenFGA may have experimental features that can be enabled by providing the--experimentals flag or the experimentals config.
Telemetry
OpenFGA telemetry data is collected by default starting on versionv0.3.5. The telemetry information that is captured includes Metrics, Traces, and Logs.
Please refer to the docker-compose.yaml file as an example of how to collect Metrics and Tracing in OpenFGA in a Docker environment using the OpenTelemetry Collector. This should serve as a good example that you can adjust for your specific deployment scenario.
Metrics
OpenFGA metrics are collected with the Prometheus data format and exposed on address0.0.0.0:2112/metrics.
Metrics are exposed by default, but you can disable this with --metrics-enabled=false (or OPENFGA_METRICS_ENABLED=false environment variable).
To set an alternative address, you can provide the --metrics-addr flag (OPENFGA_METRICS_ADDR environment variable). For example:
--metrics-enable-rpc-histograms flag (OPENFGA_METRICS_ENABLE_RPC_HISTOGRAMS environment variable).
Tracing
OpenFGA traces can be collected with the OTLP data format. Tracing is disabled by default, but you can enable this with the--trace-enabled=true (OPENFGA_TRACE_ENABLED=true environment variable). Traces will be exported by default to address 0.0.0.0:4317. You can change this address with the --trace-otlp-endpoint flag (OPENFGA_TRACE_OTLP_ENDPOINT environment variable). In order to just correlate trace_id in logs if you are propagating tracing contexts into OpenFGA, exporter can be disabled by providing none as endpoint value.
To increase or decrease the trace sampling ratio, you can provide the --trace-sample-ratio flag (OPENFGA_TRACE_SAMPLE_RATIO env variable).
Tracing by default uses a insecure connection. You can enable TLS by using --trace-otlp-tls-enabled=true flag or the environment variable OPENFGA_TRACE_OTLP_TLS_ENABLED.
Logging
OpenFGA generates structured logs by default, and it can be configured with the following flags:--log-format: sets the log format. Today we supporttextandjsonformat.--log-level: sets the minimum log level (defaults toinfo). It can be set tononeto turn off logging.
Related Sections
Check the following sections for more on how to use OpenFGA.Configuration Options
Find out all the different flags and options that OpenFGA accepts
Running OpenFGA in Production
Learn the best practices of running OpenFGA in a production environment