This guide teaches you to administer Keycloak through the web console. After the Docker installation (in French), you will create a realm, manage users in groups, assign roles and configure a client. These gestures are the foundation of any Keycloak operation.
What you will learn
By the end of this lesson, you will be able to:
- Navigate the admin console efficiently
- Create and configure realms
- Manage users and their credentials
- Organize users into hierarchical groups
- Create and assign roles (realm and client)
- Configure a basic client
- Monitor active sessions and events
Access the admin console
Open http://localhost:8080: Keycloak redirects you to the console login screen (/admin/master/console/).
Sign in with the credentials created during the installation:
- Username:
admin - Password: the one set in
KC_BOOTSTRAP_ADMIN_PASSWORD
Navigating the console
The area that matters most in this table is the realm selector. All the other sections show the content of the active realm without naming it: creating a user while believing you are working on lab, when the selector still shows master, is a classic mistake of the first days. Get into the habit of checking the name displayed at the top left before creating any object.
| Area | Description |
|---|---|
| Realm selector (top left) | Switches between the available realms |
| Side menu | Access to the different sections (Clients, Users, Groups, etc.) |
| Main area | Configuration forms and lists |
| Breadcrumb | Hierarchical navigation within the configuration |
Understand realms
A realm is an isolated space for identity management. Each realm has its own:
- Users and groups
- Roles and permissions
- Clients (applications)
- Login settings
- Tokens and sessions
The master realm vs application realms
The master realm is created at first startup and holds the instance administration account. An account in this realm can administer all the other realms: adding your end users to it amounts to giving them a foothold in the admin console. The separation below is therefore not a naming convention, it is a privilege boundary.
| Realm | Usage | Users |
|---|---|---|
master | Administration of Keycloak itself | Super-admins only |
| Application realms | Applications and end users | The users of your apps |
Create an application realm
The realm name appears in all of Keycloak's public URLs (/realms/<name>/...) and your applications will carry it in their configuration. Renaming it afterwards breaks every client already configured, so choose it at creation time, in lowercase and without spaces.
- Sign in to the admin console
- Click the realm selector (top left, shows "master")
- Click Create realm
- Fill in the information:
- Realm name:
lab(lowercase, no spaces) - Enabled: On
- Realm name:
- Click Create
You are automatically switched to the new realm.
Configure a realm
The four tabs below match the actual tabs of the Realm settings screen. The two that change what your users see are Login (what the login page offers) and Sessions (how long before they are signed out). The values shown are those of a training realm, mostly the Keycloak defaults: in production, Verify email goes to On (with an SMTP server configured) and you reconsider the session durations according to your risk level.
| Setting | Recommended value | Description |
|---|---|---|
| Display name | Lab Training | Name shown to users |
| HTML Display name | <b>Lab</b> Training | With HTML for branding |
| Frontend URL | (empty in dev) | Public URL in production |
| Setting | Lab value | Description |
|---|---|---|
| User registration | Off | Admins create the accounts |
| Forgot password | On | Allows password recovery |
| Remember me | On | "Remember me" checkbox |
| Login with email | On | Email as the identifier |
| Verify email | Off | No verification in dev |
| Setting | Value | Description |
|---|---|---|
| SSO Session Idle | 30 minutes | SSO inactivity timeout |
| SSO Session Max | 10 hours | Maximum duration of an SSO session |
| Setting | Value | Description |
|---|---|---|
| Default Signature Algorithm | RS256 | Token signature algorithm |
| Access Token Lifespan | 5 minutes | Lifetime of access tokens |
| Client login timeout | 5 minutes | Timeout during the login flow |
There is no "Refresh Token Lifespan" setting at the realm level: the validity of a refresh token is bounded by the session, therefore by SSO Session Idle (inactivity) and SSO Session Max (absolute duration), in the Sessions tab. The Access Token Lifespan is set in the Tokens tab.
Manage users
Users are identities that can sign in to your applications.
Create a user
The only truly required field is Username, and it is unique within the realm: two realms can host an alice without conflict. The account created here has neither a password nor a role, so it cannot sign in yet. This is normal, the next two sections (credentials, then roles) fill in these two gaps.
- In the menu, click Users
- Click Add user
- Fill in the information:
- Username:
alice(required, unique within the realm) - Email:
alice@example.com - First name:
Alice - Last name:
Martin - Enabled: On
- Username:
- Click Create
Configure credentials
A newly created user does not have a password yet. The deciding switch on this screen is Temporary: left On, Keycloak automatically adds the UPDATE_PASSWORD required action to the account, and the user will have to choose their own password at first login. This is the setting to keep whenever an administrator types the password for someone else, otherwise you know your user's secret.
- After creation, go to the Credentials tab
- Click Set password
- Enter the password twice
- Temporary:
- On = the user will have to change it at first login
- Off = permanent password
- Click Save
User attributes
Attributes let you store metadata about the user, in the Attributes tab, as key/value pairs. Keep in mind that an attribute added here does not leave Keycloak on its own: it stays in the database until a client mapper has explicitly copied it into the token. The examples below are common ones: applications use them to make an authorization decision or fill in a profile.
| Attribute | Example | Usage |
|---|---|---|
department | Engineering | Company department |
employee_id | EMP-001 | HR identifier |
phone | +33612345678 | Phone number |
These attributes can be included in tokens through mappers (see Protocol mappers and claims).
Required actions
Required actions force the user to do something at the next login. They are set on a specific account from the Details tab, Required User Actions section, and Keycloak interrupts the login flow until the action is done. This is the lever to use to enforce MFA on a handful of sensitive accounts without enabling it for the whole realm, or to force a password update after an incident.
| Action | Description |
|---|---|
| UPDATE_PASSWORD | Change the password |
| VERIFY_EMAIL | Verify the email address |
| UPDATE_PROFILE | Complete the profile |
| CONFIGURE_TOTP | Set up MFA (TOTP) |
VERIFY_EMAIL requires an SMTP server to be configured in Realm settings > Email: without it, the user ends up stuck on a screen waiting for an email that will never be sent.
Organize with groups
Groups let you organize users and assign them attributes and roles collectively.
Group hierarchy
Groups can be nested. A user in a subgroup inherits the attributes and roles of the parent group, and inheritance always flows in that direction: belonging to Employees/Engineering/Backend also gives what Employees carries, never the reverse. The tree below shows what this looks like for a typical organization.
Employees/├── Engineering/│ ├── Backend/│ └── Frontend/├── Marketing/└── Sales/So put the broadest rights at the top (Employees) and add to the leaves only what is truly specific. A right set too high spreads to the whole company without anyone noticing.
Create a group hierarchy
A subgroup is not created from the root screen: you must first open the parent group, then click Create group again from inside it. This is the only subtlety of this procedure, and the one that leaves you with Engineering next to Employees instead of inside it.
- In the menu, click Groups
- Click Create group
- Name:
Employees, then Create - Click the
Employeesgroup to open it - Click Create group from inside the group (this creates a subgroup)
- Name:
Engineering, then Create - Repeat for
MarketingandSales
Assign a user to a group
Membership is set from the user's page, not from the group. Always select the full path (Employees/Engineering) and not the short name: two subgroups with the same name under different parents are perfectly legal in Keycloak, and the list shows both.
- Go to Users and select a user
- Click the Groups tab
- Click Join group
- Select the group (e.g.
Employees/Engineering) - Click Join
After Join, the Groups tab shows the direct membership. Inherited groups only appear if you uncheck the Direct membership option: this is the way to check what the user actually receives from the hierarchy.
Group attributes
An attribute set on a group is inherited by all its members, present and future. This is what lets you stop entering department account by account: the day someone changes teams, changing their group updates all their metadata at once. As with user attributes, the value only reaches the token if a mapper is configured on the client.
- Go to Groups and select a group
- Click the Attributes tab
- Add an attribute:
department=Engineering - Click Save
All members of the group will have this attribute available in their tokens (if a mapper is configured).
Create and assign roles
Roles define users' permissions in applications.
Role types
The distinction that matters in this table is scope. A realm role describes who the person is in the organization (staff, manager), a client role describes what they are allowed to do in a specific application (app:read). The composite role is not a third type: it is a realm role or a client role to which other roles have been attached.
| Type | Scope | Example | Usage |
|---|---|---|---|
| Realm roles | Global to the realm | admin, user | Cross-cutting permissions |
| Client roles | Specific to a client | app:read, app:write | Application permissions |
| Composite roles | Combine other roles | manager = user + app:read | Permission bundles |
This separation avoids a classic trap: naming a realm role billing-admin when it only concerns a single application. The day a second application arrives, nobody knows what the role gives access to anymore.
Create a realm role
A role name is effectively immutable: it ends up in tokens and in the code of the applications that test for it. Stick to lowercase without spaces, and fill in the Description, the only place where you can explain in six months why this role exists.
- In the menu, click Realm roles
- Click Create role
- Role name:
staff(lowercase, no spaces) - Description:
Company employee - Click Save
Also create the manager and admin roles.
Create a composite role
A composite role groups several roles so that only one needs to be assigned. There is no "Composite" switch to turn on in the console: a role becomes composite when you attach a first associated role to it, and the Composite column of the role list then switches to True. Removing all associated roles turns it back into a simple role.
- Open the role to transform in Realm roles (e.g.
manager) - In the Action menu at the top right, choose Add associated roles
- Filter on realm roles or on a client's roles depending on what you want to include
- Check the roles to include (e.g.
staff) - Click Assign
A user with the manager role will automatically have the staff role. Nesting is recursive: admin as a composite of manager, itself a composite of staff, does give all three roles in the token. Limit yourself to two or three levels, beyond that nobody can work out an account's effective rights anymore.
Assign a role to a user
This procedure creates a direct link between a person and a role. It is justified for a special case (a replacement, a technical account), but it is not visible from the group: reserve it for exceptions and go through groups for everything else.
- Go to Users and select a user
- Click the Role mapping tab
- Click Assign role
- Select the role (e.g.
staff) - Click Assign
Assign a role to a group
This is the way of working to favor. The role is set only once, and a person's arrival or departure is handled by having them join or leave the group, without ever touching the roles again. A role set on a parent group also flows down into all its subgroups.
- Go to Groups and select a group
- Click the Role mapping tab
- Click Assign role
- Select the role (e.g.
staff) - Click Assign
All members of the group automatically inherit the role. To check what an account really receives, go back to its page, Role mapping tab, and uncheck Hide inherited roles: the list then shows the direct roles, those coming from groups and those coming from composites.
Default roles
Default roles are automatically assigned to every new user, including those created by LDAP federation or by self-service registration. Keycloak creates one by default per realm, named default-roles-<realm>: it is a composite that already carries the account client roles giving access to the Account Console. Add your roles to it rather than creating a second one.
- Go to Realm settings > User registration
- In Default roles, click Assign role
- Select the role or roles to add (e.g.
staff)
Configure clients
A client represents an application that authenticates with Keycloak.
Client types
The selection criterion is simple: can your application keep a secret? The code of a single-page web application or a mobile application is downloaded to the user's device, so it is readable: it must be public. A backend running on your servers can hold a secret, so it will be confidential.
A public client makes up for the lack of a secret with PKCE, a proof generated at each login that makes an intercepted authorization code unusable. To enable it, open the client's Settings tab, Capability config section, and turn on the Require PKCE switch. The lesson on securing an application details the procedure.
| Type | Client authentication setting | Usage |
|---|---|---|
| Public | Off | SPAs, mobile applications (no secret) |
| Confidential | On | Backend, API (with a client secret) |
Create a basic client
Two settings in this wizard deserve your attention. Standard flow enables the Authorization Code Flow, the one that redirects the user to the Keycloak login page: it is the only recommended flow for a web application. Direct access grants, by contrast, lets the application collect the password itself in order to exchange it for a token, which defeats the point of SSO and is discouraged by RFC 9700 (OAuth 2.0 security best current practice): keep it Off.
- In the menu, click Clients
- Click Create client
- Fill in General settings, then click Next:
- Client type: OpenID Connect
- Client ID:
my-app
- Fill in Capability config, then click Next:
- Client authentication: Off (public client)
- Authorization: Off
- Standard flow: On
- Direct access grants: Off (recommended)
- Fill in Login settings, then click Save:
- Root URL:
http://localhost:3000 - Valid redirect URIs:
http://localhost:3000/callback - Web origins:
http://localhost:3000
- Root URL:
Client roles
A client role lives inside the client: it does not appear in the Realm roles list and two clients can each have an admin role without stepping on each other. This lets you name permissions from the application's point of view (app:admin, invoice:approve) without polluting the realm's global namespace.
- Select your client in Clients
- Go to the client's Roles tab
- Click Create role
- Role name:
app:admin - Click Save
These roles appear in tokens if the user has them.
Monitor sessions
The Sessions section lets you see who is signed in and invalidate sessions.
View active sessions
This screen is your first source of information during an incident: it answers "who is signed in right now, and from which address". The Last access column is the one to watch, because it is the one Keycloak compares with the SSO Session Idle configured above to decide when to expire the session.
- In the menu, click Sessions
- You see the list of active sessions with:
- User
- IP
- Session start
- Last access
Invalidate a session
Deleting a session ends SSO on the Keycloak side, but access tokens already issued remain valid until they expire. This is exactly why the recommended lifetime of an access token is short: it bounds the delay during which a forced sign-out has not yet taken effect on APIs.
- In Sessions, find the session
- Click the trash icon
- Confirm the sign-out
Invalidate all of a user's sessions
This is the procedure to follow for a compromised account, and it goes hand in hand with changing the password (or disabling the account): signing out without changing the password lets the attacker sign back in immediately and obtain a new refresh token, changing the password without signing out leaves already open sessions alive. A user signed in from several browsers has several sessions, hence the Sign out all sessions button.
- Go to Users and select the user
- Click the Sessions tab
- Click Sign out or Sign out all sessions
Configure events
Events let you audit actions in Keycloak.
Event types
Keycloak separates two logs that do not answer the same questions. Login events tell you what end users did (sign in, fail, sign out), admin events tell you what administrators changed in the configuration. Both are enabled separately and are disabled by default: until you have turned them on, there is nothing to consult, even retroactively.
| Type | Examples | Usage |
|---|---|---|
| Login events | LOGIN, LOGIN_ERROR, LOGOUT | Audit of authentications |
| Admin events | CREATE_USER, UPDATE_ROLE | Audit of admin actions |
Enable events
Two settings have a cost that you should measure before pushing them to production. Expiration defines how long Keycloak keeps the rows in its database: with no value, the table grows indefinitely. Include representation stores the full JSON payload of each change, which is valuable for an investigation but multiplies the volume, and can bring personal data into the audit database.
- Go to Realm settings > Events
- User events settings tab:
- Save user events: On
- Expiration: 30 days
- Event types: check the events to capture
- Admin events settings tab:
- Save admin events: On
- Include representation: On (stores the payload)
- Click Save
View events
The event type to know first is LOGIN_ERROR: each row carries an error field (invalid_user_credentials, user_disabled, invalid_client_credentials) that gives the exact cause of the refusal, where the user only sees a generic message. This is the first place to look when someone says "it doesn't work".
- In the menu, click Events
- Use the filters:
- User events: by type, user, date
- Admin events: by operation, resource
- Click an event to see the details
Account Console
The Account Console is the end-user interface for managing their own account.
Access it at: http://localhost:8080/realms/lab/account/
Users can:
- View and edit their profile
- Change their password
- Manage their active sessions
- Set up MFA
- See the authorized applications
Wrap-up exercise: administer a complete realm
Put the concepts into practice with this guided exercise.
Goal
Create a complete realm with users organized into groups and roles.
Lab steps
Follow these seven steps in order: each one builds on the previous. The sequence reproduces that of a real setup, where you first build the structure (realm, groups, roles) before placing people in it. The last step is the one that counts: it is the only one that checks that the whole thing works from a user's point of view.
-
Create the realm:
- Name:
lab - Check the sessions: SSO Idle = 30 min, Access Token = 5 min (default values)
- Name:
-
Create the group hierarchy:
Employees/├── Engineering/└── Marketing/ -
Create the roles and assign them to the groups:
- Realm roles:
staff,manager,admin manageris composite and includesstaffadminis composite and includesmanagerEmployees→ rolestaffEmployees/Engineering→ no additional role (inheritsstaff)
- Realm roles:
-
Create the users, each in their own group and with their direct role:
User Email Group Direct role alice alice@example.com Engineering (inherits staff) bob bob@example.com Engineering manager charlie charlie@example.com Marketing (inherits staff) -
Create a test client:
- Client ID:
test-app - Type: Public (OIDC)
- Redirect URIs:
http://localhost:3000/callback
- Client ID:
-
Enable events:
- Login events: On
- Admin events: On
-
Validate:
- Sign in to the Account Console as
alice - Check the login events in the admin console
- Sign in to the Account Console as
Success criteria
Tick this list in the console, not from memory. The most telling point is the last one: if the login events do not appear even though the sign-in succeeded, Save user events was turned on after the test, and events that have already happened are never caught up.
- Realm
labcreated, session durations checked - Hierarchical groups created (
Employees/Engineering,Employees/Marketing) - Roles
staff,manager(composite),admin(composite) created - Role
staffassigned to theEmployeesgroup - Users created in the right groups
- Client
test-appconfigured - Login events visible after a user signs in
Troubleshooting
The user cannot sign in
Go through these three checks in this order: they run from the most visible to the most precise. The third is the only one that gives the actual cause, the first two rule out the common explanations in a few seconds.
- Check that the account is Enabled in the admin console
- Check that credentials are set (Credentials tab)
- Check the events of type
LOGIN_ERRORto read the error message
If the account shows a pending required action, the sign-in succeeds but the user stays stuck on an intermediate screen, which is often described as "I can't sign in".
Roles do not appear in the token
A role missing from the token does not mean it is not assigned: between the assignment and the token, there are the role mapping and then the client scope. First decode the token with an offline tool to find out whether the role is missing from realm_access.roles or from resource_access, which will tell you which of the three steps below failed.
- Check that the role is indeed assigned (direct or through a group)
- Check the client's mappers (see Protocol mappers and claims)
- For client roles, check that the scope is included
The Account Console shows "Page not found"
Check the URL: http://localhost:8080/realms/{realm-name}/account/
Replace {realm-name} with the exact name of your realm (e.g. lab).
Key takeaways
| Concept | Key point |
|---|---|
| Realm | Isolated space of identities, one per environment/application |
| Master | Reserved for super-admins, never for applications |
| Groups | Organize users with inheritance of attributes and roles |
| Realm roles | Permissions global to the realm |
| Client roles | Permissions specific to an application |
| Composite roles | Group several roles to simplify administration |
| Sessions | Monitor and invalidate active connections |
| Events | Disabled by default: enable them to audit sign-ins and administration actions |