Skip to content

Control access by role and tenant

Use role operation/field permissions and reusable named record policies; retain client isolation for tenants. This minimal policy bundle allows a non-root reader to read their own notes. It assumes the native users module and a client exist. Merge existing roles/policies modules instead of replacing them.

Syntax follows the corrected role and Bakery policy references, including $user.id and recipe on policy clauses. The combined scenario has not been executed here. Apply in a disposable preview after inspecting the plan.

[
{
"resource_module": "roles",
"resource": {
"identifier": "roles",
"title": "name",
"fields": [],
"type": "roles"
}
},
{
"resource_module": "policies",
"resource": {
"identifier": "policies",
"title": "name",
"fields": [],
"type": "policies"
}
},
{
"resource_module": "private_notes",
"resource": {
"identifier": "private_notes",
"title": "name",
"fields": [
{
"identifier": "name",
"type": "text"
},
{
"identifier": "owner",
"type": "select",
"options": {
"references": "users"
}
}
]
}
},
{
"resource_policy": "own_notes",
"resource": {
"module": "policies",
"fields": {
"name": "own_notes",
"policy": [
[
{
"field": "owner.id",
"operator": "=",
"recipe": "$user.id"
}
]
]
}
}
},
{
"resource_entity": "note_reader",
"resource": {
"module": "roles",
"fields": {
"name": "Own note reader",
"slug": "note_reader",
"modules": {
"private_notes": {
"read": {
"policies": [
"own_notes"
]
},
"create": false,
"update": false,
"delete": false,
"fields": true
}
}
}
}
}
]

Assign note_reader to a real user and set each note’s owner to that user. The module read operation names the policy, whose filter selects the actor’s records. This minimal role deliberately grants no writes; fields: true grants field access only within permitted module operations. Production write roles must also prevent unauthorized ownership reassignment.

Ordinary records are scoped by client. Leave options.shared and options.global unset for tenant-specific business data. Do not enable them to solve a role problem. Organizational capabilities do not automatically restrict business records by organizational unit; a verified user-to-organization access pattern is still an open team decision.

Create two non-root user fixtures with this role, one note per owner and a second client. Add an applicable workflow-test trigger, then assert can_read, cannot_read and visible_count as each actor. Repeat across clients and with every additional assigned role. Use field_readonly/field_editable for protected fields; field write permission is write, not update. This guide supplies no executed end-to-end permission test.

  • Recommended for a one-off scope: inline module/action filters in the role matrix. Module, action and named-policy filters combine with AND; DNF groups inside a filter combine with OR.
  • Recommended for role reuse: parent inheritance. Grants are permissive, and multiple roles are additive; a narrower role does not revoke another role’s grant.
  • Recommended only when declarative policies are insufficient: workflow policies (event/policy* → query/where).
  • Recommended for dynamic field authorization after target-version verification: event/fieldPolicy/op/protectFields; the complete pattern remains unverified.
  • Not recommended as protection: menu roles, hidden controls or layout recipes. They only affect UI presentation.
  • Not recommended on the audited Brezel 4 line: depending on hasAbility; abilities are documented separately for 3.x.

Permission model · Record filters · Role inheritance · Policy schema · Workflow tests · Assertions