clickhouse-security-basics
Secure ClickHouse with user management, network restrictions, TLS, and audit logging. Use when hardening a ClickHouse deployment, creating restricted users, or configuring network-level access controls. Trigger: "clickhouse security", "clickhouse user management", "secure clickhouse", "clickhouse TLS", "clickhouse access control", "clickhouse firewall".
Best use case
clickhouse-security-basics is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Secure ClickHouse with user management, network restrictions, TLS, and audit logging. Use when hardening a ClickHouse deployment, creating restricted users, or configuring network-level access controls. Trigger: "clickhouse security", "clickhouse user management", "secure clickhouse", "clickhouse TLS", "clickhouse access control", "clickhouse firewall".
Teams using clickhouse-security-basics should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/clickhouse-security-basics/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How clickhouse-security-basics Compares
| Feature / Agent | clickhouse-security-basics | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Secure ClickHouse with user management, network restrictions, TLS, and audit logging. Use when hardening a ClickHouse deployment, creating restricted users, or configuring network-level access controls. Trigger: "clickhouse security", "clickhouse user management", "secure clickhouse", "clickhouse TLS", "clickhouse access control", "clickhouse firewall".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
ChatGPT vs Claude for Agent Skills
Compare ChatGPT and Claude for AI agent skills across coding, writing, research, and reusable workflow execution.
SKILL.md Source
# ClickHouse Security Basics
## Overview
Secure a ClickHouse deployment with SQL-based user management, network restrictions,
TLS encryption, and query audit logging.
## Prerequisites
- ClickHouse admin access
- `CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1` for SQL-based user management
- For self-hosted: access to server config files
## Instructions
### Step 1: Create Restricted Users (SQL-Based RBAC)
```sql
-- Create a read-only analyst user
CREATE USER analyst
IDENTIFIED WITH sha256_password BY 'strong-password-here'
DEFAULT DATABASE analytics
SETTINGS
readonly = 1, -- Read-only mode
max_memory_usage = 5000000000, -- 5GB per query
max_execution_time = 60; -- 60s timeout
GRANT SELECT ON analytics.* TO analyst;
-- Create an application user with insert permissions
CREATE USER app_writer
IDENTIFIED WITH sha256_password BY 'another-strong-password'
DEFAULT DATABASE analytics;
GRANT SELECT, INSERT ON analytics.* TO app_writer;
-- Explicitly deny destructive operations
REVOKE DROP, ALTER, CREATE ON *.* FROM app_writer;
-- Create an admin user
CREATE USER ch_admin
IDENTIFIED WITH sha256_password BY 'admin-password'
SETTINGS PROFILE 'default';
GRANT ALL ON *.* TO ch_admin WITH GRANT OPTION;
```
### Step 2: Use Roles for Permission Groups
```sql
-- Create reusable roles
CREATE ROLE data_reader;
GRANT SELECT ON analytics.* TO data_reader;
CREATE ROLE data_writer;
GRANT SELECT, INSERT ON analytics.* TO data_writer;
CREATE ROLE schema_admin;
GRANT CREATE TABLE, ALTER TABLE, DROP TABLE ON analytics.* TO schema_admin;
-- Assign roles to users
GRANT data_reader TO analyst;
GRANT data_writer TO app_writer;
GRANT schema_admin, data_writer TO ch_admin;
-- Verify grants
SHOW GRANTS FOR analyst;
SHOW GRANTS FOR app_writer;
```
### Step 3: Row-Level Security
```sql
-- Create a row policy: tenant users only see their own data
CREATE ROW POLICY tenant_isolation ON analytics.events
FOR SELECT
USING tenant_id = currentUser() -- or a mapped value
TO data_reader;
-- More practical: map users to tenant IDs via settings
CREATE USER tenant_42
IDENTIFIED WITH sha256_password BY 'pass'
SETTINGS custom_tenant_id = 42;
CREATE ROW POLICY tenant_filter ON analytics.events
FOR SELECT
USING tenant_id = getSetting('custom_tenant_id')
TO tenant_42;
```
### Step 4: Network Security
```xml
<!-- config.xml — restrict listen addresses -->
<listen_host>0.0.0.0</listen_host> <!-- or specific IP -->
<!-- IP allowlist per user -->
<users>
<app_writer>
<networks>
<ip>10.0.0.0/8</ip> <!-- VPC only -->
<ip>172.16.0.0/12</ip>
</networks>
</app_writer>
</users>
```
```sql
-- SQL-based network restriction (ClickHouse 22.6+)
CREATE USER app_writer
IDENTIFIED WITH sha256_password BY 'pass'
HOST IP '10.0.0.0/8', IP '172.16.0.0/12';
```
**ClickHouse Cloud:** Use the Cloud console IP Access List to restrict connections
to specific IPs or CIDR ranges.
### Step 5: TLS Configuration
```xml
<!-- config.xml — enable TLS for HTTPS (port 8443) -->
<https_port>8443</https_port>
<openSSL>
<server>
<certificateFile>/etc/clickhouse-server/server.crt</certificateFile>
<privateKeyFile>/etc/clickhouse-server/server.key</privateKeyFile>
<caConfig>/etc/clickhouse-server/ca.crt</caConfig>
<verificationMode>strict</verificationMode>
</server>
</openSSL>
```
### Step 6: Audit Logging
```sql
-- Enable query logging (on by default)
-- All queries are logged to system.query_log
-- Check who ran what queries
SELECT
event_time,
user,
client_hostname,
query_kind,
substring(query, 1, 200) AS query_preview,
exception_code
FROM system.query_log
WHERE event_time >= now() - INTERVAL 1 HOUR
AND user NOT IN ('default') -- skip system queries
ORDER BY event_time DESC
LIMIT 50;
-- Track failed login attempts
SELECT
event_time, user, client_hostname, exception
FROM system.query_log
WHERE exception_code = 516 -- AUTHENTICATION_FAILED
ORDER BY event_time DESC;
```
### Step 7: Application Connection Security
```typescript
import { createClient } from '@clickhouse/client';
// Production: always use TLS, minimal-privilege user
const client = createClient({
url: 'https://your-host:8443', // HTTPS, not HTTP
username: 'app_writer', // Not 'default'
password: process.env.CH_PASSWORD!, // From secret manager
database: 'analytics', // Explicit database
clickhouse_settings: {
readonly: 0, // Matches user's permission level
},
});
```
## Security Checklist
- [ ] Default password changed or `default` user disabled
- [ ] Application users created with minimal privileges
- [ ] Roles used for permission groups
- [ ] TLS enabled for all connections (port 8443)
- [ ] IP allowlists configured (Cloud: console; self-hosted: config)
- [ ] Query logging enabled (`system.query_log`)
- [ ] Row policies for multi-tenant isolation (if needed)
- [ ] Secrets stored in environment variables or secret manager
- [ ] `.env` files in `.gitignore`
## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| `Authentication failed (516)` | Wrong password or user | Verify credentials |
| `ACCESS_DENIED (497)` | Missing GRANT | `SHOW GRANTS FOR user` to diagnose |
| `READONLY (164)` | User in readonly mode | Grant write if needed |
| `Not enough privileges` | Row policy blocking | Check `SHOW ROW POLICIES` |
## Resources
- [Access Control & Account Management](https://clickhouse.com/docs/operations/access-rights)
- [GRANT Statement](https://clickhouse.com/docs/sql-reference/statements/grant)
- [Row Policies](https://clickhouse.com/docs/knowledgebase/row-column-policy)
- [ClickHouse Cloud Access Management](https://clickhouse.com/docs/cloud/security/cloud-access-management/overview)
## Next Steps
For production deployment, see `clickhouse-prod-checklist`.Related Skills
performing-security-testing
Test automate security vulnerability testing covering OWASP Top 10, SQL injection, XSS, CSRF, and authentication issues. Use when performing security assessments, penetration tests, or vulnerability scans. Trigger with phrases like "scan for vulnerabilities", "test security", or "run penetration test".
checking-session-security
Analyze session management implementations to identify security vulnerabilities in web applications. Use when you need to audit session handling, check for session fixation risks, review session timeout configurations, or validate session ID generation security. Trigger with phrases like "check session security", "audit session management", "review session handling", or "session fixation vulnerability".
finding-security-misconfigurations
Configure identify security misconfigurations in infrastructure-as-code, application settings, and system configurations. Use when you need to audit Terraform/CloudFormation templates, check application config files, validate system security settings, or ensure compliance with security best practices. Trigger with phrases like "find security misconfigurations", "audit infrastructure security", "check config security", or "scan for misconfigured settings".
responding-to-security-incidents
Analyze and guide security incident response, investigation, and remediation processes. Use when you need to handle security breaches, classify incidents, develop response playbooks, gather forensic evidence, or coordinate remediation efforts. Trigger with phrases like "security incident response", "ransomware attack response", "data breach investigation", "incident playbook", or "security forensics".
analyzing-security-headers
Analyze HTTP security headers of web domains to identify vulnerabilities and misconfigurations. Use when you need to audit website security headers, assess header compliance, or get security recommendations for web applications. Trigger with phrases like "analyze security headers", "check HTTP headers", "audit website security headers", or "evaluate CSP and HSTS configuration".
generating-security-audit-reports
Generate comprehensive security audit reports for applications and systems. Use when you need to assess security posture, identify vulnerabilities, evaluate compliance status, or create formal security documentation. Trigger with phrases like "create security audit report", "generate security assessment", "audit security posture", or "PCI-DSS compliance report".
workhuman-security-basics
Workhuman security basics for employee recognition and rewards API. Use when integrating Workhuman Social Recognition, or building recognition workflows with HRIS systems. Trigger: "workhuman security basics".
wispr-security-basics
Wispr Flow security basics for voice-to-text API integration. Use when integrating Wispr Flow dictation, WebSocket streaming, or building voice-powered applications. Trigger: "wispr security basics".
windsurf-security-basics
Apply Windsurf security best practices for workspace isolation, data privacy, and secret protection. Use when securing sensitive code from AI indexing, configuring telemetry, or auditing Windsurf security posture. Trigger with phrases like "windsurf security", "windsurf secrets", "windsurf privacy", "windsurf data protection", "codeiumignore".
webflow-security-basics
Apply Webflow API security best practices — token management, scope least privilege, OAuth 2.0 secret rotation, webhook signature verification, and audit logging. Use when securing API tokens, implementing least privilege access, or auditing Webflow security configuration. Trigger with phrases like "webflow security", "webflow secrets", "secure webflow", "webflow API key security", "webflow token rotation".
vercel-security-basics
Apply Vercel security best practices for secrets, headers, and access control. Use when securing API keys, configuring security headers, or auditing Vercel security configuration. Trigger with phrases like "vercel security", "vercel secrets", "secure vercel", "vercel headers", "vercel CSP".
veeva-security-basics
Veeva Vault security basics for REST API and clinical operations. Use when working with Veeva Vault document management and CRM. Trigger: "veeva security basics".