---
metadata:
  - name: generator
    content: Diplodoc Platform v5.63.0
alternate:
  - en/concepts/secrets-instance/rotation
  - en/datalens/concepts/secrets-instance/rotation.md
  - ru/concepts/secrets-instance/rotation
  - href: en/concepts/secrets-instance/rotation.md
    type: text/markdown
    title: Markdown version
csp:
  - script-src:
      - https://mc.yandex.ru
    img-src:
      - https://mc.yandex.ru
    connect-src:
      - https://mc.yandex.ru
      - wss://mc.yandex.ru
    child-src:
      - 'blob:'
      - https://mc.yandex.ru
    frame-src:
      - 'blob:'
      - https://mc.yandex.ru
    frame-ancestors:
      - 'blob:'
      - https://mc.yandex.ru
canonical: en/concepts/secrets-instance/rotation.html
title: Secret rotation DataLens On-premises
description: >-
  This section describes a classification of secrets based on rotation
  capability and outlines the procedures for updating secrets.
vcsPath: en/concepts/secrets-instance/rotation.md
---

# Secret rotation DataLens On-premises

Classification based on rotation capability:

| Category                                          | Rotation capability | Consequences |
| -------------------------------------------------- | ------------------- | ----------- |
| [👮 Safe rotation](#safe-rotation)            | Ready for rotation   | Minimal impact on system operation |
| [🟡 Rotation with consequences](#unsafe-rotation)     | Ready for rotation   | There are side effects to consider |
| [🔴 Rotation not possible](#not-recommended-rotation) | Not recommended   | Causes data loss or malfunction |

There is no automatic rotation of secrets. Secrets are preserved between updates thanks to the `lookup` mechanism in the [Helm chart](https://helm.sh/docs/topics/charts/) that reuses existing values ​​from Kubernetes secrets.

Where necessary, rotation is performed manually with due regard to consequences for each secret type:

* [RSA authentication key rotation procedure](#rsa-auth-rotation)
* [Master token rotation procedure](#token-rotation)
* [Database password rotation procedure (built-in PostgreSQL)](#password-rotation)


## 🟢 Secrets with safe rotation {#safe-rotation}

You can rotate these secrets without significant consequences. Following rotation, pods must be restarted.

| Secret                         | Rotation procedure                                 | Consequences |
| ------------------------------ | ------------------------------------------------- | ----------- |
| `AUTH_CALLBACK_COOKIE_SECRET`  | Change in values.yaml and run `helm upgrade` | OAuth/OIDC callbacks will be invalidated during authentication |
| `DOCKER_CONFIG_JSON`           | Change in values.yaml and run `helm upgrade` | No impact on running pods |
| `AUTH_PROVIDERS_CONFIG`        | Change in values.yaml and run `helm upgrade` | No impact (provider configuration) |
| `EXPORT_DATA_VERIFICATION_KEY` | Change in values.yaml and run `helm upgrade` | Previously exported workbooks will be imported with a warning |


## 🟡 Secrets with rotation and consequences {#unsafe-rotation}

You can rotate these secrets; however, it will cause some side effects.

| Secret                                                   | Rotation procedure                                 | Consequences |
| -------------------------------------------------------- | ------------------------------------------------- | ----------- |
| `AUTH_TOKEN_PRIVATE_KEY` / `AUTH_TOKEN_PUBLIC_KEY`       | `./init.sh --auth-rsa-gen`                        | ⚠️ All active user sessions will be invalidated. Users will be required to re-login |
| `CSRF_SECRET`                                            | Change in values.yaml and run `helm upgrade` | ⚠️ Data requests will return errors until the upgrade is complete |
| `TEMPORAL_AUTH_PRIVATE_KEY` / `TEMPORAL_AUTH_PUBLIC_KEY` | `./init.sh --temporal-rsa-gen`                    | ⚠️ Temporal tasks in progress may fail with an error. We recommend to wait until all tasks are completed before rotating |
| `AUTH_MASTER_TOKEN`                                      | Change in values.yaml and run `helm upgrade` | ⚠️ Temporary unavailability of the authentication service until all dependent pods are restarted |
| `US_MASTER_TOKEN`                                        | Change in values.yaml and run `helm upgrade` | ⚠️ Temporary unavailability of United Storage until all dependent pods are restarted |
| `FILE_UPLOADER_MASTER_TOKEN`                             | Change in values.yaml and run `helm upgrade` | ⚠️ Temporary unavailability of file uploads until all pods are restarted |


## 🔴 Secrets not recommended for rotation {#not-recommended-rotation}

Rotating these secrets without further action causes data loss or system malfunction.

| Secret                                          | Why not to rotate                                                                    | What to do if compromised |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------- | --------------------------- |
| `AUTH_ADMIN_PASSWORD`                           | 🚫 The administrator password can be changed only through the DataLens interface |                             |
| `CONTROL_API_CRYPTO_KEY`                        | 🚫 Used to encrypt passwords and tokens in connections to data sources. If you change the key, all existing connections will become unreadable | Can be recreated by restoring from a backup |
| `POSTGRES_PASSWORD_*`                           | 🚫 Passwords are used both in the application and the database. Changing them only in the secrets will cause connection errors | You need to change the passwords in PostgreSQL and the secrets in a synchronized manner. When using the built-in PostgreSQL, it is a complex procedure with downtime |
| `CLICKHOUSE_PASSWORD`                           | 🚫 Similarly to PostgreSQL, the password must match in the database and the secrets.                            | Synchronized change in ClickHouse® and the secrets |
| `REDIS_PASSWORD`                                | 🚫 Similarly, the password must match in Valkey™ and the secrets.                               | Synchronized change in Valkey™ and the secrets |
| `S3_ACCESS_KEY_ID` / `S3_SECRET_ACCESS_KEY`     | 🚫 Credentials must match the S3/MinIO settings                                       | Synchronized change in S3 and the secrets |

In addition, when updating database passwords, you can create a new user and password with similar access permissions and migrate the workload to it without downtime.


## RSA authentication key rotation procedure {#rsa-auth-rotation}

```bash
# 1. (Optional) Warn users to re-login

# 2. Generate new keys and run an update
./init.sh --auth-rsa-gen

# 3. Make sure all pods have restarted
./init.sh --kubectl get pods

# 4. Check that authentication is working
```


## Master token rotation procedure {#token-rotation}

```bash
# 1. Prepare new token values ​​(32 characters, alphanumeric)
NEW_TOKEN=$(openssl rand -base64 32 | tr -dc 'a-zA-Z0-9' | head -c 32)

# 2. Create or update values.yaml with new values
# secrets:
#   US_MASTER_TOKEN: "<new token>"

# 3. Perform an update
./init.sh --values ./my-values.yaml

# 4. Make sure all pods have restarted
./init.sh --kubectl rollout status deployment --timeout=300s
```


## Database password rotation procedure (built-in PostgreSQL) {#password-rotation}

{% note warning %}

This procedure requires downtime. Perform it with extreme caution.

{% endnote %}

```bash
# 1. Create a backup
./init.sh --dump-postgres

# 2. Connect to PostgreSQL
./init.sh --pg-sql

# 3. Change user password in PostgreSQL
ALTER USER "pg-us-user" WITH PASSWORD 'new_password';

# 4. Update the secret in values.yaml
# secrets:
#   POSTGRES_PASSWORD_US: "new_password"

# 5. Perform an update
./init.sh --values ./my-values.yaml

# 6. Restart the pods using this password
./init.sh --kubectl rollout restart deployment
```

<!-- source: en/_includes/clickhouse-disclaimer.md -->
_ClickHouse® is a registered trademark of [ClickHouse, Inc](https://clickhouse.com)._
<!-- endsource: en/_includes/clickhouse-disclaimer.md -->