Skip to content

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.

  • 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, sudo or system (AlpyneAuthContext).
  • A principal context carries the principal’s Identifier and its App Role PRNs. A masquerade context carries the same data for the principal being acted as, plus the underlying principal’s Identifier. Authorization under masquerade uses the acted-as principal’s Roles.
  • sudo and system contexts hold Runtime-level authority inside their Workspace. Grant checks on operations, Items and Properties pass for them. A sudo context carries the underlying principal’s Identifier; a system context carries a tag.
  • ctx.sudo(fn) runs fn under a sudo context in the same mode. A read execution stays read-only inside sudo.
  • ctx.principalId returns the principal’s Identifier under principal and masquerade, the underlying principal’s Identifier under sudo, and throws under system.
  • 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 addRole and 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 addRole and a callback. The Runtime evaluates the callback per Item to decide whether the current principal holds the Role for that Item.
  • checkRole returns whether the current context holds a Role. assertRole returns true when it does and throws AssertRoleFailedError when it does not.
  • A Grant links a Role to what it may access. An operation Grant (addGrant on 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.
  • 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 undefined and 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.
  • totalCount on a page counts the Items matched by the coarse pass. A page may hold fewer Items than the count after the fine pass.
  • A sudo or system context stays inside its Workspace and does not promote a read execution to a write execution.
  • A Listener processed by the reactor runs under a system context in the Event’s Workspace. A Listener run by immediate runs under the publishing execution’s context. Query and Mutation handlers run under the caller’s context.