# Tenancy

# Tenancy

Drillmark groups monitored domains, data sources, and users by tenant. A tenant usually represents one MSP customer: one organization whose domains the MSP watches on their behalf.

## Current scope

Phase 1 (this release) runs as a single-admin, self-hosted deployment. The database carries `tenant_id` on domains, data sources, and users, but the day-to-day admin experience assumes one tenant per deployment unless you explicitly turn local tenant management on.

The multi-tenant surface (listing orgs, inviting users, moving domains between orgs) is implemented but gated behind the `FEATURE_LOCAL_USER_MANAGEMENT` flag. When off, the local user / org / invitation endpoints answer `410 Gone`. Flip the flag on only when per-RP tenant claims through Bunyip are wired through; otherwise the two paths will fight.

## Default tenant

New users land in `DRILLMARK_DEFAULT_TENANT_ID` on first sign-in. When the variable is unset, the first tenant row created at migration time is used. See [configuration](/docs/drillmark/configuration).

## Identity path

Drillmark has no local login. Every signed-in user arrives via the Bunyip / mokosh-server OIDC provider:

- The SPA runs as a public PKCE client at the OP.
- On successful callback, the backend verifies the bearer against the OP's JWKS and either loads the existing `users` row (matched by `sub`) or JIT-provisions one into `DRILLMARK_DEFAULT_TENANT_ID`.
- The user's tenant membership is read from the database, never from a token claim. Role mirrors (admin vs viewer) are written on sign-in and refreshed from the OP's user claims when the token is renewed.

API tokens prefixed `dmrc_` are a separate credential plane for machine clients (CI pipelines, scripts). They are issued from the api-tokens screen in the frontend, scoped to the issuing user's tenant and role.

## Roles

- Admin: can add data sources, edit alert channels and rules, see every domain in the tenant.
- Viewer: read-only across the tenant's data.

The role is stored on the `users` row and reflected into Bunyip's user record. Changing it in one place updates the other on next sign-in.

## Organizations

Within a tenant, the Organizations screen groups domains by customer. Creating an org is a bunyip-federated action when `MOKOSH_API_URL` is set and the sync status is `Synced` or `Stale`; otherwise a local-create form is offered. See [Features: Organizations](/docs/drillmark/features/organizations).

## Turning multi-tenant on

Phase 2 (self-service multi-tenant SaaS) is on the internal roadmap but not part of this release. Treat `FEATURE_LOCAL_USER_MANAGEMENT=true` as a preview path: supported but not where the UI effort is going.
