Generating and protecting the Zitadel masterkey

The Zitadel masterkey encrypts secrets at rest, so losing or mishandling it can make stored data unreadable. This page covers generation, storage, delivery and the limits you must plan around.

On this page

Why the Zitadel masterkey decides whether your identity data stays recoverable

The Zitadel masterkey is a 32-byte key that encrypts the secrets Zitadel keeps at rest, so it sits between your database backups and the identity data inside them. If the key is lost, changed or mismatched between the components that read it, the encrypted values cannot be read, and a restored PostgreSQL database may not bring your identity service back. For a platform or security lead running self-hosted Zitadel in production, the key is a custody question as much as a configuration setting. Before the first start, your team needs a deliberate plan for how the key is generated, where it is stored and how it reaches each running Zitadel process. Confirm the exact set of data Zitadel encrypts with the key in the self-hosting overview for your version.

Three decisions shape the plan. The first is generation: produce the 32 bytes from a cryptographically secure random source and never reuse a value from a test environment or an example file. The second is storage: use a dedicated secrets manager or a Kubernetes Secret with tightly restricted read access, encryption at rest for the cluster store and an audit trail on reads, so that a database administrator cannot obtain the key alongside the data. The third is delivery: decide whether the key is passed as a mounted file or as an environment variable. File mounts generally keep the value out of process listings and shell history, but either method requires the same value on every node and replica. Confirm which delivery methods your Zitadel version accepts and how it expects a file path to be configured.

The most important property is that the masterkey cannot be rotated in place. Teams used to rotating database passwords or API keys may assume the same routine applies here, but changing the value does not re-encrypt existing data for you, so the recovery plan has to be settled before go-live and tested before an incident forces the question. Treat the key as a long-lived asset with its own backup, stored apart from the database dump, and record who is authorized to restore it. Then rehearse the full restore: database and masterkey together, into a separate environment, followed by a sign-in test. If a key ever has to change, ask Zitadel or check its documentation for the supported procedure, and do not improvise one against production data.

How to pass the masterkey: file, environment or secrets manager

A mounted file keeps the masterkey out of the process environment and out of the container image. The key sits on disk with restrictive ownership and mode, and the Zitadel process reads it at start. Exposure depends on who can read that path on the host or in the volume, and on whether backups, snapshots or configuration management copy it elsewhere.

  • Readers: Only the service account running Zitadel and root on the host can normally read a file with mode 0400 or 0600, so access control is a filesystem permission question.
  • Process listings: The key does not appear in ps output because only the file path is passed on the command line or in configuration.
  • Logs: The file contents should never be echoed by startup scripts, so confirm your init scripts and container entrypoints do not print it.
  • Operations: You must create the file, set ownership, include it in host hardening baselines, and exclude it from unencrypted backups or shared repositories.
  • Setup: Confirm the file-based configuration key names and any _FILE style variants in the official Zitadel self-hosting documentation before you rely on them.

Before going live, check that the file is readable only by the Zitadel identity, that it is absent from image layers and version control, and that your backup tooling encrypts it.

Storage options for the masterkey and when each fits

This table compares four places to keep the Zitadel masterkey: a Kubernetes secret, a file on a hardened host, an environment variable from the orchestrator, and an external secrets manager. Read each row against your environment size, access model and operator capacity, then confirm the choice against your existing tooling and licensing review.

OptionBest fitAccess control and auditBackup and operator effort
Kubernetes secretClusters already run with RBAC, encryption at rest for etcd and a GitOps or secret delivery processRBAC limits who reads the secret, but reads are often not logged unless API audit logging is enabled; confirm your cluster setupBacked up with cluster state, so the key and the encrypted database can end up in the same backup set; plan separate handling
File on a hardened hostSingle-server or small systemd deployments where one administrator owns the hostFile permissions and host access control decide who reads the key; audit depends on host logging such as file access auditingLow tooling cost, but the operator must back up the file securely and track it through every host rebuild
Environment variable from the orchestratorContainer platforms where the orchestrator injects secrets at start and the team already manages those injectionsVisible to anyone who can inspect the process or container configuration, so restrict those permissions tightlySimple to wire into Docker Compose or Helm, but values can leak through logs, inspection output or shell history
External secrets manager (OpenBao or Vault-style service)Organizations that already run a managed secrets service with HA, audit logging and access policiesCentral policies, identity-based access and audit logs are the main strengths; the service must be reviewed for access and loggingHighest operator effort, since the secrets service itself needs HA, backup and upgrades. Confirm licensing before adopting Vault Enterprise or a fork
Licensing check before choosing a secrets managerAny organization weighing HashiCorp Vault or OpenBaoHashiCorp moved future Vault releases to the Business Source License 1.1; OpenBao is an MPL-2.0 forkLegal and procurement review should confirm license terms and support obligations before the design is fixed

Generating and installing the masterkey in order

This sequence produces a 32-byte masterkey that is generated with a cryptographically secure tool, stored with restricted access, wired into the Zitadel deployment and confirmed as readable by the running service, with a documented escrow location and a tested restore path.

  1. Confirm the exact generation method

    Before generating anything, the platform team checks the official self-hosting documentation for their deployment method (binary, Docker Compose or Kubernetes) to confirm the required masterkey length, the accepted character set and the exact configuration key or environment variable that reads it. Zitadel's self-hosting overview is the starting point. Record the version being deployed, because the expected format is set by the release in use. The step is done when the team has a written note of the required length and the variable or file path, approved by the person who owns the deployment.

  2. Generate the key with a secure tool

    An engineer generates the value on a trusted workstation or inside the secrets platform using a cryptographically secure random source, such as the operating system's random generator through a standard tool. The value should be produced once, never typed by hand, and never generated in a web form or shared chat. Use the generation command given in the official docs for your method, and avoid tools that derive the value from a predictable input. The step is done when the value exists only in the intended store and the generator's output has been handled without being logged to a shell history or terminal transcript.

  3. Check the key length and format

    The engineer measures the generated value and confirms it matches the length the official documentation specifies for the masterkey, which is 32 bytes for Zitadel, and that it contains the characters the release accepts. A wrong length is the most common reason a configuration fails at startup, so the check should run before the value is wired anywhere. Record the check result in the change ticket without recording the key itself. The step is done when the length check passes and a second reviewer has confirmed the method used.

  4. Store the key with restricted access

    The platform team places the masterkey in the chosen location: a secrets manager, such as an external vault the organization already operates, or a Kubernetes Secret protected by role-based access control and, where available, encryption at rest for etcd. Access is limited to the identities that run Zitadel and to a small named group of administrators. Audit logging should be enabled on the store if the platform offers it. The step is done when a read attempt from an unauthorized identity is denied and the access list is written down.

  5. Wire the key into the deployment

    The engineer passes the key to Zitadel either as a file mounted into the container or service, or as an environment value, following the method in the official docs. A file mount keeps the value out of process listings and container inspection output, so it is usually the stronger option when the platform supports it, but confirm this for the deployment method in use. The configuration must reference the key by path or variable name only, and the rendered manifest or unit file must not contain the value in plain text. The step is done when the deployment definition is committed without the key and the runtime reference points to the stored secret.

  6. Confirm the service reads the key

    The engineer starts or restarts Zitadel and checks the startup logs for a clean run of the setup and start phases, with no error about the masterkey length, format or missing value. For a file mount, the engineer confirms the file exists at the expected path with the expected permissions, and for an environment value, confirms the variable is set in the running process without printing it. The step is done when the service starts, the health endpoint responds and the logs show no masterkey errors.

  7. Scan for copies outside the store

    The team searches the infrastructure-as-code repository, Helm values, CI variables, shared drives, tickets and chat history for any copy of the value or of a file that contains it. Any copy found is removed and the owner is told. Build logs and backup jobs should also be checked for accidental output. The step is done when the search returns no copies outside the approved store and the result is recorded with the date and the name of the reviewer.

  8. Record escrow and test the restore path

    The organization records where the escrowed copy lives, who can retrieve it under which approval, and how it is kept separate from the database backups it protects, because a database backup alone cannot decrypt the secrets inside it without the masterkey. The team then rehearses a restore in a non-production environment: it restores the database and the masterkey from their stores, starts Zitadel and confirms that an encrypted value can be read. Because the key cannot be rotated in place, the escrow record and the restore test are the controls that protect against loss. The step is done when the restore test passes and the escrow location is recorded in the runbook.

Protecting the masterkey after it is deployed

The masterkey is only as protected as the places it lives and the people and workloads that can read it. The controls below cover who can read it, where it must never appear, how a recovery copy is held, how reads are recorded, and how it stays apart from database backups.

Restrict read access to two groups

Limit read access to the masterkey to the operators who perform setup and the runtime identity that starts Zitadel, and nobody else. In Kubernetes, that means RBAC rules on the Secret, and on a Linux host, file ownership and mode on the key file so that only the service account can read it. Review these grants whenever the team changes, and confirm that CI pipelines and broad cluster roles cannot read the Secret by default.

Keep the key out of images and logs

Never bake the masterkey into a container image, a Helm values file committed to Git, or a Compose file checked into a repository. Also check that startup output, debug logs and CI job logs do not echo environment variables or command arguments that contain the key. Scan images and repositories for the key value as part of routine checks, since a single leaked copy is enough to decrypt the secrets Zitadel protects at rest.

Escrow a sealed copy under dual control

Because the masterkey cannot be rotated in place, losing it means losing access to the encrypted data. Store a second copy in a sealed envelope or an encrypted vault, held under dual control so that no single person can open it or retrieve it alone. Record who holds each part, when the copy was last verified, and the steps for restoring it into a rebuilt environment. Ask your secrets platform team to confirm where this escrow will live and who approves its use.

Audit reads through the secrets platform

If the masterkey is held in a secrets manager such as OpenBao or Vault, enable audit logging on that platform so every read of the key path is recorded with the requesting identity and time. Forward those audit records to a log store that operators cannot silently edit. Alert on reads from unexpected identities, and confirm during setup that the audit device is active before Zitadel is first started, since reads made before logging is enabled cannot be reconstructed.

Separate the key from database backups

Database backups contain Zitadel's encrypted secrets, so a backup that also contains the masterkey gives an attacker everything needed to decrypt them. Store backups and the masterkey in different systems with different access paths and retention rules. Test restores using the key from its separate store, not from a copy bundled with the dump. Confirm with your backup owner who can access each store, and document the restore procedure so it can be run without the person who first set up the system.

Why the masterkey cannot be rotated in place

Changing the masterkey is not a simple in-place rotation. Zitadel uses the 32-byte masterkey to encrypt secrets that it stores in PostgreSQL, such as signing keys and other sensitive values. Those stored values were encrypted with the existing key, so swapping the key in the configuration changes how Zitadel must read them. A replacement key that does not match the one used to write the data leaves those values unreadable, and the instance can fail to start or fail when it touches the affected records. Treat the masterkey as fixed for the life of the installation and make the first choice carefully.

Because the key is tied to data already in the database, any change needs a planned migration or re-encryption approach rather than a file edit followed by a restart. Before you consider a change, confirm the supported procedure with Zitadel for your release, including whether it re-encrypts stored values, how it is run against the database, and what it requires for the running API and login services. Ask for this in writing from Zitadel or through your support channel, and do not assume that a generic secrets rotation approach from another product applies. Zitadel's self-hosting documentation at Zitadel self-hosting overview is the starting point for the deployment side of this question.

In practice, the decision that protects you is made at setup. Store the key in a secrets manager or a Kubernetes secret that your backup and recovery process already covers, and record where it is kept, who can read it, and which environments hold a copy. Before any change window, take a verified database backup that matches the key in use, test restoration in a non-production environment, and confirm that the restored instance starts with the same key. A key that is lost or changed without a tested path can make the stored secrets permanently inaccessible, so the recovery plan should be rehearsed before the first production change is ever needed.

How the masterkey flows from generation to runtime and backup

The diagram starts with the operator generating a 32-byte key and placing it in a secrets store or Kubernetes secret, then shows the deployment passing it to the Zitadel runtime by file or environment. Zitadel uses the key to read encrypted secrets held in PostgreSQL. A separate escrow copy sits outside the database backup path. Check that the store, runtime and database sit in separate trust zones, and that the escrow copy is reachable by recovery staff but not by the database backup job.

Masterkey hand-offs across the secrets store, runtime, database and escrow.

Limits to confirm in your environment before go-live

The masterkey decisions in this topic depend on details that change between Zitadel releases, cluster versions and secrets tooling. The cards below list the items to confirm in writing before go-live, and each one should be checked against the Zitadel release you deploy, including v4.19.5 if that is the version your team is targeting.

Exact configuration key and input method

Confirm the precise configuration key that carries the masterkey and which input methods the Zitadel version in use accepts, such as a file path or an environment variable. Check the exact key name against your release notes rather than relying on older blog posts or Helm values from a previous chart. Record the chosen method in your runbook, because a misspelled key can silently fall back to a default or fail at startup in a way that is hard to diagnose. Confirm the key name for your exact version before writing any manifest.

Zitadel releases

Secrets integration against cluster version

If you plan to deliver the masterkey through an external secrets operator, a CSI driver or a vault-backed sync, confirm that the integration supports your Kubernetes cluster version and its admission and volume model. Check which API versions the operator uses, whether it supports the mount style your workload needs, and how it behaves during node drains. Ask the vendor or project for its tested cluster version range and treat anything outside it as unsupported until proven in a staging cluster.

Procedure for any future key change

Establish in advance what happens if the masterkey must change, for example after a suspected exposure. Because the key cannot be rotated in place, the procedure needs a documented path for re-encrypting or migrating data, a window for the change, and the people who approve it. Ask Zitadel support or your release notes whether a supported key change path exists for your version, and do not assume that replacing the secret value in your store is enough.

Restore behavior with the escrowed key

Test how a backup restore behaves when the masterkey comes from escrow or a secrets manager. A restored database that encrypts secrets with one key will not be readable with a different key, so confirm that the escrowed copy matches the key used when each backup was taken. Include the key version in backup records and run a restore into a separate environment at least once before go-live, so that recovery does not depend on an undocumented step.

Release notes and changed behavior

Review the release notes for each Zitadel version you plan to run, including the version your team is targeting, for any change to how the masterkey is read, validated, generated or stored. Pay attention to changes in defaults, deprecated keys and startup checks. Set a rule that every upgrade ticket must include a masterkey review before the binary or chart version changes, and record the release notes you reviewed.

Release notes

Questions teams ask before handling the Zitadel masterkey

What does it cost to set up the Zitadel masterkey?

The Zitadel software has no license fee for self-hosting, so the cost of a masterkey setup is labor and the infrastructure around it. Paid work covers generating the 32-byte key, choosing where it is stored, wiring it into your deployment method and testing a restore. Most of these steps are one-time, while staff time for access reviews and any secrets platform fees you already pay recur. Costs rise when several environments need separate keys, when no secrets platform exists yet, or when auditors ask for documented procedures. For the Enterprise plan, Zitadel lists custom pricing, so request that quote from Zitadel separately. Ask any implementation partner for a fixed-scope quote that names each deliverable and the restore test.

How long does a secure masterkey setup take?

The duration depends on the scope you agree, and no published timeline exists for this step alone, so confirm it in a scoping conversation. The main drivers are how many environments need their own key, whether your secrets platform is already running and approved for this use, and how your deployment is built. Kubernetes, Docker Compose and binaries each pass the key differently. Access approvals and change-control windows often take longer than the technical steps. A restore test needs a non-production instance and a quiet window, and it should be repeated after significant changes. Ask for a written plan with dependencies listed, so approvals start before the build begins.

What must our team provide for a masterkey setup?

Your team needs to provide three things. First, access to the secrets platform or Kubernetes namespace where the key will live, with permissions limited to the people and services that need it. Second, a named deployment owner who decides on storage, backup locations and the runbook, and who signs off on the final design. Third, a recovery test window in a non-production environment, where the team restores a backup and confirms Zitadel starts with the stored key. Without these inputs, the work stalls at approvals or leaves the key in a location only one person can reach. Ask the partner to list each input in the written scope so gaps show up early.

Can our internal team set up the masterkey alone?

Yes, an internal team can do it alone if it already runs Zitadel and has a working secrets practice. The generation step is simple, but the value sits in decisions about storage, access and recovery, and in proving that the restore works. Teams new to Zitadel should read the Zitadel self-hosting overview first, since the deployment method changes how the key reaches the process. A partner makes sense when the team lacks time, needs an outside review of the design, or must produce evidence for an assessment. Whichever path you choose, document the owner, storage location, backup copies and restore steps before go-live.

What happens if the Zitadel masterkey is lost?

If the masterkey is lost, Zitadel cannot decrypt the secrets it protects at rest, so the instance cannot be recovered from database backups alone. Recovery depends on having a separate, protected copy of the same 32-byte key. Store that copy in a controlled location apart from the database backups, and log access to it. Because the key cannot be rotated in place, generating a new key on the existing instance does not repair the situation. Confirm the supported recovery path with Zitadel before go-live, and test a restore with the stored key so the team knows the process works before it is needed.

Can we change the Zitadel masterkey later without downtime?

No, the key cannot be rotated in place, so plan for it to stay the same for the life of the instance. Treat the first generation as a permanent decision and settle the storage location, access model and backup copies before the key enters production. If you suspect exposure, the response is a planned project, not a configuration change. The supported path must be confirmed with Zitadel and tested on a copy of your data before you need it. Ask Zitadel or your partner how that path would work in your deployment, how much downtime it would require and which data it touches. Keep records of where each copy is stored so any future change can be planned in advance.

Should the masterkey live in a secrets manager or a Kubernetes secret?

Both options work, and the choice depends on what your team can operate and audit. A Kubernetes secret is simpler to start with, but its protection depends on cluster role-based access control and the cluster's own controls. A secrets manager such as OpenBao, an open-source option under MPL-2.0, adds central access policies, audit logging and a separate lifecycle. It also adds a dependency, and you must decide how Zitadel receives its key during startup. Whichever you choose, restrict who can read the secret, log access, keep the key out of container images and shell history, and document the chosen path in the runbook.

What evidence will auditors expect for the masterkey?

Auditors typically ask how the key is generated, who can access it, where each copy is stored and how recovery has been tested. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports or certifications. Independent auditors and certification bodies make those determinations. Useful evidence includes the written storage and access design, the list of people and services with access, access logs, backup records, restore test results and change records for the deployment. Ask your assessor which artifacts they expect before the design is finalized, so the evidence is produced during the work rather than reconstructed afterward.

How DeployOpen scopes and delivers masterkey handling

DeployOpen plans and implements self-hosted Zitadel inside your own infrastructure, and the masterkey handling is scoped in writing before any work starts. The scope names where the 32-byte masterkey will be generated, where it will be stored, how each Zitadel component receives it, and who holds each responsibility. Because the key cannot be rotated in place, these decisions are made once and documented as a baseline. Your security team reviews that baseline before installation, so the choices about secrets manager, Kubernetes secret or file-based delivery are made deliberately rather than by default during setup.

The written deliverable is a storage, delivery and recovery procedure for your security team. It covers how the key is created and who may read it, how the chosen delivery method is configured for the setup and start phases, how access is logged in your environment, and how the key is backed up in a separate, access-controlled location. It also covers what happens if a copy is lost or exposed, including the recovery steps and the dependency on the database contents that the key protects. Each step is written so that your team can verify it independently after handover.

Before the engagement begins, confirm the scope items that depend on your environment: your secrets manager product and its licensing, your Kubernetes or host access model, your backup vault and key custody rules, and the Zitadel version you plan to run. DeployOpen does not issue audit reports or certifications, so the procedure is prepared as evidence for your own assessors. Ask for the scope, deliverables and handover schedule in writing so that ownership of the key, the backups and the runbook is clear before the first production deployment.

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.