Encrypting and rotating the Metabase encryption key

Metabase can encrypt stored database connection details with a key you supply. This page explains how to enable it on an existing instance, rotate or retire the key, back it up and recognize the startup errors that signal tampering.

On this page

Why a self-hosted Metabase needs an encryption key for stored connection details

A self-hosted Metabase stores the credentials it uses to query your warehouses in its application database, so anyone who can read that database could read those credentials. The MB_ENCRYPTION_SECRET_KEY setting gives Metabase a secret it uses to encrypt those stored database connection details at rest. Treat the key as a sensitive secret in its own right: if it is lost, the encrypted connection details cannot be recovered, and if it is exposed alongside the application database, the encryption adds little protection. Decide where the key will live, who can read it and how it will be backed up before you turn encryption on.

Teams should enable the key at the start on a new instance, or plan a deliberate change on an existing one. On an existing instance, enabling encryption is a one-time step: you run the enable-encryption command so Metabase encrypts the data already stored, and it will not start with the key set while the application database is still unencrypted. That ordering means the change needs a maintenance window, a tested backup of the application database taken before you start, and a confirmed rollback path. Confirm with your Metabase version and deployment method which steps apply to your environment before you schedule the work.

Key rotation is a separate task that runs later, using the current key to re-encrypt the stored data under a new one. Your first decision is therefore operational rather than cryptographic: record which key protects which backup, so a restore never requires a key you no longer hold. The official documentation on encrypting database connection details at rest sets out the commands and their prerequisites, and it is the source to follow for the exact sequence in your release.

How to enable encryption on an existing Metabase instance

This sequence turns on encryption for database connection details in an existing self-hosted Metabase, so the stored credentials are protected by a key you hold. It also confirms that the application database was encrypted with that key before the instance is treated as ready.

  1. Back up the application database first

    The platform team takes a full backup of the Metabase application database before changing anything, and stores it somewhere the running instance cannot overwrite. Encryption rewrites stored database connection details, so this backup is the rollback path if the change goes wrong. The step is done when the backup file or snapshot exists, has a recorded checksum or identifier, and a restore has been rehearsed on a separate host or in a test database. Confirm the backup method for your chosen application database engine with the Metabase configuring application database documentation before you start.

  2. Generate and store the encryption key

    Create a new random secret for MB_ENCRYPTION_SECRET_KEY using a cryptographically secure generator, and place it in your secrets manager or a protected host file that only the Metabase service account can read. Do not put the value in a shell history, a ticket, a container image layer or a source repository. The step is done when the key is stored in the approved location, access is limited to the people and services who need it, and a second copy is recorded in your key custody process. Losing this key means encrypted connection details cannot be read, so confirm your recovery procedure before continuing.

  3. Set the key on the instance without restarting

    Add MB_ENCRYPTION_SECRET_KEY to the environment of the Metabase process, using the same value you stored in the previous step. Do not start the application with the key set against an unencrypted application database, because Metabase will refuse to start in that state. The step is done when the variable is visible in the service definition or container configuration and the change is recorded in your configuration management system. Keep the instance stopped or on the previous configuration until the next step is complete.

  4. Run the enable-encryption command once

    Run the enable-encryption command against the existing application database, using the same Metabase version and JAR that the instance uses, with the key available to the command. This encrypts data that is already stored, and it should be run exactly once for the instance. Run it from a controlled administrator session and capture the output to your change record. The step is done when the command reports success, and you have confirmed the exact command syntax for your release in the Metabase encryption documentation. If the command fails, do not retry with a different key.

  5. Restart Metabase and check startup

    Restart the Metabase service so it loads the key and the encrypted application database together. A clean start means the instance reaches its normal listening state and the logs show no errors about the encryption key. If the instance refuses to start with the key set, the most likely cause is that the application database was not encrypted with that key, so return to the enable-encryption step and confirm it completed. The step is done when the health endpoint responds and the logs are clean for the first startup.

  6. Verify connections and sign-in

    An administrator signs in and opens an existing database connection in the admin settings, then runs a simple query or sync to confirm that the stored connection details decrypt correctly. Check that scheduled sync and any alerting tied to database connections still work. The step is done when at least one connection to each important data source succeeds and the operator has recorded the test results. Include a check that the connection details in the admin panel are not shown in plain text in the logs or support exports.

  7. Recheck startup errors and document the key

    Review the first several hours of logs for errors that mention the encryption key, a decryption failure or an integrity problem. Those messages can point to a mismatched key, a restored database from before encryption, or a tampering event, so treat them as a stop condition and investigate with the database backup in hand. Once the logs are clean, update the runbook with the key location, the custodian and the date of enablement. The step is done when the runbook is updated and the incident contact has been informed that the key is now required for startup.

Key lifecycle options and when each fits

This table compares the three key lifecycle actions for MB_ENCRYPTION_SECRET_KEY: enabling encryption on an existing instance, rotating to a new key, and disabling encryption by rotating to an empty string. Read each row for the trigger, the prerequisite that must hold before you run the command, and the main risk to plan for. The main takeaway is that enabling and rotating both depend on the current key state being exactly what Metabase expects, so confirm that before any change.

OptionTypical triggerPrerequisiteMain risk
Enable encryption (enable-encryption)Existing instance that has never encrypted stored database connection details, now being brought under the controlKey set in the environment, a verified application database backup, and a maintenance window agreed with usersMetabase will not start while the key is set but the application database is not encrypted with it, so a failed or partial run blocks startup
Rotate key (rotate-encryption-key)Suspected exposure of the key, a staff change among people who could read it, or a scheduled key policy in your organizationThe current key is still set in the environment and the new key is generated and stored in your secrets managerLosing the new key or running the command without the current key set can leave encrypted data unreadable
Disable encryption (rotate to empty string)Retiring the control, for example when moving to a platform that handles encryption at another layerCurrent key set, a verified backup taken first, and confirmation from your security owner that the decision is recordedStored connection details become unencrypted at rest, and a backup taken before the change may still hold the older encrypted form
Keep current key unchangedRoutine operation with no exposure, staff change or policy triggerKey stored only in a managed secret store with access loggedDrift over time if no one reviews who can read the key or where it is copied

How rotating the key works and what to schedule around it

Rotation replaces the active encryption key with a new one, and it can only run while the current key is still set. Metabase performs it with the rotate-encryption-key command, and the sequence is the part to plan. The new key must be stored in your secrets manager before the change starts, because the instance will need the new value at its next start and the old value will no longer be the one protecting the data once the rotation completes. Record which key value is live, where the replacement lives, and who can read both. If the new key is lost after rotation, the encrypted connection details in the application database cannot be recovered, so treat the new value with the same custody rules as the original.

A practical rotation window follows a fixed order. First, confirm the current instance starts with the existing key and that MB_ENCRYPTION_SECRET_KEY is set correctly in the deployment. Second, take a backup of the application database and confirm it can be restored, since the migration-style changes made during this work are only reversible from that backup. Third, run the rotation against the backed-up database while the current key is still in place, then update the environment variable to the new key and restart. Fourth, confirm that the instance starts and that a database connection still runs a query. Keep the old backup until the new key has been verified in normal use. Ask your Metabase contact or check the Metabase docs on encrypting database connections for the exact command arguments and the behavior when the process is interrupted, because those details decide whether a partial run needs a restore.

Before you schedule the window, confirm three things in writing with whoever operates the platform: how long a restart takes on your deployment, whether the instance is a single node or a cluster that must be reduced first, and who is authorized to approve a restore if the new key fails at startup. Do not estimate downtime from another environment. Measure it on a staging copy restored from a recent backup, which also tests the backup itself. Plan a rollback path that reuses the old key and the pre-rotation backup, and write down the exact condition that triggers it, such as a startup refusal or failed connection checks after restart.

How the key, the application database and the backup fit together

The flow starts with the operator storing MB_ENCRYPTION_SECRET_KEY in a secrets manager outside the application host. Metabase reads that key at startup and uses it to decrypt the connection details it holds in the application database. Before running enable-encryption or rotate-encryption-key, take a backup of the application database, because the encrypted values depend on the key that was in effect when they were written. Check that the key and the backup are stored separately.

Key, application database and pre-change backup, with the secrets store kept outside the application host.

Startup errors that signal a key mismatch or tampering

Metabase checks the encryption key against the data it protects when it starts. When the key, the stored data and the backup do not line up, the instance can refuse to start or fail to read connection details. The cards below cover the common causes and the first check for each, so you can separate a configuration mistake from a real integrity problem.

Key set on an unencrypted database

This usually happens when MB_ENCRYPTION_SECRET_KEY was added to the environment of an existing instance without running enable-encryption first. Existing database connection details are still stored in plain text, so Metabase will not start against them while the key is set. The first check is whether the enable-encryption step was ever run against this application database. Confirm the exact startup message against your Metabase version before changing anything, and do not remove the key until you know which state the data is in.

Encryption docs

Key changed without rotation

If the key value in your secrets store or deployment file was replaced, the stored data is still encrypted with the old value. Metabase cannot decrypt it with the new key, so startup or connection tests fail. The first check is to compare the key your running instance receives with the key recorded when encryption was last set or rotated. Restore the previous value if you have it, then use rotate-encryption-key while the current key is still set, rather than swapping values directly.

Backup restored under a different key

A backup of the application database carries data encrypted with the key that was active when it was taken. Restoring it into an environment with a newer or different key produces the same decryption failures as a changed key, often on a restore test or a disaster recovery drill. The first check is to find the key version active at the backup date and confirm the restore environment uses that value. Keep key values in a store that is backed up separately from the database, so both can be restored together.

Empty or truncated key value

A key pasted with a trailing newline, cut off by a line-length limit, or set to an empty string can look present to an operator but is not the key the data was encrypted with. An empty value also disables encryption, so an instance that starts without errors may have silently stopped protecting stored connection details. The first check is the length and presence of the variable inside the running container or service, not in the deployment template. Compare it against your recorded value byte for byte.

Unexpected decryption failures after a change

When errors appear after a deployment that changed nothing about the key, look for another process writing to the application database or a second instance pointing at it with a different key. Two instances sharing one database with different keys will each fail to read data the other wrote. The first check is the list of running Metabase instances and their environment values. Treat unexplained failures as a possible tampering or misconfiguration signal, and review database access logs for unexpected writers.

Questions teams ask before enabling or rotating the encryption key

Can our own team enable and rotate the Metabase encryption key?

Yes, if your team can run Metabase's command line tools against the instance and has a tested backup of the application database. Enabling encryption on an existing instance is a one-time step using the enable-encryption command, and rotation uses rotate-encryption-key while the current key is still set. The work itself is short. What takes care is the surrounding process: confirming the backup restores, agreeing who holds the key, and recording the change. Teams without a staff member who owns the application database and the secrets store often hand the planning to a partner, and that is where DeployOpen's planning and implementation work fits.

What drives the effort and cost of an outside partner for this work?

The main drivers are how many Metabase instances you run, how many environments (development, staging, production) must be handled, where the application database lives, and how your secrets tooling is set up. Each cost component is a different party's time: planning and the written scope, the rehearsal in a non-production copy, the production change window, and the handover documentation. Most engagements are fixed-scope, so ask for a quote that lists each instance and environment separately, what is one-time, and whether any retest or runbook update is included. DeployOpen does not publish prices; a quote follows from the written scope.

How long does enabling or rotating the key take across several instances and environments?

No duration is supplied for this work, so confirm the timeline against your own environment rather than assuming one. Timing generally scales with the number of instances, the size of each application database, how many environments must be rehearsed before production, and how quickly backups and restore tests can be completed. Ask any partner for a timeline that separates planning, rehearsal, the production window and documentation. Ask your own team to confirm the change window they can actually schedule.

What must we provide before the key work starts?

Plan to provide administrative access to each Metabase instance and its host, read access to the application database configuration, and a current, restorable backup of the application database. You will also need a secrets tool or vault where the key value is stored, with named owners and access rules, and a change window approved by your operations team. Confirm that the Metabase version on each instance is the one you expect, because the backup and rollback path depends on it.

What happens if we lose the encryption key?

Encrypted data in the application database cannot be read without the key, so a lost key can leave stored connection details unusable. Treat the key as a recovery-critical secret: keep it in your secrets store with at least one controlled, audited copy, and record which instance it belongs to. Before any change, take a backup of the application database and confirm you can restore it. Confirm with Metabase's encryption documentation how recovery is handled for your version, and do not rely on a partner or a single administrator to hold the only copy.

Can we rotate the key without downtime?

Rotation can usually be scheduled as a planned change, but whether users notice a pause depends on your deployment, load balancer and how the instance restarts after the new value is set. Confirm the restart behavior in a rehearsal on a copy of production before choosing a window. Also note that Metabase will not start if the key is set but the application database is not encrypted with it, so the sequence of steps matters more than the command itself. Schedule rotation during a low-use period and keep the rollback path ready.

What startup errors suggest the encrypted data was tampered with or the wrong key is set?

If Metabase refuses to start after a key change, check first that the value matches the key used for the last successful encryption step, and that the application database has been encrypted with it. A mismatch between the key and the stored data is the usual cause of a failed start. Treat any unexpected key error as a reason to stop, compare the key against your secrets record, and restore from the pre-change backup if the cause is not clear. Your engineers should confirm the exact messages their version prints against the encryption documentation.

How DeployOpen scopes and delivers encryption key work for Metabase

DeployOpen plans, implements and documents MB_ENCRYPTION_SECRET_KEY work on self-hosted Metabase inside your own infrastructure, from the first enable-encryption run to a tested rotation and backup. Each step is agreed in writing before work starts, so your security and operations teams know exactly what changes and what evidence they receive.

How we scope

  • Inventory the Metabase version, application database type and whether data is already encrypted.
  • Confirm who holds key material, where it is stored and how it is backed up.
  • Agree in writing whether the work covers enabling encryption, rotation, or both, as a fixed-scope engagement.

How we build

  • Run enable-encryption against a restored copy of the application database before touching production.
  • Stage the key in your secrets store and set MB_ENCRYPTION_SECRET_KEY through your deployment tooling.
  • Test a rotation with rotate-encryption-key in a non-production environment and confirm the instance starts cleanly.

How we hand over

  • Deliver a runbook covering enable, rotate, disable and key backup steps with the exact commands used.
  • Document the startup errors that signal a mismatched or missing key and the response to each.
  • Walk your operations team through a supervised rotation so they can repeat it without us.

How we support

  • Offer ongoing support and upgrade planning as a retainer, so key handling stays aligned with each Metabase release.
  • Retest key handling after upgrades, restores or infrastructure changes when the retainer covers it.
  • Ask your DeployOpen contact to confirm retainer terms and response expectations in the written quote.

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.