Your AI agent only runs SELECT. Is your data actually safe?
Why read permissions are not the same as safe access, and how native privileges, data isolation, execution control, and audit reduce risk for agents connected to PostgreSQL.
GatekeeperID Research · Agent security · PostgreSQL · Least privilege
The problem starts with a permission that looks harmless
Picture a technology company that uses an AI agent to help its analysts. The agent queries PostgreSQL, answers questions about sales, finds patterns, and drafts reports. To avoid accidents, the team creates a read-only database user.
The logic sounds reasonable: if the agent cannot run DELETE, UPDATE, or DROP, it cannot do serious harm. That decision does not answer a different question:
Should the agent be able to read every row its credential can reach?
A SQL query can be valid, change nothing, and still expose personal data, commercial secrets, or another customer’s records. Traditional applications fail at read authorization too. Agents add a difference: they interpret instructions, choose tools, write queries, and chain operations without a developer having written each decision in advance.
Access control is no longer only a guard against destructive commands. It is a question of identity, scope, context, and why the operation is running.
1. What PostgreSQL actually protects
PostgreSQL controls which operations an identity may run. The privileges documentation describes permissions such as SELECT, INSERT, UPDATE, DELETE, TRUNCATE, REFERENCES, and TRIGGER.
SELECT reads authorized tables or columns. In a database with customers, orders, and payment_transactions, an agent that analyzes orders may need orders. That does not mean it needs every customer field or payment detail.
GRANT USAGE ON SCHEMA public TO agent_reader; GRANT SELECT ON TABLE orders TO agent_reader;
That grant is tighter than unrestricted database access, and it still leaves questions. Does the table mix customers? Are there sensitive columns? Can the role execute functions that run with higher privileges? Does it inherit grants from other roles?
The same documentation notes that some privileges are granted to PUBLIC by default, including EXECUTE on functions and procedures, unless the configuration changes that. Functions that run privileged logic need care.
Least privilege means looking at the effective permission set, not only the grant written on one table.
2. Why read-only is not the same as safe
This query does not change the database:
SELECT * FROM customers;
It can still return information the end user should not see.
In a SaaS product, several organizations can share one table:
customers ├── tenant_a ├── tenant_b └── tenant_c
If the credential can read every row, a mistake in generated SQL can drop the organization filter and expose data across tenants. The absence of destructive operations does not fix that.
Writing “query only the current organization” in the prompt does not fix it either. The sentence can steer expected behavior. It is not a security boundary equivalent to authorization enforced by the database or by a trusted component.
OWASP names tool misuse, privilege abuse, and excessive autonomy as risks in model and agent systems. The applicable principle is plain: an agent should not see more information than the authorized task requires.
3. Row-Level Security: when SELECT is not enough
PostgreSQL provides Row-Level Security (RLS) for multi-tenant applications. Ordinary privileges control objects and operations. RLS restricts which rows can be seen or changed.
CREATE TABLE orders (
id BIGINT PRIMARY KEY,
tenant_id UUID NOT NULL,
amount NUMERIC NOT NULL
);
ALTER TABLE orders ENABLE ROW LEVEL SECURITY;
CREATE POLICY tenant_isolation
ON orders
FOR SELECT
USING (
tenant_id = current_setting('app.current_tenant', true)::uuid
);This code shows the idea. It is not a production-ready configuration. A trusted layer has to set and protect the tenant identifier. If the agent can freely change the session context the policy uses, isolation can be bypassed.
Connection pooling, transactions, inherited privileges, table owners, and roles with BYPASSRLS also matter. The Row Security documentation states that superusers and roles with BYPASSRLS bypass RLS. Table owners are ordinarily not subject to those policies unless a specific setting changes that. RLS does not cover every class of operation in the same way.
For agents, the distinction matters: the model may write a wrong query, and the data layer still has to enforce limits that do not depend on how the model interpreted the task.
4. The risk is not only in the generated SQL
In a Model Context Protocol integration, the agent uses tools exposed by servers or connectors. The MCP security best practices cover risks such as confused deputy, token passthrough, compromise of local servers, and overly broad scopes. Integration security is not just classifying a query as a read or a write.
An architecture has to answer:
- Who is asking, and on whose behalf?
- Which tool was authorized?
- Which database identity will be used?
- Which data set may be queried?
- How will the decision be recorded?
- What happens when identity or context cannot be verified?
The November 2025 MCP release advanced authorization and protocol security. Authenticating an MCP client does not automatically authorize every action on the database. A valid identity can still ask for an operation outside its scope.
5. Four control layers that have to work together
| Layer | Question it answers | Responsibility |
|---|---|---|
| Identity and context | Who is acting, for whom, and where? | Bind the request to a verifiable identity and environment |
| Authorization policy | Which actions are allowed? | Evaluate roles, resources, operations, and conditions |
| Native privileges and RLS | What will the database actually accept? | Enforce limits that do not depend on the model |
| Audit and monitoring | What happened? | Support traceability, investigation, and detection |
These layers do not replace one another. An audit trail does not, by itself, stop an improper query. A policy that blocks DELETE does not necessarily stop a SELECT that exposes confidential data. An authenticated identity does not mean every request from that identity is authorized. Defense depends on combined controls and on access paths that cannot skip the checks.
6. SQL classification helps, and it is not enough alone
A layer in front of the database can inspect SQL before execution:
| Operation | A possible policy |
|---|---|
| SELECT on an authorized table | Allow, subject to the data scope |
| SELECT on a sensitive table | Deny, or require a specific authorization |
| UPDATE on an operational table | Require approval under stated conditions |
| DELETE of critical data | Deny, or require a narrow authorization |
| DROP TABLE | Deny by default |
| SQL that cannot be classified | Deny and record |
This matrix is a policy proposal, not the result of an efficacy test. Real SQL is hard to classify: nested queries, views, functions with side effects, inherited permissions, and operations that consume a lot of resources. Keyword classifiers are brittle. A defensive implementation needs a real parse, semantics, authorization rules, and the permissions the database actually enforces.
Classification does not replace native privileges. PostgreSQL should still refuse an operation the identity in use is not allowed to run.
7. Human approval should not mean a generic privilege grant
Requiring a person to approve a sensitive action is different from temporarily opening a broad set of privileges. If a developer asks to delete specific rows, the approval should consider who asked, the operation, the object, the environment, the scope, and how long the decision lasts.
An authorization that simply allows DELETE on any table for ten minutes can open an unnecessary window of risk. An alternative is to bind the decision to an identified request, recheck the policy before execution, and record the action. The authorization should expire, and revocation should be possible when it applies.
Human approval reduces some risks. It does not remove mistaken decisions or compromised accounts. It complements least privilege.
8. What standards and studies actually support
The NIST AI Risk Management Framework, first published in January 2023, is a voluntary approach to AI governance and risk management. The generative AI profile was released in July 2024. The framework does not give a universal incident rate for agents that reach PostgreSQL, and it does not prove that a gateway removes a given share of attacks. Its value is a structure for identifying, assessing, responding to, and monitoring risk.
OWASP publishes risk taxonomies and examples of failures in agentic applications. The deliberately insecure agent samples are for study and training. They are not a sample of production environments. The Q1 2026 exploit round-up collects evidence of different kinds. It is not a measurement of how often those incidents occur worldwide.
It is fair to say that documented risk classes involve identity, tools, and privileges in agentic systems. These sources do not support a universal probability of data exposure for any agent connected to a database.
9. An architecture decision matrix
The comparison below is conceptual. It is not a lab result.
| Control | Benefit | Main limitation |
|---|---|---|
| Read-only user | Limits direct writes | Does not stop excessive reads |
| GRANT on an object or column | Shrinks the readable surface | May be too coarse for tenant isolation |
| Row-Level Security | Restricts visibility by row | Depends on correct context and privileges |
| A policy gateway | Decides before execution | Does not cover paths that bypass it |
| Human approval | Supervision for critical actions | Depends on the scope and quality of the approval |
| Audit | Investigation and governance | Does not automatically block an operation |
The right architecture depends on context. An agent that queries public data has different requirements from one that can reach financial records or personal data.
10. How to test the architecture in a way others can repeat
A company can build a lab with synthetic data and evaluate access policies. A protocol could set:
- Fictional tables that hold rows for several tenants.
- Identities with different native privileges.
- Allowed and forbidden queries, classified in advance.
- Cases with a missing tenant filter, functions, views, and destructive commands.
- Success criteria, including correct blocks and false positives.
- Versions, configuration, logs, and enough evidence to reproduce the run.
The same cases could be repeated in three setups: native permissions alone; native permissions with RLS; and those permissions plus an external authorization layer. Results should be published with absolute counts, denominators, and methodological limits.
No experiment of that kind was run or measured for this article. It is a proposal for later work.
11. What this means for CTOs, CISOs, and product leaders
When agents reach corporate resources, the company has to decide who answers for their operations, which data they may use, and how to show that the controls were applied.
For a CTO, the problem is adopting AI without opening privileges that do not fit the architecture. For a CISO, it is identity, prevention, governance, and investigation. For a product leader, it is shipping useful AI features without turning every integration into a security exception. For developers, it is implementing policies that can be checked, rather than relying only on the prompt.
Extra controls can add latency, complexity, and operating cost. Too few controls can increase exposure and make it harder to get corporate approval for the integration. The aim is to allow legitimate tasks inside limits that can be verified.
Conclusion: reading is a privilege too
The common mistake when protecting agents connected to databases is to treat a ban on destructive commands as the definition of safety. Blocking DROP and DELETE matters. It does not say who may read a given row, which information is sensitive, or how organizations stay isolated.
A sound architecture combines identity, contextual authorization, native privileges, isolation, and audit. The question is not only “can the agent run this query?” It is also: should this identity, in this context, reach this data, through this operation, for this purpose? That is the difference between allowing queries and building an authorization architecture.
Where GatekeeperID Agents fits
GatekeeperID Agents is designed to put a control layer between AI agents and corporate resources. In the MVP scope, the architecture is an AI agent, an MCP connector, a local gateway, and the customer’s PostgreSQL. The project includes role-based access policies, analysis of SQL operations, integration with native PostgreSQL privileges, temporary human approval for sensitive operations, and audit records. Database credentials stay out of the context sent to the model.
That architecture aims to reduce operations outside the authorized scope. It does not remove prompt injection, it does not fully prevent exfiltration, and it does not protect connections that bypass the gateway. Those claims have to be shown in integration and security tests, and the features named here have to be confirmed in the version offered to users.
References and method
This essay analyzes documentation and standards. It is not a systematic literature review and it is not an experiment. Sources were chosen for relevance, with priority on primary PostgreSQL, MCP, NIST, and OWASP documentation. No efficacy measurements or customer results were invented.
- PostgreSQL Global Development Group. Privileges — PostgreSQL 18.
- PostgreSQL Global Development Group. Row Security Policies — PostgreSQL 18.
- Model Context Protocol. Security Best Practices, 25 November 2025 version.
- Model Context Protocol. November 2025 release, 25 November 2025.
- NIST. AI Risk Management Framework. Original framework, January 2023; generative AI profile, July 2024.
- OWASP GenAI Security Project. Insecure Agent Samples. Educational examples, not production incidence.
- OWASP GenAI Security Project. GenAI Exploit Round-up — Q1 2026. A compilation of heterogeneous reports.
- OWASP GenAI Security Project. 2026 Top 10 for LLM Applications and the Agent Control Standard, 1 September 2026.
The references come mainly from four organizations, not from eight independent groups. Documentation and taxonomies do not, by themselves, give the statistical prevalence of incidents. The SQL examples are illustrative and need review before production use.