pola: mechanism vs policy as extreme modularity

Frame the API-shaping section with MarkM's "Security as Extreme
Modularity" slide: keeping policy out of a mechanism is modularity,
and in ocap code it's least authority too, since policy is which
references get handed out. The allowlist bullet now points to
acls-dont. The flower bullet gains its distinguishing force: each
step returns a new immutable handle, since a mutable builder passed
along can be widened. The section moves after the test example it had
split from its list, and a sources footer cites the slide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dckcandClaude Opus 5.5 committed 2026-11-04 21:20:17 -06:00
1 parent f720e3d341
commit b5411466e3
1 file changed
+24 -10
+24 -10
View File
@@ -30,16 +30,6 @@ So at each level, code has two roles:
- **The test takes the spontaneous step; actors carry out the consequences.** Give an actor what it knows at construction and let it decide how to act: `alice.run()`, or `alice.tradeWith(bob)` to introduce a counterparty. Don't drive it with arguments that decide for it, like `alice.pay(to, amount)`: that is the test acting with Alice's authority, as if it held her purse. What an actor hands others (a deposit facet, a shop) carries no authority to spend for it. - **The test takes the spontaneous step; actors carry out the consequences.** Give an actor what it knows at construction and let it decide how to act: `alice.run()`, or `alice.tradeWith(bob)` to introduce a counterparty. Don't drive it with arguments that decide for it, like `alice.pay(to, amount)`: that is the test acting with Alice's authority, as if it held her purse. What an actor hands others (a deposit facet, a shop) carries no authority to spend for it.
- **Modules decide what authority enters through imports and leaves through exports.** Export makers, not instances that close over power ([no-ambient-authority](../no-ambient-authority/SKILL.md)). - **Modules decide what authority enters through imports and leaves through exports.** Export makers, not instances that close over power ([no-ambient-authority](../no-ambient-authority/SKILL.md)).
## Shaping an API: hand out authority, then narrow it
- **Attenuate; don't allowlist.** Access control is which narrowed capability you were handed, not a list some component consults. A bot doesn't check senders against an allowlist; its holder narrows "hear everyone" to "hear Dan" and hands the bot only that. Then the bot can't hear anyone else, and no code needs to check.
- **A service is mechanism; its creator sets policy.** A service knows how to hand out and narrow access, and nothing about who should get it, what they say with it, or on what terms. The party that creates the service composes its pieces with others. New kinds of authority come out of that composition: a governor that fences a mower by pushes, or a seller that sells "talk to user X" at $1, refusing after N sales. Neither the mower nor the Discord vat knows about fences or prices.
- **Make it flower-shaped: narrow, then fire.** A handle to something wide offers narrowings that each return a narrower handle, and the act comes last: `socket.pathjoin(p).withHeaders(h).connect(listener)`, not `connect(url, headers, listener)`. Each step can only narrow: patterns intersect, and a header that contradicts an earlier grant throws. The raw device can keep the wide call. A vat over it hands out the flower, as WebApp does over the fetch device.
- **Narrow along the lines the protocol needs.** Check where the authority actually has to go. Discord sends a resuming client to another host, which a handle narrowed by path can't reach. A narrowing by host pattern (`withinHost('*.discord.gg')`) covers exactly that, so there's no need to widen the handle back to "anywhere".
- **A narrowing is data, not a callback.** Pass a pattern (an Endo `M` pattern; it's passable, so it can cross vats) for the service to apply. A predicate object called on every item sees everything it filters, so it already holds the authority it was meant to narrow.
- **Hand out a reference to a secret, not the secret.** When the secret has to go inside a payload, such as a token in a WebSocket frame, a splicer holds the secret and gives out a ref exo it alone can redeem. Accept the ref only in the fields that carry it to its proper recipient. If a field Discord broadcasts would also accept it, anyone with the ref can publish the secret.
- **One primitive, with libraries on top.** A timer device offers `wakeAt(t, handler)`; repeaters and cron schedules are a library over it, and each schedule is its own object whose holder can cancel only that one. Reading something is authority too: `wake(now)` reveals the clock, so a vat that may wait but not read the time gets a delay-only facet.
```ts ```ts
// wrong: one scope holds everyone's purses; Bob's code could spend Alice's // wrong: one scope holds everyone's purses; Bob's code could spend Alice's
const alice = { usdc: await E(usdc.issuer).makeEmptyPurse(), ... }; const alice = { usdc: await E(usdc.issuer).makeEmptyPurse(), ... };
@@ -59,6 +49,26 @@ const makeAlice = async ({ usdcIssuer, stockIssuer, dollars }) => {
await alice.tradeWith(bob); // the one spontaneous step await alice.tradeWith(bob); // the one spontaneous step
``` ```
## Shaping an API: hand out authority, then narrow it
Security is extreme modularity. MarkM's slide puts it as two parallel principles:
> Modularity: Avoid needless dependencies
> Security: Avoid needless vulnerabilities
> Vulnerability is a form of dependency
> Mod: Principle of info hiding - need to know.
> Sec: Principle of least authority - need to do.
So the moves that make a module well-factored also make it hold less authority:
- **A service is mechanism; its creator sets policy.** Keeping policy out of a mechanism is modularity. In ocap code it is least authority too, because policy is which references get handed out. A service that only hands out and narrows access needs no authority to decide who gets what, so it holds none. Its creator decides by what it hands out, and new kinds of authority come out of that composition: a governor that fences a mower by pushes, or a seller that sells "talk to user X" at $1 and refuses after N sales. Neither the mower nor the Discord vat knows about fences or prices.
- **Don't check who's asking; hand out narrowed capabilities.** An allowlist inside the service is policy inside the mechanism ([acls-dont](../acls-dont/SKILL.md)).
- **Make it flower-shaped: narrow, then fire.** A handle to something wide offers narrowings that each return a narrower handle, and the act comes last: `socket.pathjoin(p).withHeaders(h).connect(listener)`, not `connect(url, headers, listener)`. One wide call needs its caller to hold every argument's authority at once; a chain lets each holder narrow it and pass it on. Each step returns a new, immutable handle that can only be narrower: patterns intersect, and a header that contradicts an earlier grant throws. A mutable builder that gets passed along lets whoever holds it widen what you handed out. The raw device can keep the wide call, and a vat over it hands out the flower, as WebApp does over the fetch device.
- **Narrow along the lines the protocol needs.** Check where the authority actually has to go. Discord sends a resuming client to another host, which a handle narrowed by path can't reach. A narrowing by host pattern (`withinHost('*.discord.gg')`) covers exactly that, so there's no need to widen the handle back to "anywhere".
- **A narrowing is data, not a callback.** Pass a pattern (an Endo `M` pattern; it's passable, so it can cross vats) for the service to apply. A predicate object called on every item sees everything it filters, so it already holds the authority it was meant to narrow.
- **Hand out a reference to a secret, not the secret.** When the secret has to go inside a payload, such as a token in a WebSocket frame, a splicer holds the secret and gives out a ref exo it alone can redeem. Accept the ref only in the fields that carry it to its proper recipient. If a field Discord broadcasts would also accept it, anyone with the ref can publish the secret.
- **One primitive, with libraries on top.** A timer device offers `wakeAt(t, handler)`; repeaters and cron schedules are a library over it, and each schedule is its own object whose holder can cancel only that one. Reading something is authority too: `wake(now)` reveals the clock, so a vat that may wait but not read the time gets a delay-only facet.
## Review checklist ## Review checklist
Before committing, for each new maker, scope, and export: Before committing, for each new maker, scope, and export:
@@ -68,3 +78,7 @@ Before committing, for each new maker, scope, and export:
3. Could a narrower facet replace what's passed? Does any facet let a caller spend for its owner, or does the test decide what an actor does? 3. Could a narrower facet replace what's passed? Does any facet let a caller spend for its owner, or does the test decide what an actor does?
4. Name the wiring layer at this level. Is it small? 4. Name the wiring layer at this level. Is it small?
5. Does any component check an allowlist, or take a policy decision that its creator could make by narrowing what it hands out? 5. Does any component check an allowlist, or take a policy decision that its creator could make by narrowing what it hands out?
## Sources
- [From E to EcmaScript and Back Again](https://qconsf.com/sf2010/dl/qcon-sanfran-2010/slides/MarkS.Miller_FromEToECMAScriptAndBackAgain.pdf): Mark S. Miller, QCon SF 2010; slide 3 is "Security as Extreme Modularity".