How to Configure Gemini CLI ClickHouse Audit Log
To set up a gemini cli clickhouse audit log, give the agent a dedicated database user and record every query it runs. This separates AI actions from human queries in your system records. Teams often run AI coding agents using their own personal database logins. That approach mixes automated queries with human work in the database history. If a broad role runs a bad query, you cannot tell who sent it. Overly broad permissions also let an agent read sensitive tables or drop production data. How
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.
To set up a gemini cli clickhouse audit log, give the agent a dedicated database user and record every query it runs. This separates AI actions from human queries in your system records. Teams often run AI coding agents using their own personal database logins. That approach mixes automated queries with human work in the database history. If a broad role runs a bad query, you cannot tell who sent it. Overly broad permissions also let an agent read sensitive tables or drop production data.
How a gemini cli clickhouse audit log works with native roles
ClickHouse manages users, roles, row policies, settings profiles, and quotas through SQL statements. To use SQL-driven access control, the server needs a storage folder set up. You also need at least one admin user with access management turned on. When you create a user for Gemini CLI, you set its login method. You can also limit which hosts the agent can log in from. A user can only grant permissions that they already hold themselves.
Once the dedicated agent user exists, you can restrict what data it reads. ClickHouse lets admins grant read rights on single columns in a table. If the agent only has rights to two columns, it can query only those. A query asking for all columns with a star will fail and return nothing. It only works if the table holds just those granted columns. Since version 24.10, you can also grant read rights using a table name prefix. Every query from this dedicated user then lands in the server logs under its name.
Why native roles and logs fall short in practice
Dedicated users and column grants solve the basic problem of who logged in. They give you a clean trail of which queries came from the AI agent. They also block the agent from reading restricted columns or unknown tables. Still, native database roles only check permissions when a query hits the server. They do not inspect the context of a prompt or redact results in flight.
If an allowed column holds emails, phone numbers, card numbers, or national IDs, the query returns them. Data masking rewrites matched fields in results so raw strings do not return in plain text. Native logs also record events after the database has already run the statement. If an agent has write rights for a task, native roles cannot require human approval per statement. Teams still must store static database keys on the developer machine for the CLI tool. Rotating those local keys across many laptops takes constant manual work.
Audit Log Integrity + ClickHouse Access Management: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
How to tighten agent database controls
Start by removing shared admin accounts from all developer workstations and agent tools. Create one specific ClickHouse role for Gemini CLI with read rights on safe columns only. Set host limits on the database user so it only logs in from trusted networks. Turn on query logging in ClickHouse and filter by the agent user name during reviews. For production data, pair these native roles with real-time query approval and result masking.
Check ClickHouse queries and result columns on the wire
ClickHouse users and row policies decide who connects. They do not check each statement on the wire or redact sensitive string columns in query results. With hoop.dev, you run an open-source proxy, a sidecar for your ClickHouse, inline in ClickHouse's native TCP protocol. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
Multi-statement queries and table mutations are split and checked by hoop.dev guardrails, which refuse banned actions with a native ClickHouse error or hold risky ones for approval. On returned rows, hoop.dev data masking rewrites String and FixedString columns in memory, and the audit trail logs each query and verdict. See the MIT-licensed source on GitHub.
Frequently asked questions
Why should Gemini CLI have its own ClickHouse user?
A separate user keeps AI queries out of human audit trails. You can track agent behavior, set strict quotas, and revoke its rights fast.
What happens when Gemini CLI runs SELECT * with column grants?
ClickHouse blocks the query and returns no data at all. The query only succeeds if the user has grants on every column in that table by default.
Do ClickHouse audit logs stop bad queries before they run?
No, audit logs only write down what happened after the query starts or finishes. To block risky commands before they run, you need pre-execution checks or strict grants.
Related guides
In this post