kadet-hub logokadet-hub

Recipes / keycloak

Keycloak on Kubernetes run by the Keycloak Operator

A recipe is packed cargo for one app: inventory classes, ready to load.

Keycloak 26.8.1 as one Keycloak resource of the Keycloak Operator, on the PostgreSQL of the postgresql recipe and with a cert-manager certificate, and optionally an HTTPRoute to a Gateway the cluster already runs.

1.0.1proof level deploys

  • Latest version: 1.0.1, published
  • Source: container image quay.io/keycloak/keycloak:26.8.1@sha256:3f3c5f8e03c614774b4bd9173b88391fefa4153bfc010d8012d59ad825377332, recipe designed in kadet-hub
  • Proof level: deploys, deployed on kind and smoke tested by the kadet-hub/recipes CI
  • renders passed in the release run of with check 0.18.0, kind v0.33.0
  • Output capabilities: none
  • Inventory backends: omegaconf
  • Prerequisites, installed once per cluster before the recipe: keycloak-operator, cert-manager, gateway-api, cnpg
  • Generators: keycloak 1.1.0 sha256:7c7d3aa29b5cca627c868b166f3ed00979e04c99d01e71f2a33bd35d4393ecc4, certmanager 1.0.2 sha256:ba7632e9e06a593fbe20e9fa6774139203d7df65992adff9db94779606888ad9, kubernetes 1.14.0 sha256:787129e1eaed6b9bc868fe4c4aec58d40de6a89fc3cc08424a4cb5822b855080
  • Image security: grade F 97 findings, one per advisory and package, in the 1 image of version 1.0.1: CRITICAL 1, HIGH 9, MEDIUM 53, LOW 34, UNKNOWN 0. Scanned 2026-12-03 04:38 UTC. Full report
    The grade rates the upstream images the recipe pins, not the recipe: quay.io/keycloak/keycloak.

Replaces

This recipe replaces the keycloak recipe of kadet-hub/examples, which stood in for Bitnami’s keycloak chart. The examples recipe named the Keycloak sso and its Cluster keycloak-db. A target that moves from it keeps both names. Keycloak then keeps its realms, users and sessions in the database keycloak, and the Cluster keeps its claims keycloak-db-<n>. Clients keep the Service sso-service, and the temporary admin stays in sso-initial-admin.

parameters:
  namespace: keycloak
  applications:
    keycloak:
      name: sso
      host: sso.example.com
      issuer:
        name: keycloak-selfsigned
        kind: Issuer
    postgresql:
      cluster: keycloak-db
      database: keycloak
      owner: keycloak
      storage: 10Gi
      instances: 2
  generators:
    certmanager:
      issuers:
        keycloak-selfsigned:
          spec:
            selfSigned: {}

Moving changes these objects:

kadet-hub/examples This recipe
Namespace keycloak, rendered by the recipe no Namespace. The target sets namespace: keycloak. Keep the Namespace when the examples recipe goes, because deleting it deletes the claims.
the Keycloak Operator, cert-manager and the CloudNativePG operator in the recipe, from their charts through helm compile entries the recipes keycloak-operator, cert-manager and cnpg, each in a target of its own. keycloak-operator watches every namespace.
Issuer keycloak-selfsigned, rendered by the recipe not rendered. The snippet renders it in the target.
Certificate and Secret sso-tls Certificate and Secret keycloak-tls, for the same DNS names
Cluster settings postgresql’s, which its README lists under Replaces

Move a target in this order:

  1. Delete the examples recipe’s Keycloak Operator: the Deployment, Service and ServiceAccount keycloak-operator and the RoleBinding keycloak-operator-view in keycloak, and the cluster roles and bindings by the chart names that keycloak-operator’s README lists under Renamed RBAC objects. Keep the CRDs, because deleting them deletes the Keycloak sso.
  2. Install keycloak-operator in a target of its own. Replace cert-manager and the CloudNativePG operator as the READMEs of cert-manager and cnpg describe under “Replacing a Helm release”. The examples recipe left no Helm secrets.
  3. Apply this recipe. The operator restarts sso with keycloak-tls.
  4. Delete the Certificate and the Secret sso-tls.

The move is not tested.

What it deploys

  • recipes.keycloak (init.yml)
  • recipes.keycloak.keycloak (keycloak.yml)
  • recipes.keycloak.route (route.yml), an option

Required parameters

applications.keycloak.host, the host name Keycloak serves and its certificate names, and applications.keycloak.issuer, the name and kind of the cert-manager Issuer or ClusterIssuer that issues the certificate. Without them the compile stops with Interpolation key 'applications.keycloak.host' not found. With the option route, applications.keycloak.gateway.name and applications.keycloak.gateway.namespace name the Gateway the route attaches to, whose listener must admit routes from the target’s namespace. postgresql requires no parameter.

Include

A target includes the recipe and its options as classes and can override anything the recipe sets:

classes:
  - recipes.keycloak
  - recipes.keycloak.route   # an HTTPRoute to port 8080
parameters:
  namespace: keycloak
  kapitan:
    vars:
      target: keycloak
  applications:
    keycloak:
      host: sso.example.com
      issuer:
        name: <issuer>
        kind: ClusterIssuer
      gateway:
        name: <gateway>
        namespace: <gateway namespace>

Fetching it

The quickstart goes through these steps on a kind cluster with the uptime-kuma recipe, from installing Kapitan to the running app.

A separate fetch inventory pins the recipe by version and digest. This is fetch/targets/recipes.yml for version 1.0.1:

parameters:
  kapitan:
    dependencies:
      - type: oci
        source: ghcr.io/kadet-hub/recipes/keycloak:1.0.1@sha256:9f59c753f035de40b526cb8fd9ff8aab0f4cfd6a996750c05d5a49e6a4549b9d
        output_path: inventory/classes/recipes/keycloak

Version 1.0.1 includes postgresql 1.1.1. The consumer workflow adds the included recipes at the digests the index lists. Kapitan's --fetch reads no index, so for a local compile pull them by digest first:

tmp=$(mktemp -d)
oras pull -o "$tmp" ghcr.io/kadet-hub/recipes/postgresql@sha256:1e8465058c256cc86995dc8d6f1eb2f095df244fadcaf756935599f4d9ead6a9
mkdir -p inventory/classes/recipes/postgresql
tar -xf "$tmp/postgresql.tar" -C inventory/classes/recipes/postgresql --no-same-owner
postgresql 1.1.1
sha256:1e8465058c256cc86995dc8d6f1eb2f095df244fadcaf756935599f4d9ead6a9

The first command fetches the recipe into inventory/classes/recipes/keycloak, the second the generators and compiles:

kapitan compile --inventory-path fetch --fetch --output-path .
kapitan compile --fetch

The first command exits with status 1 because the fetch target compiles nothing. Kapitan's --fetch checks neither the digest nor the attestation. This verifies the attestation of the recipe and of the recipes it includes:

gh attestation verify \
  oci://ghcr.io/kadet-hub/recipes/keycloak@sha256:9f59c753f035de40b526cb8fd9ff8aab0f4cfd6a996750c05d5a49e6a4549b9d \
  --owner kadet-hub \
  --cert-identity https://github.com/kadet-hub/registry/.github/workflows/release.yml@refs/heads/main

gh attestation verify \
  oci://ghcr.io/kadet-hub/recipes/postgresql@sha256:1e8465058c256cc86995dc8d6f1eb2f095df244fadcaf756935599f4d9ead6a9 \
  --owner kadet-hub \
  --cert-identity https://github.com/kadet-hub/registry/.github/workflows/release.yml@refs/heads/main

The attested index must also list each digest under its recipe with the pinned version, and not as yanked. Verifying by hand shows how to read it.

Settings

Setting Inventory
Keycloak version generators.keycloak.instances.keycloak.image, tag and digest
name of the Keycloak resource, keycloak applications.keycloak.name
the Cluster and its database applications.postgresql, which postgresql’s README lists
instances, 1 generators.keycloak.instances.keycloak.instances
resources generators.keycloak.instances.keycloak.resources
an Ingress of the operator, off generators.keycloak.instances.keycloak.ingress
the Gateway listener of the route, its sectionName, unset applications.keycloak.gateway.section
any other field of the Keycloak resource generators.keycloak.instances.keycloak.spec

Keycloak serves HTTPS on port 8443 of <name>-service. The option route adds an HTTPRoute keycloak for the host to port 8080 of <name>-service. It turns on Keycloak’s HTTP listener, which the operator adds to the Service, and sets the proxy headers to xforwarded. The Gateway terminates TLS and sends plain HTTP to Keycloak, which Keycloak’s reverse proxy guide calls less secure than re-encrypting to port 8443. cloud-provider-kind, on which check proves the route, implements neither BackendTLSPolicy nor TLSRoute, so the recipe renders neither (DEC-17 in docs/specs/recipes.md). For TLS up to Keycloak, leave the option out and expose port 8443 yourself.

With xforwarded, Keycloak takes the client’s address from the X-Forwarded-For header of any request on port 8080, also of one that bypasses the Gateway. Set proxy-trusted-addresses to the addresses of the Gateway implementation’s proxies, as an entry name: proxy-trusted-addresses with value in generators.keycloak.instances.keycloak.additional_options. It has no default.

Proof

check keycloak --level deploys with tests/target.yml, on kind for each Kubernetes minor CI tests, with keycloak-operator, cert-manager, gateway-api and, through postgresql, cnpg installed first. The image has no Kubernetes objects to compare with, so the recipe is proven by deploying it (RCP-44, RCP-58). tests/target.yml adds the self-signed Issuer keycloak-selfsigned and includes the option route towards the Gateway of check. tests/smoke waits for the Cluster and the Keycloak to be ready, then gets /realms/master over TLS with the host name and the CA of keycloak-tls, a token for the temporary admin of keycloak-initial-admin, and /health/ready on the management port. Through the Gateway, with the route’s host name, it gets /realms/master and a token over HTTP, and it reads KC_PROXY_HEADERS=xforwarded from the StatefulSet. Without the option the recipe compiles to the same files as before the option existed.

Used in stacks

Versions

  • 1.0.1, : sha256:9f59c753f035de40b526cb8fd9ff8aab0f4cfd6a996750c05d5a49e6a4549b9d
  • 1.0.0, : sha256:0b176fe3b1073ce5b8f6474d762a26e61a0b0553dfaf519b1ed6c36105c2abae

The recipe's files are in kadet-hub/recipes. All recipes