Appearance
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
- Grants live in payroll.
payroll.grants (tenant_id, id, person, role, granted_by, granted_at, revoked_by, revoked_at), role one ofpreparer,approver,payroll_admin,accountant. Rows are never deleted; revoking setsrevoked_at. The manifest declares them:[provides] roles = ["preparer", "approver", "payroll_admin", "accountant"]. - How they reach Cedar. A module that declares roles ships, in its own migration, a
SECURITY DEFINERfunction<module>.roles_of(tenant uuid, person uuid) RETURNS text[](search path pinned, filtered by tenant andrevoked_at IS NULL,EXECUTEtoorbit_runtimeonly, withUSAGEon the module's schema), because the gate runs as the login, which cannot readpayroll.*(ADR 0005).orbit migraterefuses a module whose declared roles have no such function:SECURITY DEFINER, owned by the migrating login, returningtext[], with asearch_pathof onlypg_catalog,pg_tempand the module's own schema (neverpublicor$user), executable byorbit_runtime(withUSAGEon the schema) and not byPUBLIC. The migrate check cannot read the body: payroll's realroles_ofneeds a review that it filters by the tenant it is given and byrevoked_at IS NULL. Aroles_ofthat errors fails closed: every decision for a person in that tenant is denied while it does, since the principal cannot be loaded. For aPersonprincipal the authorizer adds one parentModuleRole::"payroll.<role>"per active grant, only when payroll is enabled for the tenant. The schema gains the entity typeModuleRole, andUserbecomesmemberOfTypes: ["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 theCtxin a slot only the authorizer instance the bus runs with can open (Ctx::authorizer_cache(&self)), never a handler. The loader refuses a policy literalModuleRole::"m.r"unlessris declared bymandmis the policy's own module, one it depends on, or one that consumes a query it publishes (ADR 0007: core's policy namesModuleRole::"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. - Who may grant.
payroll.grant.setandpayroll.grant.revokeare audited commands (before/after hash of the grant row), allowed to owners only, marked sensitive, and forbidden on doormcpoutright (likeagents.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. - Bootstrap. A new tenant needs no rows: owners hold every payroll permission through
Role::"owner". An owner then grants duties to others. - Salaries. Payroll's field policies permit owners and named
ModuleRoles only, and the employee their own payslip on locked runs. They never nameRole::"admin"orRole::"member"(a test scans payroll's policies for it), so an HR admin without a grant gets every amount redacted. Managers never see salaries: aFieldcarries nomanager(ADR 0001). - Four-eyes.
payroll.run.approveandpayroll.run.lockare refused (DomainError::Forbidden, auditeddenied) when the actor is the run'scalculated_by(the last person to calculate it). The handler checks it afterctx.authorize. - Single-admin exception. The owner-only command
payroll.settings.self_approval(sensitive, not on doormcp, 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 holdsapproverorpayroll_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 getsself_approved = true, and the audit entry gets the flagself_approved(newflags text[]column, set withctx.audit_flag; only onallowedandreadentries). The single-admin condition counts owners and admins withorbit_kernel::count_with_roles(authz.count_people_by_role, a definer function filtered by the tenant). - Agents only draft. An
Actor::Agentmay be permittedpayroll.run.createandpayroll.run.calculateonly, at the row level by explicit policy; payroll forbids it everypayroll.*field. For an MCP agent acting as a person, payroll forbids every payroll field on doormcp, 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.
| Action | Own employee | Manager | HR admin, no grant | Preparer | Approver | Payroll admin | Accountant | Owner | MCP | API client / agent | Other tenant |
|---|---|---|---|---|---|---|---|---|---|---|---|
| grant.set / revoke ★, settings.self_approval ★ | no | no | no | no | no | no | no | yes | never | no | no |
| components, structures (read) | no | no | no | yes | yes | yes | yes | yes | as person | client: by grant | no |
| components, structures, settings (write) ★ | no | no | no | no | no | yes | no | yes | after approval | no | no |
| assignment.create ★ | no | no | no | yes | no | yes | no | yes | after approval | no | no |
| assignment amounts (read) | own | never | redacted | yes | yes | yes | yes | yes | redacted | no | no |
| run.create, inputs, calculate | no | no | no | yes | no | yes | no | yes | as person, no amounts | agent: create, calculate | no |
| run.submit | no | no | no | yes | no | yes | no | yes | as person | no | no |
| run.approve ★, run.reject | no | no | no | no | yes, not own calc | yes, not own calc | no | yes, not own calc unless single-admin | after approval | no | no |
| run.lock ★, mark_paid ★ | no | no | no | no | no | yes (lock: not own calc) | no | yes (same) | after approval | no | no |
| correction.create ★ | no | no | no | yes | no | yes | no | yes | after approval | no | no |
| run.get, run.lines (amounts) | no | no | redacted | yes | yes | yes | yes | yes | redacted | no | no |
| payslip.mine, explain, ytd | own, locked | no | no | yes | yes | yes | yes | yes | redacted | no | no |
| file download (bank, statutory) | no | no | no | no | no | yes | no | yes | no | no | no |
| parallel import, variance explain | no | no | no | yes, not own pay | yes, not own pay | yes, not own pay | no | no | never | no | no |
| variance.report | no | no | no | yes | yes | yes | yes | yes | never | no | no |
| signoff.record ★ | no | no | no | no | no | no | yes | no | never | no | no |
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.entriesgainsflags; ADR 0007 addsvia. One migration for both.
Alternatives considered
- More token roles (
payroll_adminin 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_rolestable. 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
Userattribute (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
relationsonly, the sole owner of a tenant may grantcase_handlerto themselves (flagself_granted), and owners hold no case power through their role.