Quarkus OpenFGA Client
Overview
The Quarkus OpenFGA Client extension provides a reactive client for accessing OpenFGA instances. Additionally, it is the client that powers the Quarkus Zanzibar - OpenFGA Connector to provide Find Grained Authorization for Quarkus applications.
Installation
If you want to use this extension, you need to add the io.quarkiverse.openfga:quarkus-openfga-client
extension first to your build file.
For instance, with Maven, add the following dependency to your POM file:
<dependency>
<groupId>io.quarkiverse.openfga</groupId>
<artifactId>quarkus-openfga-client</artifactId>
<version>2.1.0</version>
</dependency>
Or with Gradle, add the dependency to your build.gradle
:
implementation("io.quarkiverse.openfga:quarkus-openfga-client:2.1.0")
Configuration
The extension requires two configuration properties to be defined at startup to define what instance and store are
targeted by the client. The url
property selects the scheme, host and, optionally, the port of the OpenFGA instance.
While store
determines which authorization store is targeted; it can be referenced by store id or name.
quarkus.openfga.url=http://localhost:80
quarkus.openfga.store=my-app-authz
# Optional authorization model id
#quarkus.openfga.authorization-model-id=11G22H33I44J55K66L77M88N99
DevServices
The extension supports Quarkus’s DevServices and will start and configure a local OpenFGA in dev
and test
if no
url
configuration property is provided. Additionally it will automatically create and configure an authorization
store in the server.
In addition to starting and creating an authorization store, an authorization model can be initialized in the store
by configuring the quarkus.openfga.devservices.authorization-model
or
quarkus.openfga.devservices.authorization-model.lcation
property.
Basic Usage
Adding the quarkus-openfga-client
extension to your project defines clients beans OpenFGAClient
that are configured to access the OpenFGA instance configured in application.properties
.
Clients
The extension provides three injectable clients for accessing the configured instance and store.
OpenFGAClient
-
Main client for accessing the OpenFGA instance.
StoreClient
-
Access authorization store configured via
quarkus.openfga.store-id
AuthorizationModelsClient
-
Manage (list, create, delete) authorization models and create
AuthorizationModelClient
instances for accessing a specific model. AuthorizationModelClient
-
Access authorization model configured via
quarkus.openfga.authoriztion-model-id
or the default model if none is configured.
Examples
Extension Configuration Reference
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|
---|---|---|
Whether a health check is published in case the smallrye-health extension is present. Environment variable: |
boolean |
|
Whether tracing spans of client commands are reported. Environment variable: |
boolean |
|
If DevServices has been explicitly enabled or disabled. DevServices is generally enabled by default, unless there is an existing configuration present. When DevServices is enabled Quarkus will attempt to automatically configure and start a database when running in 'dev' or 'test' mode. Environment variable: |
boolean |
|
The container image name to use, for container based DevServices providers. Environment variable: |
string |
|
Indicates if the OpenFGA instance managed by Quarkus DevServices is shared. When shared, Quarkus looks for running containers using label-based service discovery. If a matching container is found, it is used, and so a second one is not started. Otherwise, DevServices for OpenFGA starts a new container. The discovery uses the Container sharing is only used in 'dev' mode. Environment variable: |
boolean |
|
The value of the This property is used when you need multiple shared OpenFGA instances. Environment variable: |
string |
|
Optional fixed port the HTTP service will be bound to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
Optional fixed port the gRPC service will be bound to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
Optional fixed port the Playground service will be bound to. If not defined, the port will be chosen randomly. Environment variable: |
int |
|
Name of authorization store to create for DevServices. Defaults to "dev". Environment variable: |
string |
|
JSON formatted authorization model to upload during DevServices initialization. Environment variable: |
string |
|
Location of JSON formatted authorization model file to upload during DevServices initialization. The location can be prefixed with Environment variable: |
string |
|
JSON formatted authorization tuples to upload during DevServices initialization. Environment variable: |
string |
|
Location of JSON formatted authorization tuples file to upload during DevServices initialization. The location can be prefixed with Environment variable: |
string |
|
required |
||
Shared authentication key. If none provided unauthenticated access will be attempted. Environment variable: |
string |
|
Store id or name for default If the provided property does not match the OpenFGA store id format ( Environment variable: |
string |
required |
Always Treat If true, the store id will always be resolved at runtime regardless of the format of the Environment variable: |
boolean |
|
Authorization model id for default If none is provided the default bean will target the default authorization model for the store. Environment variable: |
string |
|
Timeout to establish a connection with OpenFGA. Environment variable: |
|
|
Request timeout on OpenFGA. Environment variable: |
|
|
List of remote hosts that are not proxied when the client is configured to use a proxy. This list serves the same purpose as the JVM Entries can use the * wildcard character for pattern matching, e.g *.example.com matches www.example.com. Environment variable: |
list of string |
|
Type |
Default |
|
Allows to bypass certificate validation on TLS communications. If true this will allow TLS communications with OpenFGA, without checking the validity of the certificate presented by OpenFGA. This is discouraged in production because it allows man in the middle type of attacks. Environment variable: |
boolean |
|
Certificate bundle used to validate TLS communications with OpenFGA. The path to a pem bundle file, if TLS is required, and trusted certificates are not set through javax.net.ssl.trustStore system property. Environment variable: |
string |
About the Duration format
To write duration values, use the standard You can also use a simplified format, starting with a number:
In other cases, the simplified format is translated to the
|