How embesozzi/keycloak-openfga-workshop works
Main components
• Keycloak Server:
– Handles authentication (OpenID Connect) and issues tokens.
– Contains the custom extension (keycloak-openfga-event-publisher) that listens to events (e.g., role assignments) and transmits them to OpenFGA.
• OpenFGA Service:
– Receives authorization events from Keycloak.
– Performs tuple-based relationship checks to determine permissions.
• Store Web Application (Store Portal):
– Implemented in the “store-oidc-app” directory. This frontend integrates with Keycloak for user authentication and displays the product catalog.
• Store Authorization Gateway:
– A custom API gateway based on Apache APISIX that enforces ReBAC policies using the “authz-openfga” plugin.
– Acts as a sidecar protecting the Store API endpoints.
• Store-api / Store OpenFGA API:
– These backend REST APIs (found in the “store-api” and “store-openfga-api” directories) serve product data and validate access by calling OpenFGA (via the OpenFGA Java SDK in one case).
• Kafka Integration:
– The kafka-integration directory suggests components that may be used for asynchronous event handling or additional inter-service communication.
Out the relationships and interactions
• User Flow:
– The end-user accesses the Store Portal (store-oidc-app) and is redirected to Keycloak for login.
– Upon successful authentication, Keycloak issues an id_token and access token.
• Authorization Flow:
– The Store Portal calls the Store API (routed first via the Store Authorization Gateway). The API validates the token and extracts the user identifier.
– For sensitive operations (e.g., “view” or “edit” product), the Store API invokes OpenFGA to check the user’s relationship (assignee, parent links) to the required roles or permissions.
• Keycloak Event Publishing:
– Internally, the custom Keycloak extension listens for role or user events and, using the OpenFGA Java SDK, publishes these events (after translating them to tuple keys based on the authorization model defined in “openfga/model.dsl”) to the OpenFGA service.
• Message Bus Integration (if applicable):
– The Kafka integration part of the project (directory: kafka-integration) suggests that there is also an asynchronous approach to collect or process events, possibly for audit or further decoupling.
Stress important architectural patterns/design principles
• Decoupling of authorization from business logic:
– Authorization is handled independently by the OpenFGA service and is integrated into both API Gateway and server endpoints.
• Policy as Code (PaC):
– The authorization model “model.dsl” and the automatic configuration imports (e.g., into Keycloak) highlight the use of PaC.
• Layered security:
– Separation between the frontend (Store Portal), API layer (store-api/store-openfga-api), and the authorization concerns (Keycloak, OpenFGA, and API gateway).
• Event-driven integration:
– Use of custom event publishers, potentially further offloaded via Kafka, shows an event-driven design where changes in roles/assignments propagate to authorization decisions.
Relevant technologies and frameworks
• Keycloak for identity and authentication management.
• OpenFGA for fine-grained, tuple-based authorization.
• Apache APISIX (via a custom plugin “authz-openfga”) as the API gateway.
• Node.js (as evidenced by package.json and source files in store-api and store-oidc-app) for building the Store API and Store Portal.
• Docker Compose is used to orchestrate the environment across different containers.
• Kafka components indicate integration points for message-based communication.