Skip to Content
IAM
Installation
IAM: External Secrets

IAM: External Secrets

The IAM chart can render ExternalSecret resources so External Secrets Operator  fills the Secrets the module already consumes. This is opt-in. With global.externalSecrets.enabled left at false, the secret-init hook creates and patches those Secrets inside the cluster. A Secret created outside the chart and named by existingSecret is also valid. ESO is the path that fills that Secret from a Secret Manager, so the value stays out of Helm values and CI variables.

The values consist of a files map from Kubernetes Secret name to the keys it should contain, one secretStore, Reloader annotations, and a rotation watcher that re-runs the realm import before restarting consumers. The shared rules for naming, client isolation, and rotation are in Secret Management.

The chart does not install the operator or Stakater Reloader, and does not create the SecretStore. It renders ExternalSecret resources as external-secrets.io/v1, so the installed operator must serve that API version. The chart only pulls values from the Secret Manager; it never writes to it, so the store identity needs read access only.

Enable

global: externalSecrets: enabled: true secretStore: name: client-a-store kind: SecretStore # chart default is ClusterSecretStore refreshInterval: "1h" nullBytePolicy: Ignore # set to "" on ESO older than 2.3 files: "{{ .Release.Name }}-oauth2-secret": data: - secretKey: client-id remoteRef: {key: acme-prod-iam-oauth2, property: client-id} - secretKey: client-secret remoteRef: {key: acme-prod-iam-oauth2, property: client-secret} - secretKey: cookie-secret remoteRef: {key: acme-prod-iam-oauth2, property: cookie-secret} - secretKey: valkey-password remoteRef: {key: acme-prod-iam-oauth2, property: valkey-password}

Each key under files is the name of a Kubernetes Secret and is rendered with tpl, so {{ .Release.Name }} works. Keys are also rendered inside the Keycloak, backend and auth-gateway subcharts, so they may reference only .Release.* and .Values.global.*; other template values can fail the render or resolve to a different name in a subchart. The chart renders one ExternalSecret per key, with creationPolicy: Orphan, so the Secret stays in the namespace when its ExternalSecret is removed. Every data item maps one Secret key (secretKey) to a Secret Manager entry (remoteRef.key) and, for JSON payloads, a property (remoteRef.property).

An entry can override secretStore and refreshInterval, and can set type if the Secret must not be Opaque. An entry’s secretStore replaces the global one completely, so it needs its own name. nullBytePolicy defaults to Ignore and applies to every data entry of every ExternalSecret. Set global.externalSecrets.nullBytePolicy to "" when the cluster runs External Secrets Operator older than 2.3, so the chart omits the field. No entry under files overrides it.

List only the Secrets that should come from the Secret Manager. secret-init does not create or patch a Secret whose name is a files key, and keeps handling every Secret that is not listed. The two writers never share a Secret. A Helm value that would feed a listed Secret can no longer take effect, so the chart refuses to render while one is set (for example keycloak.auth.adminPassword with the admin Secret listed). Those values and the matching deployment pipeline variables must be removed when a Secret is listed; the full list is under Render checks.

Secrets and Keys

The names below are the chart defaults. Consumers and the required-key check use the resolved existingSecret (or CNPG secretName) as the files key. secret-init creates <release>-oauth2-secret and <release>-appsettings-secret under those fixed names, not under existingSecret, and skips a name that is listed in files. A custom existingSecret for either Secret is not created by secret-init. List that custom name under files when ESO should sync it, or create the Secret before install.

Kubernetes SecretKeys
<release>-keycloak-admin-secret (keycloak.auth.existingSecret)admin-password
<release>-cnpg (keycloak.cnpg.cluster.secretName, keycloak.externalDatabase.existingSecret)username, password
<release>-s3-creds, only when CNPG backups are enabledaccess-key-id, access-secret-key
<release>-oauth2-secret (global.authGateway.oauth.existingSecret)client-id, client-secret, cookie-secret, valkey-password
<release>-appsettings-secret (global.backend.apiServiceAccount.existingSecret)client-secret; optionally the SMTP keys listed under SMTP settings
<release>-pat-token-exchange-secret (global.backend.patTokenExchange.existingSecret)client-secret
<release>-oidc-idp-secret (global.keycloak.oidcIdp.existingSecret)client-secret
the value of platform-api.api.storage.existingSecretusername, password

The default Secret type is Opaque, the same type secret-init creates. Set type on an entry when the Secret must be a different type. Kubernetes cannot change the type of a Secret that already exists, so the default lets ESO adopt a Secret that secret-init created earlier. Synced Secrets, and the Secrets that secret-init creates, carry the Argo CD annotations argocd.argoproj.io/compare-options: IgnoreExtraneous and argocd.argoproj.io/sync-options: Prune=false, so Argo CD automated prune does not delete them.

When CloudNativePG is enabled and both keycloak.cnpg.cluster.secretName and keycloak.externalDatabase.existingSecret are set, they must resolve to the same name. The chart refuses to render when both are non-empty and they differ, with or without ESO. Emptying either name is not covered by that check. The database Secret’s username must match keycloak.cnpg.cluster.username (default keycloak). The chart labels the database and backup Secrets with cnpg.io/reload: "true" so CloudNativePG picks up a changed password or backup key.

client-id in the oauth2 Secret must match global.authGateway.oauth.clientId. The client id is not a secret, but oauth2-proxy reads it from this Secret. cookie-secret must be 16, 24 or 32 characters long.

To take S3-compatible Platform API storage credentials from the Secret Manager, set platform-api.api.storage.existingSecret to a Secret name and list that name under files. The Platform API chart does not render ExternalSecret resources. It reads username and password from that Secret. Leaving existingSecret unset keeps passing those credentials as Helm values. Azure Blob Storage and Azure Data Lake Storage Gen2 ignore existingSecret and authenticate with Workload Identity. See Platform API Storage Configuration.

SMTP Settings

Each SMTP setting is resolved on its own: when the appsettings Secret is listed under files and its data contains the matching key, that key is used; otherwise the global.smtpServer value is used. Some SMTP settings can therefore come from the Secret Manager while the others stay in Helm values.

Secret keyglobal.smtpServer value
smtp-hosthost
smtp-portport
smtp-userauth.username
smtp-passwordauth.password
smtp-tlsstarttls
smtp-fromfrom
smtp-from-namefromDisplayName
smtp-enabledenabled
smtp-override-tooverrideTo
smtp-subject-prefixsubjectPrefix

The property names in the Secret Manager are free; remoteRef.property maps them onto the keys above. Keys that are not in the table are ignored. smtp-tls and smtp-enabled take true or false, and smtp-tls enables STARTTLS. Unset starttls defaults to false. ssl and auth.enabled are always Helm values.

In the following example, the host and password come from the Secret Manager, and the port, sender and TLS setting come from Helm values:

global: smtpServer: port: "587" from: noreply@example.com fromDisplayName: IAM starttls: true auth: enabled: true externalSecrets: enabled: true secretStore: name: client-a-store files: "{{ .Release.Name }}-appsettings-secret": data: - secretKey: client-secret remoteRef: {key: acme-prod-iam, property: client-secret} - secretKey: smtp-host remoteRef: {key: acme-prod-iam, property: SMTP_HOST} - secretKey: smtp-password remoteRef: {key: acme-prod-iam, property: SMTP_PASSWORD}

A property cannot be set in both places: the render fails when a global.smtpServer value is set and the matching key is also synced. When the appsettings Secret is listed without smtp-password, the SMTP password is taken from global.smtpServer.auth.password (empty if unset) and appears as a plain value in the pod spec; syncing smtp-password keeps the password out of Helm values. When the appsettings Secret is not listed, secret-init owns that Secret and writes auth.password into its smtp-password key; config-cli and the backend still read SMTP_PASSWORD from that key.

Moving a property between the Secret and Helm values, or changing a Helm SMTP value, renames the config-cli Job so the realm import runs again.

Rotation and Reloader

The client secrets, the SMTP settings and the Keycloak admin password reach Keycloak only through the config-cli import. When ESO is enabled and files lists a Secret that config-cli reads (Keycloak admin, appsettings, oauth2, PAT token-exchange or OIDC IdP), and global.externalSecrets.reloader is true (the default), the chart adds a <release>-secret-rotation Deployment and a suspended <release>-keycloak-config-cli-rotate CronJob.

The watcher compares the watched Secrets every 60 seconds. When ESO changes the data of a watched Secret, the watcher creates a config-cli Job from the CronJob, waits for it to complete, and only then restarts the backend, oauth2-proxy and Valkey. No kubectl step is needed. The watcher’s first start only records the current Secret data, so adding it on upgrade restarts nothing.

If the import fails, or is still running after 15 minutes, nothing is restarted. Running pods keep the values Keycloak still accepts. The watcher logs ERROR: config-cli import job/<name> failed and reports not ready until the Secret data matches the last applied state again. Check the Job logs with kubectl logs -n <namespace> job/<name>. The watcher does not retry the same data: correct the value in the Secret Manager, or delete the failed Job, to start another import. Failed Jobs are removed after 24 hours, which also starts another attempt.

With reloader: true, ESO enabled and at least one files entry, Keycloak gets reloader.stakater.com/auto: "true", so Stakater Reloader  restarts it when its database or admin Secret changes. The backend, oauth2-proxy and Valkey never get the annotation, because the watcher restarts them after the import.

Setting reloader: false removes both the watcher and the Keycloak annotation. Rotated values then follow the manual steps in What still restarts or re-imports.

Existing Installs

ESO replaces the data of an existing Secret with the remote payload. Before a Secret is listed on a running install, every key of the current Kubernetes Secret is copied into the Secret Manager unchanged:

kubectl get secret <name> -n <namespace> -o json \ | jq '.data | map_values(@base64d)'

Store that JSON as the remote secret, remove any Helm values or deployment pipeline variables that fed that Secret, then add the files entry. New values for the keys below break a running install:

  • admin-password: Keycloak keeps the master admin password in its database after first start, so the config-cli import can no longer log in.
  • database password: CloudNativePG applies it, but Keycloak keeps the old one until it restarts.
  • cookie-secret, valkey-password: oauth2-proxy sessions end.

Turning External Secrets Off

Removing a files entry or setting global.externalSecrets.enabled: false deletes the ExternalSecret on the next upgrade. Because the chart uses creationPolicy: Orphan, the Kubernetes Secret stays with the last values ESO synced, and nothing needs to be saved or re-created.

From then on secret-init handles that Secret again. It keeps the existing values and only patches a key when an explicit Helm value is set for it, such as keycloak.auth.adminPassword or a client secret other than <auto-generate>. Values rotated later in the Secret Manager no longer reach the cluster.

What Still Restarts or Re-imports

ESO updates the Kubernetes Secret. Processes that already read it into an environment variable keep the old value until they start again. With the defaults, the rotation watcher re-runs the config-cli import and then restarts the backend, oauth2-proxy and Valkey, and Reloader restarts Keycloak (see Rotation and Reloader). The manual steps below apply when reloader is false, and to the Keycloak admin password in every case.

SecretAfter the Secret Manager value changes
Any env-based credentialAutomatic with the defaults. Otherwise kubectl rollout restart the Deployment that reads it (backend, Keycloak, oauth2-proxy).
API client secret, OAuth client secret, PAT token-exchange client secret, synced SMTP settings, OIDC client secretAutomatic with the defaults: import first, then restart. With reloader: false, delete the config-cli Job, then upgrade the release so the import runs again, and restart the backend and oauth2-proxy after the import has finished, not before.
Keycloak admin passwordChange it in the Keycloak admin API or console first. The chart value is the bootstrap password and is applied only when the master-realm admin is created. Update the Secret Manager afterwards so a new cluster matches. Restarting the pod does not change an existing admin password. If the Secret Manager is updated first, the rotation import cannot log in, fails, and the watcher holds back the consumer restarts until the Keycloak password matches.
cookie-secretoauth2-proxy restarts. Existing sessions become invalid and users sign in again.
valkey-passwordValkey and oauth2-proxy restart. Sessions stored in Valkey are dropped.
Database passwordCloudNativePG applies it because the Secret is labeled cnpg.io/reload, and Keycloak restarts so KC_DB_PASSWORD matches. Do not change username after bootstrap.
Backup credentialsCloudNativePG reloads the labeled Secret. Confirm the next scheduled backup in the CNPG status before relying on it.

With reloader: false, delete the config-cli Job by label so the versioned name does not matter:

kubectl delete job -n <namespace> -l app.kubernetes.io/component=keycloak-config-cli --ignore-not-found helm upgrade iam-module <chart> -n <namespace> -f values.yaml -f eso-values.yaml

On a GitOps sync, deleting the Job is enough if the controller recreates objects that are missing.

Render Checks

The chart refuses to render when ESO is enabled and any of the following is true:

  • a files entry has no store name, neither its own secretStore.name nor global.externalSecrets.secretStore.name
  • a files entry has no data
  • a data item has no secretKey or no remoteRef.key
  • a files key renders to an empty Secret name
  • a listed Secret is one the chart reads with a fixed key set, but files.<name>.data is missing a required key: the oauth2 Secret (global.authGateway.oauth.existingSecret) needs client-id, client-secret, cookie-secret, and valkey-password; the appsettings Secret (global.backend.apiServiceAccount.existingSecret) needs client-secret; the PAT token-exchange Secret (global.backend.patTokenExchange.existingSecret) needs client-secret
  • a global.smtpServer value is set and the matching key is synced in the appsettings Secret (see SMTP settings). starttls counts as set when true, enabled when present, and the other values when non-empty.
  • a Helm value is set for a Secret that is listed under files. <auto-generate> and empty values do not count as set.
Helm valueSecret it would feed
keycloak.auth.adminPasswordkeycloak.auth.existingSecret
global.authGateway.oauth.clientSecretglobal.authGateway.oauth.existingSecret
global.backend.apiServiceAccount.clientSecretglobal.backend.apiServiceAccount.existingSecret
global.backend.patTokenExchange.clientSecretglobal.backend.patTokenExchange.existingSecret
keycloak.cnpg.cluster.backups.barmanObjectStore.username, .password<release>-s3-creds
global.keycloak.oidcIdp.clientSecretglobal.keycloak.oidcIdp.existingSecret

Independent of ESO, when CloudNativePG is enabled and both keycloak.cnpg.cluster.secretName and keycloak.externalDatabase.existingSecret are non-empty, the render also fails if those names resolve to different values.