How to Configure OpenAI Agents SDK CockroachDB Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openai agents sdk cockroachdb least privilege by creating a tight database role. Then you wire your agent tools to log in with that restricted account. Many engineering teams start by giving their agent a broad admin database key. That shortcut lets an agent alter schemas or read sensitive tables by mistake. A small prompt flaw can then wipe out production rows or expose private records. How openai agents sdk cockroachdb least privilege works The OpenAI Agents SDK lets models call

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up openai agents sdk cockroachdb least privilege by creating a tight database role. Then you wire your agent tools to log in with that restricted account. Many engineering teams start by giving their agent a broad admin database key. That shortcut lets an agent alter schemas or read sensitive tables by mistake. A small prompt flaw can then wipe out production rows or expose private records.

How openai agents sdk cockroachdb least privilege works

The OpenAI Agents SDK lets models call custom Python functions as tools. Developers write a database tool that opens a session to CockroachDB and runs SQL. The model decides when to call this tool and what inputs to send. The SDK does not restrict what the database tool does inside your cluster. Instead, CockroachDB enforces permissions based on the database user tied to that session.

To enforce least privilege, admins create a dedicated SQL role inside CockroachDB. They revoke default cluster rights and grant access only to specific schemas and tables. If the agent only answers questions, the role gets read grants on safe tables. If the agent updates state, admins grant insert or update rights on narrow targets. They never grant drop, alter, or admin privileges to the agent role.

You can also use database views to limit which columns the agent reads. A view can leave out private columns while showing general order metrics. The agent role then gets read rights on the view instead of the base table. This keeps the database user locked inside a small boundary at all times.

How to scope tool functions for safer queries

Database role limits work best when paired with strict tool definitions in your code. Avoid giving the model a single tool that runs raw SQL strings. A raw query tool lets the model guess table names and write heavy joins. Instead, build narrow Python functions for each task the agent needs to perform.

For example, create one function to look up an order status by its ID. Inside that function, use fixed query templates with bound parameters for the inputs. The model only picks the order ID, while your code controls the SQL structure. This stops prompt injection attacks from adding extra commands to the database call.

Least Privilege Principle + OpenAI API Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Teams should also separate read tools from write tools across different agent roles. A triage agent can use a read-only CockroachDB user to check customer history. A billing agent can use a separate database user that only writes refund rows. Splitting roles makes it easier to audit which agent did what in your logs.

What native roles solve and what they leave open

Native CockroachDB roles solve the problem of broad table access during login. They stop an agent from dropping tables or reading hidden schemas in the cluster. Still, static database grants only check who logs in and which table they touch. They cannot check what individual queries do in flight within an allowed table.

Suppose an agent needs to look up customer support tickets in a table. That table often holds emails, phone numbers, card numbers, or national IDs. Because the role has read access to the table, every column comes back by default. Data masking that rewrites matched fields in results is missing from basic table grants. Also, a read role cannot stop an agent from running a massive table scan. One bad prompt can still dump thousands of rows or lock up cluster memory. Static login keys also sit in app settings, where leaks can expose the database.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Should an OpenAI agent ever use a root CockroachDB user?

No, an agent should never use a root or admin database account. Always create a dedicated SQL user with grants limited to the required tables.

Can database grants stop an agent from reading sensitive columns?

Standard table grants apply to the whole table unless you set column rules or views. Even then, native grants cannot rewrite emails or card numbers inside free-text columns.

Why are parameterized tool functions safer than text-to-SQL tools?

Parameterized tools lock the SQL structure in code and treat model inputs as data. This stops a tricked model from running arbitrary commands against your CockroachDB cluster.

The query runs. The emails stay hidden.