Docs

Access Control & Tenants

API keys, the three roles, and how one engine keeps several teams' campaigns apart.

API keys

Define keys with BANDITDB_API_KEYS, a semicolon-separated list of key=role pairs:

BANDITDB_API_KEYS="admin-key=admin;app-key=writer;dash-key=reader"

Every request except /health and /openapi.yaml must then send X-Api-Key: <key>. /metrics also needs a key unless BANDITDB_METRICS_PUBLIC=true. Keys are compared in constant time, and the rate limit (BANDITDB_RATE_LIMIT_PER_SEC, default 1000) applies per key.

  • BANDITDB_API_KEY (singular) adds one admin key with no tenant. It is meant for local development.
  • Open mode: with no keys configured, every caller is granted admin. Set BANDITDB_REQUIRE_AUTH=true in production so that a missing key set stops the server at startup instead of opening it.

Roles

Roles are cumulative. Each one can do everything the role below it can.

RoleAddsGive it to
readerEvery GET: /campaigns, /campaign/:id, /report, /diagnostics, /pacing, /health/detail, /export, /limits, /metrics.Dashboards, notebooks, monitoring.
writerPOST /predict, /batch_predict, /reward, /campaign/:id/interact.The application that makes decisions.
adminCreate, delete, archive and restore campaigns. Add arms and change arm status. POST /checkpoint.Deploy pipelines and operators.

A key with too low a role gets 403 Insufficient permissions. POST /checkpoint is process-wide, so it is refused for tenant keys at any role. Only an operator key (one without a tenant) can call it.

Multi-tenancy

To share one engine between teams or customers, give each key a tenant, key=role:tenant_id, and turn tenant mode on:

BANDITDB_API_KEYS="ops-key=admin;team-a-key=admin:team-a;team-b-key=writer:team-b"
BANDITDB_TENANT_MODE=true

Tenant IDs only take effect with BANDITDB_TENANT_MODE=true. Without it, the :tenant_id suffix is ignored, and every key sees every campaign.

With tenant mode on:

  • Campaign IDs are namespaced automatically. When team-a creates prices, it is stored as team-a/prices. The tenant never sees the prefix: it creates, predicts against and lists prices.
  • Other tenants' campaigns don't exist for you. Reading, writing or rewarding another tenant's campaign returns 404, not 403, so a tenant can't even confirm that a campaign name is in use.
  • Two tenants can use the same campaign name without colliding.
  • Scoped views. /campaigns, /health/detail and /metrics show only the caller's campaigns. /export lists only exports/{tenant}/.
  • Operator keys (no :tenant_id) see everything, using the full stored IDs (team-a/prices).

Tenant mode gives logical isolation inside one process. It is not a hard security boundary. Tenants share memory, CPU and the WAL volume. If tenants must not trust each other, give each its own engine. See PRODUCTION_STAGE1.md for the SLA caveat.

Provisioned tenants (control plane)

When BANDITDB_PROVISION_KEY is set, a control plane can create, update, suspend and delete tenants at runtime through /admin/tenants/*, without restarting the engine. BanditDB Cloud works this way.

  • Provisioned tenants are always namespace-isolated, whatever BANDITDB_TENANT_MODE says.
  • The engine stores only a SHA-256 digest of each key and checks keys locally. The control plane is never asked per request.
  • An engine with a provision key never falls back to open mode, even before its first tenant exists.
  • A suspended tenant's key still authenticates but gets 403, so a lapsed account reads as "forbidden" rather than "bad key".
  • The /admin/tenants/* routes only accept the provision key. No tenant key can reach them, whatever its role.

For per-tenant ceilings, see BANDITDB_MAX_CAMPAIGNS, BANDITDB_MAX_CAMPAIGN_BYTES and the other limits in Installation and OPERATIONS.md.