Provisioning ClickHouse Users
How to set up analytics API access for workspaces
This runbook explains how to provision a ClickHouse user for a workspace which wants to use the v2 analytics API.
Prerequisites
ctrl-workerrunning withUNKEY_CLICKHOUSE_ADMIN_URLconfigured- Restate accessible
Provisioning a New User
Call the ConfigureUser endpoint via Restate:
That's it. The workflow will:
- Generate a secure password
- Encrypt it via Vault
- Store credentials in MySQL
- Create the ClickHouse user with row-level security
Customizing Quotas
Override the defaults by passing quota parameters:
| Parameter | Default | Description |
|---|---|---|
quota_duration_seconds | 3600 | Window for rate limits (1 hour) |
max_queries_per_window | 1000 | Queries allowed per window |
max_execution_time_per_window | 1800 | Total query time per window (30 min) |
max_query_execution_time | 30 | Single query timeout (seconds) |
max_query_memory_bytes | 1GB | Memory limit per query |
max_query_result_rows | 10M | Max rows returned |
Updating an Existing User
Same endpoint. The workflow detects the user exists and updates quotas while preserving the password.
Via Restate UI (Local)
- Open Restate UI (
http://localhost:8080/uiin dev) - Find
hydra.v1.ClickhouseUserService - Enter the workspace ID as the key
- Call
ConfigureUser
Via Restate Cloud (Production)
- Go to cloud.restate.dev/accounts
- Login with Google Auth → select unkey team
- Get your API key:
- From AWS Secrets Manager, or
- Create one in Restate Cloud → Developers → API Keys
Via UI
- Find
hydra.v1.ClickhouseUserServiceand click Playground - Enter your API key in the Auth section
- Set
keyto the workspace ID in Parameters - Click Send API Request
Via curl
Find <environment-id> and <region> in your Restate Cloud dashboard.
What Gets Created
For workspace ws_abc123, the workflow creates:
- User:
ws_abc123with encrypted password - Row policies: One per table, filtering to
workspace_id = 'ws_abc123'and retention window - Quota: Rate limits on queries and execution time
- Settings profile: Memory and result size limits
Troubleshooting
"Service not found"
The ClickhouseUserService is optional. Check:
UNKEY_CLICKHOUSE_ADMIN_URLis set in ctrl-worker- ctrl-worker logs for connection errors
"Quota exceeded" errors for user
Re-run ConfigureUser with higher quota values.
Password issues
If a user can't authenticate, their ClickHouse password may be out of sync with MySQL. Delete from both and re-run the workflow:
Then call ConfigureUser again to generate fresh credentials.