ObjectStackObjectStack

Access recipes — data, automation and UI

Map a real access requirement onto the right layer — object CRUD, field-level and row-level security, capabilities, navigation gating and automations.

Scenario

I have a real access requirement — "sales reps see only their own deals; managers see the team's; finance can export; nobody but admins touches the automations." How do these map onto the platform's authorization layers?

Authorization splits into three decoupled concerns (ADR-0066): capability (what can be done), assignment (who holds it — permission sets / positions, maintained at runtime), and requirement (what a resource declares it needs). A resource declares what is required; it never bakes in who.

Pick the layer that matches the requirement:

RequirementLayerWhere
Can read/create/edit/delete an object typeObject CRUDpermission-set objects.{allowCreate/Read/Edit/Delete}
Can see / edit a specific fieldField-level security (FLS)permission-set fields, or field requiredPermissions
Can no longer edit a field once a record reaches a stage, for some positions onlyRow-conditioned FLSpermission-set fields entry with when (recipe)
Which rows a user seesRow-level security (RLS)permission-set rowLevelSecurity (CEL using / depth readScope)
A functional capability (export, approve, manage)CapabilitysystemPermissions ↔ resource requiredPermissions
Can open an app / nav entry / pageSurface accessApp.requiredPermissions, tabPermissions, nav gating
Can run / configure an automationCapability + run-identitymanage_metadata to edit; flow runAs to execute

Data: CRUD + FLS + RLS, combined

definePermissionSet({
  name: 'sales_rep',
  objects: { deal: { allowRead: true, allowCreate: true, allowEdit: true } },
  fields:  { 'deal.commission': { readable: false } },     // FLS: hide a field
  rowLevelSecurity: [
    { name: 'own_deals', object: 'deal', operation: 'all', using: 'owner_id == current_user.id' },
  ],
});
  • "My own" vs "my team's" vs "the org's" is the RLS depth axis (readScope / writeScope: own | own_and_reports | unit | unit_and_below | org, ADR-0057). A manager set uses unit; a rep uses own. The hierarchy-relative scopes (own_and_reports / unit / unit_and_below) need the enterprise hierarchy resolver and fail closed to own without it — see Access depth.
  • Grants combine most-permissively across a user's sets; the tenant-isolation policy ANDs on top; the superuser bypass (viewAllRecords / modifyAllRecords) short-circuits RLS where the object's posture allows it (ADR-0066).
  • For genuinely sensitive objects, set access: { default: 'private' } so they are not covered by blanket wildcard grants — access needs an explicit grant.

Data: lock fields for a position once a record reaches a stage

Finance may edit a contract while it is a draft, but once it is approved the legal terms are frozen for finance. Legal still edits them.

Every business app meets this shape: a contract's legal terms after approval, an order's amount after shipping, an invoice after posting, a purchase order's supplier after approval. The answer is a field permission with a row condition, when, on the permission set that should lose the edit.

In the permission-set editor (Studio → All metadata → Permission Set, then open the set):

  1. Expand the object (clm_contract) to show its field rows.
  2. On each field row to lock (governing_law, liability_cap), set Read on and Edit off.
  3. In the row's When (edit) column, choose Add condition and write the stage condition: status in ["approved", "signing", "active"]. The editor lints it like a row-level security clause, and a condition the publish gate would refuse holds the save.

The same entries as metadata:

import { definePermissionSet } from '@objectstack/spec';

definePermissionSet({
  name: 'finance',
  objects: { clm_contract: { allowRead: true, allowEdit: true } },
  fields: {
    // Locked for finance from approval onward; a draft stays editable.
    'clm_contract.governing_law': { readable: true, editable: false, when: 'status in ["approved", "signing", "active"]' },
    'clm_contract.liability_cap': { readable: true, editable: false, when: 'status in ["approved", "signing", "active"]' },
  },
});

On a row the condition matches, the entry votes as declared (no edit). On every other row the entry is absent, as if the set had not named the field, so a draft stays editable under the object grant.

How to choose:

  • The field must freeze for everyone at that stage → a validation rule on the object. It refuses the write whoever sends it.
  • The field freezes depending on who is editing → a field permission with when on the sets that lose the edit, as above.

Boundaries:

  • Edit only, never read. The condition narrows the edit vote; reads are judged row-blind. Keep readable: true on the entry: readable: false beside a when is refused at parse time.
  • Same object only. The condition names fields of the entry's own object (compared with a literal or a current_user.* value). A condition that reaches across a relation, or names a field the object lacks, is refused at authoring and publish.
  • The record before the write. On an update the condition reads the stored record, so a write cannot unlock itself by moving status back in the same request. On an insert it reads the record as sent.
  • It locks, it does not grant. Grants merge most-permissively: if the same user holds another set that grants the edit, that grant still wins and the field stays editable. Grant the edit only in the sets that should keep it. A subtractive deny layer is not yet implemented.

Full semantics, including how a write with no judgeable row is treated: Row-conditioned edit locks.

Automation: the run-identity is the safety decision

Two separate questions:

  1. Who can configure it? Editing flows/automations needs manage_metadata (typically Studio users). Don't expose automation config to end users — see audience-based interfaces.

  2. As whom does it run? A flow's runAs (ADR-0049):

    • runAs: 'user' (default) — runs as the triggering user; CRUD nodes respect that user's RLS. Safer default.
    • runAs: 'system' — elevated, bypasses RLS. Make elevation explicit, and surface it in the UI as "runs as system".

    A schedule-triggered run has no user, so under user its data operations are refused — declare system to make the elevation explicit and intended.

Interface: gate the app, the nav, and the action

App.requiredPermissions gates the whole app; permission-set tabPermissions controls per-app/tab visibility; each nav item carries requiredPermissions / visible / requiresObject. Action gates are dual-surface (ADR-0066 D4): hidden/disabled in the UI and rejected by the server — UI gating is derived from the same declaration, server is the source of truth.

Why

Keeping capability, assignment and requirement decoupled means resources stay stable (requiredPermissions: ['export_data']) while admins re-assign who holds export_data at runtime, with no code change. The fixed precedence (AND-gates → most-permissive grant union → RLS; an explicit deny/muting layer is reserved but not yet implemented) is specified in ADR-0066, so combinations are predictable rather than ad-hoc.

Runnable example

Anti-patterns

  • UI-only action gating. Always pair it with the server check — use a single requiredPermissions declaration (dual-surface), never hide a button while leaving the endpoint open.
  • runAs: 'system' by reflex. Default to user; elevate only where a step genuinely needs to bypass RLS, and say so.
  • Baking "who" into a resource. Declare the capability required; assign holders in permission sets at runtime.

See also

On this page