Skip to content

0008. Payroll roles: grants held by payroll, four-eyes, agents draft only ​

Status: accepted. Applies to crates/authz (schema, principal entities, loader, audit), crates/kernel (manifest), the payroll module, and through ADR 0007 the modules payroll reads from (core, tax-benefits).

Context ​

A Cedar role comes only from the tenant membership (owner in admin in member). Payroll needs finer duties (who prepares, approves, locks and pays runs, who sees salaries) that HR administration does not imply. Contract rule 2.10 says agents only draft; rule 2.9 makes locked runs history. ADR 0001 section 6 keeps managers off personal fields. Since ADR 0006, an MCP agent acts as its person (Actor::Person, door mcp), and every sensitive tool runs only after that person approves the exact call out of band.

Decision ​

  1. Grants live in payroll. payroll.grants (tenant_id, id, person, role, granted_by, granted_at, revoked_by, revoked_at), role one of preparer, approver, payroll_admin, accountant. Rows are never deleted; revoking sets revoked_at. The manifest declares them: [provides] roles = ["preparer", "approver", "payroll_admin", "accountant"].
  2. How they reach Cedar. A module that declares roles ships, in its own migration, a SECURITY DEFINER function <module>.roles_of(tenant uuid, person uuid) RETURNS text[] (search path pinned, filtered by tenant and revoked_at IS NULL, EXECUTE to orbit_runtime only, with USAGE on the module's schema), because the gate runs as the login, which cannot read payroll.* (ADR 0005). orbit migrate refuses a module whose declared roles have no such function: SECURITY DEFINER, owned by the migrating login, returning text[], with a search_path of only pg_catalog, pg_temp and the module's own schema (never public or $user), executable by orbit_runtime (with USAGE on the schema) and not by PUBLIC. The migrate check cannot read the body: payroll's real roles_of needs a review that it filters by the tenant it is given and by revoked_at IS NULL. A roles_of that errors fails closed: every decision for a person in that tenant is denied while it does, since the principal cannot be loaded. For a Person principal the authorizer adds one parent ModuleRole::"payroll.<role>" per active grant, only when payroll is enabled for the tenant. The schema gains the entity type ModuleRole, and User becomes memberOfTypes: ["Role", "ModuleRole"]. API clients and agents never get one. Grants are read on every request, never cached across requests, so a revoke stops access on the next request; within a request the principal (membership and module roles) is loaded once, on its first decision, and kept in the Ctx in a slot only the authorizer instance the bus runs with can open (Ctx::authorizer_cache(&self)), never a handler. The loader refuses a policy literal ModuleRole::"m.r" unless r is declared by m and m is the policy's own module, one it depends on, or one that consumes a query it publishes (ADR 0007: core's policy names ModuleRole::"payroll.payroll_admin", and core does not depend on payroll). A role of a module that is not compiled into the build can never be held, so it is accepted and stays inert.
  3. Who may grant. payroll.grant.set and payroll.grant.revoke are audited commands (before/after hash of the grant row), allowed to owners only, marked sensitive, and forbidden on door mcp outright (like agents.request.approve). The grantee must be a person with a membership in the tenant; granting to oneself is refused (an owner already has every payroll power). A removed person's grants stay but have no effect: the membership check denies first.
  4. Bootstrap. A new tenant needs no rows: owners hold every payroll permission through Role::"owner". An owner then grants duties to others.
  5. Salaries. Payroll's field policies permit owners and named ModuleRoles only, and the employee their own payslip on locked runs. They never name Role::"admin" or Role::"member" (a test scans payroll's policies for it), so an HR admin without a grant gets every amount redacted. Managers never see salaries: a Field carries no manager (ADR 0001).
  6. Four-eyes. payroll.run.approve and payroll.run.lock are refused (DomainError::Forbidden, audited denied) when the actor is the run's calculated_by (the last person to calculate it). The handler checks it after ctx.authorize.
  7. Single-admin exception. The owner-only command payroll.settings.self_approval (sensitive, not on door mcp, audited) turns a tenant setting on or off. It can be turned on only while the tenant has exactly one person who is an owner or admin and no other person holds approver or payroll_admin; approve and lock re-check that condition, so adding a second admin or approver makes the setting inert. While it holds, an owner who calculated a run may approve and lock it: the result carries a warning, the run gets self_approved = true, and the audit entry gets the flag self_approved (new flags text[] column, set with ctx.audit_flag; only on allowed and read entries). The single-admin condition counts owners and admins with orbit_kernel::count_with_roles (authz.count_people_by_role, a definer function filtered by the tenant).
  8. Agents only draft. An Actor::Agent may be permitted payroll.run.create and payroll.run.calculate only, at the row level by explicit policy; payroll forbids it every payroll.* field. For an MCP agent acting as a person, payroll forbids every payroll field on door mcp, so the agent sees run status, counts and warnings, never an amount. Approve, lock, mark paid, pay changes (assignment.create), settings, corrections are sensitive, so over MCP they run only after the person's approval of that exact call (ADR 0006), and four-eyes still applies to that person. The parallel run (import, report, explanations, sign-off) and file downloads are never available over MCP or to an agent.

Allow/deny matrix ​

Rows are payroll actions; ★ sensitive. "MCP" means a person's agent on door mcp.

ActionOwn employeeManagerHR admin, no grantPreparerApproverPayroll adminAccountantOwnerMCPAPI client / agentOther tenant
grant.set / revoke ★, settings.self_approval ★nononononononoyesnevernono
components, structures (read)nononoyesyesyesyesyesas personclient: by grantno
components, structures, settings (write) ★nononononoyesnoyesafter approvalnono
assignment.create ★nononoyesnoyesnoyesafter approvalnono
assignment amounts (read)ownneverredactedyesyesyesyesyesredactednono
run.create, inputs, calculatenononoyesnoyesnoyesas person, no amountsagent: create, calculateno
run.submitnononoyesnoyesnoyesas personnono
run.approve ★, run.rejectnonononoyes, not own calcyes, not own calcnoyes, not own calc unless single-adminafter approvalnono
run.lock ★, mark_paid ★nononononoyes (lock: not own calc)noyes (same)after approvalnono
correction.create ★nononoyesnoyesnoyesafter approvalnono
run.get, run.lines (amounts)nonoredactedyesyesyesyesyesredactednono
payslip.mine, explain, ytdown, lockednonoyesyesyesyesyesredactednono
file download (bank, statutory)nononononoyesnoyesnonono
parallel import, variance explainnononoyes, not own payyes, not own payyes, not own paynononevernono
variance.reportnononoyesyesyesyesyesnevernono
signoff.record ★nonononononoyesnonevernono

Deny cases every test covers: approve or lock by the last calculator (allowed only as the recorded single-admin case); anyone changing their own pay (forbid on an assignment whose owner is the principal); managers and HR admins without a grant never see an amount; a revoked grant denies on the next request; agents and MCP never read an amount; other tenants see nothing; a disabled payroll module refuses everything and contributes no ModuleRole.

Consequences ​

  • Cedar decisions for people cost one more statement (payroll.roles_of) while payroll is enabled. Field checks run per field per row, so the authorizer should load the principal once per request rather than per decision.
  • An owner cannot be kept away from salaries; a company that needs that keeps the person as admin, not owner.
  • The single-admin setting trades four-eyes for usability in the smallest companies, and every self-approved run is visible in the run and the audit log.
  • Other modules (tax-benefits, country-lk) reuse ModuleRole::"payroll.*" in their own policies by declaring payroll as a dependency.
  • audit.entries gains flags; ADR 0007 adds via. One migration for both.

Alternatives considered ​

  • More token roles (payroll_admin in the sign-in token). Needs the auth sidecar, mixes payroll duties with tenant administration, and a revoke waits for token expiry. Rejected.
  • A generic authz.module_roles table. Simpler for the authorizer, but payroll's grants would live outside payroll's schema, against rule 2.3. Rejected in favour of a per-module definer function.
  • Grants as a User attribute (Set<String>) instead of parents. Typos in policies would not fail validation. Rejected.
  • Four-eyes always, no exception. A one-person company could never run payroll. Rejected.

Amendments ​

  • ADR 0018 (proposed, pending D5): in relations only, the sole owner of a tenant may grant case_handler to themselves (flag self_granted), and owners hold no case power through their role.

Orbit by SkySync Tech. Licensed under AGPL-3.0.