allow. Declare a guard
with forbid(scope, { message, where }) and place it anywhere in the app
tree. The host enforces it at the act, whichever function does it.
bijection/invoices.ts
Forbidden. The refusal’s message
is the guard’s reason, and its guard is the guard’s tree path
(invoices.fixedCurrency): the path is the guard’s identity.
Scopes
A scope names its declaration by value. Useact.grant to guard
ctx.grant, and act.write to guard changes to a table’s facts.
Pass an array to cover several scopes with one guard,
forbid([act.grant(hr), act.disclose(payroll)], …). It sees only the roots
the scopes have in common.
Write guards share one commit-time act per changed fact. Its before
is the committed image at the transaction’s basis, and its after is the
final staged image. Use act.write(table, { transition: "create" }) to
guard an absent fact becoming present, "update" for a present fact
changing, and "remove" for a present fact becoming absent. A write
followed by a patch of its new fact is still a creation. A keyed put
can create or update, and a retraction of a present keyed fact removes
it. Equal images and an insert followed by a deletion of the same fact
produce no write act. A fields filter compares only the two final
decision images, as does a guard on a machine’s edge.
The staged verb still matters to verb-specific scopes. The creation
followed by a patch also matches act.patch. The SDK stages keyed
patches and replacements as puts, and keyed deletes as retractions.
The last staged write supplies writer (the function’s tree path) and
the grants offered for all matching scopes, including when that write
came from a nested call.
Roots
Every guard reads one record of the act: the same values asctx.frame, the grant being decided, and the roots
of its act. The where: tier describes comparisons over those values.
The host computes
a.now, a.mfaAge, a.holdings and a.readSet; the
caller cannot supply them. a.args and a.after are chosen by the caller,
so a guard may read them only to refuse.
Field types follow the declared value types: t.boolean is a boolean, t.int
an integer, t.string, t.key(table) and t.principal strings, t.instant
an instant, t.one(...) of literals an enum, and t.maybe(x) nullable. A
field of any other type is out of the where: tier; read it in when:.
Purpose of use
A sensitive function can declarewhy as an argument using
purposeArgs from @bijectionhq/library-sensitive-data. Apply the
library’s ordinary where: guard to the function’s entry.
{ why: { purpose: "case-review", reference: "CASE-42" } } to
the call. A null or mismatched purpose returns the guard’s Forbidden
prompt. Inside the guarded handler, call recordPurpose(ctx, why) before
the sensitive operation to record the evidence in Deployment History under
the run’s label.
A guard judges each offered grant
An act is offered through each live grant of each party: the caller, its code and its credential. Every guard in scope judges each grant on its own, witha.offer bound to that grant and its whole role chain. A grant some
guard refuses is removed; the act is admitted if the grants that survive
still cover it together (how an act is decided).
- A guard only removes grants. Adding a guard never admits an act, and a guard about one role refuses only the grants of that role: it never removes a right another grant holds.
a.offer.role.equals(manager)anda.offer.role.oneOf([clerk, manager])take role values and refuse exactly the grants of those roles.a.offer.chainincludes the roles of the grants it was issued from, so a delegated or invited grant still answers for its origin.- Open entries (
allow: [role.anyone],allow: [role.signedIn]) are class grants, judged like any other grant. - A rule about the actor uses
a.as,a.holdingsor a fact read. An actor-wide rule refuses the act through every grant. - Session-bound roles (break-glass, fresh sign-in) are short grants plus
guards on
act.grantand on the entry (example). - When guards remove every grant that would cover the act, the refusal is
the first grant’s (by grant order) that reached a guard refusal:
Forbidden, with thatguard. With no covering grant at all it isDisallowed.
clerk pays through the treasury grant; the same
person acting only as a clerk is refused.
Two tiers
Give a guard exactly one of them. Prefer
where:; use when: for a
condition the builder cannot state.
The where: builder
There is no multiplication, no sum of two terms and no call. A
where: that
returns a JavaScript boolean is a type error (WhereNotTerms): build it from
terms, a.after.state.equals("paid"), not ===.
Nulls. A field read through null is null. Every comparison with a null
operand is false, except .isNull(), .isNotNull() and .equals(null).
Use .isNotNull() to test presence. To make another predicate depend on
presence, use a.before.isNotNull().ifElse(whenPresent, a.false).
Read facts
Every scope offers the frame’s roots:a.as, a.offer, a.holdings, a.chain, a.mfaAge, a.readSet, a.on, a.now,
a.under (the act’s commit label, as a set of tags), a.in (its world,
null at the head) and a.at (its valid instant).
A where: guard reads one fact with a.get(point) and tests presence with
a.has(point). A point is table(key) or table({ uniqueFields }), and its
key may be a term. A rule about the roles a person holds reads
a.holdings.has(role), not sys.grants.
Bounded arrays and deliveries
An array whose schema declares a maximum length (t.named(…, { length: { maximum } })) offers xs.every((x) => …) and xs.length.lessOrEqual(n)
(and the other comparisons with an integer literal). Both unroll into one
conjunct per possible element, which counts against the guard’s budget, and
the lock prints the unrolled form. An element’s fields are nullable terms.
An array without a declared maximum offers neither; deploy refuses a rule
over one.
A write a claimed reply lands reads a.delivery: the delivered task
record, taken from the stored task, never from args. It holds tid,
replyTo (the reply function and the place it writes at), observed,
start and the delivered rows, bounded by the receiver’s page size. On
any other act, a rule that reads a.delivery refuses.
Holdings rules
To block approval by a requester, read the caller’s holdings when they enter.a.holdings holds the roles of the caller’s live grants and, for an
agent, those of the person it acts for, so a delegate cannot approve what its
delegator could not. A requester grant committed after an earlier successful
entry makes the next entry refuse through every grant, including a
still-eligible approver grant.
separationOfDuties states the same rule per role
(library rules).
A rule that reads holdings is the one kind of guard that a new grant can make
stricter, so the lock marks it [reads holdings]. Every when: guard is
marked too, since it may read them.
A guard on a fact’s fact reads it the same way:
- Give every guard that reads facts an explicit
under, includingunder: label.publicfor public facts. - If the table can place facts above that label, the read refuses. The guard cannot mistake an unreadable fact for an absent one. A grant presence check also refuses when its role can place grants outside the lookup scope.
- The reads join the transaction’s read set: a conflicting change to a fact a guard read invalidates the decision.
- Read a family table, series, timeline or other
sysfact inwhen:.
The when: tier
A when: function receives the act’s roots as plain values, and the read
verbs get, has and list at the guard’s under. It has no other ctx
verb. Use a.list(selection.atMost(n)) to require a complete result within the stated bound.
- It runs inside the transaction it judges: at its version, as its caller,
over the facts the transaction has written so far. At commit, that is the
state the transaction leaves. Its reads of facts the transaction did not
write join that transaction’s read set, so a conflicting change to what it
read invalidates the decision, as for
where:facts. - A write in a branch is judged in the branch: the guard reads the branch at the version the call entered. When the branch lands, its writes are judged again at head, where the land reads; a conflicting change there makes the land run again.
- A refused read refuses the act, even when the function catches it.
- A guard whose
underis above the caller’s label refuses without running: a guard never reads what its caller cannot.
One transaction, several acts
A guard on a write, or on a grant, revocation, disclosure, submit or erasure, is judged at commit against the state the transaction leaves, with every write and grant of the transaction in it:- two inserts that a write guard counts against a bound both count;
- a transaction that updates two facts one guard compares commits only if
the pair it leaves passes the guard. Raising an
amountand itslimittogether commits when the newamountis within the newlimit.
ctx.open, is judged again at commit, which can only refuse
more.
An act.enter guard is judged when the call enters, over what the
transaction has written so far, and is not judged again at commit: it
decides the entry, and the writes its function then makes are its own.
Separation of duties takes two forms. “A holder of requester may not
approve” is the entry rule above, over the caller’s holdings. “No one holds
requester and approver together” is enforced at issuance: act.grant and
act.revoke offer a.grant.holdings, the roles of the recipient’s
(a.grant.to) live grants read at the grant’s label, plus the issued
grant’s own chain. Guard each role’s issue with the other. Here finance
covers both roles’ grants and flows to the label of each guarded act.
[reads holdings].
Fail closed
A guard refuses when its predicate holds or a required read fails or exceeds its budget. Awhen: function also refuses if it throws or returns a
non-boolean. The Boolean connectives .and(), .or(), and .implies()
are strict. condition.ifElse(whenTrue, whenFalse) evaluates the condition
first and reads only the selected branch. Deploy checks the condition and both
branches. A live evaluation can request up to 16 distinct fact points from
the condition and the branch it selects.
The condition and branch read from the same held view at the guard’s
under label. The commit validates those reads, including an observed
absence. If the condition’s read changes before ordering, the attempt must
retry and select a branch again. Adding a guard can only narrow admission
when the other decision inputs are fixed.
Library rules
@bijectionhq/library-policies states the common policies as guards. Each
helper returns one guard (two for breakGlass) to place in the tree, judged
per offered grant like any other:
bijection/policies.ts
The purpose of use guard of
@bijectionhq/library-sensitive-data also records the stated purpose.
A table’s writers: () => [record, pay] is a guard on act.write(table)
that refuses every write not made by one of those functions. It has no
exception: the host, operators and other functions are refused alike. An
operator correction is a mutation of the app that the table’s writers
name.
Guards over a mounted app
A mountable app is a function from its capabilities toapp(...). Its own
guards travel with it, at paths under the mount (billing.ledgerWriters).
The installer can add guards over the mounted app’s acts, naming them by
value through the mounted subtree:
bijection/app.ts
The lock
bijection check --write-lock writes bijection.lock beside
app.ts. Each guarded path lists its guards, and each guard
has one line, sorted by path:
where line carries the guard’s canonical predicate; a when line says
tested. [reads holdings] marks a guard that reads the caller’s holdings:
every when: guard, and a where: guard whose predicate reads a.holdings. The fact lines are the reads where: guards make. Review the lock
diff with the source change: it is the reviewable list of everything an
installation exposes and every guard on it.
The analyzer
bijection check lists every guard with its scopes, label and tier, and
under “Guard inputs” the tables each guard reads (with GuardReadAbove for a read
above the guard’s under). With cvc5 or z3 on PATH it translates each
where: predicate and answers:
Each question is posed per grant: a witness is a grant of a role and an act. Facts are
unknown values, so a witness may name a value no current fact holds. Vacuity
and reachability hold even when reads fail; a policy diff compares decisions
whose reads succeed. Without a solver,
check prints
analysis unavailable: no SMT solver (cvc5 or z3) on PATH and checks the
rest of the app.
Review a guard change
- Change the guard in source and run
bijection check. - Read the policy diff: every newly refused and newly allowed act, with a
witness. Ask
--provefor the acts that must stay refused. - For a
when:guard, test it on the real kernel withkernel(app): an act it refuses, one it allows, one outside its scope and a failing read. - Review each
reason: it is the sentence the caller reads. - Write the lock with
--write-lock, review its diff and commit both.
Trial a call
client.trial(fn, args) runs a call in a discarded world, under the caller’s
own authority, and commits nothing:
writes lists the facts the call would write and tasks the tasks it would
submit. From the terminal, bijection trial invoices.setAmount number=A-1 amount=-5.
A trial’s result is labelled by the join of everything it read, so it never
reveals data above the caller’s clearance.