AI Agents Don’t Need More Permissions. They Need Row-Level Security.

Artificial Intelligence / Agent Security

Most guides to securing AI agents talk about prompt injection, jailbreaks, and tool permissions. Almost none of them talk about the database. That is the gap: an agent can have a perfectly scoped set of tools and still read or write any row in your database, because the credential behind those tools was never scoped to begin with.

The problem: agents inherit the widest privilege available

When a team wires an AI agent to a database, the fastest path is almost always the same: generate a service-role key or an admin connection string, give the agent’s backend that one credential, and let the application code decide what the agent is “allowed” to do. It works in a demo. It becomes a liability the moment the agent’s reasoning does something the developer did not anticipate — which, with LLM-driven decisions, is not a hypothetical.

Supabase’s own engineering team has flagged this pattern directly: AI-generated schemas rarely include Row Level Security policies, and without an explicit ALTER TABLE ... ENABLE ROW LEVEL SECURITY, every row in a public table is reachable by anyone holding the API key — including the agent’s own backend process, and anything that manages to run code inside it.

Why this matters now, not eventually

Prompt injection is no longer a novelty attack

OWASP’s 2026 LLM security reporting places prompt injection as the fastest-growing attack category, with year-over-year growth reported around 340%. It is now the default entry point security teams plan for, not an edge case.

The target has shifted from the chat window to the data layer

2026 research on agent data injection describes a distinct threat class: attacks that manipulate the data an agent retrieves, not just the prompt it receives, to make the agent take unintended actions with its own legitimate credentials.

Supply chain compromise now reaches agent frameworks directly

A compromised package on PyPI in March 2026 sat live for roughly three hours and reached about 47,000 downloads before removal — it was a dependency used by several popular agent frameworks, not an obscure library.

None of these attacks require breaking the model. They require finding an agent whose database access is broader than its task — which, per Supabase’s own findings, describes most agents built quickly on top of a shared admin key.

What Row Level Security actually buys you

Row Level Security (RLS) moves the access decision from application code — which the agent’s own reasoning can influence — to the database itself, which cannot be argued with by a clever prompt. Three properties matter specifically for agents:

Scoped by identity, not by trust in the calling code

A policy tied to auth.uid() or an equivalent claim restricts every query to rows the authenticated identity owns, regardless of what the application layer intended to allow. The agent’s backend never gets to unilaterally decide “this one’s fine.”

Survives a compromised or manipulated reasoning step

If a prompt injection convinces the agent to query for the wrong project, customer, or user, a correctly written policy returns nothing for rows outside the caller’s own scope — the bad query still runs, but it comes back empty instead of leaking data.

Fails closed by default

Enabling RLS on a table without policies denies all access until policies are added explicitly. That is the opposite of the common alternative — a service-role key, which fails open: any code holding it can read or write anything, by default, forever.

How this looks in a real, deployed agent

This is not a theoretical recommendation. It is the access model already running in production behind IVE, InsightValues’ own execution engine, described here exactly as documented on its own reference implementation page — no new claim, no adjusted framing.

JWT VALIDATED
IDENTITY FROM sub CLAIM
RLS-SCOPED QUERY
READ-AFTER-WRITE CHECK
Identity: taken only from the validated JWT’s sub claim — never from a request body field a client could set.
Database access: public key + the caller’s own JWT — the service_role key is never used at runtime.
Row scope: Row Level Security active on every query, with no bypass path in the request handler.
Provenance: the action’s origin field is fixed by the runtime as “ive_agent” — the model cannot override it.
Verification: after a write, the agent calls a read (get_action) and only reports success if the row is actually found.

Each line above maps to a real, previously disclosed detail of the IVE Strategic Execution Agent’s implementation — not a new architectural claim introduced for this article. The pattern generalizes beyond this one system: identity from a verified token, data access scoped at the row level to that identity, and a verification step that checks the database instead of trusting the model’s own report of what happened.

Trade-offs and limitations

RLS is necessary, not sufficient, and it is worth being explicit about what it does not solve:

Policy complexity is real engineering work

Multi-tenant, role-based, or shared-resource access patterns require deliberately designed policies. A poorly written policy can silently over-restrict legitimate access or, worse, under-restrict it — RLS removes one failure mode, it does not remove the need for careful design.

It does not stop misuse within a legitimate scope

If an agent is manipulated into taking a harmful action against data it is genuinely authorized to touch, RLS will not intervene — that is a policy/authorization problem at the action level, which is a separate control (in IVE’s case, addressed by a human-in-the-loop authorization gate before execution, not by RLS).

Performance is not free

Naive RLS policies that run subqueries per row can be slow at scale; the common fix — SECURITY DEFINER helper functions or caching role claims in the JWT itself — is itself an engineering decision that needs review, not a default to assume.

What this means if your team is building agents now

A short, practical checklist that follows directly from the above:

1. Enable RLS on every table before the first agent tool is connected

Not after a review flags it. Default-deny is the entire point.

2. Never give an agent runtime a service-role or admin key

If the agent’s backend can bypass RLS, RLS is decorative.

3. Derive identity from a validated token, never from request payload fields

Anything a client can set, a manipulated agent can set too.

4. Verify writes by reading them back, not by trusting the model’s own success report

A read-after-write check catches both bugs and manipulated executions.

5. Treat action-level authorization as a separate control from data-level access

RLS answers “can this identity see this row.” It does not answer “should this action happen at all.”

Verified

The IVE architecture details cited in this article (JWT-based identity, RLS-only database access, fixed origin field, read-after-write verification) are drawn directly from the already-published IVE Strategic Execution Agent reference page, not inferred or newly disclosed here.

Honest limitation

This article does not benchmark RLS performance at scale, and it does not claim RLS alone makes an agent secure. It is one necessary layer among several — identity verification, action-level authorization, and RLS together, not any one of them in isolation.

Sources: Supabase Engineering, “Postgres Best Practices” (2026) on AI-generated schemas and Row Level Security; OWASP 2026 LLM Security reporting on prompt injection growth; arXiv, “Agent Data Injection Attacks are Realistic Threats to AI Agents” (2607.05120, 2026); Barracuda 2026 agent framework supply-chain findings; IVE Strategic Execution Agent reference implementation (insightvalues.com).