> ## Documentation Index
> Fetch the complete documentation index at: https://docs.open-metadata.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Rotate the JWT Signing Keys | OpenMetadata Deployment Security

> Replace the RSA key pair that OpenMetadata uses to sign JWT tokens, then regenerate the bot tokens and redeploy ingestion pipelines with the regenerate-bot-tokens command.

# Rotate the JWT Signing Keys

OpenMetadata signs the JWT tokens it issues with one RSA key pair, set in `jwtTokenConfiguration`. These tokens include user sessions, personal access tokens, and bot tokens such as the one the `ingestion-bot` uses. Rotate the key pair when you replace the default keys shipped for testing, when the private key may have leaked, or when your security policy requires it.

Rotation is a hard cut. You stop every server, start them all with the new key pair, and then regenerate the bot tokens with the `regenerate-bot-tokens` command. Tokens signed by the old key stop working.

> [!WARNING]
>
> Plan for downtime. Every server is stopped during the restart. Between the restart and the bot token regeneration, every bot (ingestion, automation, and integrations) is rejected with `401 Unauthorized`. Users must sign in again, and every personal access token stops working.

## Before You Start

Check the following before you rotate the keys:

* You run OpenMetadata 2.1.0 or later.
* You have picked a time when bot downtime is acceptable.
* You have shell access to a host, container, or pod that can run `./bootstrap/openmetadata-ops.sh`. It needs the same configuration as the servers and network access to the server API. A server container or pod meets both conditions.
* `pipelineServiceClientConfiguration.metadataApiEndpoint` (`SERVER_HOST_API_URL`) is set in that configuration. The command reads the server's JSON Web Key Set (JWKS) from this endpoint and redeploys pipelines through it.

## Step 1: Create a New Key Pair

OpenMetadata reads the private key as DER PKCS#8 and the public key as DER X.509. Use keys of 2048 bits or more:

```bash theme={null}
openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out private_key.pem
openssl pkcs8 -topk8 -inform PEM -outform DER -in private_key.pem -out private_key.der -nocrypt
openssl rsa -in private_key.pem -pubout -outform DER -out public_key.der
rm private_key.pem
```

Generate a new key ID:

```bash theme={null}
uuidgen
```

The new key ID must differ from the current `JWT_KEY_ID`, so that services that cache the JWKS fetch the new key. The [Enable JWT Tokens](https://docs.open-metadata.org/v2.1.x/deployment/security/enable-jwt-tokens.md) page asks you to keep the key ID unchanged across upgrades. A key rotation is the exception.

Keep `private_key.der` secret. Make it readable only by the user that runs the OpenMetadata server.

## Step 2: Restart Every Server with the New Keys

Stop every OpenMetadata server before you start any server with the new keys. Do not use a rolling restart.

During a rolling restart, a restarted server can fetch the old public key from a server that has not restarted yet. This happens when `authenticationConfiguration.publicKeyUrls` (`AUTHENTICATION_PUBLIC_KEYS`) points to an OpenMetadata URL behind a load balancer. The server caches that key for up to 24 hours and keeps accepting old user sessions and personal access tokens. The default `localhost` JWKS URL avoids this problem.

Set the following values in the configuration of every server and of the host that runs `openmetadata-ops.sh`. All of them must hold the same values.

| Configuration key | Environment variable | Value |
| - | - | - |
| `jwtTokenConfiguration.rsaprivateKeyFilePath` | `RSA_PRIVATE_KEY_FILE_PATH` | Path to the new `private_key.der` |
| `jwtTokenConfiguration.rsapublicKeyFilePath` | `RSA_PUBLIC_KEY_FILE_PATH` | Path to the new `public_key.der` |
| `jwtTokenConfiguration.keyId` | `JWT_KEY_ID` | The new key ID |

Follow the steps for your deployment:

> [tab] Bare Metal
>
> 1. Stop every OpenMetadata server.
> 2. Copy `private_key.der` and `public_key.der` to the OpenMetadata `conf` directory of each server, or to the paths set in `RSA_PRIVATE_KEY_FILE_PATH` and `RSA_PUBLIC_KEY_FILE_PATH`.
> 3. Set `JWT_KEY_ID`, or `jwtTokenConfiguration.keyId` in `conf/openmetadata.yaml`, to the new key ID.
> 4. Start every server.

> [tab] Docker
>
> These steps assume the key files are mounted from `./docker-volume/jwtkeys`, as described in [Configure JWT Key Pairs for Docker](https://docs.open-metadata.org/v2.1.x/deployment/security/enable-jwt-tokens.md#configure-jwt-key-pairs-for-docker).
>
> 1. Copy the new `private_key.der` and `public_key.der` to `./docker-volume/jwtkeys`, replacing the old files.
> 2. Set `JWT_KEY_ID` to the new key ID in your environment file, for example `openmetadata.prod.env`.
> 3. Recreate the server container so that it reads the new keys:
>
> ```bash theme={null}
> docker compose -f docker-compose.yml --env-file openmetadata.prod.env up -d --force-recreate openmetadata-server
> ```
>
> If you run more than one server container, stop all of them before you start any of them.

> [tab] Kubernetes
>
> These steps assume the Helm release is named `openmetadata` and the keys are stored in the `openmetadata-jwt-keys` secret. Point the chart to that secret with `jwtTokenConfiguration.keysSecret` in your Helm values file:
>
> ```yaml theme={null}
> # openmetadata.prod.values.yml
> openmetadata:
>   config:
>     jwtTokenConfiguration:
>       keyId: "<new key ID>"
>       keysSecret:
>         secretRef: openmetadata-jwt-keys
>         publicKeySecretKey: public_key.der
>         privateKeySecretKey: private_key.der
> ```
>
> The chart mounts the secret read-only at `/jwt-keys` in the server container and in the `run-db-migrations` init container, and sets `RSA_PUBLIC_KEY_FILE_PATH` and `RSA_PRIVATE_KEY_FILE_PATH` to the files there. `rsapublicKeyFilePath` and `rsaprivateKeyFilePath` are ignored while `keysSecret.secretRef` is set. `publicKeySecretKey` and `privateKeySecretKey` name the keys in the secret that hold each file.
>
> If you mount the keys with `extraVolumes` and `extraVolumeMounts` instead, as described in [Configure JWT Key Pairs for Kubernetes](https://docs.open-metadata.org/v2.1.x/deployment/security/enable-jwt-tokens.md#configure-jwt-key-pairs-for-kubernetes), the same steps apply. Skip the `keysSecret` values.
>
> 1. Scale the OpenMetadata deployment to zero and wait for its pods to stop:
>
> ```bash theme={null}
> kubectl scale deployment openmetadata --replicas=0 --namespace <namespace>
> kubectl wait --for=delete pod --selector app.kubernetes.io/name=openmetadata --namespace <namespace> --timeout=5m
> ```
>
> 2. Replace the key files in the secret:
>
> ```bash theme={null}
> kubectl create secret generic openmetadata-jwt-keys \
>   --from-file private_key.der --from-file public_key.der \
>   --namespace <namespace> --dry-run=client --output yaml | kubectl apply --filename -
> ```
>
> 3. Set `openmetadata.config.jwtTokenConfiguration.keyId` to the new key ID in your Helm values file. If the release doesn't use the secret yet, also set `keysSecret` as shown above.
> 4. Upgrade the release:
>
> ```bash theme={null}
> helm upgrade openmetadata open-metadata/openmetadata --values openmetadata.prod.values.yml --namespace <namespace>
> ```
>
> 5. Scale the deployment back to its original number of replicas. Helm doesn't reset a replica count that you changed with `kubectl scale`, so the pods stay stopped until you do:
>
> ```bash theme={null}
> kubectl scale deployment openmetadata --replicas=<replicas> --namespace <namespace>
> ```

After the servers start, check that each server lists only the new key ID:

```bash theme={null}
curl -fsS http://<server-host>:8585/api/v1/system/config/jwks
```

Query each server directly. A request through the load balancer checks only one of them. If a rolling restart already happened with a shared JWKS URL, stop all servers and start them again to clear the cached old key.

From this point:

* Users get `401 Unauthorized` on their old sessions and must sign in again.
* Holders of personal access tokens must create new tokens.
* Bots stay rejected until you complete step 3.

## Step 3: Regenerate the Bot Tokens

Run `regenerate-bot-tokens` from the OpenMetadata server directory, with the same configuration the servers use:

> [tab] Bare Metal
>
> ```bash theme={null}
> ./bootstrap/openmetadata-ops.sh -c conf/openmetadata.yaml regenerate-bot-tokens
> ```

> [tab] Docker
>
> ```bash theme={null}
> docker exec openmetadata_server ./bootstrap/openmetadata-ops.sh regenerate-bot-tokens
> ```

> [tab] Kubernetes
>
> ```bash theme={null}
> kubectl exec deployment/openmetadata --namespace <namespace> -- ./bootstrap/openmetadata-ops.sh regenerate-bot-tokens
> ```

The command does the following:

1. Fetches `<metadataApiEndpoint>/v1/system/config/jwks` and checks that it lists the configured key ID with the same public key. If it doesn't, the command changes nothing, prints the reason, and exits with code `2`. This check reads only the server behind `metadataApiEndpoint`, so it cannot confirm that every server restarted.
2. Gives every bot that uses JWT authentication a new token signed by the new key. Each change is recorded in the audit log as an update by `admin`. A bot whose token was revoked is skipped and stays without a token.
3. Redeploys every ingestion pipeline that is marked as deployed, so that it uses the new `ingestion-bot` token. When `pipelineServiceClientConfiguration.enabled` is `false`, the command skips this step.

A bot works again as soon as its new token is stored. You don't need to restart the servers.

### Command Options

| Option | Description |
| - | - |
| `--expiry` | Expiry of the new tokens: `OneHour`, `One`, `Seven`, `Thirty`, `Sixty`, `Ninety`, or `Unlimited`. The default is `Unlimited`. |
| `--skip-current` | Leaves unchanged any bot token that the configured key already signs, that carries the configured key ID, and that hasn't expired. Use it when you run the command again during the same rotation. |

Without `--skip-current`, the command replaces every token except revoked ones. Run it without the option to replace a leaked bot token without rotating the keys. Don't use `--skip-current` in that case, because the leaked token still verifies under the configured key and would be kept.

### Command Results

The command prints one row per bot with one of these outcomes:

* `REGENERATED`: The bot has a new token.
* `ALREADY_CURRENT`: The token was left unchanged. This outcome appears only with `--skip-current`.
* `SKIPPED`: The bot has no bot user, doesn't use JWT authentication, or its token was revoked.
* `FAILED`: The token wasn't replaced. The details column gives the reason.

| Exit code | Meaning |
| - | - |
| `0` | No bot or pipeline failed. |
| `1` | A bot or pipeline failed, or the command couldn't run. Check the table and the log. |
| `2` | The JWKS doesn't list the configured key or couldn't be read, or `metadataApiEndpoint` isn't set. Nothing was changed. |

If a bot fails with `changed concurrently, re-run`, someone edited it while the command ran. Run the command again with `--skip-current`, so that only the failed bots get new tokens.

If every bot fails with `Private key does not match the public key`, `RSA_PRIVATE_KEY_FILE_PATH` and `RSA_PUBLIC_KEY_FILE_PATH` point to keys from different pairs. No token is stored in that case.

### Pipelines That Aren't Redeployed

The command redeploys only pipelines marked as deployed. To deploy every pipeline registered in OpenMetadata, including pipelines that were never deployed, run:

```bash theme={null}
./bootstrap/openmetadata-ops.sh deploy-pipelines
```

For pipelines managed outside OpenMetadata, replace the bot token in their configuration and redeploy them through their own scheduler.

## Step 4: Check the Result

Confirm the following:

* `/api/v1/system/config/jwks` on each server lists only the new key ID.
* The command report shows every bot as `REGENERATED`, or `ALREADY_CURRENT` on a `--skip-current` run. Bots whose tokens you revoked show as `SKIPPED`.
* Ingestion pipelines run again, on schedule or when you trigger them manually.

## Update Tokens Stored Outside OpenMetadata

The new keys invalidate copies of old tokens that other systems hold. Update the following:

* **Personal access tokens**: The command doesn't re-sign or delete personal access tokens. The old tokens can still appear as unexpired in the UI, but requests that use them return `401 Unauthorized`. Ask their owners to revoke the old tokens, create new ones, and update their clients.
* **Copied bot tokens**: Copy the new token from **Settings** > **Bots** to every system that holds the old one, such as CI jobs and external pipelines.
* **Airflow lineage backend**: Replace `jwt_token` in the `[lineage]` section of `airflow.cfg`, or `metadata_config.securityConfig.jwtToken` in the JSON file set in `OPENMETADATA_LINEAGE_CONFIG`. Pipeline redeployment doesn't update these values.
* **Airflow `OpenMetadataHook`**: Replace the password of the Airflow connection that the hook uses, `openmetadata_default` by default. Pipeline redeployment doesn't update this connection.
* **Services that verify OpenMetadata tokens through the JWKS**: Make sure they reload the JWKS and accept the new key ID. Remove any cached or pinned copy of the old public key, so that they reject tokens signed by it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.