Part 3 of 14 · 3 min read
A gateway runs the same checks on every call, in code the model cannot skip
Least privilege is not one switch; it is a sequence of checks that every call has to pass in order.
Think of an airport security line. A boarding pass alone does not get you onto the plane. You pass a document check, a scanner, and a gate check, each one independent and each one able to stop you alone.
In plain words: a gateway is the one place every tool call passes through. It applies several independent dials in a fixed order: what can be said, what the grant permits, which rows, how much and how often, and who must agree. No single missing control is then the only thing standing between a request and the database.
A worked example. Starting from setup C2 (a standing grant, an approver who rubber-stamps everything) and switching off one control at a time against the same eight attacks: with every control on, the "close every ticket" attack still gets through for 2 tickets (the quota's limit). Switching off the scope check additionally exposes card endings. Switching off the row check lets a note land on another customer's ticket. Switching off the quota raises the "close every ticket" damage from 2 rows to 3. Switching off request validation (the refund cap) lets a 5000 refund straight through. Switching off approval changes nothing at all, because the approver in this setup was already saying yes to everything.
The key lines. From code/mini-privilege/privilege.py:
# from code/mini-privilege/privilege.py
if "scope" not in self.disable and tool.scope and tool.scope not in grant.scopes:
return self._log(name, args, "denied", f"missing scope {tool.scope}",
f"Error: not permitted. {name} needs the {tool.scope!r} permission, which this task was not given.")
if tool.row_check and "row" not in self.disable:
err = tool.row_check(self.desk, grant, args)
if err:
return self._log(name, args, "denied", "outside row scope", err)
if tool.validate and "validate" not in self.disable:
err = tool.validate(self.desk, grant, args)
if err:
return self._log(name, args, "denied", "invalid request", err)
if "quota" not in self.disable and tool.effect != "read" and grant.writes_used >= grant.max_writes:
return self._log(name, args, "denied", "write quota used", f"Error: this task may make at most {grant.max_writes} change(s), and has made them.")
Read it as: each if is its own independent gate, and any one of them returning early stops the call. The disable set exists only so the module's own experiment can switch off one gate at a time and show what each one was actually doing. In a real gateway every gate stays on, always, for every call.
Gateway
The gateway is the one place every tool call passes through. Scope, row, limits, quota and approval are checked there, in code outside the model, in the same order, for every call.
Example: switching off the refund-validation gate alone let a 5000 refund through, even with every other gate still on. That result is only visible because the gateway runs every gate on every call. Removing one gate and nothing else isolates exactly what it was doing.