Osy#betaRun it on Osyrin: osyrin.com

Reference / Security

Narrowing a kit's entity for your own people

partial entity <KitEntity> { security { deny read <Field>, … when <policy>; deny read when <policy> where <row>; } }

An app hides a column or a row of a kit's entity from a role of its own with a `partial entity` over it: `partial entity ModelCall { security { deny read CostMicros when IsDesigner; } }`. The deny holds on every path that reads the table — a query, an aggregate, a filter, an include, REST, MCP, a live page — and it only ever narrows: the kit's own rules stay the floor, and the kit's bookkeeping still reads what it needs.

stable1 example compiled by CIsecuritypackageskitsauthorization

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 readwhat the designer gets
ModelCall.Single() in a functionthe 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=callno cost in the body; the filter finds nothing
an MCP query_ModelCall tool, and its filterno 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 callno 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.Agents adds a call's CostMicros to the delegation that made it) reads past the app's mask — even one written deny read ReservedMicros when !ManagesModelSpend, which names everybody but one role.
  • A kit's counters are its own rows. Osysharp.Llm holds and settles budgets on its spend rows, read through allow 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 answers 0 to a designer — the narrowing holding, exactly as ModelCall.Sum does.

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 partialover a Narrowable entity (the default)over an Owned entity
deny read <Field> when …, deny read when … where …, deny create, update, delete when …acceptedaccepted
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 tablerefused
[SuppressWarning(…)]acceptedrefused

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#

Related

[Authority]

What an app that imports your entity may do to the `security { }` you declared on it. The default is `Narrowable` — the…

security { }

The rules that decide who may read and write an entity's rows. A where clause filters by the row (the owner sees their…

Security.IsMasked — was this value withheld from me?

A field a `deny read` withholds reads as its type's default — 0, false, DateTime.MinValue, the enum's zero; null for a…

allow read via

Names the functions whose OWN reads of the entity see every row — past its read rules and its field masks — to compute…

deny on an inherited field

A subtype may NARROW a field it inherits — `deny read Notes when !IsReviewer;`, `deny update Code except via Recode;` —…

when is who, where is which rows

A rule's `when` says WHO it is for and its `where` says WHICH ROWS. A rule whose `when` does not hold is never asked…