Repository navigation
Description
Description
#45303 asks for reliable external event delivery. Today each EventListenerProvider must define its own payload, filtering, transaction behavior, retries, and broker guarantees.
Add a supported export pipeline:
flowchart LR
E[Event and AdminEvent] --> C[Versioned export envelope]
C --> O[(Durable delivery state)]
O --> S[Destination SPI]
S --> K[Kafka adapter]
S --> N[NATS JetStream adapter]
Keycloak core owns normalization, filtering, transactional capture, asynchronous retry, and independent state per destination. Optional adapters map the envelope to a broker and report broker acceptance.
Delivery to the configured event queue is at least once. Duplicate queue entries are allowed and retain the same event ID. Keycloak does not provide producer-side deduplication or wait for consumer acknowledgement. Consumers decide how to acknowledge, process, and optionally deduplicate events.
Value Proposition
- Provide a reliable event feed without a custom provider JAR.
- Give every destination the same schema, privacy, transaction, and delivery contract.
- Keep broker I/O and retry off authentication and admin request paths.
- Keep Kafka and NATS dependencies in optional modules.
Goals
- Envelope: Capture an immutable, versioned event-time snapshot with one stable event ID across destinations, retries, duplicates, and replay. Preserve custom admin-resource type strings and define schema and rolling-upgrade compatibility. CloudEvents 1.0 is a candidate, not a requirement.
- Transactions: Capture in the transaction that dispatches the event.
EventBuilder#success()andAdminEventBuilder#success()normally use the current transaction.EventBuilder#error()normally uses a separate transaction.EventBuilder#storeImmediately(boolean)can override the user-event default. Publish only committed captures. - Filtering: Filter before capture. Exclude sensitive or unbounded fields by default. Treat
includeRepresentation=falseas a hard ceiling. Never export secrets, credentials, tokens, request bodies, or event-controlled routing values. - Delivery: Retry every committed capture until the configured queue accepts it at least once or an operator explicitly discards it. Do not silently expire it. Isolate destination failures and expose queue age, backpressure, retry, and discard outcomes without payload data.
- Destination SPI: Pass an immutable envelope and bounded delivery metadata to an adapter. Broker acceptance ends Keycloak's responsibility; it does not mean that a consumer processed the event.
- Kafka maps the envelope to a configured topic and key. Its adapter reports successful broker acceptance.
- NATS uses JetStream, not Core NATS, and maps the envelope to a configured subject. A successful
PubAckmeans that the stream accepted the message. Stream retention and replication define persistence; consumer delivery and acknowledgement remain outside Keycloak.
- Configuration: Let server operators provision named destinations and credentials. Realms may reference only permitted destinations. Event data and realm administrators must not select arbitrary endpoints or access credentials.
- Lifecycle: Define pause, resume, delete, replay, credential rotation, cluster failover, metrics, and old-envelope handling during rolling upgrades. Keycloak does not provision broker infrastructure.
Non-Goals
- Consumer processing, acknowledgement, idempotency, or deduplication.
- Producer-side duplicate suppression, exactly-once delivery, or global ordering.
- Inbound broker events or broker provisioning.
- Replacing SSF, the existing event store, or Admin/Account Console event views.
Acceptance Criteria
- Rollback behavior follows the transaction that dispatched the event, including
EventBuilder#storeImmediately(boolean)overrides. - A node crash after committed capture does not lose the capture. Keycloak retries until the queue accepts it at least once; an ambiguous acceptance may create duplicates with the same event ID.
- One unavailable destination does not block another. Capacity exhaustion and operator discard follow an explicit, observable policy.
- Tests prove pre-capture filtering, the
includeRepresentation=falseceiling, credential redaction, and absence of payloads from ordinary logs and metrics. - Kafka and JetStream integration tests stop at broker acceptance. They do not inspect or promise consumer acknowledgement, processing, idempotency, or deduplication.
Open Questions
- CloudEvents or a smaller Keycloak envelope?
- Server-owned destinations with realm references, constrained realm components, or both?
- Which capture failures fail the originating operation when the durable queue is full?
- What ordering scope, if any, can adapters support without serializing unrelated events?
Existing Building Block
At sampled main commit 3a720903102b161236a77ec6ec410fedc3e86545, Keycloak has generic OutboxStore, OutboxDrainerTask, and OutboxDeliveryHandler classes introduced for experimental SSF in #48256. The SSF factory constructs them directly; they are not a supported destination SPI. This issue asks whether core should keep them internal behind the new contract or expose a smaller stable outbox API.
Related
Parent #45303; CloudEvents #25133; webhooks #41175; Kafka/audit storage #44261; cache ordering #51532.
Metadata
Metadata
Assignees
Labels
Type
Fields
Value
Effort
Votes
Projects
- StatusShow more project fieldsOpen
Activity
[-]Provide a versioned external-event envelope and destination SPI[/-][+]Provide a versioned external event envelope and reliable destination SPI[/+][-]Provide a versioned external event envelope and reliable destination SPI[/-][+]Add a versioned event-export envelope and destination SPI[/+]Prasad484 commentedon Nov 4, 2026
We poll
GET /admin/realms/{realm}/admin-eventsto keep an external directory in step with users an identity provider pushes through Keycloak's built-in SCIM (26.8.1, PostgreSQL). Two things we measured make that polling route impossible to make lossless. Both look like what this proposal's transactional capture and "do not silently expire" goals would fix.DELETE /admin/realms/{realm}/admin-eventsremoved 3,997 entries and left no trace. With admin events switched off, every change made in the meantime is lost. Entries pastadminEventsExpirationare purged at the next cleanup. A reader can only detect this indirectly, for example by checking that an entry it already read is still there.Our workarounds are a delayed second read, a bookmark entry to detect clearing, and a full user listing to repair state. Together they recover each user's current state, but not the changes made while the log was missing. A committed, durable export as described here would remove the need for all three.