Write a policy
policy(id, cedar…) holds exactly one permit or forbid. Interpolate handlers, views, objects, and properties, and Tilde writes the Cedar names for you.
ontologies/crm/policies.ts
ontology({ policies }).
Who is calling
Each call carries a subject, and the actors acting for it. The subject and every actor must each be allowed. An agent never exceeds the person it acts for, and the person never exceeds the agent.- A person in Live or a space calls as
user:<id>. - An agent serving a signed-in Tilde user calls as
user:<id>, withagent:<id>as its actor. - An agent on a routine, or talking to a channel address such as a phone number, calls as
agent:<id>.
principal.type == "user" or "agent", a Tilde group with principal in ${group("sales")}, or one agent with principal == Principal::"agent:<id>".
What a policy applies to
- A view instance,
resource is ${CustomerView}, for the view’s reads and actions.resourcehas the root object’s properties, such asresource.tier. - All data,
resource == ${lake}, for view-less reads. They also needqueryon each object they read. - A property,
resource == ${Customer.internalNotes}, forreadFieldand for each edit an action makes. - A space, for
openSpace. See Spaces.
context.input is the handler’s input, typed from its zod schema.
Field masking
A caller sees a property only withreadField on it. Otherwise the value is null wherever a handler loads it, in output fields tagged with prop(), and inside handler SQL. Grant readField broadly, and forbid the sensitive properties.
Edits
Each edit an action makes is checked on its own. Edits are permitted by default, so only aforbid refuses one. The notes-for-people policy above stops agents changing internal notes through any action.
Approvals
An action can require a person’s approval. Permit it only whencontext.approved is true. A caller who is otherwise allowed then gets pending approval, and the input waits for a decision.
- Nobody in the requester’s own chain can approve their request.
- Approvals expire after seven days.
- Tilde checks the requester’s policies again when the request is approved.