Skip to content

Workspace authorization ​

Feature draft security authorization roles workspace xyz

How workspace composition decides which templates, locales and layers a user receives, from roles or a pluggable authorization provider; use when changing access rules or integrating a policy store.

Resource and sources

Behaviour ​

The XYZ API composes every locale and layer for the requesting user. Each template merged into an object adds its role to the object's scope, eg. europe.france. A template whose scope the user may not access is not merged, so its content never reaches the user. How roles are written in a workspace is described in roles.

The decision for a scope is made by authorizeScope:[1]

  • Roles (default): access when the scope is empty, or the user has the scope as a role, or a role nested below it, eg. europe.france.paris grants europe.[2] A * scope grants every user with roles but denies anonymous users, who have none; roles: {"*": true} on a locale or layer, by contrast, opens it to anonymous users too.[3] Admin routes bypass the check.
  • Provider: a user with an authorization_provider property is decided by the provider registered under that key. The provider's async checkScope(context) receives scope, scopeKey, obj and user and must return true. A missing provider, another result or an error denies.

A user with a provider also skips the roles gate of locales and layers; the provider alone decides.[3:1]

/api/workspace/scopes lists the scopes of the workspace for the admin view. /api/workspace/roles was removed and responds 410 Gone. The admin-only /api/workspace/test lists scope segments beginning with ! as negatedRoles.[4]

Flow ​

request → getLocale / getLayer → composeObj → mergeTemplateIntoObj and rolesTemplates → authorizeScope → checkScope or provider.

Where to change ​

  • Register a provider in the host before serving: setAuthorizationProvider('openfga', { async checkScope(context) { … } }) from mod/workspace/authorization.js; calling it without a provider removes the registration.
  • The authorization_provider user property is set by the host, eg. in a custom login provider; it is not an ACL column.
  • Scope semantics: mod/workspace/scopes.js exports checkScope, getScopes, scopesArray and scopesTree for hosts which evaluate scopes themselves.

Tests ​

authorization.test.mjs, scopes.test.mjs and composeObj.test.mjs in apps/xyz/tests/mod/workspace/.

Pitfalls ​

  • Since v5, composeObj takes the user object, not a roles array, and the authorization context has user instead of roles.

  1. workspace/authorization.js authorizeScope ↩︎

  2. workspace/scopes.js checkScope ↩︎

  3. workspace/composeObj.js rolesTemplates ↩︎ ↩︎

  4. workspace/_workspace.js roles and test ↩︎

XYZ v5.1.0. Generated from knowledge/ at dd7a6fa27736502733499c1bf485f15659b10338. Concepts marked draft are not reviewed.