Core concepts
masks signs people and machines in to apps. The rest of the docs use six ideas to describe how:
- Tenants: separate spaces, each with its own accounts and apps.
- Actors: the accounts that sign in.
- Clients: the apps that use masks to sign actors in.
- Scopes: names for what a token may do.
- Namespaces: scope prefixes that an app claims for its own scopes.
- Signing keys: the keys that prove a token came from masks.
Tenants
Section titled “Tenants”A tenant is a subdomain with its own actors, clients, and signing keys. A subdomain is the first
part of a web address, such as demo in demo.auth.example.com.
No record belongs to more than one tenant. See tenant isolation for how masks keeps tenants apart.
Declaring tenants
Section titled “Declaring tenants”A server declares its tenants in one of three ways. Setting both MASKS_TENANT and MASKS_TENANTS
is an error.
| Declared by | Which tenant a request goes to | |
|---|---|---|
| Single | MASKS_TENANT=acme |
Always acme. |
| Multi | MASKS_TENANTS=demo,acme |
The first label of the hostname. demo.auth.example.com is demo. |
| Dynamic | Neither set | The first label of the hostname. masks creates the tenant the first time it sees that name. |
- With Single and Multi,
bin/rails masks:tenantscreates the tenants. The container image runs it on every boot. - The container image declares a Single tenant,
masks, when neither is set andMASKS_PUBLIC_ORIGIN_TEMPLATEhas no%{subdomain}. - In every mode, masks answers only the hostnames that
MASKS_PUBLIC_ORIGIN_TEMPLATEnames, and the tenants’ custom domains. Any other hostname gets a 404 with the bodyno tenant is served at this hostname. - Without the template, each tenant answers only at the address its Set up screen was opened at. See the public address.
With Dynamic, the template decides how many tenants masks creates:
MASKS_PUBLIC_ORIGIN_TEMPLATE |
What masks does with a new hostname |
|---|---|
Has %{subdomain}, such as https://%{subdomain}.auth.example.com |
Creates a tenant for every new subdomain. The rate limits cap how many it creates each hour. |
Has no %{subdomain}, such as https://auth.example.com |
Creates one tenant, on the first request to an empty database. |
Setting a tenant up
Section titled “Setting a tenant up”Each new tenant has a setup token. masks prints it in the server’s logs when it creates the tenant.
bin/rails masks:tenants prints it again each time it runs, until the tenant is set up:
masks: demo is not set up. Its setup token is 7Hq2…- Each tenant has its own token. masks stores it encrypted and deletes it once the first account exists.
MASKS_SETUP_TOKENreplaces every generated token with one token. Outside development, it must be at least 24 characters long.
The first visit to a tenant shows the Set up screen. Only someone who can read the logs can get past it. The screen asks for:
- The setup token, a nickname, and an email address.
- A password or a passkey. masks creates the first account at this step, and the account holds
masks:manage. - A second factor, such as an authenticator app. A passkey counts as both factors, so this step is skipped after one.
- The server’s name, under This server is called. Finish setting up saves it.
The screen does not appear again.
Tenant settings
Section titled “Tenant settings”A manager changes a tenant’s settings in /manage, under Settings,
without a restart. An environment variable can pin some of them for every tenant, and then
/manage cannot change them. See environment variables.
A tenant with no mail service of its own uses the server’s SMTP settings, MASKS_SMTP_ADDRESS and
MASKS_MAIL_FROM. With neither, a manager passes each invitation and password reset link along by
hand.
Actors
Section titled “Actors”An actor is an account. It has a nickname, an email address, or both, and a list of scopes. An empty list means the standard scopes.
What names an account
Section titled “What names an account”The tenant’s Primary identifier decides which field every account needs. MASKS_NAMED_BY pins
it.
| Primary identifier | |
|---|---|
| Nickname | Every account needs a nickname. |
| Every account needs an email address. | |
| Either | Either one is enough. This is the default. |
- An account that holds any manage role needs both, because invitations and password resets go to managers.
- A person signs in with either field.
- Introspection is how a resource server, an app that accepts tokens from masks, asks masks about a
token. Its
usernameis the nickname when there is one, and the email address when there is not.
See signing in for passwords, passkeys, and second factors.
Clients
Section titled “Clients”A client is an app that starts sign-ins, or that signs in as itself. A client holds:
- its redirect URIs, the addresses masks sends an actor back to after sign-in
- the resources it acts for
- the scopes it may request
See clients to register and set up a client.
Scopes
Section titled “Scopes”A scope is a string that names something a token may do. masks reserves the masks: prefix.
Seven scopes are standard: openid, profile, email, offline_access, identities,
organization, and
groups.
The masks: scopes are:
| Scope | Lets a token |
|---|---|
masks:manage |
Use /manage and the GraphQL API behind it. |
masks:manage:read, masks:manage:support, masks:manage:security |
Use the narrower manage roles. |
masks:handshake |
Connect an app to this tenant. |
masks:scim |
Provision people over SCIM. |
masks:signals |
Receive shared signals. |
masks:delegate:<provider> |
Use an actor’s account at a provider. |
Only an approved client may hold a masks: scope.
Prefixes
Section titled “Prefixes”A scope that ends in a colon is a prefix. An app claims a prefix as a namespace.
- A prefix covers every scope that starts with it.
things:coversthings:read. - No scope covers a bare prefix, so a token never holds
things:itself.
The ceiling
Section titled “The ceiling”A token holds the requested scopes that are in the actor’s list. It can also hold groups and any
masks:delegate: scope, whatever the actor’s list says.
These rules limit what a client may ask for:
- A request that names a scope the client may not request is refused whole, with
invalid_scope. masks issues nothing. - A self-registered client follows the tenant’s Dynamic registration setting:
- With On, it may ask for any scope except a
masks:scope or a prefix. - With On, limited to these scopes, it may ask only for the scopes chosen there. With none chosen, it may ask for the standard scopes. This holds even for a scope that a resource server offers.
- With On, it may ask for any scope except a
A refresh keeps the refresh token’s scopes or fewer. It drops any scope that the client or the actor no longer holds.
The manage API checks the actor’s list on every request, so losing a manage role takes effect at once.
Namespaces
Section titled “Namespaces”A namespace lets an app publish its own scopes. An app that needs scopes such as things:read
claims the prefix things: once. It can then publish any scope under that prefix without
registering each one.
Claiming
Section titled “Claiming”An app claims a namespace through a handshake that asks for a prefix. A handshake is the request an app makes to connect to a tenant.
- Only someone who holds
masks:managecan approve a handshake that asks for a prefix. - masks adds the prefix to the approver’s scopes.
- Each name belongs to one resource. If a handshake asks for a prefix that overlaps one another resource holds, masks refuses it before the approval screen. The refusal names that resource.
Releasing
Section titled “Releasing”A claim stays after its client is archived. To free the name:
- Archive the client that holds it.
- In
/manage, open Settings, then the General tab, and choose Release beside the namespace.
After a release, the scopes under the name mean something else to the next app that claims it.
Signing keys
Section titled “Signing keys”Every tenant has its own RSA key pair. RSA is a kind of key with two parts. The private part signs tokens, and the public part checks them.
- masks encrypts the private key when it stores it.
- The public key is published at the tenant’s JWKS endpoint,
/.well-known/jwks.json, where apps fetch its keys. It is also in the tenant’s SAML metadata. - A token from one tenant has a
kid(key ID) that no other tenant publishes, so it fails verification everywhere else.
A key moves through four states:
| State | |
|---|---|
staged |
Published at JWKS. Signing nothing yet. |
active |
Signing every new token. |
retiring |
No longer signing. Still published, so tokens it signed still check. |
retired |
Removed from JWKS. |