Skip to content

Keycloak Realm Configuration

The Realm is the “Sovereign Container” of the Keycloak ecosystem. Each Realm is a self-contained universe of users, roles, groups, and clients, absolutely isolated from every other Realm on the same server. This multi-tenant architecture allows you to run a single Keycloak instance that serves multiple independent organizations, departments, or customer bases. For the IAM architect, Realm configuration is about defining the Security Perimeter—governing everything from password complexity and MFA requirements to the specific themes and languages presented to the user during login.

REALM CONFIG

Governance Sovereign
Core Mission
Multi-Tenant Isolation. Establishing rigorous security and identity boundaries within a shared infrastructure, ensuring that policy changes in one realm never affect the integrity of another.
Like a Luxury Apartment Building: Imagine a high-rise (The Keycloak Server) where every floor is a "Realm." Each floor has its own set of keys, its own decorations (Themes), its own rules (Policies), and its own list of residents (Users). A resident on the 5th floor (The Finance Realm) can’t even see who lives on the 6th floor (The Engineering Realm), and the 5th floor can have armed guards (High MFA) while the 1st floor has just a simple doorman. They share the same foundation (The Database), but their lives are completely isolated.
SaaS Multi-Tenancy / Departmental Isolation / Developer Sandboxing / B2B Partner Portals

Designing your realm structure requires balancing the complexity of management with the need for security isolation.

ProfileStrategic ResponsibilityIAM Implementation
The Master RealmSystem Control.Only used for managing Keycloak itself and creating other realms. Never host apps here!
Dedicated B2B RealmPartner Isolation.A realm created for a specific corporate partner with their own IdP brokering.
The Employee RealmInternal Workforce.Integrated with Active Directory and configured with rigid enterprise security policies.
Project SandboxDeveloper Agility.Temporary realms with relaxed policies for rapid prototyping and testing.

Creating and hardening a new Realm follows a “Birth-to-Hardening” path.

graph LR
    Create[Create Realm] --> Policy[Define Policies]
    Policy --> Federation[Integrate IdPs]
1

Isolate the Persona

Create the Realm with a unique ID and alias. This is the first "Sovereign Decision." Choose a theme—Keycloak allows you to apply custom CSS and HTML for the login, account, and admin consoles at the realm level, ensuring a consistent brand experience for that specific tenant.

2

Harden the Security Posture

Configure the **Security Defenses**. Define the password policy (entropy, expiry), the lockout policy (protecting against brute force), and the **Authentication Flow**. This is where you decide if this realm requires mandatory WebAuthn or if it allows legacy OTP.

3

Establish Trusted Federation

Connect the realm to its "Sources of Identity." This could be via **User Federation** (LDAP/AD) or **Identity Brokering** (Social IdPs). The Realm now acts as the central clearinghouse for any identity that needs to access the clients (Apps) registered within it.


Exporting and importing realm configurations as JSON allows for “Identity-as-Code.”

{
"realm": "Sovereign-B2B",
"enabled": true,
"identityProviders": [
{
"alias": "google",
"providerId": "google",
"config": {
"clientId": "google-client-id",
"clientSecret": "google-secret"
}
}
],
"passwordPolicy": "upperCase(1) and length(12) and forceExpiredPasswordChange(90)"
}

Master the technical ceremonies of multi-tenant isolation and realm-level governance.