Token keys
Registering an Ed25519 public key so your backend can sign document tokens itself, and revoking it.
Your application's users connect with document tokens: short-lived credentials for one document. Your backend can get a token by asking the database for one with a database key. A token key lets it skip that request and sign tokens itself.
A token key is the public half of an Ed25519 key pair. Your backend keeps the private half and signs tokens with it; the database accepts tokens signed by a key you registered. The private half never leaves your servers, and the service never sees it.
When to use one
- Ask the database for tokens if you issue few tokens or want the simplest setup. Nothing to register.
- Sign tokens yourself if you issue many, or do not want a request to the database for each one.
Both can be used with the same database at the same time.
Generating a key pair
Generate an Ed25519 key pair wherever your backend's secrets are managed. What you register is the raw 32-byte public key, base64url-encoded: 43 characters, with or without one trailing =.
import { generateKeyPairSync } from "node:crypto";
const { publicKey, privateKey } = generateKeyPairSync("ed25519");
// The raw 32-byte public key, base64url-encoded: this is what you register.
const jwk = publicKey.export({ format: "jwk" });
console.log(jwk.x);
// Keep this in your backend's secrets. Never register it or send it anywhere.
const privateKeyPem = privateKey.export({ format: "pem", type: "pkcs8" });Registering a key
On the database's Token Keys page, choose Register key and fill in:
| Name | Type | Description |
|---|---|---|
Name * | string | A label for the list, 1 to 64 characters. For example backend-2026. |
Key ID * | string | The kid your tokens carry to name this key. 1 to 64 letters, digits, dots, underscores and hyphens. Not . or .., and not starting with gw_. |
Public key * | string | The raw 32-byte Ed25519 public key, base64url-encoded. |
A key ID is used once in a database: registering a key under an ID that is in use, or that a revoked key had, is refused. Choose a new key ID for every key.
Token keys can be registered once the database is ready, and while it is suspended. Any member of the organization can register one.
From the management API, it is POST /v1/databases/{databaseId}/token-keys: see token keys in the API.
A key's status
| Status | Meaning |
|---|---|
| Registering | The key is being registered in the cluster. This takes a moment |
| Active | The cluster confirmed the key. Tokens signed with it are accepted |
| Unsettled | The registration ended without a clear result, and the cluster may or may not hold the key. Revoke it, then register it again under a new key ID |
| Revoked | Tokens signed with it are refused |
| Revoked in database | It was revoked or removed in the database itself with an admin key, or another key holds its key ID there. Tokens signed with it are refused |
A registration that fails outright, for example because the cluster refused the key, leaves nothing behind. Try again.
Token keys not made here
An admin key can register, revoke and remove token keys in the database itself. The service compares them with its own list about every 15 minutes, and lists the token keys the database holds that were not made here under Not made here on the Token Keys page, with their key ID, public key, when it first saw them and their status. It never revokes one on its own. You can: Revoke key on its row revokes it in the database, and the tokens it signed with it. From the management API it is DELETE /v1/databases/{databaseId}/unmanaged-credentials/token-keys/{kid}.
Signing tokens
Tokens signed with the matching private key, and naming the key by its key ID, are accepted for the database the key is registered with, and for no other database. Give every token an issued-at claim (iat, seconds since the epoch): a token without one is refused once all of a database's tokens were revoked (see below).
The format of a document token, its claims and how a client presents it are part of Mimic DB itself rather than of the hosted service, and are the same when you host it yourself.
Rotating a token key
A database can have several token keys at once, so rotate by overlap:
Register the new key
Generate a new key pair and register its public half under a new key ID.
Switch your backend
Deploy the new private key and key ID. New tokens are signed with the new key; tokens already issued with the old key are still accepted.
Revoke the old key
Once the tokens signed with the old key have expired, revoke it.
Revoking a key
Choose Revoke key. The key is removed from the database's cluster, so tokens signed with it are no longer accepted. It cannot be undone, and its key ID is not used again; the same public key can be registered again under a new key ID.
A key that is still registering cannot be revoked until its registration ends, usually within seconds and at most a few minutes. A request made before that is refused with a conflict; try again. The management API returns the time as the key's registeringUntil.
Revoking all tokens
On the Token Keys page, Revoke all tokens ends every document token issued for the database until now, whatever signed it: tokens your backend signed with any token key, and tokens minted through the HTTP API. No key is revoked. Use it when a token leaked, or to end tokens while keeping their keys. A leaked key does not need it: revoking a key ends the tokens it signed or minted already.
It sets a time, from the database's own clock plus the five minutes of clock skew a signer may have, and a second revocation only moves it later. From then on a token is accepted only if it carries an issued-at claim (iat) later than that time:
- Tokens minted through the HTTP API carry it, so they work again shortly.
- Tokens your backend signs must carry
iatlater than the returned time. Signed withiatone second after it, they are accepted from a second or two after the revocation; signed withiatfrom your clock, only once your clock passes the returned time, about five minutes later. Tokens withoutiatare refused from then on, for good, so addiatto your tokens before you use this. From the management API it isPOST /v1/databases/{databaseId}/tokens/revoke: see token keys in the API.
When a database is restored from a backup
A database restored from a backup is a new database with no credentials, so it has no token keys. Register them again for it.