CarolineDocs

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

FieldRequiredWhat it says
idyesLower-case words joined by hyphens, unique in the installation. The file is named after it.
effectyesallow or deny.
subjectsAttribute and its allowed values. Every attribute listed must match; any one of its values will do. Leave it out to mean anyone.
actionsyesThe action names; "*" means any action.
resources.typeyesThe kinds of record; "*" means any kind.
conditionsComparisons between the subject, the record and the request, all of which must hold.
descriptionYour notes. Kept across saves, unlike comments.
shadowtrue: the rule is evaluated and measured but does not decide.
ownerThe team or role that answers for the rule, never a person's name.
review_byA 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.

OperatorHolds whenTypical use
subject_eq_resourcethe subject's attr equals the record'sown department only
subject_gte_resourcethe subject's attr is at least the record'sapproval limit against amount, clearance against classification
resource_in_subject_listthe record's field is in the subject's listan aircraft type in the pilot's ratings, a gateway in the agent's gateways
subject_id_in_resourcethe subject's id is in the record's listthe care team on a patient record
subject_id_eq_resourcethe subject's id is the record's fieldwith deny: no approving what you raised yourself
subject_id_neq_resourcethe subject's id is not the record's fieldwith allow: approve only what someone else raised
context_truethe request's context flag is truea break-glass flag

attr names the attribute; resource_attr names the record's field when it is called something else (approval_limit against amount).

A missing value never opens access

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

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 ruleNot claimed
RBACsubjects.role: a role grants an action on a kind of recordrole hierarchies or inheritance; list the roles a rule grants to
ABACany declared attribute, and the seven operators across subject, record and requestfree expressions (write those in Rego); time as an operator (computed in the directory)
PBACeach 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.

Caroline DocsAuthZEN 1.0 · OPA