Authorization
The full reference for feature 003's authorization model
(packages/core/src/access/) — organisations, the role matrix, scopes,
external access (shares), the evaluator, revocation, MFA and sessions. For
the one-paragraph summary and where this fits in the request pipeline, see
Architecture overview → Authentication and
authorization and
→ Authorization model
— this page expands on both without repeating them; the ceiling table for
shares lives on Shares
and isn't duplicated here either.
:::caution Code-complete, not yet captured against a real deployment
Every mechanism on this page (packages/core/src/access/*.ts,
packages/api/src/http/context.ts) is landed and unit-tested as of
2026-10-03. The organisation-scoped routes that exercise it
(Team & Access, Invitations,
Shares, Access requests,
Access-change log) are code/synth-verified only —
not yet captured against a running dev stack.
Role-model redesign under review (2026-10-28): the owner is reviewing a redesign (five roles, no org switching). It is not implemented; this page describes the code as it is. :::
Organisations
Four kinds: PLATFORM (Crown HQ — one per account, can act on any org),
OPERATOR (owns plants), PARTNER and CUSTOMER (related to an operator
via a relationship or a share, never owning plants directly). A personal
organisation (personal: true) is a CUSTOMER-kind org created lazily and
idempotently the first time a legacy-mobile account (one holding a plant
OWNER membership with no org context) is seen by a 003-aware route — see
GET /v1/me's own
"idempotent provisioning" note. A personal organisation is exempt from the
MFA-requirement rules below (it's one person, nobody to protect from
another).
Roles and the permission matrix
Levels (cumulative, weakest to strongest): NONE < VIEW < EDIT < MANAGE < FULL. Categories (15, fixed): plants, devices, alerts, commands, firmware, service, reports, customers, team, settings, registersRead, registersWrite, sharing, roles, audit. The last five were added by ADR 0014;
see Roles & permissions for what each gates and how a
10-key map is completed.
The five product roles (2026-11-03; End User role added 2026-11-06, ADR 0021). Super Admin, Administrator ("Admin"), Business and End User are the 4 system roles; Installer is the one seeded template. End Users hold the End User role as the owner of their personal org, or as an invited member of a Business org; shares and portals still work for access outside the org. See Five product roles.
The 4 system roles are code constants (packages/core/src/access/system-roles.ts)
— identical in every organisation, never stored as an
ORG#<o>/ROLE#<roleId> item, fixed ULIDs that never change. Only their perms can change: a Super Admin may edit
Administrator, Business or End User from the PLATFORM org, for every organisation (see
Phase 2b); Super Admin itself is never editable.
Viewer (R-06) is retired: GET …/roles no longer lists it, and assigning, inviting with or copying it is
422 VALIDATION_FAILED (details.reason: "ROLE_RETIRED"). A membership or invitation already holding it keeps its
old Viewer levels. The seeded template (Installer) starts as an editable copy per organisation
(createOrganization() mints a fresh id per org and records which template it copied). New orgs no longer get the
old Operations Manager, Technician, Sales or Compliance Auditor templates; copies made earlier stay until the RBAC
backfill deletes the unused ones (Operations). A caller can
rename them or change their perms/scopeRule/auditTrail after that
(PATCH /v1/orgs/{orgId}/roles/{roleId}, roles ≥ MANAGE required (was team = FULL before ADR 0014) — see
Team & Access). A role whose scope rule is ALL (Super
Admin, Administrator, Compliance Auditor) always has scope ALL for every
holder (Business too); the other SCOPED roles are scoped per member (see
Scopes below).
| Role | Code | plants | devices | alerts | commands | firmware | service | reports | customers | team | settings | registersRead | registersWrite | sharing | roles | audit | scopeRule | auditTrail |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Super Admin (system) | R-01 | FULL | FULL | FULL | FULL | FULL | FULL | FULL | FULL | FULL | FULL | FULL | FULL | FULL | FULL | FULL | ALL | yes |
| Administrator (system) | R-02 | FULL | FULL | FULL | MANAGE | FULL | FULL | FULL | FULL | MANAGE | MANAGE | FULL | MANAGE | FULL | MANAGE | MANAGE | ALL | no |
| Business (system, ADR 0014) | R-90 | MANAGE | MANAGE | MANAGE | MANAGE | NONE | MANAGE | MANAGE | MANAGE | MANAGE | MANAGE | VIEW | MANAGE | MANAGE | MANAGE | VIEW | ALL | no |
| Installer (template, ADR 0014; IO-9 2026-11-06) | R-91 | EDIT | MANAGE | MANAGE | EDIT | NONE | EDIT | MANAGE | VIEW | NONE | NONE | VIEW | EDIT | MANAGE | NONE | NONE | SCOPED | no |
| End User (system, ADR 0021) | R-92 | MANAGE | MANAGE | MANAGE | EDIT | NONE | NONE | VIEW | NONE | NONE | NONE | VIEW | EDIT | MANAGE | NONE | NONE | SCOPED | no |
Changed 2026-11-03: Administrator settings and roles are MANAGE (were EDIT and VIEW), so an Admin holds at
least every Business level and can assign the Business role and create Businesses through the normal escalation
check. This applies to every Administrator membership, including personal-org and customer/partner-org owners, who
can now create and edit custom roles in their own org. The Installer template starts at sharing: MANAGE (was
NONE; lowered to VIEW on 2026-11-23, RBAC-S6; MANAGE again since 2026-11-26, owner), so a new Installer can share their plants and answer access requests at once, and at plants: EDIT (was
VIEW), so they can register plants (which are then assigned to them) and edit the plants they reach.
Changed 2026-11-06 (IO-9, ADR 0021): the Installer template defaults rise to the bold cells above. The RBAC backfill raises existing copies and never lowers them. The new End User role is the owner role of every personal org (it was Administrator, so personal-org owners could invite people; the backfill moves existing owners) and the role a Business or Installer invites End Users with.
Changed 2026-11-12/13 (console request; ADR 0026): Installer reports is MANAGE (was EDIT) and plants is
EDIT (was MANAGE, so Installers never archive or delete); End User service is NONE (was EDIT);
Administrator firmware is FULL (was VIEW). These are the stored levels. The levels a user actually gets also
pass through the RBAC v2 membership rules: an Administrator outside the Crown org
keeps firmware: VIEW, an Installer in a Business reaches every plant of it (scope ALL), and a connected End User
gets plants: VIEW, devices: VIEW, alerts: EDIT, sharing: VIEW (since 2026-11-23, RBAC-S10/S12/S6; plants was
EDIT) and, while remote control is off, commands and registersWrite at NONE.
Retired, still resolvable for stored data (no longer listed, assigned or seeded):
| Role | Code | plants | devices | alerts | commands | firmware | service | reports | customers | team | settings | registersRead | registersWrite | sharing | roles | audit | scopeRule | auditTrail |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Viewer (system, retired) | R-06 | VIEW | VIEW | VIEW | NONE | NONE | VIEW | VIEW | NONE | NONE | NONE | VIEW | NONE | NONE | NONE | NONE | SCOPED | no |
| Operations Manager (old template) | R-03 | EDIT | EDIT | MANAGE | EDIT | NONE | MANAGE | MANAGE | VIEW | VIEW | NONE | EDIT | EDIT | VIEW | VIEW | VIEW | SCOPED | no |
| Technician (old template) | R-04 | VIEW | VIEW | EDIT | VIEW | NONE | EDIT | VIEW | NONE | NONE | NONE | VIEW | VIEW | NONE | NONE | NONE | SCOPED | no |
| Sales (old template) | R-05 | VIEW | NONE | NONE | NONE | NONE | VIEW | EDIT | MANAGE | NONE | NONE | NONE | NONE | MANAGE | NONE | NONE | SCOPED | no |
| Compliance Auditor (old template) | R-07 | VIEW | VIEW | VIEW | VIEW | VIEW | VIEW | MANAGE | VIEW | VIEW | NONE | VIEW | VIEW | VIEW | VIEW | VIEW | ALL | yes |
Codes R-03 to R-07 are never reused for new custom roles.
auditTrail: true (Super Admin, Compliance Auditor) is a flag on the role
record itself — every 003 write already appends an access-change log entry
regardless of the ACTING caller's role (see Access-change
log); this flag doesn't change that, it's reserved
for a future per-role audit-emphasis UI treatment, not a second logging
path.
⚠ commands on Technician is a known design discrepancy
(07-security.md §3.1, OQ-04): the design intent allows a restart at
commands = VIEW, not reflected in code — the matrix above is the exact,
as-shipped values, not the aspirational ones.
Super Admin identity vs. level (R-0, 2026-11-03): Super Admin is the built-in Super Admin role (fixed
roleId 01M3W3PECH5YVC8ZC80P17ZEX9, code R-01) in an ACTIVE membership — never "FULL in every category". A custom or
built-in role edited to FULL everywhere is still not a Super Admin: it gets no bypass, cannot edit built-in roles,
cannot assign Super Admin, and does not get the role.superadmin.assign capability. Every check that needs Super
Admin uses isSuperAdminOf(facts, orgId), which is also true when a Super Admin acts in another org through the
platform fallback. A Super Admin:
- skips the anti-escalation checks (FR-031, below) on roles, members and invitations, and already holds FULL on every share, portal and access-request check;
- may set any role, built-in (Administrator, Business) or custom, to any level, FULL everywhere included;
- may create standing access (members, shares, invitations, access-request approvals) inside a personal org reached
through the platform fallback, which is refused for an Admin (
403 PLATFORM_PERSONAL_ORG).
Authentication, MFA, body validation (422) and access-log entries (including PLATFORM_ACCESS) still apply. Only a
Super Admin assigns or removes Super Admin, and the last active Super Admin cannot be demoted.
Anti-escalation (FR-031)
A caller can never grant (via PATCH .../members/{sub}, role create/patch,
or a share) a level higher than their OWN current level in that category —
checked server-side (assertCanGrantLevel/wouldEscalate), never trusted
from the client. Violating it is 403 FORBIDDEN, details.reason: "ESCALATION" — the one FORBIDDEN variant that carries a details object
on this API. A Super Admin actor is exempt (see above).
Scopes
Scope controls which plants a role's levels apply to, independent of the levels themselves. Exactly one kind per membership:
| Kind | Meaning | Cap | Who may use it |
|---|---|---|---|
ALL | Every plant the org operates (or every plant on the platform) | — | Every org kind |
REGION / TAG | Plants carrying one of N target tags | ≤ 10 targets | Operator only |
CUSTOMER | Plants belonging to one of N related customer orgs | ≤ 10 targets | Operator only |
PLANTS | Explicit plant ids | ≤ 500 ids | Every org kind |
NONE | No plants | — | Every org kind |
A partner or customer organisation may only use ALL, PLANTS or NONE
(relative to the plants already shared with or owned by it) — REGION,
TAG and CUSTOMER scopes only make sense for an operator, who has a whole
fleet to slice. The platform organisation may only use ALL or NONE — a
platform member either sees everything or nothing, never a slice. Exceeding
a kind's cap is 422 LIMIT_EXCEEDED, details.field: "scope.targets".
GET /v1/orgs/{orgId}/scopes/summary (Team & Access) is
the "who is authorized where" screen built on top of this — per-kind counts
plus a paged member list, both facet-counter-backed (eventually consistent,
same caveat as every other summary tile on this site).
External access (shares)
A share grants a plant selector to an organisation, an individual user, or
(via a portal relationship) a whole customer organisation, at one of 5
external levels (VIEW < MONITOR < EDIT < SERVICE < FULL — a separate
scale from the role levels above), each mapping to a fixed per-category
ceiling. Full mechanics, the ceiling table, "no re-sharing", and command
risk gating are all on Shares — this page only notes
where shares fit into the evaluator below. A share or customer portal may also carry a per-category limit (permsLimit / portalPermsLimit, ADR 0014 phase 2a) that lowers the ceiling as min(tier ceiling, limit). Access
requests (B15) are the other direction: a
grantee org asking the operator for a share, rather than the operator
initiating one.
The evaluator
effectiveAccess(facts, plant) (packages/core/src/access/evaluator.ts)
is the ONE place every access decision on this API is made — see
Architecture overview → Authorization
model for its
core description (max over paths of min(role level, ceiling), pure,
nothing cached). Two details worth adding here:
- Command risk ceiling. A path through a share additionally caps command
execution risk, independent of the
commandscategory level itself: aSERVICE-level share caps risk atLOW(restart, read config only), aFULL-level share atMEDIUM(adds export limits) — and aplatformOnly-flagged command is never reachable through a share at any level, regardless of risk. A role-based path (no share involved) is never risk-capped by this mechanism. - Redaction flags. An external
VIEW/MONITOR-level path (a share or a customer-portal relationship at one of those two ceilings) sets redaction flags hiding device serials and engineering data in the response — UNLESS a role-based path independently grants that same category at the same or a higher level, in which case nothing is redacted. This is why two callers with the apparently "same"devices: VIEWcan see different amounts of detail: one path'sVIEWcame from a share (redacted), the other's from their own role (not redacted).
Compatibility with the legacy mobile model
See Architecture overview →
Compatibility
— OWNER/ADMIN/VIEWER legacy plant memberships are read as a
compatibility path (FULL/EDIT/VIEW ceilings respectively) alongside
everything on this page, not replaced by it. See also
KI-12 (closed): the legacy model's lack of an
ADMIN/VIEWER-granting endpoint is no longer a gap — this page's
roles/scopes/shares are the real graduated-access mechanism now.
Assigned Installer path (R-5, 2026-11-03)
A Business member's assigned plants (POST /v1/plants/{plantId}/installer, or auto-assigned when they register a
plant on a custom role) count as inside their scope, at their own role levels. The evaluator, the plant list,
realtime tickets and alert audiences all apply it. It adds nothing for End Users. See
Plants → Assigned Installer.
Crown platform fallback (Q15)
Owner decision Q15 (2026-10-27). On org-level checks (requireOrgLevel in
packages/api/src/http/authorize.ts, and orgLevels in
packages/core/src/access/evaluator.ts so core re-checks agree), a Crown
PLATFORM member can act in another organisation without a membership
there. All of these must hold (platformOrgFallback):
-
the caller has no membership row at all in the target org (a SUSPENDED or REMOVED own membership is never bypassed; an ACTIVE own membership always wins, even if the platform role is higher);
-
the caller holds an ACTIVE,
ALL-scoped membership in a non-suspended PLATFORM org; -
the target org exists and is ACTIVE, and not itself PLATFORM. Personal orgs (Independent End Users) are included since 2026-11-02 (owner decision, RBAC policy §4.1/§4.7): Super Admin and Admin can open them too, at their own levels, MFA-gated, and every change is written to that account's access log.
An Admin can not create standing access there (revalidation 2026-11-03): invitations (create, edit), member role/scope changes, shares (create, edit) and access-request approval return
403 FORBIDDEN,details.reason: "PLATFORM_PERSONAL_ORG". Viewing and other edits work. An own membership in that org is not the fallback and is not refused. A Super Admin is never refused (R-0, owner 2026-11-03).
The grant is the platform role's own per-area levels — a read-only platform role stays read-only. Outcomes:
| Situation | Result |
|---|---|
| Eligible, level high enough | Allowed |
| Eligible, level too low for the area | 403 FORBIDDEN |
| Not eligible (any condition above fails) | 404 NOT_FOUND, as before |
Cost: one extra GetItem on the target org's META, made by
resolveRequestContext only for a platform caller who selected an org they
hold no membership in. The common path reads nothing extra.
Audit: every state-changing request decided through the fallback (refused
ones included) writes one PLATFORM_ACCESS entry with viaPlatform: true to
the target org's access log (reads are not logged, except reading or
downloading another org's report, since 2026-11-26) — see Access log →
PLATFORM_ACCESS.
The same audit covers every other place platform staff act in an org they
are not a member of: plant routes (logged to the plant's operator org),
roster/technicians/maintenance plans, work orders, reports, device binding
at plant create, lookups, plant jobs and member actions. changes.checks
lists the decisions (for example service:MANAGE, plant). Platform
access everywhere (reports, plant jobs and lookups included) requires an
ACTIVE, ALL-scoped membership in a non-suspended PLATFORM org.
Revocation
Three independent mechanisms, triggered by different actions, all converging on the evaluator re-running fresh on the caller's very next request (never cached, never requiring the token itself to change):
- Session revocation (
tokensValidAfter, FR-038, CR-18). Suspending or removing a member, or an explicit "end sessions" action (POST .../members/{sub}:end-sessions, Team & Access), stampstokensValidAfter(now) onto the membership (and, for account-wide actions, the profile). EveryresolveRequestContextcall compares the token'sauth_time— the moment of original sign-in, never a refreshediat— against this watermark; a token issued before it is401 SESSION_REVOKED. The FE response is the same for any401: drop the cached token, re-authenticate — a revoked session cannot be refreshed into a valid one. - Scope widening fan-out. A role's
scopeRuletransitioningSCOPED → ALL(Team & Access B08PATCH .../roles/{roleId}) doesn't revoke anything — it's a WIDENING — but it does need every ACTIVE holder's ownscopeupdated toALLso the evaluator reflects it without a per-holder write at PATCH time.packages/core/src/projections/access-revocation.ts'splanScopeWidening/applyScopeWideningdo this asynchronously off the DynamoDB stream, paged in batches — seconds, not inline with the response. Noaccess.revoked.v1event is published for this (nothing was revoked). access.revoked.v1(FR-062, the internal event bus → TCP). Published when a member is suspended/removed, a role/scope narrows (never widens — see #2), a share is suspended/narrowed/revoked, sessions are ended, or MFA is reset. Carriesscope: "ORG"(every user of that org loses access) or"USER"(one individual), the affectedplantIds/selector, and areason. This is how the realtime side (ws-gateway, TCP) learns to drop a live subscription — HTTP-side authorization itself never depends on this event; it's push notification for the OTHER backend, not a cache invalidation signal for this one.
MFA
Superseded 2026-11-11 (product decision): two-factor is the user's own choice. No organisation, org kind or role requires it —
effectiveMfaRequiredis alwaysfalse— so no route returns403 MFA_REQUIRED, whateverMFA_ENFORCEMENTis set to. The code stays reserved in the contract. The text below describes the earlier behaviour.
A membership's effective MFA requirement is on when any of: it's set
explicitly on the membership; the organisation is PLATFORM; or the role
holds FULL on any single category — personal organisations are exempt
from all three. Administrator meets the third condition (FULL on
plants/devices/alerts/service/reports/customers, not just Super Admin's
all-FULL row), so Administrators require MFA too, not only Super
Admins (confirmed reading of "any FULL level", 07-security.md §1 — not
a narrower "every category FULL" reading). Once the floor applies it can be
raised freely but never lowered below it (422).
Satisfaction: TOTP must be enrolled (profile.mfa.enabled, mirrored
from Cognito with a 15-minute staleness, lazily refreshed — see Account API
→ GET /v1/me field-sources table) and the request must
have come through a client in WEB_CONSOLE_CLIENT_IDS (SRP-only, always
TOTP-challenging). A mobile app token (CUSTOM_AUTH-capable client) never
satisfies MFA, however mfa.enabled reads — see GET /v1/me/context's
own MFA edge case.
MFA enforcement rollout (OQ-09)
Cognito's LITE feature plan issues no amr (authentication methods
reference) claim, so the token alone can't prove which method
authenticated a given session — the client-id check above is the
work-around. MFA_ENFORCEMENT (env var, every family function, set by
ApiStack from CDK context
-c mfaEnforcement=<value>) gates how strictly this is enforced:
| Value | Behavior |
|---|---|
warn (default) | Logs MFA_ENFORCEMENT=warn: request would be refused MFA_REQUIRED server-side (with orgId, mfaEnabled, clientAllowed, reason, viaPlatform) and lets the request through regardless |
on | Actually returns 403 MFA_REQUIRED when the requirement isn't satisfied |
The requirement is taken from whichever membership justified the selection:
the caller's own, or their platform membership when they act in a foreign
org (Q15). Personal organisations are exempt. A refusal carries
details.reason (OQ-09, owner 2026-10-27):
WEB_CONSOLE_SIGN_IN_REQUIRED— the token is not from a web-console client. The mobile app signs in with email OTP only and never satisfies an MFA requirement.TOTP_ENROLMENT_REQUIRED— web-console token, but no TOTP enrolled.
Beyond the org selector (review fixes, 2026-10-27). Under MFA_ENFORCEMENT=on,
403 MFA_REQUIRED (same reasons) can come from any route that acts through
an MFA-requiring membership, with or without X-Org-Id: plant routes and
PUT /v1/me/selected-plant, report get/download/delete/regenerate, schedule
get/patch/delete/pause/run, plant reports, delegated invitations, customer
change, plant jobs, service routes (roster, work orders) and device binding.
The membership that grants access decides. Exempt: individual shares, legacy
roles, personal orgs, and self routes (for example MFA enrolment). Lists,
batches and lookups hide gated items instead of failing.
A web user who has just enrolled TOTP may get one TOTP_ENROLMENT_REQUIRED
refusal before being accepted, when no org is selected: the cached MFA
mirror is re-checked against Cognito only after that refusal.
Live MFA re-check (B-4). A cached MFA true is trusted for 24 h; a
cached false is reused for 5 minutes (MFA_FALSE_MIRROR_TTL_MS,
packages/core/src/repositories/users.ts) before Cognito is asked again
(AdminGetUser, web-console tokens only). If that live re-check fails, the API
logs WARN mfa_recheck_failed and then: under MFA_ENFORCEMENT=on answers
503 DEPENDENCY_UNAVAILABLE with Retry-After: 1 (fails closed — a stale
value is never trusted while enforcing); under warn uses the cached value
(packages/api/src/http/context.ts).
In warn mode the API logs, once per org per request,
MFA_ENFORCEMENT=warn: plant access would be refused MFA_REQUIRED and
MFA_ENFORCEMENT=warn: org access would be refused MFA_REQUIRED, plus the
request-level MFA_ENFORCEMENT=warn: request would be refused MFA_REQUIRED.
Watch all three before setting -c mfaEnforcement=on.
The rollout plan (specs/003-organizations-access/plan.md) is to flip to
on only after the OQ-09 manual verification procedure
(specs/003-organizations-access/quickstart.md §6, repo-internal; a
companion dev check script, scripts/smoke/mfa-custom-auth-check.md)
confirms that CUSTOM_AUTH (email OTP) sign-in never independently
satisfies an org's MFA requirement on this Cognito plan. Until then, warn
is the safe default everywhere, observable in CloudWatch Logs Insights but
never blocking a real user. See Known issues →
KI-29 and Operations → Environment
setup for the exact context-key/env-var
names.
Sessions
"Session" here means one issued token's validity, not a server-side session
object — there is no session store. A session ends, from the API's point of
view, the moment its auth_time falls before the relevant
tokensValidAfter watermark (see Revocation above); there is
no separate "logout" endpoint that invalidates a specific token early
(Cognito's own GlobalSignOut/token revocation, triggered client-side, is
the mechanism for "this one device, right now" — orthogonal to
end-sessions, which is "every session this member currently holds,
account-wide for this org"). POST /v1/orgs/{orgId}/members/{sub}:end-sessions
is the one API-visible lever for the latter — see Team &
Access for its request/response shape.