cluster-rhbk

by startxfr

Helm chartv21.3.418App 26.6.9GPL-3.0-or-laterVerified publisher

Helm chart used to configure Red Hat build of Keycloak (RHBK) at the cluster level, with the rhbk-operator, Keycloak instances, realm imports and an OpenShift route

About this chart

Cluster Chart : RHBK

This helm chart is used to deploy the Red Hat build of Keycloak (RHBK), the successor of Red Hat Single Sign-On, managed by the rhbk-operator. It installs the operator, a Keycloak instance (API k8s.keycloak.org/v2beta1) with its database and bootstrap admin secrets, an OpenShift Route in front of it, and KeycloakRealmImport objects for the realms.

For demo environments the chart can also deploy a single pod PostgreSQL database. In production, Keycloak connects to an external database or to a PostgreSQL cluster managed by cluster-percona. Secrets are rendered from the values, or sourced from an external store with the External Secrets Operator.

This chart replaces cluster-sso, which is based on the Red Hat Single Sign-On 7.6 operator (API keycloak.org/v1alpha1), no longer developed.

This chart is part of the cluster-xxx startx helm chart series that doesn't necessarily deploy pods but rather represent a cluster configuration state orchestrated by gitops tools like ArgoCD.

Requirements and guidelines

Read the startx helm-repository homepage for more information on how to use these resources.

RequirementDetail
OpenShift 4.17+ (Kubernetes 1.30+)kubeVersion of the chart, tested on OpenShift 4.22
Red Hat build of Keycloak operator 26.6redhat-operators catalog, package rhbk-operator, channel stable-v26.6. Installed by the operator sub-chart in the namespace of the instances (OwnNamespace, the operator cannot watch all namespaces)
API versionk8s.keycloak.org/v2beta1 is the storage version of the 26.6 operator. With an older channel such as stable-v26.4, set rhbk.apiVersion: k8s.keycloak.org/v2alpha1 and the matching providedAPIs
Network policyThe 26.6 operator creates the NetworkPolicy <rhbk.name>-network-policy on the Keycloak pods. HTTP(S) and management ports are open to every source, the router included, unless rules are set. Cluster (JGroups) ports are restricted to the Keycloak pods. Restrict it with spec.networkPolicy.httpRules / httpsRules / managementRules, or disable it with spec.networkPolicy.enabled: false
DatabasePostgreSQL reachable from the Keycloak pods. database.enabled deploys a development instance (image registry.redhat.io/rhel9/postgresql-16, pulled with the cluster pull secret)
FIPSThe operator CSV declares features.operators.openshift.io/fips-compliant: "false". Keycloak runs on a FIPS enabled cluster (tested on OpenShift 4.22), but the RHBK image does not ship the BouncyCastle FIPS providers. A FIPS compliant deployment needs a custom image with these providers (spec.image), the fips feature and fips-mode: strict (see the FIPS guide)
SecretsDatabase and admin passwords are expected as Argo CD Vault Plugin placeholders (<path:kv/data/...#key>), from a values file kept out of Git, or from the External Secrets Operator (externalSecret.enabled). The startx values files only carry demo secrets (database password, and the grafana client secret of values-startx_noinfra-grafana.yaml)

Deploy this helm chart on openshift

1. Connect to your Openshift cluster

oc login -t <token> <cluster-url>

2. Install the repository

helm repo add startx https://helm-repository.readthedocs.io/en/latest/repos/stable/

3. Get information about this chart

helm show chart startx/cluster-rhbk

4. Install this chart

helm install cluster-rhbk startx/cluster-rhbk

Default values

Complete deployment of a project with the following characteristics, using the values-startx.yaml values :

  • 1 namespace: named default-rhbk without constraints
  • 1 operator: named rhbk-operator configured with
    • The stable-v26.6 channel of the redhat catalog, manual install plan approval
    • The v26.6.9-opr.1 version
    • Deployed under the default-rhbk project (OwnNamespace OperatorGroup)
  • 1 database: named startx-postgresql (development only), PostgreSQL 16, a 2Gi data volume
  • 1 keycloak: named startx configured with
    • one instance, database credentials read from the Secret startx-db-secret
    • HTTP enabled behind the route, X-Forwarded-* headers trusted, hostname taken from the request
    • the operator ingress disabled
  • 1 route: named startx with edge TLS termination and a generated host
  • 1 realm import: named startx with a public OpenID Connect client startx-demo
# Create the project
helm install cluster-rhbk-project startx/cluster-rhbk -f https://raw.githubusercontent.com/startxfr/helm-repository/master/charts/cluster-rhbk/values-startx.yaml --set project.enabled=true
# Deploy the rhbk operator
helm install cluster-rhbk-operator startx/cluster-rhbk -f https://raw.githubusercontent.com/startxfr/helm-repository/master/charts/cluster-rhbk/values-startx.yaml --set operator.enabled=true && sleep 30
# Approve the first install plan (manual approval)
oc patch installplan $(oc get installplan -n default-rhbk -o jsonpath='{.items[0].metadata.name}') -n default-rhbk --type merge -p '{"spec":{"approved":true}}'
# Deploy the database, the keycloak instance, its route and the startx realm
helm install cluster-rhbk-instance startx/cluster-rhbk -f https://raw.githubusercontent.com/startxfr/helm-repository/master/charts/cluster-rhbk/values-startx.yaml --set database.enabled=true,rhbk.enabled=true,route.enabled=true,rhbk_realms.enabled=true

Values files

helm install cluster-rhbk startx/cluster-rhbk -f https://raw.githubusercontent.com/startxfr/helm-repository/master/charts/cluster-rhbk/values-startx.yaml

Values dictionary

Chart level

KeyDefaultDescription
context.*default-rhbk appSTARTX deployment context (labels of every object)
externalSecretDefaultsexternal-secrets.io/v1, 1h, ClusterSecretStoreDefaults for every secret sourced from an external store. secretStoreRef.name is required as soon as a secret uses externalSecret

Development database (database)

KeyDefaultDescription
enabledfalseDeploy a single pod PostgreSQL StatefulSet and its Service (no replication, no backup)
name<rhbk.name>-postgresqlName of the StatefulSet and of the Service, used as spec.db.host
imageregistry.redhat.io/rhel9/postgresql-16:latestPostgreSQL image
databasekeycloakDatabase created at initialization, used as spec.db.database
storageClassName, size"", 2GiData volume (empty class: default StorageClass of the cluster)
resources100m / 256Mi, limit 512MiResources of the database container

The database reads its credentials from the database Secret of the Keycloak instance (rhbk.dbSecret).

Keycloak instance (rhbk)

KeyDefaultDescription
enabled, hookedfalse, falseRender the Keycloak and its secrets. hooked renders the Keycloak as a post-install hook
apiVersionk8s.keycloak.org/v2beta1API version of the Keycloak and KeycloakRealmImport objects
namedefaultName of the Keycloak. The operator names its objects after it (<name>-service, <name>-initial-admin...)
dbSecret.enabled, name, username, passwordfalse, <name>-db-secret, keycloak, ""Database Secret (keys username and password) referenced by spec.db. password is required unless externalSecret is used
adminSecret.enabled, name, username, passwordfalse, <name>-bootstrap-admin, admin, ""Temporary admin Secret referenced by spec.bootstrapAdmin.user.secret. When disabled, the operator generates <name>-initial-admin (user temp-admin)
*.externalSecret.enabled, remoteRefsfalse, {}Produce the Secret with an ExternalSecret instead (keys username and password required in remoteRefs. data, dataFrom and template are also accepted)
specone instance, HTTP, non strict hostname, xforwarded proxy headersKeycloak spec merged over a base generated by the chart (see below)

The chart builds part of the Keycloak spec from the other values, then merges rhbk.spec over it. Keys set in rhbk.spec win.

Generated keyWhen
db.vendor: postgres, db.usernameSecret, db.passwordSecretrhbk.dbSecret.enabled or database.enabled
db.host, db.port, db.databasedatabase.enabled
bootstrapAdmin.user.secretrhbk.adminSecret.enabled
ingress.enabled: falseroute.enabled

Route (route)

KeyDefaultDescription
enabledfalseExpose the instance with a Route to the <rhbk.name>-service Service, and disable the operator ingress
name, hostrhbk.name, ""Name of the route, and its host (empty: generated by OpenShift)
terminationedgeedge (to the http port, needs http.httpEnabled: true), reencrypt or passthrough (to the https port, needs http.tlsSecret)
insecureEdgeTerminationPolicy, targetPort, annotationsRedirect, "", {}Plain HTTP policy, explicit target port, extra annotations

Realm imports (rhbk_realms)

KeyDefaultDescription
enabledfalseRender the KeycloakRealmImport objects
list[].name, enabledmyrealm, trueName of the import, and its switch
list[].keycloakCRNamerhbk.nameTarget Keycloak in the same namespace
list[].placeholders{}${KEY} placeholders of the realm resolved from Secrets (KEY: {secret: {name, key}})
list[].realmminimal realmFull RealmRepresentation (YAML)
secrets[].name, enabled, data[]Secrets read by the placeholders (client secrets...), rendered at wave 1 before the imports
secrets[].externalSecret.enabled, remoteRefsfalse, {}Produce the Secret with an ExternalSecret instead

A KeycloakRealmImport only creates a realm. It never updates or overwrites an existing one, so changing a realm in the values after its first import has no effect. Apply later changes with the admin console or the admin API, or delete the realm before a new import.

Sub-charts

project (namespace) and operator (OLM subscription and OperatorGroup of the rhbk operator) are the STARTX basic charts, see their own documentation. The chart objects use Argo CD sync waves: Secrets and ExternalSecrets (1), development database (10), Keycloak (15), Route (20), KeycloakRealmImport (30).

Procedures

Admin console access

# URL of the admin console
echo "https://$(oc get route startx -n default-rhbk -o jsonpath='{.spec.host}')/admin/"
# temporary admin credentials generated by the operator (rhbk.adminSecret disabled)
oc get secret startx-initial-admin -n default-rhbk -o jsonpath='{.data.username}' | base64 -d; echo
oc get secret startx-initial-admin -n default-rhbk -o jsonpath='{.data.password}' | base64 -d; echo

The bootstrap admin is temporary. Create a permanent administrator in the master realm (or federate an identity provider), then remove the temporary user.

Production database with cluster-percona

Deploy the database with cluster-percona in the default-rhbk namespace and keep database.enabled: false. Then point the Keycloak to the Secret generated by the Percona operator (<cluster>-pguser-<user>, keys user and password):

rhbk:
  dbSecret:
    enabled: false
  spec: |
    instances: 2
    db:
      vendor: postgres
      host: keycloak-db-pgbouncer
      database: keycloak
      usernameSecret:
        name: keycloak-db-pguser-keycloak
        key: user
      passwordSecret:
        name: keycloak-db-pguser-keycloak
        key: password
    http:
      httpEnabled: true
    hostname:
      hostname: https://sso.apps.example.com
    proxy:
      headers: xforwarded

End to end TLS (reencrypt)

Let the OpenShift service CA issue the certificate of the Keycloak Service and serve HTTPS only, behind a reencrypt route (the router trusts the service CA):

rhbk:
  spec: |
    http:
      httpEnabled: false
      tlsSecret: startx-tls
      annotations:
        service.beta.openshift.io/serving-cert-secret-name: startx-tls
    hos

Deploy cluster-rhbk with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has cluster-rhbk on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartcluster-rhbk is pinned at v21.3.418 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply