Skip to content

Realms

Use a Realm when you need an isolated Keycloak boundary for a tenant, environment, or application domain. Because every other Keycloak resource belongs to a realm, this is usually the first resource you create for a new deployment.

API Reference

Working YAML Examples

Basic realm

apiVersion: realm.keycloak.crossplane.io/v1alpha1
kind: Realm
metadata:
  name: dev
spec:
  deletionPolicy: Delete
  forProvider:
    realm: "dev"
    attributes:
      userProfileEnabled: "true"
  providerConfigRef:
    name: "keycloak-provider-config"

Realm with timeouts and lifespans

apiVersion: realm.keycloak.crossplane.io/v1alpha1
kind: Realm
metadata:
  name: dev-durations
spec:
  deletionPolicy: Delete
  forProvider:
    realm: "dev-durations"
    enabled: true
    accessTokenLifespan: "5m0s"
    accessTokenLifespanForImplicitFlow: "1800s"
    ssoSessionIdleTimeout: "30m0s"
    ssoSessionMaxLifespan: "10h0m0s"
    ssoSessionIdleTimeoutRememberMe: "0s"
    ssoSessionMaxLifespanRememberMe: "0s"
    offlineSessionIdleTimeout: "720h0m0s"
    offlineSessionMaxLifespan: "1440h0m0s"
    clientSessionIdleTimeout: "0s"
    clientSessionMaxLifespan: "0s"
    accessCodeLifespan: "1m0s"
    accessCodeLifespanUserAction: "5m0s"
    accessCodeLifespanLogin: "30m0s"
    actionTokenGeneratedByAdminLifespan: "12h0m0s"
    actionTokenGeneratedByUserLifespan: "5m0s"
    oauth2DeviceCodeLifespan: "10m0s"
    oauth2DevicePollingInterval: 5
  providerConfigRef:
    name: "keycloak-provider-config"

Managing an existing realm without deleting it

apiVersion: realm.keycloak.crossplane.io/v1alpha1
kind: Realm
metadata:
  name: existing-master
spec:
  deletionPolicy: Orphan
  forProvider:
    realm: master
    displayName: Customized Keycloak
  providerConfigRef:
    name: "keycloak-provider-config"
  managementPolicies: [Observe, Update]

Realm with organizations enabled

apiVersion: realm.keycloak.crossplane.io/v1alpha1
kind: Realm
metadata:
  name: orgs
spec:
  deletionPolicy: Delete
  forProvider:
    realm: "orgs"
    organizationsEnabled: true
  providerConfigRef:
    name: "keycloak-provider-config"

Key Fields

FieldDescription
realmRealm ID and top-level container name used by all child resources.
enabledTurns the realm on or off.
displayNameHuman-friendly name shown in the Keycloak UI.
passwordPolicyPassword rules enforced for users in the realm.
attributesExtra realm settings such as feature flags and provider-specific options.
smtpServerOutbound email settings for verification, reset, and notification flows.
otpPolicyRealm-wide OTP settings for MFA behavior.
organizationsEnabledEnables organization features in supported Keycloak versions.
accessTokenLifespanDefault lifetime for access tokens.
accessTokenLifespanForImplicitFlowAccess token lifetime for implicit flow clients.
ssoSessionIdleTimeoutIdle timeout before a normal SSO session expires.
ssoSessionMaxLifespanMaximum duration of a normal SSO session.
ssoSessionIdleTimeoutRememberMeIdle timeout for remember-me SSO sessions.
ssoSessionMaxLifespanRememberMeMaximum duration for remember-me SSO sessions.
offlineSessionIdleTimeoutIdle timeout for offline sessions and refresh tokens.
offlineSessionMaxLifespanMaximum duration for offline sessions.
clientSessionIdleTimeoutIdle timeout for client sessions.
clientSessionMaxLifespanMaximum duration for client sessions.
accessCodeLifespanLifetime of authorization codes.
accessCodeLifespanUserActionLifetime for user action tokens during browser flows.
accessCodeLifespanLoginMaximum time allowed to complete login.
actionTokenGeneratedByAdminLifespanLifetime for admin-generated action tokens.
actionTokenGeneratedByUserLifespanLifetime for user-generated action tokens.
oauth2DeviceCodeLifespanLifetime for OAuth 2.0 device codes.
oauth2DevicePollingIntervalPolling interval for device authorization clients.

Related Resources