Keycloak RBAC: realm roles, client roles, groups and admin permissions

Keycloak supports role-based access control through built-in realm roles, client roles, composite and default roles, groups and fine-grained admin permissions, all included in the open source release. This page explains the model, the decisions it forces and the gaps to plan for.

On this page

Does Keycloak support role-based access control out of the box?

Yes. Keycloak supports role-based access control natively in the open source release, with realm roles, client roles, composite roles, default roles, groups and fine-grained admin permissions. None of these features requires a paid edition, so a checklist item that asks for RBAC before approval can be answered from the Apache 2.0 distribution itself. The open question is not whether the product can do RBAC, but how your organization will design the roles and who will be allowed to manage them.

The design work sits with you. Decide whether an application's roles belong in a realm namespace shared by the whole realm or in a client namespace dedicated to one application, since Keycloak keeps each client's roles separate. Decide which roles are composite, so that a single assignment grants a bundle of others, and which roles are default roles that every new or imported user receives. Map groups to the organizational structure that owns access, and use role scope mappings to limit which roles appear in each client's access tokens. Finally, decide who may administer users, groups, clients, roles and organizations. Fine-grained admin permissions are turned on per realm under Admin Permissions in Realm settings, and the server administration guide notes that version 1 of that feature is deprecated, so confirm which version your build uses before you write the policy.

This page covers the role model and delegated administration. Resource-level policies, such as attribute-based, time-based or rule-based decisions, are covered in depth on the authorization services page, which uses the separate Keycloak Authorization Services Guide as its reference.

RBAC capabilities by edition, built in, paid or outside component

This table compares each RBAC building block in Keycloak with how it is configured and whether it is current or deprecated. Read it to see which role, group and admin features you can use directly and which need a feature flag or a separate authorization design. Confirm Red Hat build of Keycloak support scope against the current Red Hat product page before relying on any row for that edition.

CapabilityBuilt in or configuredStatus and notes
Realm rolesBuilt in, defined in the realm namespaceNamespace for roles shared across the realm's clients and users
Client rolesBuilt in, defined per clientEach client gets its own namespace, so role names can repeat across clients
Composite rolesBuilt in, one role bundles othersA user mapped to a composite role gains every role it contains
Default rolesBuilt in, assigned at user creation or importApplied automatically, so review them before enabling broad self-registration
Role scope mappingsBuilt in, set per clientLimit which roles are declared inside access tokens issued to that client
GroupsBuilt in, organize users and their role mappingsModel organizational collections, separate from roles that define user types
User federation role mappingBuilt in for LDAP and Active Directory federationConfirm which group and role mappers your directory version needs
Fine-grained admin permissions v2Built in, enabled with the Admin Permissions setting per realmCovers Users, Groups, Clients, Roles and Organizations resource types
Fine-grained admin permissions v1Behind the admin-fine-grained-authz:v1 feature flagDeprecated and slated for removal in a future release, so do not start new designs on it
Attribute, role-based and other authorization policiesBuilt in through Authorization Services on a clientCovers attribute, role, user, context, rule and time-based policies, plus custom providers
Red Hat build of Keycloak RBAC scopeSame role model as the upstream projectConfirm supported features and versions on the current Red Hat product page

How Keycloak's role model works

Keycloak keeps roles in two namespaces. Realm roles belong to the realm as a whole, so a role such as billing-approver is visible to every client in that realm. Client roles belong to one client, and each client gets its own namespace, so admin defined on the reporting client and admin defined on the billing client are different roles that can share a name. Before you design the model, decide which roles genuinely apply across applications and which describe one application's internal permissions. Keeping application-specific roles in client namespaces prevents unrelated applications from colliding on names and keeps each application's access rules under the control of the team that owns it.

Two mechanisms change which roles a user ends up with. A composite role bundles one or more additional roles, so mapping a user to the composite gives them everything it contains, including roles from other clients. Default roles work at a different point: they are assigned automatically when a user is created or imported, which means a default role set is effectively a baseline for every new account. Review both before going live, because a composite that includes a broad client role or a default role that grants more than intended will widen access for every user who receives it, and the effect is easy to miss when you only look at the individual user.

Role scope mappings then control what reaches the token. Keycloak's server administration guide says they limit the roles declared inside an access token, so a client can receive a narrower set of roles than the user holds. This is the lever that keeps a high-privilege account from passing its full role set to a low-trust application. Confirm the scope settings for each client against the roles that client actually checks, and test with a real user in the target realm, since the token is where applications see the result.

Groups and roles answer different questions. The server administration guide describes groups as collections of users and their roles within an organization, such as a department or a regional team, while roles define the types of users that applications use to assign permissions. In practice you assign roles to groups and users inherit them, but the group itself does not make an access decision. Access decisions are made when an application reads the roles or groups claims in the token and enforces its own rules, or when Keycloak's authorization services evaluate a policy. Keycloak issues the claims; the application or resource server enforces them, so the team building each application must agree on which claim it trusts.

How a user's roles reach an application

The diagram starts with a user who is a member of a group or has a direct role mapping. Realm and client roles attach to the user, and any composite role expands into the roles it contains. Default roles apply when the user is created or imported, and scope mappings decide which of those roles appear in the access token. Check that the token carries only the roles the application needs, because the application's authorization check reads what the token contains.

Roles flow from users and groups through composites and scope mappings into the token.

Role model decisions to settle before configuration

Most Keycloak RBAC rework comes from a few early choices: where roles live, whether groups or roles carry permissions, and which realm holds administrators. Settle these on paper first, because each one shapes token contents, audit trails and how much work a later change takes.

Realm roles or client roles

Realm roles sit in a single namespace shared by every client in the realm, while each client gets its own namespace for client roles. Put a permission in a realm role and every client can see it in tokens, which inflates token size and blurs ownership. Client roles keep an application's permissions with that application, at the cost of a little more mapping work. Decide this per permission, not per project.

Keycloak docs

Groups or roles carry permissions

Keycloak documents groups as collections of users organized around the organization, and roles as types of users that applications use to grant permissions. Attaching application permissions to groups makes membership changes do the access work, but it hides which application rule grants what. Most teams keep permissions on roles and use groups to assign those roles to people.

Layering composite roles

A composite role bundles other roles, and a user gains every role it contains. Layers such as a business role built from several client roles are easy to read at first, then hard to audit once composites nest several levels deep. Set a limit on nesting and record which composite grants which effective permission before you publish it.

Scope of default roles

Default roles are assigned to every user at creation or import, so anything placed there applies to the whole realm, including accounts created by federation or automation. Keep the default set small and free of administrative or sensitive rights. Also check role scope mappings, which limit which roles appear inside an access token, because they decide what each client actually receives.

Realms that hold administrators

Users with the admin role in the master realm are superusers who can manage any realm, so keep that role to a very small break-glass group. Day-to-day administration is better delegated with realm-admin grants on a per-realm console at /admin/{realm-name}/console. Decide early which realm holds platform administrators and which realm holds each tenant's administrators, because moving them later means reassigning access across realms.

Mapping directory groups to roles

When users come from LDAP, Active Directory or a brokered identity provider, their directory groups must map to Keycloak roles or groups. Keep one documented mapping table that names each external group, the Keycloak role it grants and the owner who approves it. Test the mapping with a sample account before go-live, because a stale or broad mapping quietly grants access that nobody reviewed.

Delegated administration: master realm admins versus realm admins

Keycloak ships with a master realm, and administrators who hold the admin role in that realm are superusers. According to the Keycloak Server Administration Guide, they have full access to manage any realm on the server. That reach is what makes the master realm the most sensitive part of a deployment: a compromised superuser account can change any realm's clients, users, identity providers and signing keys.

  • Reach: A master realm superuser can create, change and delete every realm, not only the one it was created for.
  • Scarcity: Keep the number of superuser accounts small and named, so each action can be traced to one person.
  • Separate credentials: Require strong authentication for these accounts, and do not reuse them for daily work.
  • Break-glass use: Treat superuser access as an emergency path with a documented procedure, not a standing working account.
  • Network placement: Expose the admin console and Administration REST API on a separate hostname or context path from public frontend URLs, as the Keycloak production guide advises.

Check which accounts currently hold the admin role in the master realm, who controls their credentials, and whether each use is logged and reviewed.

Gaps in RBAC and the usual way to cover each

Keycloak gives you realm roles, client roles, groups, composite roles and fine-grained admin permissions, but it does not run your access governance for you. The cards below name the gaps that most often surface after go-live and the common ways teams close them, so you can confirm each one before you commit to a role design.

No built-in access requests or recertification

Keycloak assigns roles through the admin console, the Administration REST API or federation mappers, but it does not provide a workflow where a user requests a role, a manager approves it, or reviewers periodically certify who still holds it. Many teams cover this with an identity governance tool, a ticketing workflow that calls the admin API, or a scheduled report reviewed by role owners. Confirm with your auditors which evidence of approval and review they expect, and whether your team or a governance product will produce it.

Keycloak docs

Resource-level and attribute rules need authorization services

Realm and client roles answer the question of which role a user holds, not which record or field that user may touch. Rules such as ownership of a record, an attribute of the user, a time window or a context such as network location are handled by the authorization services, which support attribute-based, role-based, user-based, context-based, rule-based and time-based policies, and can be extended through a service provider interface. Plan the policy model and the custom provider work separately from the role model, and confirm which of these rules your applications will enforce in code.

Authorization guide

Role lifecycle tied to HR sources

Keycloak does not decide on its own when a role should appear or disappear when an employee changes teams or leaves. Teams usually map directory attributes or groups from LDAP, Active Directory or an upstream identity provider into roles through federation and mapper configuration, or drive changes from an HR-fed provisioning process that calls the admin API. Check which system is the source of truth for each role, how removals are handled for users who are disabled rather than deleted, and how a mapper change affects users who already hold a role.

Fine-grained admin permissions are version 2 only

Delegated administration over Users, Groups, Clients, Roles and Organizations is switched on per realm under Realm settings. The server administration guide describes version 1 of fine-grained admin permissions as deprecated, to be removed in a future release, and enabled only through the admin-fine-grained-authz:v1 feature flag. Design delegated admin around the version the guide describes as current, do not build new automation against v1, and confirm the behavior of your target release before you rely on any permission model.

Admin permissions docs

Global admins and realm admins need separate controls

Users with the admin role in the master realm are superusers who can manage any realm, while each realm has its own console for administrators granted the realm-admin role. Without a deliberate split, a small group of master realm administrators ends up with reach into every application. Decide who holds master realm access, keep that group small, and confirm how you will review and log changes made through either console and the Administration REST API.

Role sprawl and default role drift

Composite roles and default roles make access easy to grant, and they also make it easy to over-grant. A default role applies to every user created or imported, and a composite role passes its child roles to every user mapped to it. Scope mappings limit which roles appear in an access token, but they do not remove a role from a user. Review composites and defaults on a fixed schedule, and confirm with your application owners which roles they actually read from tokens.

What changes when you apply roles to many applications

Every role you add to a client is a decision you will review later, so the cost of a role model grows with the number of applications, not with the number of roles on paper. Each client in Keycloak gets its own namespace for client roles, and realm roles sit above all of them. When teams create similar roles in several clients, such as admin or viewer, nobody can tell from the token alone which application a permission belongs to, and reviewers end up reading every client to answer a simple access question. Naming conventions are the cheapest control here. Agree on a pattern for role names, decide which roles are realm-wide and which belong to one client, and write that down before the first application is onboarded.

Composite roles and default roles add a second effect that is easy to miss. A composite role that includes other composites can grant far more than its name suggests, and a default role assigns mappings to every new or imported user. Both settings change what ends up in the access token, because the roles a user holds, and the scope mappings that limit which roles appear in a token, determine its contents. Larger role sets mean larger tokens, which can affect header sizes at proxies and in front of APIs. Ask each application team which role claims it actually reads, and remove scope mappings that no client needs. Keep the nesting shallow enough that an auditor can trace a user's effective permissions on one page.

Role-model changes also need a test plan that matches Keycloak's release rhythm. The project plans four minor releases a year, and since Keycloak 26.0 it says breaking changes in a minor release will be opt-in, so an upgrade can arrive without a visible break and still change how roles, composites or token contents behave in your realm. Build a non-production realm that mirrors the production role model, export the configuration, and run login and authorization tests for each application after every upgrade and every role change. Confirm the exact behavior of your target version against the Keycloak Server Administration Guide and the upgrade notes before you schedule the change in production.

How the RBAC design changes by situation

When one team owns the applications and the users, a single realm is usually enough. Realm roles act as the shared namespace for the job types that apply across applications, while client roles hold permissions that only one application understands. Groups carry the organizational view, such as a department or a support queue, and assign roles to every member at once. The design work is mostly about keeping the role list short enough that people can reason about it.

  • Realm roles for shared job types: Keep a small set such as employee or manager at realm level and avoid putting application-specific permissions there.
  • Client roles for application permissions: Define permissions like orders:approve inside the client that enforces them, so renaming an application does not change its role model.
  • Composite roles for bundles: Build a composite role only when several people always need the same set of client roles together.
  • Default roles for baseline access: Use default roles so every new user receives the baseline mapping on creation or import.
  • Groups for assignment: Assign roles to groups, not individuals, and let the group membership drive access.

Before you go live, confirm the total number of realm and client roles against what your team can review and explain during an access review.

Order of work to put RBAC into production

This sequence moves a Keycloak role model from an agreed catalogue to a recorded, tested and access-controlled configuration. Each step produces a artifact that the next step depends on, so gaps surface early rather than after applications go live.

  1. Agree the role catalogue and naming

    Security, application owners and the identity team list the roles each application needs, the job functions they map to, and the naming convention for every role. Write down which roles are business roles, which are application permissions and which are administrative. Done when every role has an owner, a description and an approved name, and the list is signed off before anything is created in the realm. Changing names after tokens are issued is costly, so this step deserves the most review time.

  2. Decide realm and client role placement

    For each role, decide whether it belongs in the realm namespace because several clients share it, or in a client namespace because only one application uses it. Keep cross-application roles in the realm and application permissions inside the client that enforces them. Check the placement against the catalogue from the previous step. Done when a reviewer can point to the namespace of every role and explain why it was placed there.

  3. Configure groups and default roles

    Create groups for collections of users who share an organizational function, and map roles to groups rather than to individual users. Set default roles only for the minimum access every new account should hold, because default roles are applied when a user is created or imported. Test with a sample account in a non-production realm and confirm that the expected roles appear and that nothing extra is granted. Done when group membership alone produces the approved role set for each test persona.

  4. Map federated groups and roles

    If users come from LDAP, Active Directory or an upstream identity provider, decide which directory groups or claims map to Keycloak groups or roles. Configure the mappers in each federation or brokering provider and test one account per mapping. Confirm what happens when a user leaves a directory group, since removal upstream must also remove access in Keycloak. Done when a change in the source directory produces the expected change in Keycloak on the next login, and the mapping table is recorded.

  5. Restrict administrative access with fine-grained permissions

    Enable Admin Permissions for each realm under Realm settings, then grant realm-admin scope through groups or roles to the resource types the delegated administrators need: Users, Groups, Clients, Roles and Organizations. Keep the master realm superuser role to a small break-glass set. Confirm that version 1 of fine-grained admin permissions is not the one in use, since it is deprecated and only enabled through a feature flag. Done when a test administrator can manage users in one realm but cannot change clients or roles outside the granted scope.

  6. Test token contents for each application

    For every client, obtain tokens for representative users and inspect the access and ID tokens. Check that the roles present match the approved model and that scope mappings limit roles declared in the access token to what the application should receive. Confirm that composite roles expand as expected and that no administrative role leaks into application tokens. Done when each client has a recorded test result showing the expected role claims for each test persona, and any mismatch has been fixed and retested.

  7. Record and approve the RBAC model

    Export the realm configuration, store it in version control, and write the approved model: the catalogue, role placement, groups, default roles, federation mappings, admin permission grants and token test results. Obtain sign-off from security and each application owner. Set a review process so that future role or group changes follow the same approval path. Done when the recorded model matches the live realm and the approvers have signed it, which gives auditors and operators one reference to check against.

Evidence a security reviewer asks for on RBAC

This table maps each piece of evidence a security reviewer typically requests for Keycloak role-based access control to where it lives in Keycloak and who produces it. Use it to plan evidence collection before an assessment starts. DeployOpen prepares the exports, configuration records and test results, but independent auditors issue any audit report or attestation.

Reviewer asks forWhere it comes from in KeycloakWho produces it
Role and group inventoryRealm roles, client roles and groups listed in the admin console or exported from the realm configurationClient platform team, with DeployOpen preparing the export
Realm and client role definitionsRole names, descriptions and the client each client role belongs to, per realm and per client namespaceRealm administrators, reviewed by the security owner
Composite and default role settingsComposite role associations and the default roles applied when users are created or importedRealm administrators, confirmed against the realm export
Admin role assignmentsUsers holding the master realm admin role and the realm-admin role for each realm consoleIdentity team, reconciled against the HR or directory joiner-mover-leaver records
Admin Permissions settingWhether fine-grained admin permissions are enabled per realm under Realm settings, and which resource types (Users, Groups, Clients, Roles, Organizations) are delegatedRealm administrators, with the setting captured in a dated screenshot or export
Token samples showing role claimsSample access and ID tokens from representative clients, showing realm and client role claims and scope mappingsApplication or platform engineers, generated in a test realm
Admin change logsAdmin event records and audit trail for role, group and permission changes, which must be enabled and retained according to your own policyPlatform operations, with logs forwarded to your central log store

Questions buyers ask before approving Keycloak RBAC

Is role-based access control included in the open source Keycloak release?

Yes. Keycloak's role model, including realm roles, client roles, composite roles, default roles, groups and fine-grained admin permissions, is part of the Apache 2.0 licensed project, so you do not need a paid edition to use it. The server administration guide documents realm-level roles as a namespace for the whole realm and client roles as a separate namespace for each client. Confirm the exact behavior of each feature against the release you plan to run, since the Keycloak Server Administration Guide is the reference for how these features are configured and tested.

Do we need a paid Red Hat subscription to delegate admin permissions?

No supplied fact says that fine-grained admin permissions are limited to a paid tier, and the feature is documented in the open source server guide. It is switched on per realm with the Admin Permissions setting under Realm settings and covers Users, Groups, Clients, Roles and Organizations. Version 1 of the feature is deprecated and is enabled only through the admin-fine-grained-authz:v1 feature flag, so plan on the current version of the feature. A Red Hat subscription changes who stands behind the build and its support terms, which is a separate question from whether the feature exists. Ask Red Hat directly if support scope for this feature matters to your decision.

How long does role design take, and what drives the effort?

The effort depends mostly on how many applications, business functions and user populations need separate access, and on how clearly your owners can state who should hold which permission. Typical drivers are the number of clients and their role sets, whether you need groups for organizational structure, how many composite roles are needed, and whether delegated admins must manage users, groups or clients inside a realm. Design work is often where scope grows, because each application team usually has its own definition of a role. Ask any partner for a written scope that lists the applications, role catalog, group structure and admin delegations covered, then quote from that list.

What can our own team configure without outside help?

Most teams with an experienced Keycloak administrator can create realm roles, client roles, groups, composite roles and default roles in the admin console or through configuration tooling, provided they have a written role model to implement. The harder parts are usually the design decisions: which roles should be composite, what goes into access tokens through role scope mappings, how group membership maps to roles, and how delegated admin permissions are bounded so that a realm admin cannot grant more than intended. Those decisions are worth reviewing with a security engineer before rollout. Changes to admin permissions should be tested in a non-production realm first.

Does Keycloak replace an identity governance tool for access reviews?

No. Keycloak stores roles, groups and admin permissions and issues tokens that carry the roles an application checks. It does not, by itself, run joiner, mover and leaver workflows from an HR system, approval chains for access requests or periodic access certification campaigns across target systems. If you need those controls, plan them as a separate governance layer and decide which system is the source of truth for each role assignment. Teams often connect an identity governance product such as midPoint for these workflows, and the scope of that integration should be written down before build starts.

Which Keycloak feature handles resource-level rules beyond roles?

Roles answer whether a user holds a given permission, while resource-level decisions such as attribute, context or time-based rules are handled by Keycloak's authorization services. The authorization services guide lists attribute-based, role-based, user-based, context-based, rule-based and time-based access control, plus custom mechanisms through a service provider interface. Those policies add design and testing work on top of the role model, so decide early which checks belong in roles and which belong in policies. The dedicated authorization services page covers that topic in depth.

What is the risk if superuser or realm admin roles are granted too widely?

Users with the admin role in the master realm are superusers with full access to manage any realm, so that role should be held by very few people, and each realm has its own admin console at /admin/{realm-name}/console for administrators granted the realm-admin role. Over-granting these roles is one of the most common access risks in an identity platform. Review who holds them at setup, record the approval for each grant, and check the list on a fixed schedule. Keep the master realm for platform administration only and confirm your current hardening steps with the production guide before go-live.

Primary sources for Keycloak roles and admin permissions

The two official references for this page are the Keycloak Server Administration Guide and the Keycloak Authorization Services Guide. Use the administration guide as the source of truth for how realm roles, client roles, composite and default roles, groups, role scope mappings and fine-grained admin permissions behave. Use the authorization services guide when a requirement moves past roles into resource-level policies, such as attribute, rule or time-based decisions. Keep the two apart in your design notes so that a role assignment is never mistaken for a policy decision.

Read the Admin Permissions setting in the administration guide before you plan delegated administration. It is switched on per realm under Realm settings and covers the Users, Groups, Clients, Roles and Organizations resource types. The same guide says version 1 of fine-grained admin permissions is deprecated, will be removed in a future release, and is only enabled with the admin-fine-grained-authz:v1 feature flag. Confirm which permission version your target release uses, and avoid building new delegation models on the deprecated flag.

Check the guides against the exact release you plan to run, not against memory of an earlier version. Keycloak ships four minor releases a year, and the current release line is documented at the same URLs, so the page you read may describe behavior that has changed since your last test. Record the release number and the guide date in your design document, and repeat the role and permission checks in a non-production realm after each upgrade. Your own environment, with its realms, clients and admin accounts, is the final test of any behavior described in either guide.

How DeployOpen designs and delivers Keycloak RBAC

DeployOpen plans Keycloak RBAC as a designed role model before any realm is configured, covering realm roles, client roles, groups and delegated admin permissions in infrastructure you control. Each step produces written decisions and deliverables that your team can review, test and run after handover.

How we scope

  • We inventory the applications, APIs and teams that will consume roles, and agree which role namespace each one uses.
  • Engagements are fixed-scope, so the role catalog, group structure and admin delegation model are written down before work starts.
  • We confirm which admin permission resource types, such as Users, Groups, Clients, Roles and Organizations, your administrators need.

How we build

  • We configure realm roles, client roles, composite roles and default roles, and test that token claims match the role design.
  • We set up groups for user collections and map them to roles, keeping role assignment in one reviewed place.
  • We enable fine-grained admin permissions per realm and test delegated administration with non-superuser accounts before go-live.

How we hand over

  • You receive a documented role and group model, with a mapping from each application permission to its Keycloak role.
  • We provide test cases for token contents, role inheritance and admin access boundaries that your team can rerun after changes.
  • We document the configuration in a form your team can review, version and reproduce in each environment.

How we support

  • Ongoing support, upgrades and continuous testing are available as a retainer, so role changes are reviewed as your applications change.
  • We plan role model reviews alongside Keycloak release upgrades, since admin permission settings and role behavior can change between versions.
  • Ask any partner to confirm how they handle admin permission version 1 deprecation and the feature flag in your target release.

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.