Playbook: External authorization with Topaz (AuthZEN 1.0)
How to pair Plat5’s multi-tenant runtime with Topaz (or any OpenID AuthZEN 1.0 PDP such as Cerbos or OpenFGA with an AuthZEN adapter) for ReBAC/ABAC — without losing zero-auth services, uniform edge 403s, node list filtering, or POST /access/routes.
This playbook uses full-external authorizer mode (top-level authorizer without roles), because Topaz stores both relationships and policy. (Policy engines without their own role store, such as Cerbos or OPA, can alternatively combine authorizer with Plat5-stored roles — see reference/config/authorizer.md.) Whenever authorizer is set, the PDP decides every permission-gated route, node list filter (list_permission), and identity /access/v1/* check across all kinds, while Plat5 still handles authentication, tree membership, org security policies, suspension, credential scope narrowing, rate limits, and audit.
1. Topaz manifest (topaz/manifest.yaml)
Section titled “1. Topaz manifest (topaz/manifest.yaml)”Define types matching Plat5’s AuthZEN payloads (member subjects, node kinds, and your record types). Topaz permission identifiers cannot contain :, so use underscore-separated permission names (organization_read, project_read, docs_read, …) across your Topaz manifest, plat5.yml list_permission values, and service route files (the topaz authorizer integration in plat5dev/registry sets routes.permission_separator: "_" for plat5 routes generate, and the standalone topaz-documents example in plat5dev/templates puts the whole stack together via plat5 init my-docs --example topaz-documents):
model: version: 3
types: member: {}
organization: relations: admin: member viewer: member permissions: organization_read: viewer | admin organization_write: admin organization_delete: admin organization_bindings_read: admin organization_bindings_write: admin project_create: admin audit_read: viewer | admin
project: relations: organization: organization admin: member editor: member viewer: member permissions: project_read: viewer | editor | admin | organization->admin project_write: editor | admin | organization->admin project_delete: admin | organization->admin project_bindings_read: admin | organization->admin project_bindings_write: admin | organization->admin audit_read: viewer | editor | admin | organization->admin
document: relations: owner: member editor: member viewer: member permissions: docs_read: viewer | editor | owner docs_write: editor | owner docs_delete: ownerRun Topaz on your plat5 Docker network exposing its Directory v3 + OpenID AuthZEN 1.0 HTTP gateway on :9393 (or add the authorizer/topaz plugin with plat5 init / plat5 add). Wire both gateway and identity via process environment (reference/env.md):
AUTHORIZER_URL=http://topaz:9393AUTHORIZER_TIMEOUT=2sAUTHORIZER_CACHE_TTL=5sAUTHORIZER_NEGATIVE_CACHE_TTL=2s# AUTHORIZER_TOKEN=<api-key> # optional bearer token when Topaz requires auth2. Plat5 config (plat5.yml & services/docs.yml)
Section titled “2. Plat5 config (plat5.yml & services/docs.yml)”Declare top-level authorizer: in plat5.yml instead of roles / creator_role (authorizer reference):
kinds: organization: path: /orgs/{organization} list_permission: organization_read project: parent: organization path: /projects/{project} list_permission: project_read
authorizer: mode: authzenIn services/docs.yml, declare route permissions as usual, and add a flat resource: { type, id } on routes that check a record instead of the node:
docs: url: http://docs:3000 scopes: project: upstream_prefix: /projects/{project.id} routes: # Collection: checked against resource { type: "project", id: "<project ulid>" } - path: /documents methods: GET: { permissions: project_read } POST: { permissions: project_write }
# Record-level routes: checked against resource { type: "document", id: "<project ulid>:<doc_id>" } - path: /documents/{doc_id} methods: GET: permissions: docs_read resource: { type: document, id: "{project.id}:{doc_id}" } PATCH: permissions: docs_write resource: { type: document, id: "{project.id}:{doc_id}" } DELETE: permissions: docs_delete resource: { type: document, id: "{project.id}:{doc_id}" }Using {project.id}:{doc_id} (or globally unique ULIDs) as resource.id guarantees tenant-scoped object IDs inside Topaz.
Identity automatically queries Topaz on node lists (GET /orgs/{org}/projects using each kind’s list_permission) and /access/v1/* calls. In external authorizer mode, creating a root/member/invite/service account creates the member without requiring a role (passing role or grants returns 422), and built-in RBAC endpoints (/bindings, /groups, /roles, /permissions) return 404.
3. What your service does
Section titled “3. What your service does”Your docs service still does no auth checks on individual document endpoints — the gateway already enforced Topaz before forwarding. Your service only:
- Bootstraps root and project relations in Topaz: in external
authorizermode, creating an organization creates the creator’smemberrow but writes no role in Plat5. The cleanest synchronous pattern is to wrapPOST /orgsandPOST /orgs/{organization}/projectsin your own service (wrapping identity routes): call identity’s service API (POST /roots/organization,POST /nodes/{org_id}/children/project), write(subject: member:<member_id>, relation: admin, object: organization:<org_id>)(and(subject: organization:<org_id>, relation: organization, object: project:<project_id>)for inheritance) to Topaz’s directory, forward identity’sX-Plat5-Audit-*response headers back to the gateway, and return 201 — so the creator’s very next request succeeds immediately with no async race. - Writes record relations to Topaz on create/share/unshare using
X-Plat5-Member-Idand the document ID:- On
POST /projects/{project_id}/documents: create the document in your DB and write(subject: member:<X-Plat5-Member-Id>, relation: owner, object: document:<project_id>:<doc_id>)to Topaz’s directory. - On
POST /projects/{project_id}/documents/{doc_id}/shares: write/delete theviewer/editorrelation in Topaz.
- On
- Tunes cache TTLs for freshness vs latency: keep
AUTHORIZER_CACHE_TTL=0sandAUTHORIZER_NEGATIVE_CACHE_TTL=0s(the default) when share/unshare changes must take effect immediately, or set short TTLs (2s–5s) for high-traffic read paths. - Cleans up tuples on lifecycle events: when consuming
node.purged(kind: project) ormember.removedfrom identity’s lifecycle log, delete the corresponding objects/relations in Topaz.
4. UI button visibility (POST /access/routes)
Section titled “4. UI button visibility (POST /access/routes)”Frontends don’t talk to Topaz either. Pass the concrete document paths to POST /access/routes:
POST /access/routes{ "checks": [ { "method": "PATCH", "path": "/orgs/acme/projects/web/documents/doc-42" }, { "method": "DELETE", "path": "/orgs/acme/projects/web/documents/doc-42" } ]}The gateway batches all checks into a single AuthZEN POST /access/v1/evaluations call and returns { "checks": [{ "allowed": true }, { "allowed": false }] }.
5. Single-root workspaces with arbitrary inner hierarchies
Section titled “5. Single-root workspaces with arbitrary inner hierarchies”You do not need a multi-level kinds tree in Plat5 when your product’s primary structure is a user-created, arbitrarily nested, or movable hierarchy (such as nested folders, Notion-style pages, or Drive-style share graphs):
kinds: workspace: path: /workspaces/{workspace} list_permission: workspace_read
authorizer: mode: authzenWith one root kind and an external AuthZEN PDP:
- Plat5 owns the workspace boundary and edge: JWT and API key verification, scope narrowing, workspace membership and suspension, per-workspace security policies (IP allowlists, required IdP claims, key restrictions), rate-limit tiers, fail-closed audit, lifecycle events, and batched
POST /access/routesUI checks. - Your service and PDP own the inner graph: folder trees, reparenting/moves, inheritance, and per-item shares live in your database and Topaz/OpenFGA, enforced at the gateway through route
resource: { type, id }templates (for exampleresource: { type: page, id: "{workspace.id}:{page_id}" }). - Public links and cross-workspace views: unauthenticated “anyone with the link” endpoints use
scope: public, and cross-workspace views (such as “shared with me”) usescope: user(which receivesX-Plat5-User-Id).
If you instead combine authorizer with Plat5-stored roles (for example with Cerbos), keep in mind that Plat5 denies members holding zero roles on the node before calling the PDP (authorizer reference), so assign workspace members a base role or use standalone authorizer mode when the PDP owns all assignments.