Summary#
A kit decides who may read its entities, and an app often needs to say less: a build system whose designers read the
model meter must not see what each call cost; a desk whose agents read a kit's contacts must not see their phone
numbers. The app says so in its own source, with a partial entity over the kit's entity and a deny:
partial entity ModelCall {
security {
deny read CostMicros, ReservedMicros when IsDesigner;
}
}That is the whole of it. There is no other spelling and nothing to filter by hand in each read: the rule is the kit entity's own, so every path that reads the table is decided by it.
Signature#
partial entity <KitEntity> {
security {
deny read <Field>, <Field> when <policy>; // a column, for a kind of caller
deny read <Field> when <policy> where <row>; // a column, on some rows
deny read when <policy> where <row>; // whole rows
}
}Name the entity bare beside the kit's using, or qualified (partial entity Osysharp.Llm.ModelCall). The kit must be
one the app uses itself — see [[#through-another-kit]].
Description#
Where does the deny hold?#
On every path that reads the kit's table, because the rule is stored as one of the table's own rules — not as a filter
beside a particular read. Measured on Osysharp.Llm's ModelCall with the deny above, for a designer:
| the read | what the designer gets |
|---|---|
ModelCall.Single() in a function | the row, with CostMicros reading 0 and Security.IsMasked(row.CostMicros) true (Security.IsMasked — was this value withheld from me?) |
ModelCall.Sum(c => c.CostMicros) | 0 — an aggregate is computed over what the caller may read |
ModelCall.Count(c => c.CostMicros > 0) | 0 — a filter on a masked column answers as if it were null, so it cannot find the value one guess at a time |
the app's own LotCall.Include(l => l.Call) (one hop, or .Include(l => l.Call.Price) two) | the included row masked the same way, in the same statement |
LotCall.Count(l => l.Call.CostMicros > 0) | 0 — through the reference too |
REST GET …/entities/ModelCall, $filter=costMicros gt 0, …/LotCall?$expand=call | no cost in the body; the filter finds nothing |
an MCP query_ModelCall tool, and its filter | no cost in the result; the filter finds nothing |
a page's live var calls = ModelCall.…ToList() — and the rows it is pushed when another desk makes a call | no cost on the screen, then or after |
Everyone else reads as before: a curator the deny does not name reads the same rows in full. The kit's own tests app
carries each of these as a test (kits/llm/tests/designers.test.osy).
Can it give anybody more?#
No. A kit's rules are a floor under the app's ([Authority]): a partial's deny takes
away, and a partial's allow admits nobody the kit did not already admit. A keeper the kit does not let read the
meter reads no row of it with or without the partial.
Does it break the kit's own arithmetic?#
No — a mask is on CALLERS, not on the kit:
- What runs as the app reads the real value. An
[On]handler, a workflow body, a kit's own bookkeeping that runs as the app (Osysharp.Agentsadds a call'sCostMicrosto the delegation that made it) reads past the app's mask — even one writtendeny read ReservedMicros when !ManagesModelSpend, which names everybody but one role. - A kit's counters are its own rows.
Osysharp.Llmholds and settles budgets on its spend rows, read throughallow read via(allow read via), never by summing the meter — so a designer's calls are still held against the budget and settled at what they really cost, and refused when the budget has no room. - A figure computed AS ITS CALLER answers what that caller may read.
SpentOn("app:")sums the meter as whoever calls it, so it answers0to a designer — the narrowing holding, exactly asModelCall.Sumdoes.
What about a kit the app has only through another kit?#
An app that uses Osysharp.Agents has Osysharp.Llm's ModelCall in its database without naming that kit. To narrow
it, use the kit yourself — use Osysharp.Llm; in the app { } block and using Osysharp.Llm; in the file. A partial
over it without that is refused, and the refusal names exactly those two lines.
Can every kit entity be narrowed?#
Yes — an entity its kit marks [Authority(Owned)] too, with one difference: over an Owned entity the partial may
carry deny rules and nothing else. The kit keeps every grant and the table's shape; your app may only take access
away from its own people.
partial entity Charge {
security {
deny read Cents when IsDesigner; // a column
deny read when IsDesigner where Purpose == "payroll"; // whole rows, some of them
deny create, update, delete when IsDesigner; // the writes the kit admits them to
}
}Anything else in it is refused at the line you wrote, naming what it found and the shapes above:
| in the partial | over a Narrowable entity (the default) | over an Owned entity |
|---|---|---|
deny read <Field> when …, deny read when … where …, deny create, update, delete when … | accepted | accepted |
allow … | accepted for a verb the kit grants, and admits nobody new (osy lint: security-partial-allow-grants-nothing) | refused |
a member (string? Note;) | accepted — an optional column on the kit's table | refused |
[SuppressWarning(…)] | accepted | refused |
A block-wide default …; or message "…";, and an allow read via, are refused over an Owned entity too.
Deny only a verb the kit grants somebody. On a verb the kit grants nobody, there is nobody to take it from, and a
deny on a write still binds the kit's own code: deny create over a table the kit writes for itself refuses that
write, and the kit's feature fails with it. osy lint names such a line (security-owned-deny-repeats-the-packages);
osy explain prints what the kit grants.
It holds on the same paths and narrows the same way: an Owned entity's own block is a floor exactly like a
Narrowable one's, so the deny takes away and nobody the kit did not admit reads or writes any more; the kit's
allow read via figures still count every row. The test app demo/owned-narrowing proves it on a query, an aggregate,
a filter, an include, REST, MCP and a live page.
Examples#
app Plans {
use Osysharp.Llm;
model "model/**/*.osy";
}
using Osysharp.Llm;
[Principal] entity Person {
[Unique, MaxLength(200)] string Email;
bool Designer = false;
bool Treasurer = false;
security { allow read when IsAuthenticated; }
}
// The kit's three questions: who reads the meter, who sets prices and budgets.
policy ReadsModelUsage => Person.Any(p => p == user && (p.Designer || p.Treasurer));
policy ManagesModelSpend => Person.Any(p => p == user && p.Treasurer);
policy IsDesigner => Person.Any(p => p == user && p.Designer);
// The app's own narrowing of the kit's entity: a designer reads every call, model and purpose — not its cost.
partial entity ModelCall {
security {
deny read CostMicros, ReservedMicros when IsDesigner;
}
}
/// What the meter cost — 0 to a designer, the real total to the treasurer.
long MeterTotal() { return ModelCall.Sum(c => c.CostMicros); }See also#
- [Authority] — why a kit's rules are a floor, and what
Narrowable,OwnedandExtensiblemean - security { } — the layers a
deny read <Field>is decided in - Security.IsMasked — was this value withheld from me? — telling a masked value from a real 0
- allow read via — how a kit computes a figure over rows its caller may not read
- deny on an inherited field — narrowing a field on a subtype instead