How to Configure Claude Code ClickHouse Least Privilege
To set up claude code clickhouse least privilege, create a restricted SQL role for your agent. Then, give that user read-only rights on specific tables and columns. Many teams first hook their coding agent straight to an admin database account. They do this to move fast during early testing. If an agent holds broad rights, one bad query can drop tables or leak secrets. How to set up claude code clickhouse least privilege Claude Code talks to outside systems and databases in two main ways. It
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 claude code clickhouse least privilege, create a restricted SQL role for your agent. Then, give that user read-only rights on specific tables and columns. Many teams first hook their coding agent straight to an admin database account. They do this to move fast during early testing. If an agent holds broad rights, one bad query can drop tables or leak secrets.
How to set up claude code clickhouse least privilege
Claude Code talks to outside systems and databases in two main ways. It can use Model Context Protocol servers, or it can run shell commands. The agent runs shell tasks through its built-in Bash tool. In Manual mode, the Bash tool asks for human approval before it runs most commands. Only a small built-in list of safe read commands can run without a prompt. When teams use an MCP server for database work, the server holds the connection string. Vendor docs tell teams to put a read-only database user in that string. This stops the queries that the agent runs from changing any stored data.
On the database side, ClickHouse handles users and roles as SQL access entities. It also manages row policies, settings profiles, and quotas the same way. To turn on SQL access control, an admin sets a storage path on the server. At least one admin account also needs the access management flag turned on. That admin can then create a fresh user just for the coding agent. The user creation statement sets how the account logs in and which hosts can connect. It also sets default roles and user settings for that specific agent account.
A database user can only hand out rights that they already hold themselves. For tight control, admins can grant read rights on single columns instead of full tables. If an agent only gets rights on two columns, it can query only those two. Any query that asks for other columns will fail right away. A wildcard query for all columns will also fail and return zero data. That wildcard query only works if the table holds just the allowed columns. Admins can also use a trailing asterisk to grant rights by table name prefix.
Why native roles are only half the fix
Native database roles and column grants solve a big part of the safety puzzle. They decide who can log in and which tables or columns remain in reach. If the agent tries to write data or read a blocked column, the database stops it. This protects your core tables from accidental edits or deletions during a coding session.
Least Privilege Principle + Claude Code Security: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Still, static roles leave a clear gap during daily work. A read-only user can still pull raw values from every column it is allowed to read by default. Analytics tables often mix app logs with sensitive fields like user emails or phone numbers. They might also hold card numbers or national IDs inside columns the agent needs to check. Native grants are all-or-nothing for each column. Once a column is open, the database sends every row value back to the agent context. Also, storing static database keys in local config files creates key sprawl across laptops. Native roles check who logs in, not what each query returns in flight.
Steps to keep agent queries safe
Start by auditing which tables your coding agent actually needs to see. Create a dedicated ClickHouse role that holds read rights on those specific tables only. Avoid giving the agent access to system tables or user credential stores. Grant column-level select rights whenever a table mixes safe metrics with private user fields. Set host limits on the database user so it only accepts logins from known networks. Apply quotas and settings profiles to cap how much memory or time one query can use. Finally, add runtime controls that rewrite matched sensitive fields like emails or card numbers in results.
Check ClickHouse queries and results before execution
Access control in ClickHouse is essential setup. Setup alone does not check single queries for risk or rewrite sensitive strings in returned rows. By design, hoop.dev sits inline in the protocol beside the server as a sidecar for your ClickHouse. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human approval.
First, hoop.dev guardrails block disallowed deletes, drops, and alter mutations or hold them for review. Then hoop.dev data masking rewrites sensitive string columns in responses in memory and logs each decision per resource. Read the docs and source on GitHub.
Frequently asked questions
How does Claude Code run queries against a ClickHouse database?
The agent connects through a Model Context Protocol server or runs CLI tools via its Bash tool. Both paths use the database login details that you set up on your machine.
What happens if an agent runs a wildcard query on a column-restricted table?
ClickHouse blocks a select-all query and returns no data at all. It only allows the query if the user holds rights on every column in that table by default.
Can a ClickHouse user grant extra permissions to the coding agent?
A user in ClickHouse can only grant privileges that they already hold themselves. The agent cannot raise its own access level if its account lacks access management rights.
Related guides
In this post