Workspace authorization
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
- ../../apps/xyz/mod/workspace/authorization.js
wikihttps://github.com/GEOLYTIX/xyz/wiki/Workspace-Authorization/3fc379b7ada42dff57f19e9f28694868e5a17cac (revision3fc379b7ada42dff57f19e9f28694868e5a17cac)securityhttps://github.com/GEOLYTIX/xyz/wiki/Security/3fc379b7ada42dff57f19e9f28694868e5a17cac (revision3fc379b7ada42dff57f19e9f28694868e5a17cac)authorization../../apps/xyz/mod/workspace/authorization.jsscopes../../apps/xyz/mod/workspace/scopes.jscompose../../apps/xyz/mod/workspace/composeObj.jsworkspace../../apps/xyz/mod/workspace/_workspace.js- ../../apps/xyz/tests/mod/workspace/authorization.test.mjs
- ../../apps/xyz/tests/mod/workspace/scopes.test.mjs
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.parisgrantseurope.[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_providerproperty is decided by the provider registered under that key. The provider's asynccheckScope(context)receivesscope,scopeKey,objanduserand must returntrue. 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) { … } })frommod/workspace/authorization.js; calling it without a provider removes the registration. - The
authorization_provideruser property is set by the host, eg. in a custom login provider; it is not an ACL column. - Scope semantics:
mod/workspace/scopes.jsexportscheckScope,getScopes,scopesArrayandscopesTreefor 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,
composeObjtakes the user object, not a roles array, and the authorization context hasuserinstead ofroles.