How to Configure Gemini CLI ClickHouse Data Masking

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up gemini cli clickhouse data masking, limit column reads or rewrite query results. You must restrict what the command line agent reads from your database tables. Many teams connect AI tools to analytics databases using shared admin keys. When a role is too broad, the agent reads raw emails and card numbers. That sensitive text then goes straight to the external model provider during debugging. How native gemini cli clickhouse data masking works ClickHouse manages users, roles, row rul

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 gemini cli clickhouse data masking, limit column reads or rewrite query results. You must restrict what the command line agent reads from your database tables. Many teams connect AI tools to analytics databases using shared admin keys. When a role is too broad, the agent reads raw emails and card numbers. That sensitive text then goes straight to the external model provider during debugging.

How native gemini cli clickhouse data masking works

ClickHouse manages users, roles, row rules, settings, and quotas as database objects. Admins create and change these objects using standard SQL statements. First, you must turn on SQL-driven access control in the server storage path. At least one database account needs management permissions turned on to create roles. A database user can only hand out permissions that they already hold themselves.

When you create a user for Gemini CLI, you set its login method. You can also restrict which host machines that user may log in from. To protect private fields, admins grant read permissions on safe columns only. The database user can then query those allowed columns without any issue. If the agent asks for a restricted column, the database blocks the query.

Wildcard queries that ask for all columns also fail on restricted tables. They return no data unless the user has rights to every single column. In newer versions, a trailing asterisk grants rights by table name prefix. Teams also build custom views that replace phone numbers or national IDs. The AI agent then queries the custom view instead of the base table.

Why native roles and column grants fall short

Native database roles and column grants work well for fixed reporting jobs. They decide who can log in and which objects they can touch. Still, they create big friction when an AI agent explores your schema. Gemini CLI often runs broad queries to inspect tables and fix broken queries. When column grants block a wildcard query, the agent hits an error fast.

Engineers then have to rewrite prompts or build dozens of custom views. Maintaining safe views across hundreds of fast-changing analytics tables takes hours every week. Each time a developer adds a column, someone must update the view grants. If an engineer skips this step, a raw column keeps the session active to queries.

Data Masking (Static) + ClickHouse Access Management: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Native roles also cannot inspect or change what individual statements do in flight. Once a role grants read rights on a text column, all values return raw. A free-text log column might hold emails, phone numbers, or card numbers. Column grants are all or nothing, so they cannot mask patterns inside text. Masking that rewrites matched fields in results solves this problem without breaking queries. It lets the agent run normal queries while replacing sensitive values in flight.

Setting up safe database workflows for AI agents

Start by creating a dedicated read-only database role just for your AI tools. Never let Gemini CLI share a login with a human developer or service. Assign strict quota limits so a bad loop cannot overload your cluster. Next, list every table that holds emails, card numbers, or national IDs.

Keep the agent away from raw tables that it never needs for coding. For tables the agent must read, apply field rewriting on the query results. This approach keeps wildcard queries working while rewriting sensitive fields in the output. Your team gets helpful query assistance, and private data stays inside your network.

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

What happens when Gemini CLI runs a wildcard query on restricted ClickHouse columns?

ClickHouse refuses the wildcard query and returns no data at all. The query only succeeds if the user has grants for every column by default.

Can a ClickHouse user grant column access to another role for Gemini CLI?

Yes, if that user has management permissions turned on in the server. Still, a user can only grant permissions that they already hold themselves.

Why do custom views take so much time to maintain for AI agents?

Analytics schemas change often, and every new table or column needs view updates. Masking that rewrites matched fields in results avoids manual view maintenance.

The query runs. The emails stay hidden.