Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

KeycloakRole

A KeycloakRole manages Keycloak roles. Roles can be either realm-level (shared across all clients) or client-level (specific to a single client).

Specification

apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakRole
metadata:
  name: my-role
spec:
  # One of realmRef, clusterRealmRef, or clientRef must be specified
  
  # For realm roles:
  realmRef:
    name: my-realm
  
  # For client roles:
  # clientRef:
  #   name: my-client
  
  # Required: Role definition (Keycloak RoleRepresentation)
  definition:
    name: admin-role
    description: Administrator role

Status

status:
  ready: true
  roleName: "admin-role"
  message: "Role synchronized successfully"

Examples

Realm Role

apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakRole
metadata:
  name: my-realm-role
  namespace: keycloak
spec:
  realmRef:
    name: my-realm
  definition:
    name: admin-role
    description: Administrator role with full access
    composite: false

Client Role

apiVersion: keycloak.hostzero.com/v1beta1
kind: KeycloakRole
metadata:
  name: my-client-role
  namespace: keycloak
spec:
  clientRef:
    name: my-client
  definition:
    name: editor
    description: Can edit resources

Parent Reference

A KeycloakRole can belong to one of three parent types:

ReferenceScopeUse Case
realmRefRealm roleShared across all clients in the realm
clusterRealmRefRealm roleFor cluster-scoped realms
clientRefClient roleSpecific to a single client

Note: Exactly one of these must be specified.

Definition Properties

The definition field accepts any valid Keycloak RoleRepresentation:

FieldTypeDescription
namestringRole name (required)
descriptionstringRole description
compositebooleanWhether this is a composite role
compositesobjectComposite role definitions (realm/client roles)
attributesobjectCustom attributes

Status Fields

FieldTypeDescription
readybooleanWhether the role is synchronized
statusstringCurrent status (e.g., “Ready”, “Error”)
messagestringHuman-readable status message
roleNamestringThe role name in Keycloak
observedGenerationintegerLast observed generation

Short Names

AliasFull Name
kcrlkeycloakroles
kubectl get kcrl

Notes

  • Role names must be unique within their scope (realm or client)
  • When using clientRef, the role becomes a client role
  • Composite roles can reference other realm or client roles