How to Configure Mastra ClickHouse Approval
To set up mastra clickhouse approval, you combine SQL access rules with human review steps. Your AI agent pauses before it runs queries and waits for a person to approve. Engineering teams often give AI agents a single database account with broad read rights. That choice lets a single bad prompt pull huge tables or expose private rows. Tight roles and clear review steps stop those risky queries before they hit your cluster. How mastra clickhouse approval works with native SQL roles A safe set
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 mastra clickhouse approval, you combine SQL access rules with human review steps. Your AI agent pauses before it runs queries and waits for a person to approve. Engineering teams often give AI agents a single database account with broad read rights. That choice lets a single bad prompt pull huge tables or expose private rows. Tight roles and clear review steps stop those risky queries before they hit your cluster.
How mastra clickhouse approval works with native SQL roles
A safe setup starts inside the database with SQL-driven access control. ClickHouse treats users, roles, row policies, settings profiles, and quotas as access entities. You create and manage these entities with standard SQL statements. To turn this feature on, your server needs a storage directory path for access rules. You also need at least one admin user with access management rights turned on.
Once you turn on SQL access control, you create a dedicated user for your Mastra agent. Creating a new user takes the create user privilege. A database user can only grant privileges that they already hold themselves. During user creation, you set how the account logs in and which hosts can connect. You also assign default roles and specific per-user settings for that agent account.
Next, you restrict what the agent can read by granting select rights on specific columns. If you grant select on just two columns, the agent can query only those two columns. If the agent tries to query a third column, the database blocks the query. A wildcard select query also fails and returns no data unless every column is allowed. Since version 24.10, you can also grant select rights across table name prefixes with a trailing asterisk.
Where native database roles fall short for AI agents
Native roles and column grants solve the first half of the access problem. They decide which account can log in and which columns that account can touch. In a Mastra workflow, you can also add a step that pauses the agent task. The workflow waits until a human reviewer checks the planned action and clicks approve.
Yet static database grants cannot judge the context of an individual query in flight. Once an account has select rights on a column, it can read every row anytime. Native ClickHouse grants do not require human sign-off for a single risky query. And app-level workflow checks only guard the agent code path you built yourself. If someone reuses the database key in another script, those app checks do not run.
Approval Chains & Escalation + ClickHouse Access Management: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static column grants are also all-or-nothing for sensitive fields like emails or phone numbers. If a table holds card numbers or national IDs, you must allow or block the column. When you allow the column for a support task, the query returns raw data in full. A complete review flow needs query-level checks and field masking that rewrites matched fields in results.
Building a practical review workflow for agent queries
Start by mapping every query type your Mastra agent needs to run for its job. Group routine read queries onto safe summary tables that hold no emails or phone numbers. Grant the agent user column-level select rights on only the fields it needs to read. Restrict the user host list so the account can only log in from your app servers.
For tasks that touch sensitive tables or run heavy aggregations, require a human review step. Route the exact SQL statement to a reviewer in your team chat before it runs. Make sure your team checks both the tables used and the row limits on the query. Combining tight column grants with per-query review keeps your analytics cluster fast and safe.
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 beside the server as a sidecar for your ClickHouse and parses every statement before execution.
First, hoop.dev guardrails block disallowed deletes, drops, and alter mutations. Then hoop.dev data masking rewrites sensitive string columns in responses and logs each decision per resource. Read the docs and source on GitHub.
Frequently asked questions
What happens when an agent runs a wildcard query with column-level grants?
ClickHouse refuses a wildcard select query and returns no data at all. It only works if the user has select rights on every column in that table by default.
How do you turn on SQL-driven access control in ClickHouse?
You set a storage directory path for access entities in the server settings. You also set the access management and named collection flags to one for an admin user.
Can a ClickHouse user grant table access to a Mastra agent account?
Yes, if that user holds those exact rights and has permission to grant them. In ClickHouse, a user can only grant privileges that they already have themselves.
Related guides
In this post