Keycloak Ops
Isometric pink crystal on a dark platform ringed by small cubes, linked by glowing lines to nodes and side pedestals, evoking a Keycloak realm and its contents
fundamentals

What Is a Realm in Keycloak? What Lives Inside One

A Keycloak realm is an isolated tenant with its own users, clients and signing keys. What a realm holds, what stays server-wide, and how many to run.

By Keycloak Ops Editorial · ·Updated · 8 min read

A Keycloak realm is an isolated tenant inside one Keycloak server, with its own users, groups, roles, clients, login flows, email settings and signing keys, served under its own URL path, /realms/{name}. Keycloak’s getting-started guide calls a realm “equivalent to a tenant.” Every server ships with a master realm for administration. Your apps belong in a realm you create.

For a homelab, the right count is almost always one application realm, with master left alone. Choose the name with care, because every realm’s OpenID Connect endpoints sit under /realms/{realm-name}, so the name ends up in the OIDC settings of every app you connect.

Based on Keycloak’s official documentation, checked against the 26.8.2 docs on 2026-11-18. The commands and compose file were not run on a test server.

What does a Keycloak realm actually contain?

A realm contains everything Keycloak needs to log a person into an app: the user directory and credentials, groups and roles, a client registration per app, login flows, identity providers and its own signing keys. The Server Administration Guide says a realm “manages a set of users, credentials, roles, and groups,” and that realms “are isolated from one another and can only manage and authenticate the users that they control.”

In the Admin Console, it splits between the left-hand menu and the tabs under Realm settings:

What Where in the Admin Console Worth knowing
Users and credentials Users An account exists in exactly one realm
Groups and realm roles Groups, Realm roles Client roles hang off each client
Clients Clients One registration per app that logs users in
External identity sources Identity providers, User federation Social login, LDAP, Active Directory
Login options Realm settings → Login Self-registration, forgot password, verify email
Email Realm settings → Email SMTP for verification and reset mail
Signing keys Realm settings → Keys Generated when the realm is created
Brute force detection Realm settings → Security defenses Off by default
Session and token lifetimes Realm settings → Sessions, Tokens Idle and maximum lifetimes
Themes Realm settings → Themes Login page and account console look

Three of those rows are worth a closer look.

Keys are per realm. The key management docs say that “When a realm is created, a key pair and a self-signed certificate is automatically generated,” and suggest creating new keys every three to six months. Because each realm signs with its own keys, an API that trusts realm home rejects a perfectly valid token from realm lab. That is the isolation working, not a bug.

Email is per realm. The email settings live under each realm’s Email tab and drive address verification and password resets. A second realm means configuring SMTP a second time, the first hint that extra realms cost upkeep.

Brute force protection is off by default. The brute force docs state that “Brute force detection is disabled by default” and configure it under Realm settings, Security defenses. If a realm’s login page is reachable from outside your LAN, switch it on there.

A realm is one JSON document

Under the console, a realm is a single JSON object. Exports produce it, imports consume it, and its top-level fields map onto the tabs above. The field names below come from Keycloak’s RealmRepresentation class, trimmed to a lab realm’s essentials (lifespans are in seconds):

{
  "realm": "lab",
  "displayName": "Lab (safe to break)",
  "enabled": true,
  "sslRequired": "external",
  "registrationAllowed": false,
  "loginWithEmailAllowed": true,
  "verifyEmail": false,
  "bruteForceProtected": true,
  "passwordPolicy": "length(12)",
  "accessTokenLifespan": 300,
  "ssoSessionIdleTimeout": 1800,
  "ssoSessionMaxLifespan": 36000,
  "groups": [
    { "name": "admins" },
    { "name": "family" }
  ],
  "users": [],
  "clients": []
}

Started with --import-realm, Keycloak imports realm files from /opt/keycloak/data/import, and the import and export guide says it skips any realm that already exists. That makes a throwaway lab realm a two-file job:

# compose.yaml, with lab.json saved in ./realms/
services:
  keycloak:
    image: quay.io/keycloak/keycloak:26.8.2
    command: start-dev --import-realm
    environment:
      KC_BOOTSTRAP_ADMIN_USERNAME: admin
      KC_BOOTSTRAP_ADMIN_PASSWORD: change-me
    ports:
      - "127.0.0.1:8080:8080"
    volumes:
      - ./realms:/opt/keycloak/data/import:ro

The image tag is 26.8.2, the tag in Keycloak’s own docker run command, current on 2026-11-18. start-dev is development mode, which the configuration guide describes as a way to try Keycloak out; it says to use production mode for production deployments. The real deployment wants start, PostgreSQL and the settings covered in Keycloak behind a reverse proxy.

What is not inside a realm?

Anything that configures the server process sits outside every realm: hostname, proxy headers, database connection, caches, HTTP and TLS, feature flags and the bootstrap admin. These are kc.sh options or KC_ environment variables, and they apply to all realms at once. The configuration reference groups them under headings like Database, Hostname v2, Proxy, Cache and Feature.

One small exception: the hostname guide lists “Realm configuration for frontend URL” among the sources Keycloak uses to resolve its URLs, so a realm can advertise its own public URL. Leave it empty unless you know why you need it.

Two consequences matter on a single mini-PC:

  • A realm is not a resource boundary. The database is a server option in the configuration reference, so every realm uses the same one. Realm data, including clients, roles and groups, sits in a local realms cache capped at 10,000 entries by default, per the caching guide. Keycloak memory usage and heap sizing covers what that costs in heap.
  • A realm export is not a backup. The import and export guide warns the process “has limitations to be used as a backup and restore mechanism.” Run pg_dump on a schedule and rehearse a restore. Keep realm exports in git because they diff nicely, not because they will save you.

Why should apps stay out of the master realm?

Because master is the administration realm, used to create and manage every other realm on the server. The master realm docs say it is created when you first start Keycloak. The getting-started guide says to use it “only for managing Keycloak and not for managing any applications.” Your dashboard client and your partner’s account do not belong next to that.

The separation buys least privilege without extra software. Each realm gets its own admin console at {admin path}/{realm-name}/console and a built-in realm-management client with roles such as realm-admin, manage-users and view-users for granting realm management permissions, per the per-realm admin docs. The master realm docs go further and describe disabling master entirely in favour of admins defined inside each realm.

For a homelab, that last step is more ceremony than it is worth. The sensible middle ground: one strong master admin stored in your password manager for realm-level surgery, and an ordinary account in the application realm for logging into apps every day. If someone else should reset family passwords, manage-users in that realm is enough.

How many realms does a homelab need?

One application realm, plus master. You, your family and your friends can all live in it, with groups and client roles deciding who reaches which app. A second realm earns its place only for a genuinely separate user population with its own login rules, or for a disposable lab realm rebuilt from JSON like the one above.

Realm-per-app looks tidy in the console and defeats the point of running an identity provider:

  • No single sign-on between apps. A user belongs to and logs into one realm, per the Server Administration Guide, so logging in to the realm guarding your photo library does nothing for the one guarding your dashboards.
  • Duplicate accounts. Each person needs an account in each realm, or you wire up brokering between realms to fake it.
  • Repeated configuration. SMTP, password policy, themes and key rotation all multiply by the realm count.
  • More memory. Each realm’s configuration and clients occupy entries in the realms cache.

If you are building a product for many customer companies rather than a house, Keycloak’s tool is Organizations, which the organizations docs describe as enabling “multi-tenancy within a realm.” Good to know it exists; your homelab does not need it.

Realm vs client, and how to create a realm and register your first client: Keycloak realms, clients and token design fundamentals.

How does an app know which realm to use?

Through the realm’s URL. Every realm publishes its OpenID Connect endpoints under the server’s base URL plus /realms/{realm-name}, per Keycloak’s OIDC endpoint reference. The discovery document beneath that path lists the other endpoints, so an app given it finds the rest on its own.

Endpoint Path under the base URL
Realm base path /realms/{realm-name}
Discovery /realms/{realm-name}/.well-known/openid-configuration
Authorization /realms/{realm-name}/protocol/openid-connect/auth
Token /realms/{realm-name}/protocol/openid-connect/token
Certificate endpoint (JSON Web Keys) /realms/{realm-name}/protocol/openid-connect/certs

Name the realm like a hostname: short, lowercase and not tied to whichever app you set up first. It lands in every app’s config.

If you suspect you will never want a second realm, only a login wall in front of a few apps, authentik vs Keycloak explains why Keycloak may be more server than you need.

FAQ

What is the default realm in Keycloak?

The default realm is master, created when Keycloak first starts and meant only for administration. See Why should apps stay out of the master realm? for why apps belong in a realm you create.

Do Keycloak realms share a database?

Yes. The database is a server-wide setting, so every realm uses the same one; see What is not inside a realm? for what that means for outages and backups.

Can users from one Keycloak realm log in to another?

Not directly, because a realm only authenticates the users it controls. The Server Administration Guide describes brokering to OpenID Connect providers, including another Keycloak realm through its discovery URL. On first login through a provider, Keycloak creates the user if none exists, or may ask to link an existing account.

How do I export a single Keycloak realm?

Per the import and export guide, run kc.sh export with --realm and a --dir or --file target, for example bin/kc.sh export --file home.json --realm home, with all Keycloak nodes stopped first. Add --users skip to leave accounts out of a config copy. Treat the result as reviewable configuration for git, not as a backup; dump the database for that.

Sources

  1. Keycloak: Server Administration Guide
  2. Keycloak: Getting started with Docker
  3. Keycloak documentation source: The master realm
  4. Keycloak documentation source: Managing realm keys
  5. Keycloak documentation source: Configuring email for a realm
  6. Keycloak documentation source: Brute force detection
  7. Keycloak documentation source: Dedicated realm admin consoles
  8. Keycloak documentation source: Organizations introduction
  9. Keycloak source: RealmRepresentation.java
  10. Keycloak: Importing and exporting realms
  11. Keycloak: All configuration options
  12. Keycloak: Configuring the hostname
  13. Keycloak: Configuring distributed caches
  14. Keycloak: Securing applications and services with OpenID Connect
  15. Keycloak: Configuring Keycloak

Related