How to Configure OpenAI Agents SDK ClickHouse Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openai agents sdk clickhouse read only access by creating a restricted database user. Then you bind your agent tool to that account with select grants only. Many teams start by giving their agent a default admin login during tests. That broad role lets a bad prompt alter tables or read secret rows. A dedicated read-only user blocks writes at the database layer before queries run. This setup forms the base of safe agent database queries in production. How openai agents sdk clickhouse

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 clickhouse read only access by creating a restricted database user. Then you bind your agent tool to that account with select grants only. Many teams start by giving their agent a default admin login during tests. That broad role lets a bad prompt alter tables or read secret rows. A dedicated read-only user blocks writes at the database layer before queries run. This setup forms the base of safe agent database queries in production.

How openai agents sdk clickhouse read only access works

ClickHouse manages users, roles, row policies, settings profiles, and quotas as SQL objects. To turn on SQL access control, you set up a storage directory on the server. You also need at least one user account with access management turned on. That admin user can create new users and roles with SQL statements. A user can only grant privileges that they hold on their own account.

Creating a user requires the create user privilege in the database. The user statement sets the login method and the allowed client hosts. It also assigns default roles and user settings for each new session. For an agent, you create a dedicated user and grant select rights only.

You can grant select rights on specific columns in a database table. The agent can then query those exact columns, while other columns stay off limits. If the agent runs a select all query, the database refuses the request. It returns no data unless the table holds only the granted columns. You can also use a trailing asterisk to grant rights by table prefix. In the OpenAI Agents SDK, your custom function tool uses this restricted database user. The model picks the tool, sends a query string, and gets the rows back.

Why native read-only roles leave gaps for AI agents

Database roles and column grants stop an agent from changing or dropping tables. They also block the agent from reading columns outside its grant list. This native setup decides who logs in and which tables they can touch. Still, it does not check what individual queries do while in flight.

An agent with select rights on a customer table can still pull sensitive data. If the tool needs that column for joins, the model gets raw values back. Returned rows might include emails, phone numbers, card numbers, or national IDs. Static database grants cannot rewrite matched fields in results before the model reads them.

Auditor Read-Only Access + ClickHouse Access Management: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Shared agent credentials also create blind spots in your database audit logs. Every tool call from every user shows up under the same database account. You cannot tell which human user or agent run triggered a heavy query. Also, the app host must store the database password in its local state. If an attacker compromises the agent host, they can steal that static key.

How to tighten column grants and host rules

Start by listing the exact tables and columns your agent needs for its task. Do not grant select rights on an entire database when two tables will do. Grant select on named columns so a broad query fails right away. Update your agent prompt so the model knows which columns it can ask for. This stops the agent from wasting turns on refused select all queries.

Next, lock down the hosts that the agent user can log in from. Set the host rule on the user account to match your app server IP. Assign a settings profile and a quota to cap how much work runs. These limits keep a stuck agent loop from draining all cluster memory. Rotate the agent password often and audit the granted roles after schema changes.

Add runtime guardrails and masking beside ClickHouse

Database grants and network rules control who can reach ClickHouse. Even so, an allowed client or agent can send an alter mutation that deletes rows or read raw personal data. In practice, hoop.dev runs beside the server as a sidecar for your ClickHouse and checks native TCP queries with no change to your drivers.

With hoop.dev ClickHouse support, guardrails refuse banned queries before they run, and data masking rewrites matched string columns in results. The audit trail logs which entity types were masked and how many without storing raw values. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

What happens if the agent runs a select all query on a column-restricted table?

ClickHouse refuses a select all query when the user lacks rights on every column by default. The query returns no data at all unless the table has only granted columns.

Can a ClickHouse user grant read access to another agent account?

A user can only grant privileges that they hold on their own account. They also need access management rights to create users or grant roles via SQL.

Does a read-only ClickHouse user stop sensitive data from reaching the LLM?

Column grants block access to restricted columns, but allowed columns still return raw text. You need data masking to rewrite emails, phone numbers, or card numbers in results.

The query runs. The emails stay hidden.