Credential Shape Determines Agent Risk When Connecting Claude or GPT to Supabase
How you shape agent credentials determines what damage a compromised AI can inflict.

For governed data access for AI agents on Supabase via MCP, expose a pre-modeled analytical copy through an MCP server rather than give Claude or GPT a production database credential. For tasks that need direct access, use explicit grants and short-lived, brokered credentials. Credential shape determines agent risk because its scope, lifetime, and privileges define what a mistaken or compromised agent can do.
Why the credential is the agent's blast radius, not just its password
Teams often choose credentials as part of deployment, when an integration needs to connect. For an agent, that choice is the primary risk variable. A credential does not merely establish that a request comes from a recognized identity. It authorizes the queries, record updates, and workflows that identity can perform, whether those actions follow the intended task or depart from it.
The distinction is between generating content and taking action. Generative AI risk lives in the prompt and output, while agentic AI risk extends into the systems the agent can change. A misleading answer and an unauthorized database update have different consequences because the latter crosses an authorization boundary. The limits of the damage are thus set at configuration time, before a prompt injection, mistaken query, or credential leak tests them.
How agents are actually being connected to Supabase today, and why the defaults are dangerous
Most deployments give an agent a static, long-lived credential kept in a configuration file or environment variable. Access begins at setup and may never be revisited. Akeyless's 2026 State of AI Agent Identity Security report found that organizations commonly connect agents through persistent credentials, including API keys, static secrets, OAuth tokens, and service accounts. Many are built right into application code, workflows, and configuration files, so the integration keeps the authority they grant.
Supabase makes the consequences of that pattern concrete. It auto-generates a REST API from the Postgres schema, so a table becomes reachable through the API when it exists. Tables created through SQL or migrations have Row Level Security, or RLS, disabled by default, while tables created through the Dashboard have RLS enabled by default. An API connection can therefore work before anyone has decided which rows the agent should reach.
The two keys expose different authorization boundaries. The anon key is designed for client-side code and cannot bypass RLS, but tables with RLS disabled are fully accessible to it. The service_role key bypasses all RLS policies and should never be used in client-side code. It represents a highly privileged database role with full RLS bypass.
AI-assisted scaffolding makes that distinction especially consequential for early-stage founders. Tools that scaffold Supabase projects, including agents executing CREATE TABLE statements from prompts, have historically created tables without enabling RLS or writing policies. RLS is not the Postgres default. Infrastructure shaped by those agents can therefore contain accessible tables without the security policies its builder assumed were part of the setup.
What "excessive agency" means at the Postgres level when an agent holds the service_role key
An agent holding the service_role key operates outside the row policies that would otherwise constrain its access. This is superuser-like authority over RLS-protected data, distinct from literal Postgres superuser status. The distinction is technically important without making the credential less consequential. A policy separating one user's rows from another's does not restrain an identity that bypasses it.
That authority enables the Confused Deputy Pattern. A trusted agent can be manipulated into modifying records or altering access groups under its legitimate identity, even though the requested action is unauthorized in the context of its task. The database sees an identity with permission. Standard detection can miss the misuse because the action comes through a trusted entity.
Over-privilege can also cause disruption without an attacker. An agent generating ad-hoc SQL against production can exhaust Postgres connection pools while attempting a legitimate task. PostgreSQL has a hard limit on concurrent connections, and each connection consumes memory. A traffic spike can exhaust those connections in seconds, turning unconstrained analytical work into a denial-of-service pattern.
Supabase's Postgres Best Practices for AI Agents skill, in the supabase/agent-skills repository, addresses query performance, connection management, Security & RLS, schema design, concurrency and locking, and data access patterns. These limits govern how the database runs as well as how queries are written. Giving an agent broad access does not establish that its work will respect any of them.
The four credential shapes and the risk profile each one produces
The first shape is a broad, static, long-lived service_role key. Its RLS bypass exposes project data to reads, modifications, or deletions when an agent is compromised or misdirected. The authority persists beyond any individual task. Detection is difficult because actions use a trusted identity, and the Akeyless report found that more than two-thirds of organizations suspect agents have already accessed data beyond their intended scope.
The second shape is a scoped, read-only Postgres role with a static credential. Writes and deletes are structurally unavailable, narrowing the blast radius to the data the role can read. That is a substantial change in authority. However, a leaked credential still provides persistent read access, and grants that expand over time can reopen exposure beyond the original task.
The third shape uses short-lived, dynamically issued tokens. An agent requests access from a credential broker, which issues a token scoped to the task and subject to instant revocation without changing underlying application credentials. The token's TTL bounds the exposure window. This narrows risk in time as well as scope, but direct production access remains, including connection-pool risk and RLS bypass if the token is over-scoped.
The fourth shape places a pre-modeled governed data layer behind a single MCP server. The agent queries pre-calculated, Parquet-backed datasets through DuckDB. It holds no production credential at all. The production blast radius from that agent credential is zero, though teams still need to choose the scope of access to the analytical copy.
Pre-defined metric definitions are built into the datasets, so the agent does not build competing definitions against raw tables. The 2026-07-28 MCP specification made the protocol stateless at the protocol layer, enabling MCP server instances to scale independently behind a plain load balancer without session affinity. That supports scaling the access layer separately from production, but the security boundary comes from what the server exposes.
Why model alignment and sandboxing cannot substitute for credential design
Model alignment, sandbox containment, and pre-action authorization address different failure points. Alignment shapes what a model chooses to do, while authorization sets what an action is allowed to do. A sandbox bounds the damage within the space where code runs. These controls are all still needed, and safety training leaves in place the authority a database credential has already granted.
The Open Agent Passport preprint, Before the Tool Call, describes the need to authorize actions before execution. Training-time alignment is probabilistic, and retrospective evaluation occurs after the relevant action. Neither provides deterministic policy enforcement for each tool call. In the paper's adversarial testbed, social engineering worked against the model alone in a large majority of attempts under a permissive policy, but a comparable group of attackers had a zero percent success rate under a restrictive pre-action authorization policy.
That finding rebuts reliance on model refusal as the security boundary, without establishing that every restrictive policy is sufficient. Policy design still determines what is allowed. Bluebear Security's APV framework describes agentic posture vulnerabilities as structural exposures that persist across tasks and outlive individual events. Model updates or runtime guardrails alone cannot close an exposure if the authority behind it is still too broad.
How credential shape becomes a data integrity problem, not just a security problem
A broad credential gives an agent permission to query data, but it does not tell the agent what that data means. Without semantic context, the agent constructs metric definitions as it constructs SQL. Different constructions can produce different answers from the same records. Read-only access prevents destructive writes, yet it does not prevent an authoritative-looking answer built on the wrong definition.
The difference can be as simple as SUM(revenue) versus SUM(amount_captured). Q2 revenue can differ by as much as 11% across reports with correct underlying data because the queries encode different definitions. Giving an agent more tables to inspect does not supply the missing agreement about which definition governs the answer.
The reverse limitation is also important. An agent with semantic context but no query access cannot answer, while one with query access but no semantic context has to guess. A governed analytical layer joins the two by exposing pre-modeled, pre-calculated datasets whose definitions were established by humans. The agent can query the metric without deciding what the metric should mean.
For Supabase teams, that separates analytical work from production while constraining the basis of the answer. Direct table access risks connection-pool exhaustion and RLS bypass, but it also permits subtly inconsistent business numbers. Those numbers can shift executive attention from decisions to disputes over dashboards. Credential design therefore affects data trustworthiness as well as confidentiality and operational stability.
Building toward the right credential shape — how to let AI agents query Supabase without direct database access
The practical sequence begins by withholding the service_role key from the agent. The anon key is the upper bound for agents that should remain subject to RLS, with the important condition that the relevant tables actually have RLS enabled and appropriate policies. For tasks requiring more access, the alternative is a dedicated Postgres role with explicit grants. More access should not mean unrestricted authority.
Once the identity boundary is established, scope access by granting read rights only to the schemas and tables the task requires. Each additional table expands the potential exposure. That expansion needs a documented reason, because a credential described as read-only can still expose far more information than the task warrants.
After scope is explicit, make credentials short-lived and brokered where possible. A configurable TTL bounds the exposure window when a token leaks, while brokering permits task-specific access and revocation. Short-lived credentials retain their granted privileges until expiry, so this decision depends on the scope decision.
For analytical work, the next decision is to route queries to a governed copy. The MCP server should make that analytical layer available without giving the agent a way to build metric definitions against production tables. The selection criteria are explicit scope, governed metric definitions, an auditable interface, and no production credential at the agent layer. This removes the agent's direct production connection-pool and RLS-bypass risks and sets which definitions it can use for analytical answers.
These decisions form a sequence. A short-lived but over-scoped token still grants too much authority until it expires, while a narrowly scoped static credential keeps data exposed over time. MCP access alone does not set row-level controls, so teams still need to distinguish a governed interface from a broad database connector.
The OAP specification intercepts tool calls synchronously before execution, evaluates a declarative policy, and produces a cryptographically signed audit record. It can block actions that a misconfigured credential would otherwise permit. Supabase's Metrics API then supplies database telemetry in Prometheus format, including connection-pool metrics, so teams can watch connection saturation and query performance for unintended load.
Credential design is an architecture decision with compounding returns. A tighter shape at the start leaves fewer privileges and paths to production for teams to monitor, audit, and investigate later. That reduces the surface on which ongoing oversight must succeed.


