How to Configure Gemini CLI ClickHouse Least Privilege
You set up gemini cli clickhouse least privilege by making a scoped SQL role. Next, you attach that role to a dedicated database user for the agent. Many teams start by giving their AI agent an existing developer key. Those broad keys often hold full write rights across every table. If the agent makes a mistake, it can drop tables or leak data. Scoping the database account stops the agent from touching unauthorized tables. How to set up gemini cli clickhouse least privilege in SQL 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 gemini cli clickhouse least privilege by making a scoped SQL role. Next, you attach that role to a dedicated database user for the agent. Many teams start by giving their AI agent an existing developer key. Those broad keys often hold full write rights across every table. If the agent makes a mistake, it can drop tables or leak data. Scoping the database account stops the agent from touching unauthorized tables.
How to set up gemini cli clickhouse least privilege in SQL
ClickHouse manages users, roles, row rules, settings profiles, and quotas through SQL statements. Before you make a new user, you must turn on SQL access control. This setup needs a server storage directory and an admin account with management rights. A database admin can only grant rights that they already hold themselves. Once that is ready, you can create a fresh user account for the agent.
When you create the user, you define how the account logs in. You can also restrict which host addresses the agent can connect from. Next, you assign a default role and custom settings to that user. Instead of granting full table rights, you can grant read rights on specific columns. The agent can then query only the exact columns you allowed.
If the agent runs a query for all columns, the database refuses it. That broad query returns no data unless the user holds rights to every column. You can also grant read rights across a group of tables using a prefix. This helps when your data sits in many tables that share a naming pattern.
How the terminal agent runs database queries
Terminal AI agents work by running shell commands or calling external tools on your machine. When you ask a question, the agent writes a query and runs it. It uses the local credentials stored in your shell or tool files. Because the agent acts on its own, it can run many queries fast.
If a prompt confuses the model, it might try to change data or read secret tables. Scoped roles in ClickHouse block the agent from reading restricted columns or dropping tables. Row rules and quotas also help cap how much data the user can pull.
Least Privilege Principle + ClickHouse Access Management: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native roles solve and what they leave open
Native database roles and column grants solve the first half of the access problem. They decide which user can log in and which columns they can read. This stops an AI agent from modifying schemas or reading blocked tables.
Still, static database roles leave big operational gaps open during live sessions. First, you still have to store a database key on the developer machine. Any script or terminal process on that machine can read and use that key. Second, column grants are all or nothing for the columns you allow. If an allowed text column holds emails, phone numbers, card numbers, or national IDs, the query returns them in plain text. Native grants cannot rewrite matched fields in results while a query runs. Third, static roles do not require a human check before a sensitive query runs. The database only checks who logged in, not the live context of each statement.
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
Why do select all queries fail when using ClickHouse column grants?
ClickHouse blocks wildcard queries when a user only has rights to specific columns. The query will fail unless the user holds read rights on every single column. Tell your AI agent to name each allowed column in its queries.
How do you limit where the Gemini CLI database user can log in from?
When you create the user in ClickHouse, you can set a host rule. This rule limits logins to specific IP addresses or hostnames that you trust. Logins from any other machine will fail even with the right key.
Can native ClickHouse roles hide sensitive data inside an allowed column?
No, column grants only let you allow or block an entire column. If you allow a column, the user gets every value stored inside it. To hide emails or card numbers inside allowed columns, you need data masking.
Related guides
In this post