Guide
Keycloak Audit Log: How to Use Events in an Access Review
How to turn on Keycloak audit logging, what user and admin events record, how to search and export them, what they miss, and how to use them in reviews.
Part of the guide User Access Review: How to Run One, Step by Step
Your auditor asks about Keycloak, the system that signs your people in to your apps. Who was given admin roles since the last review? Did the removals the reviewers decided on really happen? When did this account last log in? Keycloak can answer all three, but only if someone switched on its events before the question was asked. This guide explains what Keycloak records, how to switch it on, how to search and export the events, what they leave out, and how they fit into a user access review.
The Keycloak audit log is two sets of events per realm: user events, such as logins and failed logins, and admin events, which record each change made through the Admin Console or the Admin REST API. Keycloak stores neither by default. You switch them on under Realm settings, then Events, and read them under Events.
A few Keycloak words come up on this page:
- A realm is one walled-off set of users, groups, roles and apps. Events are switched on, kept and read per realm.
- A role is a named permission, such as
billing-admin. A role mapping is the link that gives a role to a user or a group. - A group is a set of users. Its roles go to every member.
- The Admin REST API is the web interface Keycloak offers for managing it. The Admin Console, the screens an admin clicks through, uses the same API.
- An event listener is a part of Keycloak that receives each event and does something with it, such as writing it to the server log.
What the Keycloak audit log records
Keycloak’s Server Administration Guide describes two kinds of events, in its chapter on configuring auditing to track events. They are switched on separately and answer different questions.
| Question | User events | Admin events |
|---|---|---|
| What they record | Events that affect a user: a login, a failed login, a logout, a password change, an account locked by brute force protection. | Each change an administrator makes through the Admin Console or the Admin REST API: creating a user, putting someone in a group, giving a role. |
| Where you switch them on | Realm settings, Events, User events settings, Save events. | Realm settings, Events, Admin events settings, Save events. |
| What each event holds | A time, a type such as LOGIN, the client (app), the user id, the session, the IP address, an error if there was one, and details. | A time, the admin who acted (realm, client, user id and IP address), an operation, a resource type, the resource path, and the JSON that was sent if you switch that on. |
| Where you read them | Events, User events tab. | Events, Admin events tab. |
| The question they answer in a review | When did this account last log in? | Who gave this access, and when? Was it removed? |
The fields in the third row come from the EventRepresentation and AdminEventRepresentation objects in Keycloak’s Admin REST API reference. Every time is a number of milliseconds since 1 January 1970, not a date.
User events that matter in a review
Keycloak’s guide describes most user event types, and the EventType list names all of them, without descriptions. Each one also has an error event, such as LOGIN_ERROR for a failed login. These are the ones to know for an access review:
| Event type | What it records | Why it matters |
|---|---|---|
| LOGIN | A user logs in. | The newest one is the last login, as far back as the stored events reach. |
| LOGIN_ERROR | A login failed, such as a wrong password. | Attempts on an account nobody should be using. |
| CLIENT_LOGIN | A program logs in with its own client credentials, through a service account. | Whether a service account is still in use. |
| USER_DISABLED_BY_PERMANENT_LOCKOUT, USER_DISABLED_BY_TEMPORARY_LOCKOUT | Brute force protection, if you switched it on, disabled the account after too many failed logins. | Why an account is disabled, if nobody decided to disable it. |
| UPDATE_CREDENTIAL, REMOVE_CREDENTIAL | A password or one-time password setting changed, or a credential was removed. | Changes to how an account logs in. |
| IMPERSONATE | An administrator started acting as another user. | Use of the impersonation role, which gives its holder another person's access. |
Admin events that matter in a review
An admin event has an operation and a resource type. Keycloak’s list of operation types has four: CREATE, UPDATE, DELETE and ACTION. Its list of resource types has more than thirty. The list gives names only, no descriptions. All four operations are changes or actions: looking at users or exporting them leaves no admin event. For access, these are the ones to search:
| Resource type | What changed | What to look for |
|---|---|---|
| USER | A user account. | Accounts created, deleted or changed. An UPDATE does not say which field changed. With Include representation on, the stored JSON shows the values sent, such as enabled. |
| GROUP_MEMBERSHIP | Who is in a group. | CREATE for people put in a group, which gives them the group's roles. DELETE for people taken out. |
| REALM_ROLE_MAPPING | Which realm roles a user or a group holds. | Roles given or taken away, directly or to a whole group. |
| CLIENT_ROLE_MAPPING | Which client roles a user or a group holds. | The same for the roles of one app, including the realm-management roles that let people run the realm. |
| REALM_ROLE, CLIENT_ROLE | A role itself. | Roles created, deleted or changed, including roles added to a composite role, which reach everyone who holds it. |
| GROUP | A group itself. | Groups created, deleted or changed. A subgroup gets the roles of the group above it. |
| CLIENT | An app registered in Keycloak. | A service account switched on for a client, which creates a login for a program. |
Here is what a role grant looks like when you read it through the API. It is an example, shortened, and the ids are made up. Without Include representation, the representation line is not there, and nothing in the event names billing-admin.
{
"time": 1764417600000,
"authDetails": { "realmId": "1b7e40c2-master", "userId": "5d21a9f0-kim", "ipAddress": "203.0.113.10" },
"operationType": "CREATE",
"resourceType": "REALM_ROLE_MAPPING",
"resourcePath": "users/9c4f2e11-dana/role-mappings/realm",
"representation": "[{\"name\":\"billing-admin\",\"composite\":false}]"
}
The Keycloak access review guide explains how groups, composite roles and the default role pass access down, and why a list of direct roles is too short.
How to turn on Keycloak audit logging
The steps below follow Keycloak’s guide. Do them in every realm you review, including the master realm, where the people who run Keycloak itself sign in.
User events
- In the Admin Console, open the realm and click Realm settings in the menu.
- Click the Events tab, then the User events settings tab.
- Switch Save events on.
- In Expiration, set how long Keycloak keeps each event. Pick a time at least as long as the gap between two reviews, so the last login of each account is still there on review day.
- Check the list of saved types. Keycloak saves a set of types by default, and Add saved types shows the others. Make sure
LOGIN,LOGIN_ERRORandCLIENT_LOGINare on it, then save.
Admin events
- On the same Events tab, click the Admin events settings tab.
- Switch Save events on.
- If your version shows an Expiration field on this tab, set it the same way as for user events. Admin events older than that are deleted.
- Switch Include representation on. Keycloak then stores the JSON document sent with each change. Without it, an admin event says whose roles changed, but not which role.
- Click Save.
The reason for step 4: to give a role, the Admin REST API takes the role in the body of the call, not in its address. The event’s resource path names the user or the group, and only the stored JSON names the role. Keycloak warns that this can store a lot of data in the database, and lets your Keycloak administrator cap the length of the stored JSON with the --spi-events-store--jpa--max-field-length server option. That is the spelling in the current guide: older versions write server options differently, so check the guide for your version.
The same settings from the command line
For the engineer who manages Keycloak, the guide’s chapter on the Admin CLI shows the same settings through kcadm.sh, the command-line tool that ships with Keycloak. This example switches both on in a realm named corp and keeps user events for 400 days. The realm name and the time are an example: use your own. Log in first with kcadm.sh config credentials, as the Keycloak access review guide shows.
kcadm.sh update events/config -r corp \
-s eventsEnabled=true -s eventsExpiration=34560000 \
-s adminEventsEnabled=true -s adminEventsDetailsEnabled=true
kcadm.sh get events/config -r corp
eventsExpiration is in seconds. adminEventsDetailsEnabled is the Include representation switch. The second command prints the settings back, so you can keep a copy with your review records.
How to search and export Keycloak events
In the Admin Console
Click Events in the menu. The User events tab has a Search user event form, and the Admin events tab has a search of its own. This works for a quick look at one account. For a record you can hand to an auditor, with the search you ran written on it, use the API.
Through the Admin REST API
Keycloak’s Admin REST API reference has two calls for reading events, both under /admin/realms/{realm}:
GET eventsreturns user events. It filters bytype,user(the user id),client,ipAddress,dateFromanddateTo.GET admin-eventsreturns admin events. It filters byoperationTypes,resourceTypes,resourcePath,authUser(the id of the admin who acted),authClient,authRealm,authIpAddress,dateFromanddateTo.
Dates are written yyyy-MM-dd or as milliseconds since 1970, and both ends are included. Both calls page with first and max, and the reference says max defaults to 100 for admin events. A result of exactly 100 events is a sign there are more. The reader needs the view-events role of the realm’s realm-management client, or the same role on the corp-realm client for an admin who lives in the master realm.
This example, for the engineer who runs the export, lists the group memberships created since a date as tab-separated text, with the date in UTC. It uses kcadm.sh and jq, and it only reads:
kcadm.sh get admin-events -r corp \
-q operationTypes=CREATE -q resourceTypes=GROUP_MEMBERSHIP \
-q dateFrom=2026-06-01 --offset 0 --limit 500 |
jq -r '.[] | [(.time / 1000 | floor | todate), .operationType, .resourcePath, .authDetails.realmId, .authDetails.userId] | @tsv'
Change resourceTypes and operationTypes to run each search in the steps below. If a run returns as many lines as --limit, run it again with --offset moved on by that number until it returns fewer. The last two columns are the realm and the user id of the admin who acted, not a username. Look the id up in the users of that realm.
Write on each export the search you ran, the realm and the day you ran it. An auditor who sees a file with no search cannot tell what was left out.
What the Keycloak audit log does not tell you
The events are useful, and it is easy to ask too much of them. Six limits to keep in mind:
- It is not a list of who has access. It records events. Someone given a role three years ago, and not touched since, appears in no recent event and still holds the role. The list of who holds what comes from the users, groups and role mappings. The Keycloak access review guide has a script that builds it.
- It starts when you switch it on. Keycloak does not store events by default. A login or a change made before Save events was on was never stored, and no setting brings it back. If events are off, last login is unknown. Write “unknown”, never “never”.
- It forgets what has expired. A user event older than the Expiration you set is gone. Keycloak’s guide presents Expiration as a way to stop the database from filling, so whoever set it may have picked a short value. Depending on your version, the Admin events settings tab may show an Expiration field too. Check both before review day, not on it.
- It records calls to the Admin REST API. Keycloak’s guide says the Admin Console works by calling the Admin REST API, and that Keycloak audits those calls. If people come from an LDAP directory or another identity provider, part of their access starts outside Keycloak, so look for the record of those changes in that system too. A role that reaches someone without an admin call, such as the default role or a mapping from a directory, may leave no admin event at all.
- It does not say why. An admin event names who made a change, not who approved it. Match each addition to the request or ticket where someone said yes.
- The people who manage events can clear them. The Admin Console has Clear user events and Clear admin events buttons, and the Admin REST API has a call to delete each kind. The
realm-managementclient has amanage-eventsrole, andrealm-admincontains it. Review who holds them, and keep exports outside Keycloak.
Sending events to the server log
Stored events live in Keycloak’s database. You may also want them in the log system you already keep, where retention is set once for everything. Keycloak’s built-in jboss-logging event listener writes events to the server log under the org.keycloak.events category.
The guide says this listener writes error events as WARN and other events as DEBUG, and that Keycloak leaves debug messages out of the server log by default. So a successful LOGIN does not reach the log until your Keycloak administrator raises its level, with a server option such as --spi-events-listener--jboss-logging--success-level=info. The listener must also be in the realm’s Event listeners field, on the Events tab of Realm settings.
The log line for an admin event leaves out the JSON by default, so a role-mapping event in the log does not name the role. Keycloak’s provider configuration reference lists the --spi-events-listener--jboss-logging--include-representation option for that, and says the realm must have Include representation on for admin events too.
From there, Keycloak’s logging guide covers the handlers that carry the log out of the server: the console, a file, or a syslog server, chosen with the --log option, and JSON output for each, so a log system can read the fields.
How to use the Keycloak audit log in a user access review
The review starts from the current list. The events then answer the questions an auditor tends to ask about it: was each new access asked for, was each removal made, and is each account still used. Here is how they fit together.
- Take the current list first. For each realm, list every user and service account with every role they hold, by any route: directly, through a group or subgroup, or through a composite role. The Keycloak access review guide shows how, and why the direct role list is too short.
- Add last login to each line. From user events, the newest
LOGINof each person, orCLIENT_LOGINfor a service account. Write the date the stored events start, so a reviewer knows what “no login seen” covers. - Find the access added since the last review. Search admin events from the day of your last review for
CREATEonUSER,GROUP_MEMBERSHIP,REALM_ROLE_MAPPINGandCLIENT_ROLE_MAPPING. Also search for any event onREALM_ROLEandCLIENT_ROLE, where a composite role may have grown, onGROUP, where a subgroup may have moved, and onCLIENT, where a service account may have been switched on. Export each result. - Match each addition to an approval. For every person given a role or put in a group, find the request where someone approved it. Look hardest at the
realm-managementroles, such asmanage-usersandrealm-admin, which are privileged access. An addition with no approval is a finding, even if the access is fine today. - Send the current list to the reviewers. Each manager or app owner decides keep or remove for each line. Last login helps here: an account nobody has used in months is easy to remove.
- Make the removals at their source. Your Keycloak admins take each access away where it was given: the role mapping on the person, their group membership, or the role on the group.
- Check the removals in the events. Search admin events from the day the decisions were made for
DELETEonGROUP_MEMBERSHIP,REALM_ROLE_MAPPING,CLIENT_ROLE_MAPPINGandUSER. Each removal you decided on should have its event. Then take the current list again, because a person can keep a role through a second route, such as another group. - Keep the files together. Save the first list, the decisions with who made them and when, the event exports with the search for each, the event settings, and the second list. That set is the evidence pack an auditor asks for.
Watch for accounts that are disabled but still hold roles: a disabled account keeps its roles, and they come back if someone switches it on. Look for UPDATE events on USER for those. And watch for people who left the company but still have an enabled Keycloak account with no recent login. They are an orphaned account and belong in your leaver process.
How often to review, and how long to keep events
SOC 2 and ISO 27001 set no interval for access reviews: your access control policy sets one. If PCI DSS applies to the systems your Keycloak signs people in to, PCI DSS v4.0.1 requirement 7.2.4 says user accounts and access privileges are reviewed at least once every six months. Requirement 10.5.1 says audit log history is kept for at least 12 months, with at least the most recent three months available right away for analysis. The PCI DSS user access review guide reads 7.2.4 line by line.
If PCI DSS applies, the 12 months of 10.5.1 is the longer of the two, and you can keep that history in Keycloak or in the log system you send events to. Whatever the interval, set the user event Expiration longer than the gap between two reviews, and export admin events at each review so the history of the period is in your records, not only in Keycloak’s database.
Where Acciew fits
Acciew, in early access, runs the listing and asking steps of this review for Keycloak, and for GitHub and AWS. It reads accounts, groups, roles and who holds them, through groups and composite roles, and the last login of each account where the realm stores login events. Where it does not, the answer is “unknown”, never “inactive”. It sends each manager a link to their own short list. It only reads, so removing access, and checking the events after, stays with your admins.
Have an access review coming up?
Acciew is in early access. We are looking for design partners: teams with a user access review ahead of them.
Apply as a design partnerQuestions and answers
Does Keycloak have an audit log?
Yes, but Keycloak does not store it by default. It has two kinds of events: user events, such as logins and failed logins, and admin events, which record changes made through the Admin Console or the Admin REST API. You switch each one on for each realm, under Realm settings, then Events.
Where are Keycloak audit logs stored?
Keycloak stores saved events in its own database, where you read them in the Admin Console or through the Admin REST API. Its built-in jboss-logging listener also writes events to the server log, under org.keycloak.events. By default only error events reach a server log at the usual info level.
How long does Keycloak keep events?
For user events, as long as the Expiration field on the User events settings tab says. Depending on your version, the Admin events settings tab may have an Expiration field of its own. Keycloak's guide describes it as a way to stop your database from filling up. Keep in mind that nothing is recorded before you switch events on, so the history starts on that day.
How do I see who gave a user a role in Keycloak?
Only from admin events, and only if they were switched on before the change. Search the admin events for the resource type REALM_ROLE_MAPPING or CLIENT_ROLE_MAPPING and the operation CREATE. The event names the admin who acted by user id and gives the path of the user. To see which role was given, Include representation must also have been on. If the role came through a group, search GROUP_MEMBERSHIP as well.
Does the Keycloak audit log show who has access today?
No. It records events: logins and changes, with when and by whom. Someone given a role before events were switched on, or before the oldest event you kept, appears in no event and still holds the role. Take the list of who holds what from the users, groups and role mappings, and use the events to explain how it came to be.
This guide is part of User Access Review: How to Run One, Step by Step. Read the whole guide there.