File size: 23,129 Bytes
4e28517 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | # Workspaces and keys
Core owns who belongs to which team and what they may do there.
- An **organization** is one Core deployment and its database. It has no
identifier: services reach it at its URL.
- A **workspace** is a team inside the organization. Core stores its id
(`ws_…`), name, memberships, invitations, keys and audit trail.
- A person is a Core user (`mentraUserId`), the same one the Mentra App has. A
person can belong to any number of workspaces, with an independent role in
each.
## Roles and capabilities
Roles are cumulative: each holds everything the one before it holds.
| Capability | Member | Developer | Admin | Owner |
| --- | --- | --- | --- | --- |
| `workspace.read`, `miniapps.access` | Yes | Yes | Yes | Yes |
| `miniapps.publish`, `miniapps.credentials.create` | | Yes | Yes | Yes |
| `workspace.members.read`, `workspace.members.manage`, `workspace.settings.manage`, `workspace.audit.read`, `workspace.credentials.revoke`, `fleet.read`, `fleet.devices.manage`, `miniapps.assign`, `workspace.licenses.read`, `workspace.licenses.assign`, `workspace.billing.manage` | | | Yes | Yes |
| `workspace.roles.managePrivileged`, `workspace.delete` | | | | Yes |
- Admins invite, remove and change Members and Developers. Only Owners grant,
demote or remove Admins and Owners, on either side of the change.
- A workspace keeps at least one Owner: the last Owner cannot leave, be demoted
or be removed. Concurrent changes are serialized in a transaction on the
workspace, so two Owners demoting each other at once leave one Owner.
- Renaming, changing a role and removing a member carry the workspace revision
the caller last saw (`expectedRevision`); a stale one answers
`409 membership_changed`.
- Membership rows are never deleted. Leaving or removal ends the membership and
keeps it as history, with every role it held; rejoining starts a new one.
- The member list (`GET /:workspaceId/members`, the same on the workspace and
admin portals' routes) names each member. `name` is the last one a sign-in
through Core's provider carried, trimmed, read for the whole list in one
query; a sign-in that carries no name keeps the one Core has. It is `null`
when no sign-in has carried a name, when the person has not signed in through
the provider, and for a pending imported membership; the `email` stays the
one the membership was made for.
- Every member sees the licenses they hold; Admins and Owners see every product and
assign its licenses ([Licenses](licenses.md)). Ending a membership frees
its licenses, and deleting a workspace ends its products.
**Organization Admins** are the people whose verified email is on
`CLOUD_CORE_ADMIN_EMAILS` or in a domain on `CLOUD_CORE_ADMIN_EMAIL_DOMAINS`.
They hold every organization capability (`organization.workspaces.administer`,
`organization.credentials.manage`, `organization.incidents.read`,
`organization.supportProfiles.read`, `organization.testing.read`,
`organization.testing.manage`, `organization.fleet.administer`,
`organization.licenses.read`, `organization.registry.administer`) and act as
Owner in every workspace, which is how they recover a workspace whose Owners
are gone. Recovery names an existing account; a deleted account is refused
(`404 user_not_found`).
## The workspace portal
The workspace portal (`websites/portal`) is centred on the current workspace. A switcher at
the top of the sidebar shows it and your role (your membership's; "Member · Organization
Admin" when an Organization Admin's powers go beyond it), and lists your other workspaces,
**Create workspace** and your pending invitations with **Accept** and **Dismiss**.
**Addresses.** Your own workspace is never in the address: `/licenses`
([Licenses](licenses.md#in-the-workspace-portal)), `/members` (members, with pending
invitations under them) and `/settings` are its pages. The sidebar lists Licenses, Members and
Settings, in that order, and offers only what your role opens; Fleet Management (`/fleet`), where
Fleet is installed, is its own group under them. `/` opens the current workspace's first sidebar
page. Another workspace is named
by `?workspace=<workspaceId>` on any of them, which is how an Organization Admin opens a
customer's; the sidebar's links carry it exactly when the workspace is not the one the bare
address opens, and a `?workspace=` that names the bare address is dropped from the address in
place. A `?workspace=` you cannot open is "Workspace not found". The older
`/w/<workspaceId>[/<page>]` addresses redirect to these, keeping their query
(`?purchase=`, `?fleet=`). There is no personal page: `/account/billing` is "Page not found".
**The current workspace** is `?workspace=` when the address has one; else the workspace this
browser tab last opened from your own list while it is still there (remembered in the browser,
never an authority, and another tab's pick does not move this one); else your first (oldest)
workspace; else none. A workspace you reach only as an Organization Admin is never remembered.
**The first run.** With no current workspace, the portal shows the invitations you can accept in
place, at the address you came to; another account's invitation does not count. With none, it
asks Core for your workspace (`POST /api/portal/workspaces/ensure`) and shows "Setting up your
workspace" while it does, then opens it at the same address, so a `?buy=` link survives.
Core answers with your workspace if you have one and makes one named for you ("Dana Reyes's
Workspace") if not. If that fails, or Core answers but your list still has no workspace, the page
says "Couldn't set up your workspace." with **Try again**. Nothing is made while the portal cannot
tell whether an invitation waits (a dropped connection or a server error reading your invitations
or the link's): the page says so, with **Try again**, and **Dismiss** for a link. Someone who may
not have a workspace (an unverified email, or a deployment where only Organization Admins create
them), or whom Core refuses with a `403` because the rules changed after the page loaded, sees
"You're not in a workspace yet." with the reason ("You can't create a workspace with this
account." when Core gave none) and "Open an invitation link someone sent you to join their
workspace." Accepting an invitation from the first run keeps
the address, now in the joined workspace.
An invitation link lands on `/invitation`, which reads the token from the tab's session storage.
A link Core reports as no longer valid is shown as such once and then forgotten. Pending
invitations are the link's and those addressed to your verified email, each shown once;
**Dismiss** hides one in this browser only (Core does not record a refusal, and its link keeps
working). The sidebar has no link to the Developer Console. Company sign-in
(enterprise orgs and trusted issuers) is not in the navigation; its pages stay reachable
at `/enterprise` until it returns as workspace settings.
The sign-in page's button reads "Sign into Mentra account", with nothing under it.
**Members** lists each member by name over email (the email alone where Core has no
name), with a "You" mark on your own row, "Pending first sign-in" on an imported
membership, their role, the licenses they hold and when they joined (the date is left
out on a tablet or a phone, where each row stacks). Nothing on a row opens anything;
licenses are assigned from the Licenses page.
- **Licenses.** Where billing's catalog can be read, and you hold
`workspace.licenses.read` in a workspace with a product that has not ended, the list
has a Licenses column: a chip per product the member holds a license for (three chips
and "+n" past four), "None", or "After first sign-in" for a pending membership. The
chips only show: licenses are assigned from the Licenses page ([the portal's
Licenses](licenses.md#in-the-workspace-portal), [Assigning
licenses](licenses.md#assigning-licenses)). Without the catalog, and on a Private
Cloud, the list has no column.
- **The row's menu** ("…", named for the member, with `workspace.members.manage`) holds
Change role to each role you may move that member to, and Remove from workspace,
which asks first in a dialog ("Remove <name> from this workspace?", Cancel and a
destructive Remove; a refusal is shown inside it). Neither is offered on your own
row (you leave in Settings, and another Owner or an Organization Admin changes your
role), and a row has no menu where neither is yours to do. Both carry the revision
you last saw (`409 membership_changed`), and a role change that fails says so above
the list.
- **The admin portal** has the same list and menu, so role changes and Remove are
there too, with each member's Mentra user id and a Copy id button for recovering a
workspace's ownership. It has no Licenses column.
## Creating and joining
- Anyone signed in with a verified email may create a workspace and becomes its
Owner. A Private Cloud may limit creation to Organization Admins with
`CLOUD_CORE_WORKSPACE_CREATION=organization-admins`.
- **The automatic workspace.** `POST /ensure` (no body) answers the caller's
workspace as a workspace detail: `200` with their oldest workspace (the first
`GET /` gives: the one created first), whatever made it, or, when they have none, `201` with a
new one made for them, with them as its Owner. The same rules as creating
apply to that one (`403 email_unverified`, and `403 forbidden` for a
non-admin under `organization-admins`); someone with a workspace gets it
either way. The new workspace is marked automatic, and its
`workspace.created` event carries `after.automatic: true`. Its name is the
person's last sign-in name, trimmed with inner whitespace collapsed, and
"'s Workspace" ("Dana Reyes's Workspace"). Without a name it is made from the
verified email's local part, any `+tag` dropped, split on `.`, `_` and `-`,
each word capitalized ("john.smith+x@…" is "John Smith's Workspace"); without
either it is "My Workspace". The person's part is cut so the whole is at most
80 characters; invisible format characters (zero-width spaces, bidi marks)
are dropped, and the cut never splits a character or an emoji sequence. Each ensure writes the person's `users` row
(`portalWorkspaceAt`) in its transaction before it looks for their
memberships, so two at once (two tabs, or a retry racing its first try)
conflict there, the one retried finds the other's workspace, and the person
ends with one. A join (below) writes that row too, so an ensure never answers
a workspace a join is deleting. Core does not look at invitations here: the portal decides
when to ask.
- An automatic workspace **holds nothing** while its Owner is its only member
(an imported membership waiting for sign-in counts as another) and it has no
pending invitation, unrevoked key, license that has not ended, or deletion
hold. `GET /` marks each of the caller's workspaces `replaceable`: `true`
only for their own automatic workspace, which they own, while it holds
nothing. A workspace made with `POST /` never is.
- **Giving way.** In the transaction that gives a person a membership in
another workspace, their automatic workspaces that hold nothing are deleted
(`yieldAutomaticWorkspace`): accepting an invitation (by token or by id,
after its checks), claiming an imported membership (`claimPendingMemberships`,
when it moves a membership to the person rather than merging it into one they
hold), and `recoverOwnership` when it creates the membership. The deletion is
the workspace deletion's own steps without the typed name: the memberships
end (`workspace_deleted`), `workspace.deleted` is recorded with
`after.reason: "joined_another_workspace"` (for the person, or for the system
in a claim), and the deletion and the join commit together or not at all, so
both are on the change feed or neither is. The workspace being joined is never
the one deleted. A workspace that holds anything is kept, as is any the person
did not make for themselves: one where they are a Member or share ownership,
or one made with `POST /`. A person is in one workspace at a time, so while
they keep one, accepting and `recoverOwnership` are refused (`409
already_in_workspace`) and a claim discards the imported membership.
- An invitation names an email, a role and an expiry (14 days). Admins invite
Members and Developers, Owners anyone. Core stores only a hash of the
invitation token; the link carries the token. The email names the inviter.
The invitee opens the link in the workspace portal, signs in with that
verified email, and accepts. Signed in with that verified email, they also see
the invitation without the link (`GET /invitations/mine`) and can accept it by
its id, with the same checks.
Accepting adds the membership without touching others. A newer invitation to
the same address replaces the pending one.
- An invitation is only as good as its inviter, and records the authority it
was sent with. Sent on a membership whose role grants it, it is revoked when
that membership ends and refused at acceptance once the role no longer grants
the invited role. Sent by an Organization Admin on the organization's
authority, it is refused while the inviter's email is off the admin allowlist,
and revoked when their account is deleted. A person may send 100 invitations
an hour, and a workspace hold 200 pending ones; replacing the pending
invitation to an address does not count against that.
- Memberships imported from the Mentra Miniapp Store's developer organizations
([Store integration](store-integration.md#moving-developer-organizations-from-the-store))
wait for their person's first sign-in with a matching verified email. Until
then the member list shows them as pending (`pending: true`, `mentraUserId`
and `name` null), and the portals mark them "Pending first sign-in". They
hold their role meanwhile: a pending Owner counts toward the last Owner while
a verified email can still claim it (its legacy identity exists), Admins
change or remove them like any other member, and the keys they created
validate.
- Deleting a workspace ends its memberships and revokes its keys and
invitations at once, and forgets the miniapps it assigned through Fleet
([Fleet integration](fleet-integration.md#assigned-miniapps)). It is refused (`409 workspace_has_holds`) while a
service holds the workspace, whoever asks, Organization Admins included: the
Mentra Miniapp Store holds a workspace while it owns any miniapp that is not
deleted, a draft included, and the portals say so where the delete is ("This
workspace still owns 3 miniapps. Delete them in the Developer Console
first."). Once the miniapps are deleted, the Store clears its hold and the
workspace can be deleted ([Store
integration](store-integration.md#deletion-holds)).
- Deleting a Mentra account first marks it deleted, which makes it no
principal at all (see `signin.md`), so it can neither create nor join a
workspace, and its owner memberships never count toward the last Owner. It
then ends that person's memberships and revokes the keys (both kinds) and
pending invitations they created. It then clears their
identity from the rows that stay as history: the email on their membership
rows, the creator's email and user id on their keys, their address on keys a
service issued at their request, and the inviter's email and user id on their
invitations. Membership rows keep the opaque user id their history is keyed
by, and audit events keep what they recorded. The last write of the transaction
that ends the memberships is a `user.deleted` event, on the change feed services
read ([Fleet integration](fleet-integration.md#account-deletion)).
## Keys
Both kinds are shown once, at creation, and Core keeps only the SHA-256 of the
secret. A token is `<prefix>_<env>_<id>.<secret>`; Core accepts only the
environment labels it is configured for.
- **Workspace keys** (`msk_…`) belong to one workspace and its creator's
membership. A key does what its scopes allow, narrowed to what its creator's
role allows now: demoting the creator narrows it, and their leaving or removal
revokes it. A key may be limited to some packages. Developers manage their own
keys; Admins and Owners can revoke any. Workspace keys hold no organization
capability and never administer people, keys or workspaces.
- **Operator keys** (`mak_…`) are for tools that read organization data, such as
`scripts/fetch-incident-logs.sh`. An Organization Admin creates one in the
admin portal's **Operator keys** page with some of
`organization.incidents.read`, `organization.supportProfiles.read`,
`organization.testing.read` and `organization.testing.manage`. It works only
while its creator's email stays on the Organization Admin allowlist, so create
shared keys from an admin who will stay. A key whose creator is admitted by
`CLOUD_CORE_ADMIN_EMAIL_DOMAINS` keeps working while the domain is listed:
revoke it when that person leaves. Operator keys never administer workspaces
or keys.
- **Admin keys made before operator keys** (`msk_…` with their address,
`api-key@<keyId>.local`, on `CLOUD_CORE_ADMIN_EMAILS`) become operator keys
at Core's startup, with every operator scope, and keep their tokens. They work
while that address stays on the allowlist.
## APIs
The same handlers serve each portal under its own route group, so each portal's
session authenticates only its own routes:
| Route group | Who | Authenticates with |
| --- | --- | --- |
| `/api/portal/workspaces/*` | The workspace portal | Its session, or a bearer |
| `/api/portal/billing/*` | The workspace portal | Its session, or a bearer; forwarded to the billing module ([Portal modules](portal-modules.md)) |
| `/api/admin/workspaces/*`, `/api/admin/organization/*` | The admin portal | Its session, or a bearer |
| `/api/workspaces/*`, `/api/organization/*` | Servers and tools | Identity-provider access tokens and Core keys |
Workspace routes (`GET`/`POST /`, `POST /ensure`, `GET`/`PATCH`/`DELETE /:workspaceId`,
`/members`, `/invitations`, `/invitations/mine`, `/invitations/peek`, `/invitations/accept`
(by `token` or `invitationId`), `/credentials`, `/leave`, `/audit`, and `/licenses` with
its seats and `/seat-assignments`, [Licenses](licenses.md#assigning-licenses)) are for people;
a key gets 403. A workspace's detail says whether the caller is an Organization Admin
(`organizationAdmin`). Audit events name their subject: `target.email` for memberships and
invitations, `target.name` for keys. Each checks
the caller's capability in that workspace. A workspace's detail lists what holds it
from deletion (`deletionHolds`), and `DELETE /:workspaceId` answers
`409 workspace_has_holds` with those holds while there are any. `GET /api/organization` tells any
caller, a key included, its organization capabilities and whether it may create
a workspace. `/api/organization/workspaces` lists every workspace and
`/api/organization/workspaces/:workspaceId/owners` makes a person (by Core user
id, or on hosted Core by confirmed email) an Owner; `/api/organization/credentials`
manages operator keys. Those need the matching organization capability and a
person.
`/api/admin/*` checks a capability per area: incidents
(`organization.incidents.read`), support profiles
(`organization.supportProfiles.read`), test runs, the routine catalog and
system health (`organization.testing.read`, and `organization.testing.manage`
to write). `/api/admin/me` answers any caller with its capabilities and whether
Fleet is installed on this Core (`fleet.installed`). `/api/admin/fleet/*` forwards
to the optional Fleet service for a person holding `organization.fleet.administer`
(an Organization Admin); keys get 403 ([Fleet integration](fleet-integration.md)).
The Store calls Core through a signed service API ([Store integration](store-integration.md)),
and its billing module writes licenses through it ([Licenses](licenses.md)).
`/api/portal/billing/*` forwards the workspace portal's billing requests
to that module for a signed-in person, with the workspace or the person's own
account as the scope Core decides ([Portal modules](portal-modules.md)).
`/api/portal/me` says whether to offer it (`modules.billing`), the same for everyone
who signs in.
## Configuration
| Variable | Meaning |
| --- | --- |
| `CLOUD_CORE_ADMIN_EMAILS`, `CLOUD_CORE_ADMIN_EMAIL_DOMAINS` | Organization Admins (verified emails only). |
| `CLOUD_CORE_WORKSPACE_CREATION` | Optional. `open` (default) or `organization-admins`. Any other value stops Core at startup. |
| `CLOUD_CORE_WORKSPACE_INVITE_URL_TEMPLATE` | Optional. The invitation link, an absolute URL containing `{token}`. Default `<CLOUD_CORE_ENTERPRISE_PORTAL_URL origin>/?workspaceInvite={token}`, the workspace portal. With neither set, inviting answers `503 invitations_unavailable`. |
| `CLOUD_CORE_CREDENTIAL_ENVIRONMENTS` | Optional. Comma-separated environment labels keys may carry; the first is the one new keys get. Default: this Core's own label (`CLOUD_CORE_ENVIRONMENT`, else derived from `CONSOLE2_URL`, else `local`), which is the label existing keys carry. |
| `CLOUD_CORE_SERVICE_SECRETS` | Optional. The signed service API's secrets by service (`store`, `fleet`), `{"store": ["<newest>", "<older>"], "fleet": ["<newest>"]}`. Unset: every service call is refused. |
| `CLOUD_CORE_FLEET_URL`, `CLOUD_CORE_FLEET_SECRET`, `CLOUD_CORE_ENABLED_FEATURES` | Optional. The Fleet service Core forwards to, its shared secret, and (on a Private Cloud) the features the deployment has bought, which must list `fleet.managed` (case-sensitive). Unset: Fleet is not installed. See [Fleet integration](fleet-integration.md). |
| `CLOUD_CORE_BILLING_URL`, `CLOUD_CORE_BILLING_SECRET` | Optional, hosted Core only. The billing module Core forwards to, and its shared secret. Unset: billing is not installed. Set: billing is offered to every signed-in person, on every Core. See [Portal modules](portal-modules.md). |
| `RESEND_API_KEY`, `EMAIL_SENDER` | Invitation emails. Without them, inviting still works and returns the link to copy. |
Workspace writes use multi-document transactions across collections, so they
need a MongoDB replica set (Atlas, or `docker-compose.test.yml` locally). Azure
Cosmos DB for MongoDB (RU) and a standalone `mongod` cannot run them: there,
workspace writes fail, while sign-in, incidents and operator keys keep working
(an operator key is one document, written without a transaction). Core builds
the workspace collections and their unique indexes before it serves; a database
that refuses one is logged and does not stop Core.
|