Skip to content

Realms

A realm is the top-level container in Keycloak. Every object in Keycloak — users, clients, roles, identity providers, token policies — belongs to exactly one realm. Realms are completely isolated from each other: a user in realm shop cannot log in to an application registered in realm blog, and their sessions are never shared.

You can think of a realm as a tenant in a multi-tenant SaaS system, except that each realm is managed entirely within one Keycloak server.

Keycloak is installed with one realm already in place: master. The master realm has a special purpose: it is the administrative realm. When you open the Keycloak admin console and log in, you are authenticating against master.

The master realm can create and manage other realms, but it should never be used to register your own applications or store your application’s users. Mixing your app users with the administrative super-users of master is a serious security risk.

  1. Open the Keycloak admin console at http://localhost:8080 and sign in with your admin credentials.
  2. In the top-left corner, click the realm name drop-down (it initially shows Keycloak or master).
  3. Click Create realm.
  4. In the Realm name field, enter a short, lowercase, hyphen-separated name for your realm (e.g., my-app).
  5. Make sure Enabled is toggled on.
  6. Click Create.

Keycloak creates the realm and switches your console context into it. All subsequent configuration (clients, roles, users) will belong to this new realm.

Organizations: multi-tenancy without realm sprawl

Section titled “Organizations: multi-tenancy without realm sprawl”

The obvious way to serve many customers is one realm per customer. It works, but it scales badly: every realm needs its own clients, roles, mappers, and themes, and a user who belongs to two customers becomes two accounts.

Keycloak 26 added Organizations as a first-class answer. An organization is a group of users inside a realm, so all of them share the realm’s clients and roles while still being separated by tenant. The organization:v1 feature is supported and on by default; you switch it on per realm from Realm settings → General → Organizations.

What an organization gives you:

  • Members — existing realm users you add, or people you invite by email. Members can be managed by the organization or federated in from elsewhere.
  • A linked identity provider — a tenant can bring its own IdP, so their staff sign in with their own corporate login while everyone else uses yours.
  • Domain matching — map an email domain to an organization and new users land in the right tenant automatically.

Choose between the two models like this:

Realm per tenantOrganizations
IsolationTotal: separate users, clients, roles, keysShared realm, members separated by organization
Config duplicationEvery client and role repeated per tenantConfigure clients and roles once
A user in two tenantsTwo separate accountsOne account, two memberships
Per-tenant login providerYesYes, via a linked IdP
Good forHard regulatory or data separationSaaS with many customers on one product

After creating a realm, click Realm settings in the left sidebar. The settings are organised into tabs:

  • Display name — a human-readable name shown on the login page.
  • Frontend URL — override the URL Keycloak uses to build redirect links (useful behind a reverse proxy).
  • HTML display name — supports HTML for branded login pages.
  • User registration — allow self-service sign-up.
  • Forgot password — enable the password reset flow (requires email configured).
  • Remember me — let users stay logged in across browser restarts.
  • Verify email — require users to confirm their email address after registration.
  • Login with email — allow users to enter their email address instead of a username.

Configure the SMTP server Keycloak uses to send verification and password-reset emails. Required if you enable any email-triggered flows.

Key settings that control token lifetimes and behaviour:

SettingDefaultWhat it controls
Access token lifespan5 minHow long an access token is valid
SSO session idle30 minSession expires if idle for this long
SSO session max10 hoursHard limit on session length
Refresh token lifespanMatches SSO sessionHow long a refresh token can be used

Shorter access-token lifespans reduce the window of exposure if a token is stolen, at the cost of more frequent refreshes.

Keycloak automatically generates cryptographic keys for signing tokens. The Keys tab shows the active key providers. For production, you should rotate keys periodically. The RS256 provider is the default and produces JWTs signed with an RSA private key; clients verify signatures using the public key available at the realm’s JWKS endpoint:

http://localhost:8080/realms/{realm-name}/protocol/openid-connect/certs
OptionBenefitCost
One realm per app (realm-per-app)Completely separates each app’s users, sessions, and token policy, limiting the blast radius if one app has a security issueYou must maintain multiple realms — theme, SMTP, and identity provider settings must be repeated per realm, adding operational overhead
Shared realm (several apps in one realm)Simpler to set up and maintain; one user can access several apps via SSO immediatelyWeaker isolation — a misconfiguration or role mistake in one app can affect another app in the same scope
  • Registering real applications in the master realm — master should be reserved for administering Keycloak itself. Create a separate realm for every project or product so application users aren’t mixed in with super-user administration.
  • Forgetting to set token lifespans appropriate to each app’s risk — using the same defaults for every realm, even though some realms (e.g. banking) should have a shorter access-token lifespan than a lower-risk realm.
  • Not rotating the signing key periodically in production — leaving the same key in use for the system’s whole lifetime increases risk if the private key ever leaks unnoticed.

Real-world example

A multi-tenant SaaS platform — many SaaS platforms use a realm-per-customer pattern, creating a separate realm for each customer so their users, roles, and sessions are completely isolated from each other, while supporting custom branding and a per-tenant identity provider.

A large organisation with multiple teams — a company running both internal tools and a customer-facing product commonly separates realms by user population, e.g. a staff realm for employees and a customers realm for customers, so password or MFA policy on one side never affects the other.

You run a SaaS product for many customers who all use the same clients and roles. Which model does Keycloak 26 recommend?
What is the purpose of the master realm in Keycloak?
Which token setting should you shorten to reduce the exposure window if an access token is stolen?
Where in the admin console do you start the process of creating a new realm?
What URL path exposes a realm's public signing keys for token verification?