Storing Keycloak secrets with the vault SPI and Kubernetes secrets

Keycloak stores SMTP passwords, LDAP bind credentials and identity provider client secrets in its database and exports unless you move them. This page explains how the file or keystore vault and mounted Kubernetes secrets keep them out of both, and what the work involves.

On this page

Storing Keycloak secrets with the vault SPI and Kubernetes secrets: why it matters

A production Keycloak usually holds several credentials that grant access to other systems: the SMTP password for password reset and notification mail, the bind credential for each LDAP or Active Directory federation provider, and the client secret for each brokered identity provider. If these are typed directly into realm settings, they are stored in the database, included in realm exports, and visible to anyone who can open the admin console with sufficient rights. Before any hardening work, inventory every place these values appear, including backups, export files kept in version control, and screenshots shared with auditors. The goal of this section is to move the secret values out of Keycloak's stored configuration so that the configuration holds only references.

Keycloak's vault SPI, described in the server administration guide, lets configuration refer to a secret by name while the value is read from an external provider when the server needs it. This topic covers the file vault and the keystore vault. On Kubernetes, the file vault pairs naturally with Secrets mounted as files into the Keycloak pod. That pairing moves the problem rather than removing it, because Kubernetes Secrets are stored unencrypted in etcd by default. Before relying on them, confirm that encryption at rest is enabled for the cluster, that list and watch access to Secrets is limited by least-privilege RBAC, and whether an external store through the Secrets Store CSI Driver fits your environment. Confirm the exact reference syntax and provider settings for your Keycloak release in the documentation before writing configuration.

Plan this work when the realm connects to a directory, a brokered identity provider or a mail relay, when realm exports leave the team that runs the server, or when an auditor will ask how credentials are protected. It also has to be designed with rotation in mind. A secret that cannot be replaced without editing the realm and risking a missed update will tend to stay in use for years. Decide now who owns each credential, how a rotated value reaches the running pod, and whether a restart or reload is needed for Keycloak to pick up the new value. Test that sequence in a non-production realm first, and record the result, because it becomes the runbook your operations team follows the next time a bind password expires.

Which Keycloak secrets belong in a vault

Keycloak stores several kinds of credentials that it must use to reach other systems: mail servers, directories and upstream identity providers. Each one is a secret that a database dump, realm export or admin console view can expose, so the inventory comes first. Confirm the list against your own realm before choosing what to move.

SMTP account credentials

Realm email settings hold the username and password that Keycloak uses to send password reset, verification and notification mail. These values are saved in the realm configuration, so they appear in the database and in realm exports unless they are moved out. Check the Email tab of each realm, including realms that were created for testing and later promoted. Note the StartTLS requirement in the 26.8 upgrade notes, since the mail account must also work with enforced encryption.

Server admin docs

LDAP and Active Directory bind credentials

User federation providers use a bind DN and password to query the directory for users and groups. A service account with broad read access is often reused across several realms, which makes its password high value. Export the realm and search for the bind credential field on every federation component. Confirm which directory account each provider uses and whether that account can write to the directory.

Server admin docs

OIDC identity provider client secrets

When Keycloak brokers login to an upstream OpenID Connect provider, the client secret that Keycloak presents at the token endpoint is stored in the identity provider configuration. Anyone who can read that configuration, or a realm export that includes it, can impersonate Keycloak to the upstream provider. List each brokered OIDC provider, record who issued its client ID and when the secret was last changed, and flag any shared between realms.

SAML identity provider signing material

SAML brokering can involve keys and certificates that Keycloak uses to sign requests or decrypt assertions, and some configurations pair them with a shared secret. These values are often pasted into the admin console during setup and then forgotten. Inventory every SAML provider, identify which entries hold private key material rather than public metadata, and decide whether each one belongs in a keystore or a mounted file instead of the database.

Social provider application secrets

Social providers such as Google, GitHub, GitLab, Microsoft, Facebook, LinkedIn, PayPal and Twitter each require an application client secret issued by the provider's developer console. These secrets often belong to a developer account rather than the owning team, so rotation depends on that person. Record the owner of each provider application, the realms that use it and the last rotation date, and remove providers that no longer have users.

Server admin docs

Secrets already in exports and backups

Moving a secret into a vault does not remove copies already made. Realm exports, database backups, support bundles and version control history can still hold the old plaintext value. Search those locations for each credential you plan to move, then rotate the credential after the move so the old copy becomes useless. Ask your team whether any export was shared outside the security boundary.

Choosing between the file vault, keystore vault and Kubernetes secrets

This table compares three places to keep Keycloak secrets such as SMTP passwords, LDAP bind credentials and identity provider client secrets. Read each row as a question to answer for your cluster, and treat the encryption and source-of-truth rows as the decision points that drive the rest.

FactorFile or keystore vault in KeycloakKubernetes Secrets mounted as filesExternal store via Secrets Store CSI Driver
Best fitSingle-node or simple deployments where secrets can be placed on the host or in a mounted volumeClusters where the platform team already manages Kubernetes Secrets and wants Keycloak to read them without extra componentsOrganizations that already run a central secret manager and need one source of truth across many systems
Who manages the source of truthThe team that writes the vault files or keystore on the host or volumeCluster administrators and whoever holds RBAC rights to create or edit Secrets in the namespaceThe security or platform team that owns the external store and its access policies
Encryption at restDepends on how the host volume or keystore file is protected, so confirm disk encryption and file permissionsSecrets are stored unencrypted in etcd by default, so confirm that encryption at rest is enabled for your clusterStored in the external store, which the team must confirm is encrypted and access logged
Access control to the secretFile permissions and host access, which must be checked on every node that runs KeycloakLeast-privilege RBAC on Secrets, including restricting list and watch access, which the Kubernetes good practices page recommendsPolicies in the external store plus the provider configuration that the CSI driver uses to fetch values
Rotation effortManual update of files and a Keycloak restart or reload, confirmed against the version in useUpdate the Secret and restart or redeploy pods so the mounted values are rereadRotation happens in the external store, but the sync and restart path must be tested
Audit trailUsually limited to host or file system logs unless added by the teamDepends on Kubernetes API audit logging being configured and retainedUsually provided by the external store, if its audit logging is enabled and kept
Extra components to runNone beyond the Keycloak deployment itselfNone beyond the cluster, though etcd backups then contain secret valuesCSI driver and a provider plugin, both of which must be upgraded and monitored
Confirm before choosingWhere the files live, who can read them and how they are restoredWhether etcd encryption at rest is on, who holds list and watch rights, and whether backups are encryptedWhich provider the platform supports, how authentication to it works and who can change its policies

How a vault secret reaches the Keycloak pod

The flow starts with a value stored in a Kubernetes Secret or an external secret store, which is then mounted as a file into the Keycloak pod. Keycloak's vault provider reads that file at runtime, and the realm configuration refers to the secret by name, so the plaintext value never needs to be written to the database or an export. Check the boundary between the cluster API and etcd, since Secrets are stored unencrypted in etcd by default unless encryption at rest is configured.

Secret values flow from cluster storage through a mounted volume into Keycloak's vault.

How vault key naming rules work in practice

Vault entries are referenced by name from realm settings, so the naming convention must be fixed before any migration starts. Once an SMTP password, an LDAP bind credential or an identity provider client secret is moved into the vault, the realm configuration holds a reference to that name rather than the value. Renaming an entry later means updating every referencing setting, which is easy to miss across several realms and clients. Decide the scheme for each secret type, for each realm, client and provider, and write it down before the first entry is created.

Choose names that describe the owner and purpose, not the current value or a person's name. A pattern such as realm, component type, component name and credential purpose keeps names stable when a mail server, directory or broker is replaced. Avoid embedding environment names or dates into the key unless each environment has its own vault, because those details tend to become wrong during promotion. Keep a register outside Keycloak that maps each vault name to the owning team, the system it authenticates to, the rotation interval and the Kubernetes secret that supplies it. Auditors and incident responders will ask for exactly that mapping.

The naming scheme also determines how rotation and audits work. During rotation, a stable name lets you replace the value in the mounted source without editing realm exports or touching unrelated components. During an audit, a consistent register shows which credentials exist, who owns them and when they last changed. Confirm the exact reference syntax, the characters allowed in names and how the vault is enabled for your Keycloak version in the server administration guide before you write the convention into your runbook, and test one reference in a non-production realm first.

Setting up the vault and mounting Kubernetes secrets

This sequence moves SMTP passwords, LDAP bind credentials and identity provider client secrets out of the Keycloak database and realm exports, and into Kubernetes Secrets that Keycloak reads through its vault at runtime.

  1. Inventory secrets and their consumers

    The Keycloak administrator lists every credential stored in realm settings: SMTP passwords, LDAP and Active Directory bind credentials, identity provider client secrets and any client secrets used by custom providers. For each one, record the realm, the component or client that uses it, and the owner who can rotate it at the source system. Confirm the vault configuration for your Keycloak version in the server administration guide before you choose a naming scheme, because the exact placeholder syntax and supported vault types are version-specific. The step is done when you have a table with one row per secret and no secret value is copied into the document.

  2. Create Kubernetes Secrets with least-privilege RBAC

    The platform team creates one Kubernetes Secret per logical credential in the Keycloak namespace, using names that match the inventory. They then create a Role that grants get access to only those named Secrets for the Keycloak service account, and bind it with a RoleBinding. Ask whether the cluster also has a Secrets Store CSI Driver or an external store in place, since the Kubernetes good practices guidance covers that option. The check is an impersonation test: the Keycloak service account can read the named Secrets, and it cannot list or watch all Secrets in the namespace.

  3. Enable encryption at rest for etcd

    The cluster administrator configures encryption at rest for Secret objects in the API server so that values are not stored in plaintext in etcd. Kubernetes stores Secrets unencrypted by default, so this step is required before you rely on Kubernetes Secrets for production credentials. Coordinate the change with whoever runs etcd backups, because existing Secrets must be rewritten after encryption is enabled, and backups taken earlier still contain plaintext. The check is to read one Secret directly from etcd or the datastore backup tooling and confirm the stored value is not readable as plaintext.

  4. Mount the secrets into the Keycloak pods

    The operator or deployment manifest mounts the named Secrets into the Keycloak pods, either as files under a fixed directory or as environment variables. File mounts are generally easier to rotate without redeploying, and they keep values out of the pod spec and process listings. Set the mount to read-only and keep the Keycloak Operator or Helm values under version control with the secret values excluded. The check is that a shell in a running Keycloak pod can read each expected file, and that kubectl describe pod shows the mount without displaying the secret contents.

  5. Configure the vault to read the mounted files

    The Keycloak administrator points the file-based vault at the mount directory and confirms the key names match the inventory. Keycloak resolves vault references at runtime, so realm components can refer to a secret name instead of its value. Start Keycloak with the vault enabled and check the startup log for vault initialization messages and any missing-key warnings. Missing or misspelled keys should fail visibly during testing, not silently in production. The check is that Keycloak starts cleanly and the vault resolves each test key to the expected value inside the pod.

  6. Replace plaintext values in realm settings

    The Keycloak administrator edits each SMTP configuration, LDAP or Active Directory user federation provider, and identity provider with a client secret, replacing the stored password with the vault reference for that secret. Make the change in a non-production realm or a copy first, and record which components were changed so the rollback path is clear. Do not paste the secret value into the admin console at any point during this step. The check is that each affected component saves with the vault reference displayed in place of the value and that no component still holds a literal credential.

  7. Verify the database and a fresh export

    The administrator performs a realm export after the changes and searches the export file for each secret value. Then they query the Keycloak database tables that hold component configuration and search for the same values. Both checks should return no matches for any credential, and should show vault references instead. Keep the search commands and their output as evidence, and do not store the matched values in the evidence file. The check is a clean search across the export and the relevant database tables, recorded with the date and the Keycloak version used.

  8. Test a login and an SMTP send

    The tester signs in through an LDAP or identity provider path that depends on a vaulted bind credential, and sends a test email from the SMTP configuration that uses a vaulted password. Both tests exercise the runtime resolution path, which the startup check does not fully prove. Run them after a pod restart so the test covers a fresh mount. The step is done when the login completes, the email arrives, and the Keycloak logs show no secret values or resolution errors. Record the results alongside the inventory so future rotations can repeat the same tests.

Rotating vault secrets without breaking sign-in

Rotating a vault-backed secret is a four-step runbook: change the credential at its source, update the value in the Kubernetes Secret or keystore that Keycloak reads, restart the pods so the mounted values load, then verify sign-in paths before retiring the old credential. The order matters. If the upstream system drops the old password before Keycloak has picked up the new one, every LDAP sync and brokered login that uses it fails at once. Keep the old credential valid at the upstream system until verification is complete, and confirm with your directory or identity provider team whether it supports two valid credentials during a transition window.

Mounted file values do not refresh inside a running Keycloak process, so plan a rolling restart of the Keycloak pods after the Secret changes. Confirm how your deployment picks up the change: the Keycloak Operator reconciles its custom resources, while a plain Deployment or Helm release needs an explicit rollout. Pick the rollout strategy with your upgrade path in mind. A restart that coincides with a Keycloak version change combines two risks, so schedule them separately, and check the Keycloak upgrading guide before bundling them. Confirm that your high availability design keeps at least one healthy node serving during the roll.

After the restart, verify each dependency explicitly. Trigger a manual LDAP or Active Directory sync from the admin console and check the result, sign in with a test account that authenticates through each brokered identity provider, and review the Keycloak logs for bind or authentication errors. Record the time of the change and the test results as rotation evidence. Only then disable or delete the old credential upstream. Client secret rotation for identity provider and application clients has its own runbook, so treat those steps separately even when they appear in the same change window.

Security and operational risks of vault-backed secrets

Moving SMTP passwords, LDAP bind credentials and client secrets out of Keycloak's database is only useful if the Kubernetes layer holding them is also controlled. The cards below cover the places secret values and references can leak after the move, and the control and evidence to confirm each one.

Unencrypted Secrets in etcd

Kubernetes stores Secret objects unencrypted in etcd by default, so a Keycloak SMTP or LDAP credential mounted from a Secret is only as protected as the etcd data itself. Confirm that encryption at rest is configured for the Secret resource on every API server, and keep the encryption configuration file and the API server manifest change record as evidence. Check that existing Secrets were rewritten after encryption was enabled, since older objects stay in plaintext until they are updated.

Secrets good practices

Broad list and watch access

Any identity that can list or watch Secrets in the Keycloak namespace can read every credential Keycloak mounts there, even if it never touches the Keycloak pod. Review RoleBindings and ClusterRoleBindings that grant get, list or watch on secrets, and confirm that Keycloak's service account has no more than it needs. Keep the output of an access review for the namespace as evidence, and rerun it after each change to operators or CI pipelines.

Secret values in pod specs and logs

Mounting a Secret as an environment variable places the value in the pod spec view and in anything that dumps the process environment. Prefer mounting Secret files and referencing them through the file or keystore vault, then check that kubectl get pod -o yaml shows secret references rather than values. Search Keycloak startup and admin event logs for the password strings in a test run, and keep the search results and the chart values that set the mount method.

Etcd backups holding secret data

An etcd snapshot contains every Secret object, so a backup file is as sensitive as the live credentials it captures. Confirm that snapshots are encrypted at rest, that access to backup storage is restricted to the people who run restores, and that retention and deletion follow your policy. Record the backup job definition, the storage access list and a successful restore test in a non-production cluster.

Realm exports that reveal secret names

A realm export can keep vault references such as ${vault.smtp-password} along with secret names, which tells an attacker where credentials live even though the values are absent. Review exports before they leave the cluster, confirm that the export does not include plaintext values, and restrict who can run realm exports from the admin console. Keep a dated sample export that you have checked, along with the review procedure used.

Unrotated secrets after a change

A secret that is updated in Kubernetes does not change the value Keycloak already loaded unless the pod is restarted or the vault reference is reloaded, so rotations can silently fail. Write a runbook that updates the Secret, restarts Keycloak in a controlled order and confirms that the SMTP and LDAP connections still succeed. Keep the change ticket, the restart record and a test result showing the new credential in use.

Questions buyers ask about Keycloak secret storage

How much effort does moving Keycloak secrets out of the database take?

The effort depends mostly on how many secrets exist and how many places reference them. Teams usually list every SMTP password, LDAP or Active Directory bind credential, and identity provider client secret, then find each one in realm settings, exports and automation scripts. The main drivers are the number of realms, the number of identity providers and user federation links, whether realm exports already sit in version control, and how many deployment pipelines must change. Ask any partner for a written scope that lists each secret, its owner and the change to each deployment, since that list sets the work.

Can our own team move Keycloak secrets without outside help?

A team that already runs Keycloak and Kubernetes can often do the change itself, especially for a small number of realms. The work involves mounting secrets into the Keycloak pods, configuring the file or keystore vault, updating the realm configuration to reference secret names, and testing each integration after the switch. Teams with limited Keycloak or Kubernetes experience, or with many realms and federated directories, tend to find the testing and rollback planning the hardest part. DeployOpen plans, implements and documents this work in the client's own infrastructure, so you can weigh that against your staff's time.

What does the work need from our platform and security teams?

Platform teams need to supply the Kubernetes secret objects, the way they are mounted into Keycloak, and the RBAC rules that limit who can read or list them. Kubernetes stores Secrets unencrypted in etcd by default, so the platform team must confirm encryption at rest is enabled or choose an external store through the Secrets Store CSI Driver. Security teams need to approve the naming convention, the access model, the audit approach and the rotation owner. Both groups should agree on which secrets are safe to change during a maintenance window and who signs off on the cutover.

How long does the migration take, and what sets that timeline?

Timing is set by the size of the inventory, the number of change windows available and how many integrations must be retested after each change. A single realm with a few secrets is a small change, while several realms with federated directories and brokered identity providers need more sequencing and testing. Other factors include the change approval process, the availability of test environments that mirror production, and whether the Keycloak upgrade is planned in the same window. No fixed duration applies to every environment, so ask for a timeline in the written scope that ties each phase to the systems it touches.

Do we need an external secret manager to do this?

No. Keycloak's file or keystore vault can hold the values, and Kubernetes Secrets can supply them to the pods, so an external secret manager is not required for the core change. An external store becomes worth considering when the organization already runs one, needs central rotation and audit across many systems, or wants Kubernetes secrets sourced from a vault through the Secrets Store CSI Driver. The choice affects cost and operations: an external store adds a system to run, back up and monitor. Confirm your organization's standards before deciding, and ask a partner to compare both paths in the scope.

How does rotating a secret affect users who are signed in?

Most users are not affected when an SMTP password or LDAP bind credential changes, because they do not sign in with those values. Client secret rotation for an identity provider or application can affect sign-in if the old value stops working before every consumer is updated, so plan a window where both old and new values are accepted, or update both sides together. Existing sessions and tokens generally continue to work, but you should verify this for your own versions and configuration during testing. Ask for a rotation runbook as part of the written scope, including a rollback step.

What should a quote for this work include?

DeployOpen does not publish a price list, so a quote follows from a written scope. Ask that the scope list each secret and its location, the Kubernetes objects and RBAC changes, the vault configuration, the test cases for each integration, the rotation runbook, the rollback plan and the documentation handed over. Confirm who performs testing, whether changes happen in staging before production, and which items are one-time versus recurring, such as scheduled rotation or retainer support. A quote without these items is hard to compare with another offer.

How DeployOpen scopes secret storage work

DeployOpen plans and implements this work inside your own Kubernetes clusters and Keycloak deployment, as a fixed-scope engagement with the scope, deliverables and timelines agreed in writing before any work starts. The scope usually starts with an inventory of where SMTP passwords, LDAP bind credentials and identity provider client secrets are currently stored, including the database, realm exports, Helm values and CI pipelines, so the agreed work matches what actually exists in your environment. The written scope should also name which Kubernetes namespaces, service accounts, RBAC roles and secret encryption settings are in play, and who on your side approves changes to them.

Each engagement should state what the deliverables are: the vault configuration and mounted secret paths, the naming convention for secret keys, the Kubernetes secret manifests or external store integration, the rotation runbook, and the evidence your security and compliance teams will ask for. Confirm with your platform team which Kubernetes version and secret store options your clusters support, and whether encryption at rest for Secrets is already enabled, because those facts change the build. A quote follows from this written scope rather than from a fixed price list, so ask for the scope items and assumptions to be listed line by line.

Once the configuration is in place, DeployOpen can test the result as part of a security assessment, checking whether secrets appear in admin exports, logs, the database or pod environment variables. Ongoing rotation support, including periodic rotation runs and updates when upstream identity providers change, can be covered by a retainer. Ask any provider, DeployOpen included, to confirm in writing which parts of the work are one-time and which recur.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.