Authorization
Every execution runs as one auth context inside one Workspace. Authorization answers two questions for that execution: which operations it may invoke, and which Items and Properties it may read and write. This chapter defines the rules a Runtime applies.
Workspace authority
Section titled “Workspace authority”- An execution belongs to exactly one Workspace. No auth context grants access to Items, Events or Metrics of another Workspace.
- An auth context is one of
principal,masquerade,sudoorsystem(AlpyneAuthContext). - A
principalcontext carries the principal’s Identifier and its App Role PRNs. Amasqueradecontext carries the same data for the principal being acted as, plus the underlying principal’s Identifier. Authorization undermasqueradeuses the acted-as principal’s Roles. sudoandsystemcontexts hold Runtime-level authority inside their Workspace. Grant checks on operations, Items and Properties pass for them. Asudocontext carries the underlying principal’s Identifier; asystemcontext carries a tag.ctx.sudo(fn)runsfnunder asudocontext in the same mode. A read execution stays read-only insidesudo.ctx.principalIdreturns the principal’s Identifier underprincipalandmasquerade, the underlying principal’s Identifier undersudo, and throws undersystem.- Nothing is visible by default. A principal sees an Item, reads a Property or invokes an operation only through a Grant.
- An App Role is declared on an App with
addRoleand assigned to principals. A principal holds an App Role when the Role’s PRN is in its auth context. - A Template Role is declared on a Template with
addRoleand a callback. The Runtime evaluates the callback per Item to decide whether the current principal holds the Role for that Item. checkRolereturns whether the current context holds a Role.assertRolereturnstruewhen it does and throwsAssertRoleFailedErrorwhen it does not.
Grants
Section titled “Grants”- A Grant links a Role to what it may access. An operation Grant (
addGranton a Query or Mutation) governs invocation. A Template Grant (addGrant(role, properties)) governs Item visibility and Property access. A Metric Grant governs Metric queries. A transition Grant governs executing a transition. - Grants combine additively. A principal has the union of the access its Roles’ Grants allow. No Grant removes access.
- A principal may invoke an operation when it holds at least one Role granted on that operation.
Item and Property access
Section titled “Item and Property access”- A principal sees an Item when it holds at least one Role granted on the Item’s Template, evaluated for that Item. Otherwise the Item is absent: lookups return
undefinedand selectors omit it. - The Workspace Item is visible to every context in its Workspace, with no Properties unless a Grant names them.
- The Properties a principal may read on an Item are the union of the Properties named by its matching Template Grants, plus the Item’s extension Properties. A Property outside that set reads as absent.
- Visibility of an Item does not imply that every Property is readable or writable. Each Property is governed by the Grants that name it.
- Selection applies two passes. A coarse pass narrows by Workspace, Template, state, archive mark and Property filters. A fine pass evaluates Grants per Item and filters Properties. A Runtime must apply the fine pass to every Item it returns; the coarse pass never widens access.
totalCounton a page counts the Items matched by the coarse pass. A page may hold fewer Items than the count after the fine pass.
Privileged contexts
Section titled “Privileged contexts”- A
sudoorsystemcontext stays inside its Workspace and does not promote a read execution to a write execution. - A Listener processed by the reactor runs under a
systemcontext in the Event’s Workspace. A Listener run byimmediateruns under the publishing execution’s context. Query and Mutation handlers run under the caller’s context.
Related
Section titled “Related”- Workspaces and access explains Workspaces, auth contexts, Roles and Grants.
- Grant access declares Roles and Grants and tests them with principal contexts.
AlpyneAuthContextis the auth context type.TemplateGrantBuilderdeclares Template Grants.

