Configure database encryption

Grafana encrypts these secrets before they are written to the database, by using a symmetric-key encryption algorithm called Advanced Encryption Standard (AES), and using a secret key that you can change when you configure a new Grafana instance.

Since Grafana v9.0, it uses by default, which adds a layer of indirection to the encryption process that represents an implicit breaking change for older versions of Grafana.

For further details about how to operate a Grafana instance with envelope encryption, see the section below.

Envelope encryption

Note: Since Grafana v9.0, you can turn it off by adding the term to the list of feature toggles in your .

Instead of encrypting all secrets with a single key, Grafana uses a set of keys called data encryption keys (DEKs) to encrypt them. These data encryption keys are themselves encrypted with a single key encryption key (KEK), configured through the secret_key attribute in your Grafana configuration or with a .

As stated above, envelope encryption represents an implicit breaking change because it changes the way secrets stored in the Grafana database are encrypted. That means Grafana administrators will be able to transition to Grafana v9.0 with no action required from the database encryption perspective, but will need to be extremely careful if they need to roll back to a previous version (e.g. Grafana v8.5) after being updated, because secrets created or modified after upgrade the update to Grafana v9.0 won’t be decryptable in previous versions.

Fortunately though, envelope encryption was added in Grafana v8.3 behind a feature toggle. So, in case of emergency, Grafana administrators will be able to downgrade up to Grafana v8.3 and enable envelope encryption as a workaround.

Operational work

From the database encryption perspective, there are several operations that Grafana administrator may want to perform:

  • Re-encrypt secrets: re-encrypt secrets with envelope encryption and a fresh data key.
  • : decrypt secrets encrypted with envelope encryption and re-encrypt them with legacy encryption.
  • Rotate data keys: disable active data keys and stop using them for encryption in favor of a fresh one.

Find more details about each of those below.

Re-encrypt secrets

Secrets re-encryption can be performed when a Grafana administrator wants to either:

  • Move forward already existing secrets’ encryption from legacy to envelope encryption.
  • Re-encrypt secrets after a data keys rotation.

Note: This operation is available through Grafana CLI by running grafana-cli admin secrets-migration re-encrypt command and through Grafana . It’s safe to run more than once. Recommended to run under maintenance mode.

Used to roll back secrets encrypted with envelope encryption to legacy encryption. It can be used to downgrade to a Grafana version earlier than Grafana v9.0 after an unsuccessful upgrade.

Re-encrypt data keys

Used to re-encrypt data keys encrypted with a specific key encryption key (KEK). It can be used to either re-encrypt existing data keys with a new key encryption key version (see KMS integration rotation) or to re-encrypt them with a completely different key encryption key.

Note: This operation is available through Grafana CLI by running grafana-cli admin secrets-migration re-encrypt-data-keys command and through Grafana . It’s safe to run more than once. Recommended to run under maintenance mode.

New data keys for encryption operations are generated on-demand.

Encrypting your database with a key from a Key Management System (KMS)

If you are using Grafana Enterprise, you can integrate with a key management system (KMS) provider, and change Grafana’s cryptographic mode of operation from AES-CFB to AES-GCM.

You can choose to encrypt secrets stored in the Grafana database using a key from a KMS, which is a secure central storage location that is designed to help you to create and manage cryptographic keys and control their use across many services. When you integrate with a KMS, Grafana does not directly store your encryption key. Instead, Grafana stores KMS credentials and the identifier of the key, which Grafana uses to encrypt the database.

Grafana integrates with the following key management systems:

Grafana encrypts secrets using Advanced Encryption Standard in Cipher FeedBack mode (AES-CFB). You might prefer to use AES in Galois/Counter Mode (AES-GCM) instead, to meet your company’s security requirements or in order to maintain consistency with other services.

To change your encryption mode, update the value in the [security.encryption] section of your Grafana configuration file. For details, refer to Enterprise configuration.