Keycloak audit logging with login and admin events

Keycloak can record user login activity and administrator changes, store them in its database, and send them to a SIEM through a custom event listener. This page explains the settings, the trade-offs and the work involved.

On this page

Keycloak audit logging with login and admin events: what auditors will ask for

An auditor or security team will usually ask three questions: who signed in, from where and when, and who changed users, clients, realms or permissions in Keycloak. Keycloak answers these with two separate event types. User events record authentication activity such as logins, failed logins, logouts, token requests and account changes made by users. Admin events record configuration changes made through the Admin Console or the Administration REST API, such as creating a client, altering a role or changing a realm setting. Each serves a different audit question, so both need to be turned on and reviewed deliberately.

Keycloak does not capture everything by default. The realm's event settings decide which user event types are stored, whether admin events are saved, and whether the representation of the changed object (the request body, for example a client's new redirect URIs) is included with each admin event. Those choices determine whether an auditor can later reconstruct what changed and what the value was before or after. Confirm the exact settings and their names against the version you deploy, since the server administration guide documents them and they can change between releases. Record the configuration as a baseline so you can show the auditor what was enabled and when.

DeployOpen prepares the Keycloak configuration, the event retention approach and the evidence package, including sample exports and a description of how the logs are reviewed. DeployOpen does not issue audit reports or attestations. Auditors and certification bodies decide whether your event coverage, retention and review process are sufficient for the framework in scope. Ask them early which event types, fields and retention periods they expect to see, so the configuration is designed to meet that test rather than adjusted after the fact.

How login and admin events move from Keycloak to storage and the SIEM

The diagram starts with a user sign-in and an administrator change made in the Admin Console or Administration REST API. Both produce events that pass through the event settings enabled in the realm. Keycloak stores the enabled events in its database, and an optional custom Listener SPI provider can forward them to a SIEM. The Keycloak database and the forwarding path are the two places to protect and monitor, because a gap in either one leaves the audit trail incomplete.

Login and admin events flow from Keycloak to its database and an optional SIEM.

Event settings and when each one fits

This table compares the realm-level event settings that control what Keycloak records for logins and administrator changes. Read each row as a separate switch: the capture it turns on, the audit question it answers, and the storage or privacy cost it adds. The main takeaway is that the more detail you store, the more evidence you have, but also the more personal data and database growth you must govern.

SettingWhat it captures and the audit question it answersStorage or privacy cost to weigh
Save user eventsSign-in, token, logout and account events for users, answering who signed in to which client, when, and whether it succeededGrows the events table with every login and token request; may include IP addresses and user identifiers that fall under your privacy policy
Selected user event typesNarrows the saved user events to chosen types, such as login errors, answering whether failed attempts need to be retained for investigationLower volume than saving all types, but a missing type cannot be reconstructed later, so confirm the list against your audit scope
Save admin eventsRecords changes made through the Admin Console and Administration REST API, answering who changed a realm, client, user or role and whenUsually modest volume, but changes to realm or client settings are high-value evidence, so retain them longer than routine login data
Include representation of changed objectsStores the JSON representation of the object an administrator changed, answering what the object looked like before or after the changeCan store secrets or personal attributes inside the representation; review what is saved and restrict who can read the events table
Event expirationSets how long saved events remain in the database, answering how far back you can prove activity for your retention periodLonger expiration increases database size and backup cost; align it with your log retention policy and confirm the default for your release
Enable event listenersPasses events to configured listeners, such as a custom Listener SPI provider that forwards them to a SIEM, answering whether events reach a central system outside KeycloakAdds a delivery path to maintain and secure; a listener failure can mean lost events if you do not keep the database copy

Keeping events in the database or forwarding them to a SIEM

This setup keeps login and admin events in the Keycloak database, where administrators can review them in the Admin Console under the events views. The platform team operates it as part of the Keycloak database, so backup, retention and access to that database become audit controls in their own right. Security staff get a simple starting point, but the Admin Console is not built for long-term correlation, cross-system searches or alerting, so most review happens by exporting or querying data by hand.

  • Operator: the platform team, through the Keycloak configuration and the database that backs it.
  • What security gets: event review in the Admin Console, filtered by user, client, event type and time.
  • What to build and test: event and admin event settings, a retention period that matches the audit requirement, and a tested restore of the database with its event tables.
  • Failure modes: events age out or are pruned earlier than the audit window, a database failure removes the only copy of the record, and manual review misses patterns across systems.

Confirm the event retention behavior and export options for your Keycloak version with the Keycloak server administration guide before you commit the audit process to this setup.

How to set up Keycloak audit events step by step

This sequence takes you from a written list of audit questions to a Keycloak configuration that records login and admin activity, forwards it to your SIEM, and has been checked with test events. Each step ends with a check you can repeat during an audit.

  1. Write the audit questions first

    Before changing any setting, the compliance lead and the security team write the questions the audit must answer, such as who signed in to which application, from where, which logins failed, and who changed a client, role or user in the admin console. Each question maps to an event type and a realm. Done means every question has a named owner and a list of the event types it needs. Confirm with your auditor which evidence period and format they expect, since Keycloak only records what you enable.

  2. Choose the realms in scope

    The platform owner lists every realm that holds production users or clients, including the master realm that holds administrator accounts, and marks which ones fall under the audit. Test and development realms are usually excluded or kept separate. Event settings are configured per realm, so a realm missed here will have no login history. Done means a written inventory of realm names with an in-scope or out-of-scope decision for each.

  3. Enable user and admin event saving

    In the Admin Console, the platform owner opens each in-scope realm, goes to the Realm settings and Events area, and turns on saving for user events and admin events. Select the user event types the audit questions need, such as login, login error, logout, register and password updates, and turn on admin events with the option to include representations only where you decided to store them. Done means a saved configuration for each realm and a note of the chosen event types. Check the Realm settings page after saving to confirm the values persisted.

  4. Decide how representation data is stored

    Admin events can include the request and response representation of a changed object, such as a client or user. Including representations gives detail about what changed but can also store personal data and secrets in the event store, so the security and privacy owners decide case by case. Record the decision per realm and document who can read the stored events. Done means a written decision that states whether representations are stored, what data they may contain, and who approved it.

  5. Set event retention and confirm storage behavior

    Keycloak keeps saved events in its database, so retention is a decision about database growth and about how long evidence stays available inside Keycloak. Set the expiration for stored events to match the audit period, and make sure the forwarding step below keeps a copy outside the database. Confirm the database backup schedule covers the event tables. Done means a written retention value per realm, a test restore or a documented backup policy, and a confirmation from the database owner that the event tables are included.

  6. Build and deploy the Listener SPI provider in a test realm

    If events must reach a SIEM such as Wazuh, the platform or development team builds an event listener provider that implements the Keycloak Listener SPI, packages it as a JAR, and deploys it to a test instance. Add the listener to the event listeners list in a test realm only, then keep production unchanged until tests pass. The provider should forward events to the SIEM over a TLS connection with its own credential. Done means the provider loads without startup errors in the server log and appears as an option in the test realm's event settings.

  7. Generate test sign-ins and admin changes

    The QA owner runs a scripted set of test actions in the test realm: successful and failed logins, a logout, a new user registration, a password change, and an admin change to a client and a role. Each action is tied to a test account so the events are easy to find. Done means each action has a recorded timestamp and a matching event type in a list of expected results.

  8. Verify each event in the Admin Console and the SIEM

    For every test action, the QA owner checks the Admin Console Events view for the matching user event or admin event, confirms the user, client, IP address and event type are correct, and then checks that the same event arrived in the SIEM with the same timestamp and fields. Missing or duplicate events are logged as defects and fixed before production. Done means a signed-off test record that shows each expected event in both places, which can be reused as audit evidence for the configuration.

What stored representations contain and how long to keep events

Storing representations in admin events is a privacy and access decision as well as an audit one. When Include representation is enabled, an admin event carries the JSON of the user, client, role or setting that was created or changed, so the record can hold personal data such as names, email addresses and attributes, and sensitive configuration such as redirect URIs, client settings and mapper definitions. Anyone who can read the events in the admin console or through the Admin REST API can therefore see that content. Decide before go-live which resource types need representations, restrict who holds the view-events role, and confirm with your privacy team whether storing personal data in event records fits your retention commitments. Also confirm which secrets could appear in a representation and test whether they are masked in your Keycloak version.

Treat retention as two separate decisions. The first is how long events stay in the Keycloak database, which is governed by the realm's event expiration setting and the cleanup that Keycloak runs on that table. The second is how long your SIEM or log archive keeps copies of the events, which is governed by your storage tier, index lifecycle and legal hold rules. The second decision usually drives audit evidence, because auditors ask for records across the audit period and a short database window is not evidence that a longer window is not needed. Set the database window for operational lookups and recovery, set the archive window to the period your audit and regulatory obligations require, and confirm that exported copies are complete and tamper-evident before you rely on them.

Keycloak 26.8 upgrade notes state that login failures are persisted to the database by default. Failed login events, which attackers and misconfigured applications generate in large numbers, will grow the event tables faster than successful sign-ins, so a database sized on successful logins alone can fill sooner than expected. Estimate the failure rate from a test or staging realm before setting the expiration window, and include the event tables in your database capacity plan, monitoring and backup scope. Confirm how the event tables are included in your backup and restore tests, and whether the upgrade path for your deployment keeps this default or changes it, so that growth and retention are reviewed together at each upgrade.

Security risks in audit logging that teams often miss

Audit logs are only useful if the systems that produce, store and forward them are themselves protected. The risks below sit around the event pipeline rather than inside the login flow, and each one can leave a gap that an auditor or incident responder finds later.

Admin endpoints on a public hostname

The Admin Console and Administration REST API can change event settings, listeners and realm configuration, so exposure of them is a risk to the audit trail itself. Keycloak's production guide recommends serving them on a different hostname or context path from public frontend URLs, with a reverse proxy restricting paths. Check that a request to the admin path from outside your management network fails and that the proxy rules match the documented setup for your version.

Production guide

Unprotected event database

Stored login and admin events usually sit in the same database that holds user records and credentials. If that database is reachable from application networks or uses shared accounts, an attacker or an insider can edit or delete the events that would show their activity. Confirm that the database accepts connections only from the Keycloak nodes, that it runs over encrypted connections, and that its backups are restricted in the same way. Confirm who can run deletes against the event tables.

Forwarding paths without TLS

A custom listener that sends events to a SIEM over plaintext HTTP or an unencrypted syslog path exposes user names, IP addresses and client identifiers in transit. The events can also be altered before they arrive. Require TLS on every hop from the listener to the SIEM, validate the receiver certificate, and check the traffic with a packet capture on a test login. Plaintext event traffic is a finding.

Listener failures that go unnoticed

An event listener runs inside the Keycloak process, so an exception or a timeout in the forwarding code can drop events without any user-visible error. Logins keep working while the SIEM receives nothing, and the gap only appears when someone searches for an event that never arrived. Add a delivery counter or heartbeat that alerts when the SIEM stops receiving events, and log listener errors at a level your monitoring collects. Test a forced listener failure and confirm an alert fires.

Administrators who change audit settings silently

An administrator with rights to the realm can turn event saving off, change retention or remove a listener, and the change may not be recorded as an admin event unless admin event saving is enabled and checked. Limit the realm roles that can change event configuration, keep those accounts separate from daily administration, and review changes to event settings as part of your access reviews. Confirm that admin events are enabled and that a test change to event settings appears in the admin event log.

Server admin guide

Metrics left open on the management interface

When metrics are enabled with --metrics-enabled=true, Keycloak serves Prometheus-format data at /metrics on the management interface. That output can reveal request volumes, cache behavior and deployment details useful to an attacker. Keep the management interface off public networks, allow only your Prometheus scraper, and confirm that /metrics does not answer from the public hostname. Request /metrics from outside the scraper network and expect a refusal.

Metrics guide

Running audit events after go-live

The recurring work on Keycloak audit events starts with proving that events still arrive. Each Keycloak upgrade and each change to the event listener configuration can alter what is recorded or how it is delivered, so every upgrade should include a test of the audit pipeline: trigger a test login, a failed login and an administrative change in a non-production realm, then confirm each event reaches the SIEM with the expected fields. Keep the list of enabled event types and the listener settings under version control so a reviewer can compare them before and after each change. Confirm the upgrade notes for each target release, since behavior around login failures and related events has changed between releases and should be checked rather than assumed.

Event tables grow with every login and admin action, so monitor database growth as a standing operational metric and set a retention schedule that matches your audit requirements. In supported high availability designs the Keycloak database must be synchronously replicated, and that replication determines how event data survives failover: confirm with your database team that committed events are not lost when a primary fails over, and test that claim rather than relying on the design diagram. Restore testing matters here too. Periodically restore event data into an isolated environment and confirm you can answer a specific question about a past login or admin change, because an unrestorable backup does not satisfy an audit request.

Limit who can change event settings. Administrators who can alter event storage, listener configuration or retention can also remove the evidence of their own actions, so review membership of the realm administration roles on a fixed schedule and log changes to the event configuration itself. Feed Keycloak's Prometheus-format metrics, exposed at /metrics when started with --metrics-enabled=true, and its health endpoints into the same monitoring stack that watches the SIEM connection, so a stopped listener or a failing database becomes an alert instead of a gap found during an audit. Ask your team to document who owns each alert and who approves configuration changes.

Limits to confirm before you commit to an audit design

An audit design for Keycloak login and admin events rests on several limits that depend on your exact release, your event pipeline and the framework you are assessed against. Each card below names one limit to verify with the Keycloak documentation in your environment and with your auditor before you commit to a design.

Event types and representation settings

Confirm which login and admin event types your chosen Keycloak release records, and whether it can store full admin representations of changed objects. Event coverage has changed between releases, so check the event list against the version you plan to run. Record which user and admin events are enabled, and which representation settings are on, so the auditor can see exactly what the trail contains. Test a sample login, a failed login and an admin change in a non-production realm and compare the output with your written list.

Current release
26.8.1
Keycloak docs

Listener SPI provider fit with the release

If you forward events with a custom Listener SPI provider, confirm it is built and tested against the exact Keycloak release you run. SPI interfaces and packaging can change between releases, so a provider that compiled against an earlier line may fail at startup or silently drop events after an upgrade. Ask who owns the provider code, where it is built, and whether a rebuild is part of each upgrade. Verify this in a staging realm before any production release.

Delivery guarantees and failure behavior

Establish whether event delivery from your listener to the SIEM is at least once or best effort, and what Keycloak and your provider do when the SIEM or network is unavailable. A provider that sends events synchronously can slow sign-in, while one that drops events on error leaves gaps an auditor will ask about. Define a buffer or retry path, alert on delivery failures, and document how you detect and backfill missing events. Confirm this behavior in writing with your SIEM vendor and in your own failure tests.

Event volume against database and SIEM capacity

Estimate event volume from your user count, login patterns and admin activity, then test it against the database that stores events and the SIEM that ingests them. Login events scale with every sign-in, token refresh path and failed attempt, so volume can grow faster than expected in large or automated environments. Load-test the pipeline with realistic traffic and watch database growth, indexing lag and SIEM license limits. Plan purge jobs and index lifecycle rules before go-live.

Retention against framework requirements

Confirm that your retention period for Keycloak events, both in the database and in the SIEM, meets the record-keeping rules of each framework your auditor tests. Keycloak's own event expiration is a database setting, so the SIEM copy is often the one that serves as the long-term record. Ask the auditor which records they will sample, how far back they will look, and whether they expect tamper protection or write-once storage. Map each answer to a stored location and an owner.

Custom code maintenance through upgrades

Determine who maintains any custom event code and how it is retested with each Keycloak upgrade, including minor releases. Keycloak's upgrade notes can add or change behavior that affects events, so a custom provider needs a regression test that covers login, failed login and admin changes. Name an owner, schedule upgrade testing into your change process, and keep the provider's dependencies current. Ask whether a support retainer covers this work or whether your team carries it.

Keycloak upgrade guide

Questions teams ask before setting up Keycloak audit events

What does setting up Keycloak audit events cost, and what drives the effort?

Most of the cost is labor, and the main drivers are the number of realms, whether you need a custom listener, how many SIEM integrations you run, and how your retention rules are written. Enabling user and admin events in the database is a configuration task. Writing and testing a Listener SPI provider that forwards events to a SIEM is a development task with its own review cycle. Realm count matters because event settings are applied per realm and each one needs verification. Ask for a written scope that lists each realm, each event type, the SIEM target, the retention rule and who signs off on the evidence. Ask whether the quote includes retesting after Keycloak upgrades, because a custom listener must be checked again each time the server changes. Costs for the software itself are zero under the Apache 2.0 license, so the quote covers implementation, testing and handover.

How long does a Keycloak audit event setup take?

Duration depends on the environment more than on the Keycloak settings themselves. A team that only needs login and admin events stored in the database with a defined retention process can finish that part quickly. Timelines grow when the SIEM is not yet chosen, when the auditor's evidence list is still changing, when many realms have different requirements, or when a custom Listener SPI must be built, reviewed and tested in a non-production environment first. Ask for a timeline in the written scope that separates discovery, configuration, listener development, testing and handover. Ask which dependencies sit outside the engagement, such as SIEM onboarding windows or change approvals in your own environment.

What does our team need to provide for the work?

Three groups of people are needed. Keycloak administrators must confirm the realms in scope, the clients that matter for audit, and the access model for the admin console. SIEM owners must confirm the ingestion format, the destination, the parsing rules and the retention period on their side. Compliance or audit leads must provide the list of evidence the auditor expects, such as which login outcomes, administrator changes and client updates must be traceable and for how long. Without that evidence list, the team cannot tell whether the event types and retention settings are sufficient. Confirm access to a non-production Keycloak instance for testing before the work starts, since event configuration should not be validated for the first time in production.

Can an internal team set up Keycloak audit events alone?

Yes, for the basic settings. Turning on user events and admin events, choosing which event types to store, and setting an expiration for stored events can be done in the Keycloak admin console by a team that knows the product. The effort increases when you need to forward events to a SIEM through the Listener SPI. That requires Java development against the Keycloak provider interfaces, packaging the provider into the server, testing it against your event volume and failure modes, and repeating those tests after each upgrade. Storing representations of changed objects adds privacy and storage review. Teams that lack Java or Keycloak development skills, or that cannot allocate testing time, should price the listener work separately.

Does DeployOpen issue audit reports for Keycloak?

No. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports, attestations or certifications. Independent auditors and certification bodies perform those assessments. What DeployOpen can deliver for audit events is a configured Keycloak with documented event settings, retention rules, SIEM forwarding where scoped, and evidence that the settings were tested. Ask your auditor which evidence format they accept and share that requirement before the scope is written. Your auditor decides whether the evidence is sufficient for your framework.

Which Keycloak settings should an engineer check first?

Start with the realm event configuration, where user events and admin events are enabled and the event types to store are selected. Next, confirm the event expiration setting, since stored events are removed after that period. Check whether admin events include representations of changed objects, because those records can contain personal data and should be reviewed against your privacy rules before you enable them. Then confirm that the server is reachable from the SIEM path and that failures in forwarding are logged. Test each setting with a login success, a failed login, an administrator change and a client update, and confirm each one appears where the auditor expects it. Keep the test results with the configuration record.

How DeployOpen scopes and delivers Keycloak audit logging

DeployOpen plans Keycloak audit logging as a written scope that covers login events, admin events, retention and SIEM forwarding inside infrastructure you control. The work is built, tested, documented and handed over so your security and compliance teams can review the evidence themselves.

How we scope

  • Agree in writing which login and admin event types the audit must capture and which realms are in scope.
  • Confirm where event storage, retention periods and export paths will live in your own environment before build starts.
  • Define the SIEM target, the Listener SPI approach and who receives alerts, with the scope and deliverables set out before work begins.

How we build

  • Configure user and admin event settings, including whether representations are stored, and record each setting in the change log.
  • Build and test the Listener SPI forwarding path so events reach the SIEM with the fields your analysts need.
  • Verify test logins and administrator actions appear in both Keycloak and the SIEM, and document any gaps found during testing.

How we hand over

  • Deliver written configuration records, event field mappings, retention settings and runbooks for your operations team.
  • Walk your security and compliance reviewers through the evidence so they can check the audit trail against their own requirements.
  • Provide a clear list of open items, such as settings to confirm with your auditors, before the engagement closes.

How we support

  • Offer ongoing support, upgrades and continuous testing for audit logging as a retainer when you want it maintained after handover.
  • Review audit logging again when Keycloak upgrades change event behavior or when your SIEM or retention requirements change.
  • Coordinate fixes and retesting for any logging gaps found after go-live, within the agreed support arrangement.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.