keycloak

by sammyeby

Helm chartv1.4.2App 26.7.4Verified publisher

A Helm chart for Keycloak using SamSoft hardened Docker image (runs as UID 1001)

About this chart

Keycloak Helm Chart

A Helm chart for deploying Keycloak using SamSoft hardened Docker images.

Overview

This chart deploys Keycloak, an open-source Identity and Access Management solution, on Kubernetes. It uses SamSoft's hardened container images that run as non-root with security best practices.

Features

  • Hardened Images: Uses SamSoft's security-hardened Keycloak images
  • Non-root Execution: Runs as UID 1001 for enhanced security
  • Optimized Image Support: Automatic detection of pre-built optimized and debug images
  • PostgreSQL Integration: Bundled PostgreSQL subchart for database
  • High Availability: Support for clustered deployments with Infinispan caching
  • Metrics & Monitoring: Prometheus ServiceMonitor and metrics endpoint
  • Security: Network policies, PodDisruptionBudget, and securityContext configuration
  • Ingress: Built-in ingress support with TLS

Prerequisites

  • Kubernetes 1.23+
  • Helm 3.8+
  • PV provisioner support in the underlying infrastructure (for persistence)

Installing the Chart

From OCI Registry

helm install keycloak oci://ghcr.io/sammyeby/charts/keycloak \
  --namespace keycloak \
  --create-namespace \
  --set auth.adminPassword=your-admin-password \
  --set postgresql.auth.postgresPassword=your-postgres-password \
  --set postgresql.auth.password=your-keycloak-db-password

From Source

helm dependency update keycloak
helm install keycloak ./keycloak \
  --namespace keycloak \
  --create-namespace

Configuration

The following tables document all available configuration options in values.yaml.


Global Parameters

ParameterTypeDefaultDescription
global.imageRegistrystring""Global Docker Image registry
global.imagePullSecretsarray[]Global Docker registry secret names as an array
global.defaultStorageClassstring""Global default StorageClass for Persistent Volume(s)
global.security.allowInsecureImagesbooleanfalseAllows skipping image verification
global.compatibility.openshift.adaptSecurityContextstring"auto"Adapt the securityContext sections. Values: auto, force, disabled

Common Parameters

ParameterTypeDefaultDescription
kubeVersionstring""Override Kubernetes version reported by .Capabilities
apiVersionsarray[]Override Kubernetes API versions reported by .Capabilities
nameOverridestring""String to partially override common.names.name
fullnameOverridestring""String to fully override common.names.fullname
namespaceOverridestring""String to fully override common.names.namespace
commonLabelsobject{}Labels to add to all deployed objects
commonAnnotationsobject{}Annotations to add to all deployed objects
clusterDomainstring"cluster.local"Default Kubernetes cluster domain
extraDeployarray[]Array of extra objects to deploy with the release
diagnosticMode.enabledbooleanfalseEnable diagnostic mode (all probes disabled, command overridden)
diagnosticMode.commandarray["sleep"]Command to override all containers in diagnostic mode
diagnosticMode.argsarray["infinity"]Args to override all containers in diagnostic mode
useHelmHooksbooleantrueEnable use of Helm hooks if needed (e.g., on post-install jobs)
usePasswordFilesbooleanfalseMount credentials as files in addition to env vars (for init scripts/sidecars)

Image Parameters

ParameterTypeDefaultDescription
image.registrystring"ghcr.io"Keycloak image registry
image.repositorystring"sammyeby/keycloak"Keycloak image repository
image.tagstring"26.7.4"Keycloak image tag (immutable tags are recommended)
image.digeststring""Keycloak image digest (sha256:...). Overrides tag if set
image.pullPolicystring"IfNotPresent"Keycloak image pull policy
image.pullSecretsarray[]Keycloak image pull secrets
image.debugbooleanfalseEnable Keycloak image debug mode

Image Variants: ghcr.io/sammyeby/keycloak publishes three variants per version:

VariantTagBaseImage UIDStartupRuntime providers/SPIs
Flexible (default)26.7.4Alpine1001Auto-builds when providers changeYes
Optimized26.7.4-optimizedDistroless65532Pre-built (~5s)No — build-time only
Debug26.7.4-debugDistroless + busybox65532Pre-built (~5s)No — build-time only

The chart detects the pre-built variants from the tag — 26.7.4-optimized, 26.7.4-debug, and the floating optimized/debug tags (immutable versioned tags are still recommended). For those tags it:

  • passes start --optimized instead of start
  • keeps containerSecurityContext.readOnlyRootFilesystem at its configured value (default true)
  • skips the prepare-write-dirs init container and the writable lib overlay (distroless has no /bin/sh)
  • omits build-time env vars (KC_HTTP_RELATIVE_PATH, KC_CACHE*), which are already baked into the image

Flexible tags get the inverse: readOnlyRootFilesystem is forced to false so the Quarkus auto-build can write.

containerSecurityContext.runAsUser defaults to 1001 and works with all three variants — /opt/keycloak is world-readable and the pre-built variants never write to it. Set it (and runAsGroup/podSecurityContext.fsGroup) to 65532 if you want the pod to match the distroless image's own user.


Authentication Parameters

ParameterTypeDefaultDescription
auth.adminUserstring"user"Keycloak administrator username
auth.adminPasswordstring""Keycloak administrator password (auto-generated if empty)
auth.existingSecretstring""Existing secret containing Keycloak admin password
auth.passwordSecretKeystring""Key in existing secret for admin password
auth.annotationsobject{}Additional custom annotations for Keycloak auth secret object

Keycloak Configuration Parameters

ParameterTypeDefaultDescription
productionbooleanfalseRun Keycloak in production mode (TLS required unless using proxy)
httpRelativePathstring"/"Path relative to '/' for serving resources
proxyHeadersstring""Proxy headers configuration
configurationstring""Keycloak configuration (auto-generated if empty)
existingConfigmapstring""Name of existing ConfigMap with Keycloak configuration
trustedCertsExistingSecretstring""Name of existing Secret with trusted certificates
adminRealmstring"master"Name of the admin realm
hostnamestring""Keycloak server hostname. Falls back to ingress.hostname if empty
hostnameStrictbooleantrueReject dynamically resolved hostnames (Keycloak default)
httpEnabledbooleanfalseForce enabling HTTP endpoint
extraStartupArgsstring""Extra default startup args
initdbScriptsobject{}Dictionary of initdb scripts to run at first boot
initdbScriptsConfigMapstring""ConfigMap with initdb scripts (overrides initdbScripts)
commandarray[]Override default container command
argsarray[]Override default container args
extraEnvVarsarray[]Extra environment variables
extraEnvVarsCMstring""Name of existing ConfigMap containing extra env vars
extraEnvVarsSecretstring""Name of existing Secret containing extra env vars

TLS/SSL Parameters

ParameterTypeDefaultDescription
tls.enabledbooleanfalseEnable TLS in Keycloak
tls.usePemCertsbooleanfalseUse PEM certificates instead of PKS12/JKS stores
tls.autoGenerated.enabledbooleantrueEnable automatic TLS certificate generation
tls.autoGenerated.enginestring"helm"Certificate generation mechanism (helm or cert-manager)
tls.autoGenerated.certManager.existingIssuerstring""Name of existing Issuer (cert-manager only)
tls.autoGenerated.certManager.existingIssuerKindstring""Existing Issuer kind (cert-manager only)
tls.autoGenerated.certManager.keySizenumber2048Key size for certificates (cert-manager only)
tls.autoGenerated.certManager.keyAlgorithmstring"RSA"Key algorithm for certificates (cert-manager only)
tls.autoGenerated.certManager.durationstring"2160h"Duration for certificates (cert-manager only)
tls.autoGenerated.certManager.renewBeforestring"360h"Renewal period for certificates (cert-manager only)
tls.existingSecretstring""Name of existing Secret with TLS certificates
tls.certFilenamestring"tls.crt"Certificate filename in existing secret (PEM mode)
tls.certKeyFilenamestring"tls.key"Certificate key filename in existing secret (PEM mode)
tls.keystoreFilenamestring"keycloak.keystore.jks"Keystore filename in existing secret
tls.truststoreFilenamestring"keycloak.truststore.jks"Truststore filename in existing secret
tls.keystorePasswordstring""Password for keystore
tls.truststorePasswordstring""Password for truststore
tls.passwordsSecretstring""Name of existing Secret with keystore/truststore passwords

Cache Parameters

ParameterTypeDefaultDescription
cache.enabledbooleantrueEnable Keycloak distributed cache for Kubernetes
cache.stackstring"jdbc-ping"Cache stack to use
cache.configFilestring"cache-ispn.xml"Path to file for cache configuration
cache.useHeadlessServiceWithAppVersionbooleanfalseCreate headless service with app version for ispn
cache.javaOptsAppendExtrastring""Extra java options to append

Logging Parameters

ParameterTypeDefaultDescription
logging.outputstring"default"Log output format (default or json)
logging.levelstring"INFO"Log level (FATAL, ERROR, WARN, INFO, DEBUG, TRACE, ALL, OFF)

Container Configuration Parameters

ParameterTypeDefaultDescription
containerPorts.httpnumber8080Keycloak HTTP container port
containerPorts.httpsnumber8443Keycloak HTTPS container port
containerPorts.managementnumber9000Keycloak management container port
extraContainerPortsarray[]Extra list of additional ports for container
extraVolumesarray[]Extra list of additional volumes for pods
extraVolumeMountsarray[]Extra list of additional volumeMounts for container
initContainersarray[]Add additional init containers to pods
sidecarsarray[]Add additional sidecar containers to pods

Security Context Parameters

ParameterTypeDefaultDescription
podSecurityContext.enabledbooleantrueEnable pods' Security Context
podSecurityContext.fsGroupnumber1001Pod Security Context fsGroup
podSecurityContext.fsGroupChangePolicystring"Always"Filesystem group change policy
podSecurityContext.sysctlsarray[]Set kernel settings using sysctl interface
podSecurityContext.supplementalGroupsarray[]Set filesystem extra groups
containerSecurityContext.enabledbooleantrueEnable containers' Security Context
containerSecurityContext.runAsUsernumber1001Containers' Security Context runAsUser. Works with all variants; use 65532 to match the distroless image user on -optimized/-debug tags
containerSecurityContext.runAsGroupnumber1001Containers' Security Context runAsGroup
containerSecurityContext.runAsNonRootbooleantrueRun containers as non-root
containerSecurityContext.privilegedbooleanfalseSet container privileged
containerSecurityContext.readOnlyRootFilesystembooleantrueRead-only root filesystem. Automatically overridden to false for flexible images (kept for -optimized/-debug tags)
containerSecurityContext.allowPrivilegeEscalationbooleanfalseAllow privilege escalation
containerSecurityContext.capabilities.droparray["ALL"]List of capabilities to drop
containerSecurityContext.seccompProfile.typestring"RuntimeDefault"Set seccomp profile type
containerSecurityContext.seLinuxOptionsobject{}Set SELinux options in container

Resource Management Parameters

ParameterTypeDefaultDescription
resourcesPresetstring"small"Resource preset (none, nano, micro, small, medium, large, xlarge, 2xlarge)
resourcesobject{}Container resource requests and limits (overrides resourcesPreset)

Deploy keycloak with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has keycloak 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 chartkeycloak is pinned at v1.4.2 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