Roles & permissions (dynamic RBAC)
Tenant admins compose custom roles from a curated set of permissions and assign them to users in their workspace. A user's effective permissions are the union of their platform role and every custom role assigned to them; the server re-checks every permission on every request — including sessions that are already open: a platform-role downgrade or a custom-role change is enforced on that session's very next request (the session stays signed in with the reduced set; nothing needs to be re-issued). These endpoints and the SPA's role editor are a convenience layer, never the authorization boundary.
All routes below require the ROLE_MANAGE permission and are tenant-scoped to the caller's own
workspace — the acting tenant is taken from the authenticated session, never from the request body
or URL. A caller with no tenant is refused (403 { "error": "forbidden", "code": "caller_has_no_tenant" }) on every route except the
permission catalog. A body that is a JSON scalar, array or null is 400 { "error": "invalid request body", "code": "invalid_body" } and nothing is written; an absent body is treated as an empty object, so the route's own <field>_required answers instead.
Every refusal below carries a stable top-level code next to the unchanged error text and status — key off code, not the prose (the full list is in Typed codes on the org admin routes). The one exception is the plain 404 { "error": "not found" } for an unknown, foreign or system role or user, which stays uncoded, as does a storage fault (5xx).
Two role classes exist:
- Custom roles (
origin: "user") — created and edited here, scoped to the tenant. - System roles (
origin: "system") — Myra-curated, global, read-only through this API and not assignable in this release (listed for reference only).
Delegation & fences (what is rejected)
Every write is validated fail-closed before any database change:
| Rule | Rejection |
|---|---|
| You may only grant a permission you hold yourself (subset-gate) | 403 { "error": "cannot grant a permission you do not hold", "code": "permission_not_held", "key": … } |
A cross-tenant / platform permission, or a non-delegable one (SSO_MANAGE, MCP_TENANT_MANAGE: they can take over sign-in or the chat bridge), may never sit on a custom role; checked before the subset-gate, so even a tenant_admin gets this 400, not a 403 |
400 { "error": "permission not grantable on a tenant role", "code": "permission_not_grantable", "key": … } |
| An unknown permission key | 400 { "error": "unknown permission", "code": "invalid_permissions", "key": … } |
permissions not a JSON array / a key not a string |
400 invalid_permissions |
| more than 200 keys | 400 too_many_permissions |
PUT /roles/{id}/permissions with the permissions key absent → 400 permissions_required; null or not an array → 400 invalid_permissions |
Nothing changes either way. To remove every grant send an explicit empty array []. |
name absent, null, "" or with nothing visible |
400 { "code": "name_required" } |
name present but not a string, containing a control character (C0 or DEL), not valid UTF-8, or longer than 80 characters (code points, not bytes) |
400 with code invalid_name (non-string, control character or invalid UTF-8) / name_too_long |
description present but not a string, not valid UTF-8, or longer than 255 characters |
400 with code invalid_description (non-string or invalid UTF-8) / description_too_long (rejected, never truncated). Absent, null and "" all mean "no description" |
| A role name already used in the tenant | 409 role_name_taken |
| Assigning a role that grants a permission you do not hold | 403 permission_not_held (delegation — prevents escalating the target past yourself) |
| Unassigning a role that grants a permission you do not hold | 403 permission_not_held (same delegation check as assigning) |
| Assigning a system role | 400 { "error": "system roles are not assignable", "code": "system_role_not_assignable" } |
Assignment routes additionally pass through the same access check as other per-user admin routes: a tenant admin cannot touch a platform admin's roles or reach across tenants (rank guard).
These fences are enforced again at the storage boundary independent of the client — a role can never carry a platform-class or non-catalog permission even if the API validation were bypassed.
Storage faults. A failed database read on any role route (list, read, a user's roles, and
the role lookup before a delete or an assignment) answers 503 { "error": "temporarily unavailable; retry later" } (nothing written; retry). A failed
write (create, rename, recompose, delete, assign, unassign) answers the sanitised 500 { "error":
"internal error", "request_id": "…" } unless nothing was written. Neither carries the database's own
error text (see
Storage faults).
Listing the permission catalog
GET /admin/v1/roles/permissions
Returns the tenant-grantable catalog grouped by module (the role editor's tabs). Platform-class
(cross-tenant) permissions are not included. Each entry carries held — whether the calling
admin holds it — so the editor renders a permission the admin lacks as disabled.
{ "modules": { "gateways": [ { "key": "GATEWAYS_MANAGE", "label": "Manage gateways and routing", "held": true } ], "…": [] } }
The tenant module
| Key | Label | Held by default | What it allows |
|---|---|---|---|
TENANT_AUDIT_VIEW |
View the tenant audit log | admin, tenant_admin |
Read and export the workspace's own audit trail (GET /admin/v1/tenants/{id}/audit and /audit/export). Myra staff actions are shown as a pseudonym only — see Tenant audit log. Tenant-scoped, so a tenant admin can grant it to a custom role (subject to the subset-gate). |
The billing module
| Key | Label | Held by default | What it allows |
|---|---|---|---|
BILLING_SETTINGS_MANAGE |
Manage billing settings | admin, tenant_admin, finance |
Read and change the gateway-owned billing settings (the invoice recipient) — see Finance. On a paid self-serve workspace it also shows the Invoices tab (the invoice list on GET /billing/summary, read-only — replacing the card stays with the workspace owner) — see Billing. |
BILLING_PURCHASE |
Buy plans and add budget | admin, tenant_admin (not finance) |
On a self-serve workspace: convert the free trial to a paid plan, top up the prepaid wallet and set the automatic top-up — see Billing. It does not allow the Stripe billing portal (payment method, cancellation), reactivation or removing the saved card, which stay with the workspace owner, nor the invoice list (that is Manage billing settings). A holder's top-up pays once and changes neither the saved card nor the workspace's billing address, name or tax ID. |
BUDGETS_MANAGE |
Manage spending limits | admin, tenant_admin, finance |
Set a spending limit on a person or a team: a member's personal budget cap (PUT /users/{id}/budget-cap) and a department's budget_usd / budget_period (on create and edit, including clearing it) — see Users and Departments. It does not allow any other department change (name, gateways, members: that stays Manage departments) and not the workspace budget (Manage workspace settings). A custom role that held Manage workspace settings was granted it once when this permission was introduced; a custom role holding only Manage departments no longer edits department budgets until it is given this permission. The usual rank rules apply: a holder cannot cap a user who out-ranks them, and finance (below tenant_admin) cannot change the budget of a department that a tenant admin or admin belongs to or of its own department. |
LIMIT_REQUESTS_APPROVE_DEPARTMENT |
Approve limit requests for your own department | admin, tenant_admin |
Granted through a custom role (by hand or by an identity-provider role mapping), it makes the holder their department's approver for limit requests: requests from their own department are routed to them, and they see and decide those (never their own). It grants nothing for other departments. Tenant admins hold it through their system role but already decide every request; they are not routed as department approvers. |
The billing-module permissions are tenant-scoped, so a tenant admin can grant them to a custom role (subject to the subset-gate
above). A demo account (demouser) never purchases, even when a custom role grants it
BILLING_PURCHASE. Removing the permission does not switch off an automatic top-up the holder set
up — it is a workspace setting (see Billing).
Listing roles
GET /admin/v1/roles
Returns the tenant's custom roles and the global system roles. Each row carries id,
tenant_id, name, origin, description, created_at (Unix seconds), plus grant_count and
assign_count. [] never appears as {} (array-encoded).
assign_count is scoped to the caller's own tenant and counts only active (non-deleted)
users: for a system role it is the number of your tenant's users who hold it, never a
cross-tenant total. grant_count is the role's own permission count (for system roles this is the
Myra-curated definition, identical for every tenant).
Choosing the tenant (tenant_id)
GET /admin/v1/roles?tenant_id=<tenant-uuid> — optional, and only a platform admin widens the scope with it.
With the parameter the list is the global system roles plus that tenant's custom roles (nothing of any other
tenant); the row shape is the same as without it. The SSO Mapping card uses this so a platform admin can pick any of
the acting tenant's custom roles as a role target.
- Absent: the caller's own tenant, for every role (unchanged). This is deliberately unlike
GET /admin/v1/departments, which answers400to a platform admin withouttenant_id. - Platform admin, present: the UUID is matched case-insensitively.
tenant_id=(empty) is400 tenant_id_required; a non-UUID, a repeated or a bare?tenant_idis400 invalid_tenant_id; an unknown or deleted tenant is404 tenant_not_found. A rejected value never falls back to the caller's own tenant. - Any other caller: the value is ignored and the caller stays pinned to its own tenant (never another tenant's roles).
ROLE_MANAGE is still required. sys:admin stays in the list; it is the save of a group mapping that refuses it as a
role target.
Getting one role
GET /admin/v1/roles/{id}
Returns the role and its perm_keys (a string array), alongside the same identity fields as the
list row (id, tenant_id, name, origin, description, created_at). A role in another tenant is the audited 404 (see ids of a group or role you cannot see).
Creating a custom role
POST /admin/v1/roles — body { "name": string, "description"?: string, "permissions"?: string[] }
On success 201 { "id": "<role-id>" }. name is 1–80 characters and description at most 255 characters; a rejected value answers 400 with a stable code (see the fences table). permissions is optional (an empty role is valid). See the
fences table for every rejection.
Renaming / re-describing a custom role
PATCH /admin/v1/roles/{id} — body { "name": string, "description"?: string } → 200 { "ok": true }.
An unknown, foreign, malformed or system role id is the audited 404 (ids of a group or role you cannot see); a name already used in the tenant is 409 role_name_taken. The body is validated first: a malformed body answers 400 for any id, known or not, and records no audited 404 row, so it reveals nothing about the id.
Recomposing a custom role's permissions
PUT /admin/v1/roles/{id}/permissions — body { "permissions": string[] } → 200 { "ok": true }
(an unknown, foreign, malformed or system role id is the audited 404). The body is validated first: a malformed body answers 400 (and a permission you do not hold answers 403) for any id, known or not, and records no audited 404 row, so it reveals nothing about the id. This is a
full replace: the role's grants become exactly the supplied set. Every supplied key is
subset-gated against the actor's held permissions fail-closed: if any key is one the actor does
not hold, the whole request is rejected 403 { "error": "cannot grant a permission you do not
hold", "key": … } and nothing changes — it does not silently strip. Consequently a role
that already carries a permission you do not hold cannot be recomposed by you (any PUT you send
must re-list that key, which 403s); it can still be renamed (PATCH), but changing its
permissions requires an admin who holds the full set. The SPA editor reflects this: it detects such
a role up front, locks the permission editor, and offers rename only.
Deleting a custom role
DELETE /admin/v1/roles/{id} → 200. The role's grants and all its user assignments are removed
with it. System roles cannot be deleted (404); the role is resolved (tenant-fenced) before
anything else, so a system or foreign id is the audited 404 (ids of a group or role you cannot see) and never reveals how many users hold it. A role that vanishes between that check and the delete (a delete race on a role you could see) stays a plain 404 and is not recorded.
Refused while a holder is out of your reach. Deleting a role changes the effective permissions of everyone who holds it, so it is allowed only if you could also unassign it from each holder under the same rank guard the assignment routes use (a tenant admin cannot reach a platform admin of the same tenant). Otherwise:
409 { "error": "role is assigned to a user you cannot manage",
"code": "role_held_by_unreachable_user", "count": 1 }
and nothing changes — the check and the delete run in one transaction (the holder rows are
locked, so an assignment landing concurrently cannot slip past the check). count is the number of
holders you cannot manage, deactivated accounts included (a deactivated user regains the role
on restore), so it can exceed the list's active-only assign_count. A row whose user was moved to
another tenant is permission-inert and outside the tenant fence; it is cascaded silently.
The SPA (Custom roles → delete) asks a one-click confirmation for a role nobody holds and a
typed confirmation (the role name) naming the active holder count for a held role; a 409
surfaces as an error toast with count.
Audit trail
Every successful role mutation writes an audit-log row, and the change
and its row are one transaction: either both are stored or neither is. A refused request writes
none (a 403 grant-above-own is recorded as access.denied). If a lock is held for longer than
5 seconds or the change conflicts with a concurrent one, the route answers 503
{ "error": "temporarily unavailable; retry later" } and nothing was written; retry. If the audit row
is refused or the outcome is unknown, the route answers a sanitised 500 (no database detail); check
the role before retrying.
role.created (after {name, description, perm_keys}), role.updated (before / after
{name, description}), role.permissions_changed (before / after {perm_keys}, sorted) and
role.deleted (before {name, perm_keys}) have the role as entity; role.assigned (after
{role_id, role_name}, only when a row was actually inserted) and role.unassigned (before
{role_id}) have the user as entity. The actor is the caller; under "View as User" it is the
impersonating admin, with after.impersonated_user_id naming the viewed user.
A user's roles
GET /admin/v1/users/{user_id}/roles — the roles assigned to a user (custom + any system role),
for the assignment UI. Each row: id, name, origin (system | user), description (string or
null) and assigned_at — when the role was assigned, unix seconds (the user page's
Custom roles card shows it as "‹role› · assigned ‹date›"). The UI treats a missing or non-numeric
assigned_at as "no date" and shows the role name alone.
Assigning / unassigning a role
PUT /admin/v1/users/{user_id}/roles/{role_id} → 200 — assign a custom role to a user in the
tenant (idempotent). Subject to the delegation and rank-guard rules above; system roles are 400.
An unknown, foreign or malformed role id is the audited 404; a user outside the tenant is 404. A role that grants a permission you do
not hold is 403 { "error": "cannot assign a role granting a permission you do not hold", "key": … }.
DELETE /admin/v1/users/{user_id}/roles/{role_id} → 200 — remove the assignment. An assignment that does not exist is 404 (a plain one, not recorded).
Unassigning follows the same delegation rule as assigning: a role that grants a permission you do not hold is
403 { "error": "cannot unassign a role granting a permission you do not hold", "key": … } and nothing is
removed or audited. An unknown, foreign or malformed role id is the audited 404; a system role is 400.