How to Configure OpenHands ClickHouse Least Privilege
To set up openhands clickhouse least privilege, create a dedicated database user with strict read-only roles. Then, limit that user to specific tables, columns, and allowed source hosts. Engineering teams often connect AI coding agents to analytics databases using shared admin keys. This shortcut speeds up early testing, but it exposes production tables to bad queries. If an autonomous agent has broad rights, one wrong command can drop vital data. Scoping down permissions at the database level s
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 openhands clickhouse least privilege, create a dedicated database user with strict read-only roles. Then, limit that user to specific tables, columns, and allowed source hosts. Engineering teams often connect AI coding agents to analytics databases using shared admin keys. This shortcut speeds up early testing, but it exposes production tables to bad queries. If an autonomous agent has broad rights, one wrong command can drop vital data. Scoping down permissions at the database level stops agents from touching restricted schemas.
How openhands clickhouse least privilege works in practice
ClickHouse manages users, roles, row policies, settings profiles, and quotas as SQL access entities. Before you create scoped accounts, you must turn on SQL-driven access control on the server. This setup needs a storage directory path and an initial user with management rights. In ClickHouse, an admin can only grant privileges that they already hold themselves. Creating a new account for your AI agent also requires the user creation privilege.
When you create the OpenHands database account, you define its login method and default roles. You can also lock down which network hosts the agent may use to log in. Next, you attach a role that grants read access to safe tables and columns. ClickHouse lets you grant read rights on single columns rather than a whole table. If the agent queries only those allowed columns, the database returns the matching rows.
If the agent tries to read an unapproved column, ClickHouse blocks the query right away. A wildcard query across all columns will also fail and return no data at all. That wildcard query only works when the user has rights to every column in the table by default. Since version 24.10, admins can also grant rights across tables that share a name prefix. This prefix rule helps teams group safe staging tables for automated tools to read.
What native roles solve and where gaps remain
Native database roles and column grants give your team a strong first line of defense. They verify who logs in and block the agent from reading restricted tables. Host rules also stop someone from using those agent keys from an unknown network. Column grants keep the agent away from fields you leave out of its role.
Still, static database grants only check access at the schema and column level. Once a column is open for reading, every row value inside it returns in clear text. Analytics tables often mix app logs with sensitive fields like emails or phone numbers. If an agent needs a column that holds card numbers or national IDs, static grants cannot clean the output. Native roles also require you to store a static database password inside the agent setup. Static grants cannot rewrite matched fields in results or ask a human before a risky command runs.
Least Privilege Principle + ClickHouse Access Management: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Steps to keep agent database sessions safe
Start by mapping out the exact tables and columns your OpenHands agent needs for its task. Build a dedicated role in ClickHouse that holds only read rights for those specific columns. Assign that role to a unique user account created just for the agent workflow. Set a strict host rule on that user so it can only log in from your agent runner.
Apply a settings profile and resource quota to stop runaway analytical queries from draining memory. Test the new account by running a broad wildcard query on a multi-column table. Confirm that ClickHouse refuses the wildcard request and only answers when allowed columns are named. Review your agent roles each month and drop grants for tables the team no longer uses.
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 runs beside the server as a sidecar for your ClickHouse and checks native TCP queries with no change to your drivers.
With hoop.dev ClickHouse support, guardrails refuse banned queries before they run, and data masking rewrites matched string columns in results. The audit trail logs which entity types were masked and how many without storing raw values. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
What happens if OpenHands runs a wildcard query on a restricted ClickHouse table?
ClickHouse refuses a wildcard select query unless the user has rights to every column. The query returns no data at all until the agent names only its allowed columns.
How do you turn on SQL access control in ClickHouse for agent accounts?
You must set the access control storage directory path on the server first. You also need at least one user account with access management and collection control enabled.
Can a ClickHouse user grant OpenHands more permissions than the user holds?
No, ClickHouse enforces a strict rule that users can only grant privileges they already hold. Creating a new agent user also requires the specific privilege to create users.
Related guides
In this post