cluster-rhbk
by startxfr
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.
| Requirement | Detail |
|---|---|
| OpenShift 4.17+ (Kubernetes 1.30+) | kubeVersion of the chart, tested on OpenShift 4.22 |
| Red Hat build of Keycloak operator 26.6 | redhat-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 version | k8s.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 policy | The 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 |
| Database | PostgreSQL reachable from the Keycloak pods. database.enabled deploys a development instance (image registry.redhat.io/rhel9/postgresql-16, pulled with the cluster pull secret) |
| FIPS | The 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) |
| Secrets | Database 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
- startx : rhbk operator on infra nodes, demo instance, development database and startx realm (see values-startx.yaml)
- startx_noinfra : the same without the infra node placement of the operator (see values-startx_noinfra.yaml)
- startx_noinfra-grafana : the same, plus a confidential
grafanaclient in the startx realm, used by thevalues-startx_noinfra-rhbk.yamlvalues of cluster-grafana (see values-startx_noinfra-grafana.yaml)
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
| Key | Default | Description |
|---|---|---|
context.* | default-rhbk app | STARTX deployment context (labels of every object) |
externalSecretDefaults | external-secrets.io/v1, 1h, ClusterSecretStore | Defaults for every secret sourced from an external store. secretStoreRef.name is required as soon as a secret uses externalSecret |
Development database (database)
| Key | Default | Description |
|---|---|---|
enabled | false | Deploy a single pod PostgreSQL StatefulSet and its Service (no replication, no backup) |
name | <rhbk.name>-postgresql | Name of the StatefulSet and of the Service, used as spec.db.host |
image | registry.redhat.io/rhel9/postgresql-16:latest | PostgreSQL image |
database | keycloak | Database created at initialization, used as spec.db.database |
storageClassName, size | "", 2Gi | Data volume (empty class: default StorageClass of the cluster) |
resources | 100m / 256Mi, limit 512Mi | Resources of the database container |
The database reads its credentials from the database Secret of the Keycloak instance (rhbk.dbSecret).
Keycloak instance (rhbk)
| Key | Default | Description |
|---|---|---|
enabled, hooked | false, false | Render the Keycloak and its secrets. hooked renders the Keycloak as a post-install hook |
apiVersion | k8s.keycloak.org/v2beta1 | API version of the Keycloak and KeycloakRealmImport objects |
name | default | Name of the Keycloak. The operator names its objects after it (<name>-service, <name>-initial-admin...) |
dbSecret.enabled, name, username, password | false, <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, password | false, <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, remoteRefs | false, {} | Produce the Secret with an ExternalSecret instead (keys username and password required in remoteRefs. data, dataFrom and template are also accepted) |
spec | one instance, HTTP, non strict hostname, xforwarded proxy headers | Keycloak 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 key | When |
|---|---|
db.vendor: postgres, db.usernameSecret, db.passwordSecret | rhbk.dbSecret.enabled or database.enabled |
db.host, db.port, db.database | database.enabled |
bootstrapAdmin.user.secret | rhbk.adminSecret.enabled |
ingress.enabled: false | route.enabled |
Route (route)
| Key | Default | Description |
|---|---|---|
enabled | false | Expose the instance with a Route to the <rhbk.name>-service Service, and disable the operator ingress |
name, host | rhbk.name, "" | Name of the route, and its host (empty: generated by OpenShift) |
termination | edge | edge (to the http port, needs http.httpEnabled: true), reencrypt or passthrough (to the https port, needs http.tlsSecret) |
insecureEdgeTerminationPolicy, targetPort, annotations | Redirect, "", {} | Plain HTTP policy, explicit target port, extra annotations |
Realm imports (rhbk_realms)
| Key | Default | Description |
|---|---|---|
enabled | false | Render the KeycloakRealmImport objects |
list[].name, enabled | myrealm, true | Name of the import, and its switch |
list[].keycloakCRName | rhbk.name | Target Keycloak in the same namespace |
list[].placeholders | {} | ${KEY} placeholders of the realm resolved from Secrets (KEY: {secret: {name, key}}) |
list[].realm | minimal realm | Full RealmRepresentation (YAML) |
secrets[].name, enabled, data | [] | Secrets read by the placeholders (client secrets...), rendered at wave 1 before the imports |
secrets[].externalSecret.enabled, remoteRefs | false, {} | 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.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartcluster-rhbk is pinned at v21.3.418 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- 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