14 Tenants and memberships
A tenant is a boundary for sessions, for example an organization or a customer. It is not a role system. Its tables
are the feature tenants (10).
Tenant
| Column | Content |
|---|---|
id | 16 random bytes |
name | The tag in a host name or a path: ^[a-z0-9](https://github.com/audiochad/auth-chad/blob/main/spec/[a-z0-9-]{0,30}[a-z0-9])?$, unique |
created | Time |
The root tenant (01) has no row and no memberships. The HTTP layer refuses a name whose tenant host would be a configured origin.
Tenant names are not secret: a host or a path shows that a tenant exists. What a refusal does not show is whether a person may enter it.
Membership
A membership says who may enter a tenant. The library owns four columns: tenant, user, state (active or
suspended) and version. The application MAY add its own columns, for example a role. Each one MUST have a default in
the database, because the library inserts only its own columns. The application can set them in the same transaction.
- Memberships are in the same database as users, so that one commit can end a membership and everything that it allowed.
- The library reads the application’s columns with each request in a tenant, and hands them to the handler. It does not use them.
- An unknown tenant, and a tenant that the user may not enter, give the same refusal:
not_found.
The rule
A session, token, device, grant or API key in a tenant needs an active membership of its user:
- when it is made: the commit has a precondition on the membership row;
- with each request: a membership that is gone or suspended refuses the request, also if a row was left behind.
Machines act as themselves (07), so rule 2 does not apply to them.
Entering
A login makes a root session: a session in the root tenant. A user enters a tenant with it.
- Entering makes a session in the tenant with the root session as
parent. It has the passkey of the root session, and its end is not later. Its proof time is the later of its own and the root session’s, so a fresh login at the login origin counts in every tenant. - Use of a session in a tenant renews its root session too.
- The root session MUST be the user’s own: not a view, not a session in a tenant.
- Ending the root session ends its sessions in tenants in the same commit.
- A session in a tenant is valid only while its root session is valid.
On the tenant’s own host
A cookie belongs to one host. A tenant at <name>.<parent> therefore gets its session with a code:
- The tenant’s host makes a verifier (256 random bits) and keeps it in its own cookie
__Host-enter,SameSite=Lax, at most 5 minutes. It sends the browser to the login origin withchallenge= SHA-256 of the verifier. - The login origin needs the root session. It makes a code: 256 random bits, stored as a hash, single use, 60 seconds, for one tenant, with the root session and the challenge. It sends the browser back to the tenant’s host.
- The tenant’s host sends the code and the verifier. A wrong verifier, another tenant, or a used or late code gives
invalid_grant. A root session that ended givesunauthenticated, and a membership that ended givesnot_found.
These two GET requests change state, as in the authorization code flow of OAuth. A code alone opens nothing: the
verifier is in a cookie of the tenant’s host only. The address to return to MUST be a path on the same host: it starts with one /, and has only printable ASCII
without \.
Key-bound clients enter at the login origin with their root token and a proof by the same key. A key-bound token renews in its own tenant, at any path.
Ending
| Action | Ends in the tenant, in the same commit |
|---|---|
| Suspend | Sessions with their tokens, the user’s devices with their tokens, connected-app grants and their codes, API keys |
| End | The same, and the membership row |
| Remove the tenant | The same for each member, the invites of the tenant, and the tenant row |
Resuming a membership opens nothing: the user enters again.
Invites
An invite belongs to one tenant (05).
- A signup with an invite of a tenant makes the user a member in the same commit. The signup opens a root session. Without an invite of that tenant, a signup in a tenant is closed.
- A user with an account accepts an invite of a tenant: the invite is used and the membership is made in one commit. An
invite for another identifier is refused, and a second membership is
taken.
Requests
An application names the tenant of a request in one way, set when it starts:
| Way | Tenant | Session cookie |
|---|---|---|
| None | Root only | __Host-session |
| Host | <name>.<parent>. The hosts of the configured origins are the root tenant | __Host-session on each host |
| Path | <prefix><name>/… on the login origin | __Host-session-<name> |
- With hosts, each tenant has its own web origin. A
DPoPproof names the tenant’s host, and a request that changes state accepts the tenant’s own origin. - With paths, all tenants share one web origin. A script flaw in one tenant reaches the sessions of all open tenants. Browsers limit the number of cookies of a host: keep the open tenants of a person below 20†.
Accounts, sessions, recovery, invites and members are managed at the login origin with the root session. The application decides who may manage members, often from its own columns. The commit then has a precondition on the manager’s own membership row, so a manager who is suspended meanwhile cannot finish.