API keys¶
Named, per-tenant credentials for automation: Terraform, CI, the Kubernetes
operator, gslb-mcp, dashboards. Each key acts as one role within one
tenant. It can expire, be rotated, and be revoked on its own, and every request
made with it is attributed to it in the audit log.
Design: docs/audits/2026-09-G06-tenant-keys-design.md.
Model¶
| Field | Meaning |
|---|---|
id |
Stable identity. What Terraform imports and what the audit log names (key:<id>). |
tenantId |
The tenant the key acts for. Deleting the tenant deletes its keys. |
name |
A label. Not unique: during a rotation's grace window two live keys share one. |
prefix |
First 8 characters of the secret, so you can tell keys apart. Empty for migrated legacy keys. |
role |
A role name, resolved exactly like a user's. Immutable — a key that changes power should be a new key. |
createdBy |
Actor that minted it (see Actors). |
expiresAt |
Unix seconds, or null for never. |
lastUsedAt |
Updated at most once a minute per node. |
revokedAt |
Set on revoke. The row is kept as history. |
The secret itself is 64 hex characters, shown once, in the response to create or rotate. Only its SHA-256 is stored.
How a key authenticates¶
A key is accepted when its hash matches a row that is neither revoked nor expired:
There is no cache and reads are leader-consistent, so a revoke or expiry takes effect on the next request, on every node.
A key is then treated exactly like a session with the same tenant and role:
- its permissions are its role's permissions;
- it is a system admin when, and only when, its role is
tenant_adminand its tenant isdefault— the same rule as for users.
So a default-tenant tenant_admin key can do everything GSLB_API_KEY does,
and can replace it for remote automation. A tenant_admin key in any other
tenant administers only that tenant.
The ceiling rule¶
Nobody can mint a key more powerful than themselves. The requested role's permissions must be a subset of the caller's own; the system admin is exempt. Rotation re-applies the rule, because the successor inherits the role. An unknown role name is refused.
apikey:read and apikey:write are held by tenant_admin only. operator and
viewer cannot mint keys.
Rotation¶
POST /api/v1/keys/{id}/rotate with {"grace": <seconds>} (0–604800, default
3600) creates a successor with the same name, role and expiry, and sets the old
key to expire after grace. It never extends an earlier expiry. Both keys work
during the window, so a fleet of consumers can repoint without an outage. With
grace: 0 the old key stops working immediately.
For a hard cutover without the endpoint: create a new key, repoint, revoke the old.
Endpoints¶
All tenant-scoped via the caller's tenant. A system admin may add
?tenantId=<id> (or tenantId in the create body) to act on another tenant.
| Method | Path | Permission | Notes |
|---|---|---|---|
GET |
/api/v1/keys |
apikey:read |
?includeRevoked=true to include history |
POST |
/api/v1/keys |
apikey:write |
{name, role, expiresAt?} → 201 {key, secret} |
GET |
/api/v1/keys/{id} |
apikey:read |
404 for another tenant's key |
PATCH |
/api/v1/keys/{id} |
apikey:write |
{name?, expiresAt?, clearExpiry?} |
POST |
/api/v1/keys/{id}/rotate |
apikey:write |
{grace?} → 201 {key, secret} |
DELETE |
/api/v1/keys/{id} |
apikey:write |
Revoke. 204, idempotent |
GET /api/v1/auth/me with a key returns principal: "key" and the key's metadata.
Surfaces¶
- WebUI — Admin → Identity → API Keys: create (with an expiry preset), rotate (with a grace picker), revoke. The role picker offers only roles you may mint.
- gslbctl —
gslbctl keys list|create|show|rotate|revoke.--expirestakes90d,720hor2027-01-01;--tenant <name>and--all-tenantsare for the system admin. - Terraform —
nexus_api_key. Name and expiry update in place; role and tenant force replacement. The secret is in state from create only (null after import). Rotate withterraform apply -replace=nexus_api_key.ciandlifecycle { create_before_destroy = true }.
Actors¶
Every request carries an actor ID, and the audit line records it with the tenant it acted for:
| Actor | Credential |
|---|---|
root |
GSLB_API_KEY |
dev |
keyless loopback dev mode |
user:<id> |
a login session |
key:<id> |
a named API key |
anon |
the unauthenticated endpoints (login, setup, reset) |
migration |
createdBy of keys carried over at upgrade |
Upgrade notes¶
- Existing tenant keys keep working. On startup each tenant's pre-existing key
becomes a named key
legacywith theoperatorrole it always had. The plaintext is unknown, so itsprefixis empty. Mint a named replacement and revokelegacywhen convenient. Revoking it really does revoke it: the oldtenants.api_key_hashlookup is gone, and that column is now unused. - New tenants get a first key named
initialwith roletenant_admin(previously a fixedoperatorkey), so the tenant can create its own users and keys without the root key. GSLB_API_KEYis unchanged. It still works everywhere and is audited asroot. An opt-in loopback-only mode for it is planned.- Rolling upgrade: keys minted after the upgrade authenticate only on upgraded
nodes, so mint them once every node is on the new version. Rolling back to the
previous binary keeps
legacykeys working; newer keys stop. - Restoring an old snapshot: a snapshot taken before named keys existed carries
none. Restoring one recreates each tenant's
legacykey and drops newer keys.
What revocation does not end: an existing login session (sessions are not keys), and a WebSocket token already issued (24 h).