Write the rules / The rule model
The rule model
Every rule has the same small shape: an effect, who it is about, what they do, to what kind of record, and the conditions that compare them. One evaluator reads them all, so every rule is checked the same way and reads back as a sentence.
A rule
# A teller or payment officer may approve a payment order up to their approval limit,
# provided they did not raise it themselves.
id: approve-within-limit
effect: allow
subjects:
role: [teller, payment_officer]
actions: [approve]
resources:
type: [payment_order]
conditions:
- {attr: approval_limit, op: subject_gte_resource, resource_attr: amount}
- {attr: initiator, op: subject_id_neq_resource}
It is one file, policies/rules/approve-within-limit.yaml, from the banking pack. The comment on top is Caroline's sentence for the rule, written on every save and never read back: the fields decide. The attribute names are your vocabulary's, so they differ from pack to pack.
The fields
| Field | Required | What it says |
|---|---|---|
id | yes | Lower-case words joined by hyphens, unique in the installation. The file is named after it. |
effect | yes | allow or deny. |
subjects | Attribute and its allowed values. Every attribute listed must match; any one of its values will do. Leave it out to mean anyone. | |
actions | yes | The action names; "*" means any action. |
resources.type | yes | The kinds of record; "*" means any kind. |
conditions | Comparisons between the subject, the record and the request, all of which must hold. | |
description | Your notes. Kept across saves, unlike comments. | |
shadow | true: the rule is evaluated and measured but does not decide. | |
owner | The team or role that answers for the rule, never a person's name. | |
review_by | A date (YYYY-MM-DD) by which someone should look at it again. |
Attribute values are strings or whole numbers. When a person's attribute holds a list, the rule matches on any item in it.
Conditions
Seven operators compare what Caroline holds about the subject, the record and the request.
| Operator | Holds when | Typical use |
|---|---|---|
subject_eq_resource | the subject's attr equals the record's | own department only |
subject_gte_resource | the subject's attr is at least the record's | approval limit against amount, clearance against classification |
resource_in_subject_list | the record's field is in the subject's list | an aircraft type in the pilot's ratings, a gateway in the agent's gateways |
subject_id_in_resource | the subject's id is in the record's list | the care team on a patient record |
subject_id_eq_resource | the subject's id is the record's field | with deny: no approving what you raised yourself |
subject_id_neq_resource | the subject's id is not the record's field | with allow: approve only what someone else raised |
context_true | the request's context flag is true | a break-glass flag |
attr names the attribute; resource_attr names the record's field when it is called something else (approval_limit against amount).
On an allow, a condition whose attribute is missing or blank does not hold, so the rule does not match. On a deny, the same miss means the deny does not fire, with one exception: subject_id_eq_resource on a deny also fires when the field names nobody, because if no initiator is recorded the caller cannot be ruled out. Pair that deny with subject_id_neq_resource on the allow it guards.
How rules combine
- Default deny. No matching allow, no access.
- Deny overrides. One matching deny refuses, whatever allows it. Order does not matter.
- Shadow rules take no part. The answer is the one the installation would give without them; what they would have done is reported beside it.
- The gates come first. An agent without its required key, or a call outside its gateway's binding, is refused before any rule is read.
- An agent never exceeds its person. An agent acting for someone is allowed only when its own rules and that person's would both allow it.
Where the values come from
Caroline looks each id up in its own directory at the moment of the decision. A request may describe a subject or a record that Caroline does not hold, and an installation can refuse even that; for anything it holds, and for every agent, what the request says about itself is not read.
RBAC, ABAC and PBAC
Three readings of the same rule, not three engines.
| In a rule | Not claimed | |
|---|---|---|
| RBAC | subjects.role: a role grants an action on a kind of record | role hierarchies or inheritance; list the roles a rule grants to |
| ABAC | any declared attribute, and the seven operators across subject, record and request | free expressions (write those in Rego); time as an operator (computed in the directory) |
| PBAC | each rule a governed policy: a file with an owner, a review date and a shadow mode, every change previewed, recorded and reversible |
Relationship-based access (ReBAC) is not claimed: subject_id_in_resource reads a list on the record, and there is no relationship graph.
When the model cannot say it
Write the rule in Rego instead (Rules in Rego). A Rego rule keeps its id, effect, owner, review date, shadow and description in the YAML, and its logic in policies/rules/<id>.rego, which says only whether it matches. Deny overrides, shadow, the agent gates and the gateway binding apply to it exactly as to any other rule. Caroline checks the module at save: its own package only, no network or random functions, and it must compile beside the evaluator.
The files
policies/policy.yaml the pack, and the rules' ids in order
policies/rules/<id>.yaml one rule
policies/rules/<id>.rego its module, for a rule written in Rego
A change to a rule is a change to one file, so a review or a history is about that rule alone. The schema is served at GET /api/policy-schema, and caroline pull puts it beside your files for your editor.