How to Configure Gemini CLI ClickHouse Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up gemini cli clickhouse read only access by creating a restricted database user. Then you give that user account only select rights on specific tables and columns. Many engineering teams start by giving AI tools shared admin keys for fast testing. This broad setup creates big risks when an agent runs a bad query. A single bad command can drop tables or expose private customer data. Locking down database roles before connecting your command line agent stops these mistakes early. How to

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 gemini cli clickhouse read only access by creating a restricted database user. Then you give that user account only select rights on specific tables and columns. Many engineering teams start by giving AI tools shared admin keys for fast testing. This broad setup creates big risks when an agent runs a bad query. A single bad command can drop tables or expose private customer data. Locking down database roles before connecting your command line agent stops these mistakes early.

How to set up gemini cli clickhouse read only access

ClickHouse manages users, roles, row rules, settings profiles, and quotas as access items. You create and change these items with SQL statements. First, an admin turns on SQL access control in the server storage folder. The admin account also needs access management rights turned on. A user can only grant rights that they hold themselves. Creating a new user account requires the create user right on the server.

When you create the user, you set the login method and allowed host machines. You also assign default roles and user settings during this step. Next, you grant select rights to the role or user account. ClickHouse lets you grant select rights on single columns in a table. The user can then query only those exact columns. If the agent runs a query for all columns, the database refuses it. That broad query returns no data unless the table holds only the allowed columns. You can also grant select rights by table name prefix using a trailing star.

How the agent runs database queries

Once the database role is ready, the developer sets up the command line tool. The agent runs shell commands or talks to external tools on the local machine. It uses the credentials stored in the local shell or tool file to log in. When you ask the agent a question, it writes a SQL query. Then it sends that query to the ClickHouse server using the read-only account.

If the agent tries to change rows or drop a table, ClickHouse blocks it. The database checks the role grants before running the statement. This setup keeps your tables safe from accidental writes or deletes during coding sessions.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native read-only roles solve and what they miss

Native ClickHouse roles do a great job of blocking write commands at the database level. Column grants also stop the agent from reading columns you did not allow. This gives your team a solid base layer of protection for data tasks.

Still, static database roles only decide who can log in and which columns exist. They do not inspect what individual queries do in flight inside those allowed columns. An allowed text column might still hold emails, phone numbers, card numbers, or national IDs. If the agent queries that column, the database sends the raw strings back. Static credentials also sit on developer laptops where scripts or agents can read them. Teams also lack a unified audit log tying each AI prompt to the exact SQL query. Also, you cannot pause a risky select query for human approval with static grants alone.

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 sits inline in the native TCP protocol beside the server as a sidecar for your ClickHouse. For every production query an agent or human sends, hoop.dev decides whether to pass, mask, block, or escalate it for review.

With hoop.dev ClickHouse support, guardrails refuse banned queries before they run or hold risky calls for approval, and data masking rewrites matched string columns in results in memory. 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 star query with column grants?

ClickHouse refuses a select star query when the user only has specific column grants. The query returns no data unless the table contains only those exact granted columns.

Who can grant read-only privileges to a new ClickHouse user?

An account with access management turned on can grant privileges in ClickHouse. Also, a user can only grant the privileges that they already hold themselves.

Do read-only grants hide sensitive text inside allowed columns?

No, column grants only allow or block access to the whole column. If an allowed column contains emails or phone numbers, native grants still return those values.

The query runs. The emails stay hidden.