Access management

Managing database keys, users, grants, token keys and limits through the server's administration API.

This page covers the calls that control who can reach a database: database keys, users and their grants, token keys, and limits. The model behind them is explained in Authentication and access.

They are the server's administration API, under /v1/admin, which takes and answers JSON and is authenticated like any request. The engine SDK has no calls for it: call it with fetch, or with curl from deployment tooling. The samples assume a helper like this one:

const admin = async (method: string, path: string, body?: unknown) => {
  const response = await fetch(`${server}/v1/admin${path}`, {
    method,
    headers: {
      authorization: `Bearer ${adminKey}`, // or `Basic …` for a user
      ...(body === undefined ? {} : { "content-type": "application/json" }),
    },
    ...(body === undefined ? {} : { body: JSON.stringify(body) }),
  });
  if (!response.ok) throw new Error(`${response.status} ${await response.text()}`);
  return response.json();
};

Database keys

A database's admins and superusers create its keys:

const { id, key } = await admin("POST", `/databases/${databaseId}/keys`, {
  name: "web-backend",
  permission: "write",
});

permission is read, write or admin. key is the secret, as clients present it (mk_…). Store it in your secret manager right away: the server keeps only a digest of it and never returns it again.

A creation whose answer was lost can be sent again safely if you draw the key yourself: send key in the body, in the form mk_<32 hex>_<43 base64url characters> from a cryptographically secure generator, and the same creation sent again is done and answered the same. Drawing only id lets the server draw the secret, and a creation sent again is then refused already_exists: revoke that key and create another.

RequestDoes
GET /v1/admin/databases/{db}/keysLists the database's keys, without secrets
POST /v1/admin/databases/{db}/keys/{id}/revokeRevokes a key
DELETE /v1/admin/databases/{db}/keys/{id}Removes a revoked key
GET, POST /v1/admin/keysDeployment-wide keys (read or write): superusers only

A listed key is { id, name, permission, revoked }. A revoked key stops working within seconds. Keys count against the database's limit of keys (by default 1,000) until they are removed, revoked or not: remove a revoked key once no client presents it.

To rotate a key, create a new one, deploy it, and then revoke the old one.

Users

Users authenticate with a name and a password, on the HTTP API only. Managing them is for superusers; a user may change its own password.

await admin("POST", "/users", { name: "ada", password: "…", superuser: false });
await admin("PUT", "/users/ada/password", { password: "…" });
await admin("PUT", "/users/ada/disabled", { disabled: true });
await admin("DELETE", "/users/ada");

GET /v1/admin/users lists them, never with a password. A name is 1 to 64 characters of letters, digits and - . _ @. Removing a user also removes their grants. The last enabled superuser cannot be disabled, demoted or removed.

Grants

A grant gives a user one permission on one database. A database's admins and superusers manage them.

await admin("PUT", `/databases/${databaseId}/grants/ada`, { permission: "read" });

const grants = await admin("GET", `/databases/${databaseId}/grants`);
// [{ user, permission }]

await admin("DELETE", `/databases/${databaseId}/grants/ada`);

Granting again replaces the user's earlier grant on that database, so a user has at most one permission per database.

Token keys

A token key is the public half of an Ed25519 key pair your backend signs document tokens with; see Signing tokens yourself. A database's admins and superusers manage them.

RequestDoes
PUT /v1/admin/databases/{db}/capability-keys/{id}Registers a public key, { "public": "…" }
GET /v1/admin/databases/{db}/capability-keysLists them: { keys: [{ id, public, revoked }], not_before }
POST /v1/admin/databases/{db}/capability-keys/{id}/revokeRevokes one, and every token it signed
DELETE /v1/admin/databases/{db}/capability-keys/{id}Removes a revoked one
PUT /v1/admin/databases/{db}/capabilities-not-beforeEnds every document token of the database issued before now

Registering the same public key again under the same id is done; another key under an id in use is refused already_exists. A database holds at most 100 token keys.

Limits

Limits bound what a database, or the budget group it belongs to, may use at once or per second. They are set by superusers only, never by a database's admins:

const { limits, effective, revision } = await admin("GET", `/databases/${databaseId}/limits`);

await admin("PUT", `/databases/${databaseId}/limits?revision=${revision}`, {
  connections: 2_000,
  transfer: 10_000_000,
});

The body names a limit for each resource it limits, and replaces the database's record whole; a resource it does not name is unlimited. A database without a record takes the deployment's default limits. The resources include connections (open sessions), in_flight (requests being served), memory, retained (bytes of storage), append (bytes written per second), cpu, scanned, transfer (bytes sent and received per second) and presence (presence deliveries per second). Work beyond a limit is refused resource_exhausted: over the HTTP API with status 429, and in a session as a refusal the client retries with backoff.

?revision= makes the change only while the record is still at the revision you read, so a change you did not see is never overwritten. See Quotas for the full model, budget groups and the default limits.

A database can also be made read-only or blocked without removing it: PUT /v1/admin/databases/{db}/access-mode with { "mode": "read_only" } (or blocked, or read_write), by a superuser.