Contents

Threat model

The adversary is the agent. A model that hallucinates, a model that was prompt-injected, or a fully hostile client: it holds a connection as its role and can send anything the wire protocol carries – any statement, any startup parameter, the extended protocol, a cursor, garbage.

Where the line is. The gate bounds what the agent names – the statement it proposes and the rows that statement changes – plus the row count. What a DBA attaches to a table (a trigger, a CHECK or DEFAULT, a generated column, a view) is trusted code that runs with its own rules: the gate refuses the nested utility such code fires (0.2.4) and counts the rows it writes, but it does not read a definer function’s body or re-decide what a view may show.

What the gate guarantees against it, each with a suite above:

  • nothing the session types executes except the seven verbs, transaction control, SHOW, DISCARD, DEALLOCATE, RESET and the settings an agent may SET;
  • a proposal runs only after PostgreSQL’s parser, planner, analyzer and rewriter accept it as one statement of a kind the agent may run;
  • a write that touches more than max_rows rows, or breaks a bound assertion, is undone; and its writes over a window stay within its budget (0.4.0); an allow_ddl agent’s CREATE TABLE AS or SELECT INTO cannot carry a write (0.4.2), and the rows a DDL’s default, constraint or index expression changes in other tables are counted like a write’s (0.4.3);
  • a read changes nothing the record would not show: no sequence, lock or large object, wherever the code that would change it sits (0.4.3);
  • no other role can become it: with the library in shared_preload_libraries, an agent role has no members, so no session but its own login can SET ROLE into it (0.4.1) – connect each agent, or each seat of a broker, as its own role. With only the per-role session_preload_libraries that register_agent sets, the sessions of other roles do not load the gate, and a superuser’s session that has not loaded it can still GRANT the agent role to another (measured on 18.6, 2026-11-12): don’t, or preload it;
  • nor do its rights work for it outside its session (0.4.5): where PostgreSQL runs code as an object’s owner – maintenance and the autovacuum evaluating an index expression, a view or a rule writing, a SECURITY DEFINER or trigger function – and that owner is an agent, no function of the agent’s starts, nor a built-in that changes state, and nothing is written with its rights outside its own relations (what that costs and leaves out: docs/limits.md);
  • the context its row-level policies read cannot be moved – not by SET, not at connection start, not by set_config() inside a proposal: in the statement, in SQL passed to a function as text, in a function’s body, a constraint or a default (0.4.2), a domain’s CHECK or a type’s support function (0.4.3), nor by a function’s SET clause (0.4.2);
  • everything it proposed and did is recorded append-only, including why anything was refused.

What it trusts, and is out of scope:

  • superusers, and whoever can edit postgresql.conf or restart the server: they can unload the gate. That is why register_agent refuses a superuser role – an agent that can leave the gate is not behind it;
  • the DBA’s grants: GRANT is still the authorization. The gate adds verification, it does not invent privileges or take them away;
  • grants that reach the server’s files: register_agent refuses the roles that can leave the gate, not the ones that read more, such as pg_read_server_files. An agent granted EXECUTE on pg_read_file reads a server file through a proposed read. Grant those only on purpose;
  • the functions and views the agent is granted: they run with their own rules (see below);
  • the operating system and the server binaries.

What it does not protect, by design: intent. A well-formed statement, within the agent’s privileges and under max_rows, runs. Measured: asked to “set every customer’s plan to free”, the model wrote UPDATE ... WHERE plan <> 'free', which touched 2 rows under a limit of 5, and the gate kept it – correctly, by its contract. Bound the blast radius with a small max_rows, bind assertions that must keep holding, and put a human on dry_run for writes that matter.