
# Recover dashboard access

Find the heading that matches what you see, and get back in without losing people, keys or settings.

**Kubernetes**

The master key is in the gateway Secret:

```bash
kubectl -n tokedex get secret tokedex-keys \
  -o jsonpath='{.data.TOKEDEX_MASTER_KEY}' | base64 -d
```

**Docker**

The gateway the [quickstart](/gateway/quickstart) starts keeps its master key in the `master-key` file of its `gateway-data` volume, and prints it in the start-up log. From the clone you started it in:

```bash
docker compose exec gateway cat /home/node/.tokedex/master-key
```

You need: access to the gateway's release and its Secrets (Docker: clone and its volume). Take a [backup](/gateway/backup-restore) before you change stored state.

## The dashboard refuses the address

The browser shows **This gateway does not answer to that address** (HTTP 421): the dashboard answers only at the gateway's public URL, or at `localhost` while none is set.

**Kubernetes**

Set `publicUrl` in `release-values.yaml` to the URL you open, such as `https://gateway.example.com`, and `ingress.host` to its hostname, then run `helm upgrade`.

**Docker**

Open `http://127.0.0.1:4000` on the machine that runs the gateway. If you set `TOKEDEX_PUBLIC_URL` in your shell or in `.env`, the dashboard answers only at that URL: set it to the URL you open, or remove it, then run `docker compose up -d`.

Behind a proxy, pass the browser's `Host` header unchanged; see [HTTPS and reverse proxies](/gateway/https).

## A person cannot sign in

| Problem | Fix |
| --- | --- |
| Forgotten password | An administrator, or the master key, opens the person in **Members** and chooses **Danger zone → Create reset link**. The link works once, for an hour. |
| Identity provider outage | On the sign-in page, choose **Emergency sign-in with a password** if the account has emergency sign-in, or **Use the master key**. |
| No Owner can sign in | Sign in with the master key. In **Members**, enable a disabled Owner and create a reset link. If no one holds the Owner role, choose **Create account** in the **Using master key** banner. |

Once anyone has an account, a master-key session ends after 15 minutes idle or one hour in all.

## The master key is lost or mismatched

If the master key is lost or refused, set a new one with every replica stopped: a gateway refuses a new key while another runs.

**Kubernetes**

The key that signs in is the `TOKEDEX_MASTER_KEY` the gateway last started with.

```bash
helm upgrade tokedex ./helm/tokedex -n tokedex -f release-values.yaml \
  --set replicaCount=0 --set autoscaling.enabled=false --wait --timeout 10m
kubectl -n tokedex wait --for=delete pod --timeout=10m \
  -l app.kubernetes.io/instance=tokedex,app.kubernetes.io/component=gateway
new_master_key=$(openssl rand -hex 32)
kubectl -n tokedex patch secret tokedex-keys --type merge \
  -p "{\"stringData\":{\"TOKEDEX_MASTER_KEY\":\"$new_master_key\"}}"
helm upgrade tokedex ./helm/tokedex -n tokedex -f release-values.yaml \
  --set replicaCount=1 --set autoscaling.enabled=false \
  --set podDisruptionBudget.enabled=false --wait --timeout 10m
helm upgrade tokedex ./helm/tokedex -n tokedex -f release-values.yaml --wait --timeout 10m
```

One replica takes the new key first, then the release returns to its own replica count and disruption budget.

**Docker**

Start the gateway once with a new key in `TOKEDEX_MASTER_KEY`, then read it from the volume:

```bash
TOKEDEX_MASTER_KEY="$(openssl rand -hex 32)" docker compose up -d --wait
docker compose exec gateway cat /home/node/.tokedex/master-key
```

The gateway saves the new key in place of the old one, and later starts use it. If `.env` sets `TOKEDEX_MASTER_KEY`, put the new key there instead and run `docker compose up -d`.

The start-up log reads:

```text
gateway: TOKEDEX_MASTER_KEY changed, so it is now the master key. The previous key no longer signs in.
```

The **Audit log** records the change. Store the new key wherever you keep the old one before you sign out, since the old one no longer works. A master key needs at least 32 characters, and no access-key prefix such as `tokedex_ik_`.

## A password pepper is missing or wrong

The pepper keys every stored password.

**Kubernetes**

It is `TOKEDEX_PASSWORD_PEPPER` in the gateway Secret or, when the Secret has no such key, `auth/password-pepper.key` on the claim.

**Docker**

It is `auth/password-pepper.key` in the `gateway-data` volume.

When it is missing or wrong, the gateway refuses to start with an error that names the pepper, or one replica answers password sign-ins with `503 pepper_mismatch`.

Restore it from the backup that matches the state, the same on every replica. If it is lost for good, make a new pepper under the next version, `2:` and 64 hex characters:

```bash
new_pepper="2:$(openssl rand -hex 32)"
```

**Kubernetes**

Write it to `TOKEDEX_PASSWORD_PEPPER` in the gateway Secret with every replica stopped, then start them, as for the master key.

**Docker**

Write it to the pepper file with the gateway stopped, then start the gateway:

```bash
docker compose stop gateway
printf '%s\n' "$new_pepper" | docker compose run --rm --no-deps -T --entrypoint sh gateway \
  -c 'umask 077 && cat > /home/node/.tokedex/auth/password-pepper.key'
docker compose start gateway
```

A new value under the lost version is refused. Every password then stops working: create a reset link for each person.

## Rotate the password pepper

Keep the old pepper and add a new one under a higher version.

**Kubernetes**

Set `TOKEDEX_PASSWORD_PEPPER` in the gateway Secret to the old value and the new one, as `1:<old-hex>,2:<new-hex>`, and restart every replica:

```bash
kubectl -n tokedex rollout restart deployment/tokedex
```

Until the restart finishes, a password set on a restarted replica can fail on one that has not restarted yet.

**Docker**

With the gateway stopped, rewrite `auth/password-pepper.key` in the volume as two lines, `1:<old-hex>` and `2:<new-hex>`. A file that holds one bare key holds version 1.

New passwords use the highest version, and each person moves to it at their next sign-in. Remove the old entry only once nobody's password still uses it: a password under a version the gateway no longer holds stops working.

## A verifier root or key-encryption key is lost

Restore both from the same backup as the state.

**Kubernetes**

With Postgres, the verifier root is `TOKEDEX_VERIFIER_ROOT` in the gateway Secret; without, it is `auth/verifier-root.key` on the claim. The key-encryption key is `kek/credential-kek.json` on the claim, or your KMS key.

**Docker**

Both are files in the `gateway-data` volume: `auth/verifier-root.key` and `auth/credential-kek.json`.

- **Verifier root lost:** a gateway whose verifier root is a file starts with a new one. Every API key and admin key then answers `401 invalid_api_key`, and the log reports that the master key changed. If it is lost for good, create the keys again.
- **Key-encryption key lost:** the gateway refuses to start with `Failed to open the stored credential "<NAME>"`. If it is lost for good, enter that credential again while the gateway is stopped, and repeat for each name the error gives.

**Kubernetes**

With Postgres, a Secret without `TOKEDEX_VERIFIER_ROOT` leaves the Pod in `CreateContainerConfigError`; a different value acts as a new root. Enter a credential with [Run a gateway command while the gateway is stopped](#run-a-gateway-command-while-the-gateway-is-stopped), with this command in place of `catalogue status`:

```bash
kubectl -n tokedex exec -i deployment/tokedex -- \
  node /app/dist/cli.js keys set --name OPENAI_API_KEY --value-stdin < openai-key.txt
```

**Docker**

```bash
docker compose stop gateway
docker compose run --rm --no-deps -T gateway \
  keys set --name OPENAI_API_KEY --value-stdin < openai-key.txt
docker compose start gateway
```

## Catalogue or configuration is unreadable

| The gateway | Fix |
| --- | --- |
| Starts and logs a `catalogue_rebuilt` event | Nothing: it replaced a damaged model catalogue with its own and kept the damaged copy, named in `backup`. |
| Refuses to start: the catalogues are out of sync | Keep the gateway stopped and follow the startup log's [catalogue recovery instructions](/gateway/upgrades#recover-a-failed-upgrade). If a newer release wrote the stored catalogue, upgrade to that release or restore a backup. |
| Refuses to start: `invalid configuration document` | Restore the gateway's configuration from your backup. |

## Run a gateway command while the gateway is stopped

**Kubernetes**

Swap the gateway process for `sleep`, run the command, then undo the swap and put the release back. Set `values` to the values file the release last ran.

```bash
values=release-values.yaml
kubectl -n tokedex patch deployment tokedex --type json -p '[
  {"op": "add", "path": "/spec/template/spec/containers/0/command", "value": ["sleep", "infinity"]},
  {"op": "remove", "path": "/spec/template/spec/containers/0/startupProbe"},
  {"op": "remove", "path": "/spec/template/spec/containers/0/readinessProbe"},
  {"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}
]'
kubectl -n tokedex scale deployment/tokedex --replicas=1
kubectl -n tokedex rollout status deployment/tokedex --timeout=5m
kubectl -n tokedex exec -i deployment/tokedex -- node /app/dist/cli.js catalogue status
kubectl -n tokedex scale deployment/tokedex --replicas=0
kubectl -n tokedex wait pod -l app.kubernetes.io/name=tokedex,app.kubernetes.io/instance=tokedex,app.kubernetes.io/component=gateway --for=delete --timeout=5m
kubectl -n tokedex patch deployment tokedex --type json \
  -p '[{"op": "remove", "path": "/spec/template/spec/containers/0/command"}]'
helm upgrade tokedex ./helm/tokedex -n tokedex -f "$values" --wait --timeout 10m
```

Scale to zero before you undo the swap, so the gateway starts only when `helm upgrade` starts it, with the image in `$values`. Undo the swap before `helm upgrade`: the chart never sets `command`, so Helm leaves it in place. If your values turn on `autoscaling`, first run `helm upgrade` with `--set autoscaling.enabled=false`, or the autoscaler starts the gateway again.

Replace `catalogue status` with the command you need.

**Docker**

```bash
docker compose stop gateway
docker compose run --rm --no-deps gateway catalogue status
docker compose start gateway
```

Replace `catalogue status` with the command you need.

Commands that change state refuse while a gateway runs on the same state.

## Recommendations

- **Keep copies of the password pepper, verifier root and key-encryption key with your backups.** A restored copy keeps passwords, API keys and stored provider credentials working; a new one stops them.
- **Keep at least two Owners, and give one emergency sign-in.** An absent Owner then needs no master key, and someone can sign in while the identity provider is down.
- **Rotate the password pepper instead of replacing it.** A rotation keeps every password working; a replacement stops them all.

Next: [Troubleshooting](/gateway/troubleshooting), [Backup and restore](/gateway/backup-restore) or [Single sign-on](/gateway/single-sign-on).
