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.
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
checking-session-security
This skill enables Claude to check session security implementations within a codebase. It analyzes session management practices to identify potential vulnerabilities. Use this skill when a user requests to "check session security", "audit session handling", "review session implementation", or asks about "session security best practices" in their code. It helps identify issues like insecure session IDs, lack of proper session expiration, or insufficient protection against session fixation attacks. This skill leverages the session-security-checker plugin. Activates when you request "checking session security" functionality.
performing-security-testing
This skill automates security vulnerability testing. It is triggered when the user requests security assessments, penetration tests, or vulnerability scans. The skill covers OWASP Top 10 vulnerabilities, SQL injection, XSS, CSRF, authentication issues, and authorization flaws. Use this skill when the user mentions "security test", "vulnerability scan", "OWASP", "SQL injection", "XSS", "CSRF", "authentication", or "authorization" in the context of application or API testing.
performing-security-audits
This skill allows Claude to conduct comprehensive security audits of code, infrastructure, and configurations. It leverages various tools within the security-pro-pack plugin, including vulnerability scanning, compliance checking, cryptography review, and infrastructure security analysis. Use this skill when a user requests a "security audit," "vulnerability assessment," "compliance review," or any task involving identifying and mitigating security risks. It helps to ensure code and systems adhere to security best practices and compliance standards.
security-policy-generator
Security Policy Generator - Auto-activating skill for Security Advanced. Triggers on: security policy generator, security policy generator Part of the Security Advanced skill category.
finding-security-misconfigurations
This skill enables Claude to identify potential security misconfigurations in various systems and configurations. It leverages the security-misconfiguration-finder plugin to analyze infrastructure-as-code, application configurations, and system settings, pinpointing common vulnerabilities and compliance issues. Use this skill when the user asks to "find security misconfigurations", "check for security vulnerabilities in my configuration", "audit security settings", or requests a security assessment of a specific system or file. This skill will assist in identifying and remediating potential security weaknesses.
responding-to-security-incidents
Assists with security incident response, investigation, and remediation. This skill is triggered when the user requests help with incident response, mentions specific incident types (e.g., data breach, ransomware, DDoS), or uses terms like "incident response plan", "containment", "eradication", or "post-incident activity". It guides the user through the incident response lifecycle, from preparation to post-incident analysis. It is useful for classifying incidents, creating response playbooks, collecting evidence, constructing timelines, and generating remediation steps. Use this skill when needing to respond to a "security incident".
security-headers-generator
Security Headers Generator - Auto-activating skill for Security Fundamentals. Triggers on: security headers generator, security headers generator Part of the Security Fundamentals skill category.
analyzing-security-headers
This skill analyzes HTTP security headers of a given domain to identify potential vulnerabilities and misconfigurations. It provides a detailed report with a grade, score, and recommendations for improvement. Use this skill when the user asks to "analyze security headers", "check HTTP security", "scan for security vulnerabilities", or requests a "security audit" of a website. It will automatically activate when security-related keywords are used in conjunction with domain names or URLs.
security-group-generator
Security Group Generator - Auto-activating skill for AWS Skills. Triggers on: security group generator, security group generator Part of the AWS Skills skill category.
security-benchmark-runner
Security Benchmark Runner - Auto-activating skill for Security Advanced. Triggers on: security benchmark runner, security benchmark runner Part of the Security Advanced skill category.
scanning-database-security
Process use when you need to work with security and compliance. This skill provides security scanning and vulnerability detection with comprehensive guidance and automation. Trigger with phrases like "scan for vulnerabilities", "implement security controls", or "audit security".
scanning-container-security
Execute use when you need to work with security and compliance. This skill provides security scanning and vulnerability detection with comprehensive guidance and automation. Trigger with phrases like "scan for vulnerabilities", "implement security controls", or "audit security".