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

KeycloakUserCredential

The KeycloakUserCredential resource manages user credentials (passwords) in Keycloak via Kubernetes Secrets.

Overview

This CRD provides a way to:

  • Store user passwords in Kubernetes Secrets
  • Automatically create secrets with generated passwords
  • Sync passwords to Keycloak users
  • Manage password policies

Example

Using an existing Secret

apiVersion: keycloak.hostzero.io/v1beta1
kind: KeycloakUserCredential
metadata:
  name: user-credential
spec:
  userRef:
    name: my-user
  userSecret:
    secretName: my-user-credentials
    usernameKey: username
    passwordKey: password

Auto-creating a Secret

apiVersion: keycloak.hostzero.io/v1beta1
kind: KeycloakUserCredential
metadata:
  name: user-credential
spec:
  userRef:
    name: my-user
  userSecret:
    secretName: my-user-credentials
    create: true
    usernameKey: username
    passwordKey: password
    passwordPolicy:
      length: 24
      symbols: true

Spec

FieldTypeDescriptionRequired
userRefResourceRefReference to the KeycloakUser resourceYes
userSecret.secretNamestringName of the Kubernetes SecretYes
userSecret.createbooleanCreate secret if it doesn’t existNo (default: false)
userSecret.usernameKeystringKey in secret for usernameNo (default: “username”)
userSecret.passwordKeystringKey in secret for passwordNo (default: “password”)
userSecret.passwordPolicy.lengthintLength of generated passwordNo (default: 16)
userSecret.passwordPolicy.symbolsbooleanInclude symbols in passwordNo (default: true)

Status

FieldTypeDescription
readybooleanWhether the credential is synced
statusstringCurrent status (Synced, Error, SecretError)
secretCreatedbooleanWhether the secret was created by the operator
messagestringAdditional status information
lastPasswordSyncstringTimestamp of last password sync

Behavior

Secret Creation

When create: true is set:

  1. The operator creates a new Secret if it doesn’t exist
  2. A password is generated according to the password policy
  3. The username is set to match the Keycloak user’s username

Password Sync

When the Secret exists (created or pre-existing):

  1. The operator reads the password from the Secret
  2. The password is set in Keycloak for the referenced user
  3. The lastPasswordSync timestamp is updated

Cleanup

When the KeycloakUserCredential is deleted:

  • If secretCreated: true in status, the Secret is also deleted (via owner references)
  • Pre-existing secrets are not deleted

Use Cases

Initial User Setup

Create users with auto-generated passwords:

apiVersion: keycloak.hostzero.io/v1beta1
kind: KeycloakUser
metadata:
  name: new-user
spec:
  realmRef:
    name: my-realm
  definition:
    username: new-user
    email: user@example.com
    enabled: true
---
apiVersion: keycloak.hostzero.io/v1beta1
kind: KeycloakUserCredential
metadata:
  name: new-user-creds
spec:
  userRef:
    name: new-user
  userSecret:
    secretName: new-user-password
    create: true

Service Account Passwords

Manage service account credentials that can be mounted into pods:

apiVersion: keycloak.hostzero.io/v1beta1
kind: KeycloakUserCredential
metadata:
  name: service-account-creds
spec:
  userRef:
    name: service-account-user
  userSecret:
    secretName: app-keycloak-credentials
    create: true
    passwordPolicy:
      length: 32
      symbols: false