Security Lab: Trying to Break Each Control
Logins, TLS, least privilege, row policies, quotas and secrets, each checked by an attempt to get around it
labs/security.py doesn't read the configuration back; it tries to do
what each control should stop, and passes only if the attempt fails.
docker compose -f compose_prod.yaml run --rm labs python security.py1. Logins
[ok] the image's passwordless `default` user is gone
[ok] wrong password is refused
[ok] TLS with the lab CA works
[ok] plain HTTP to the TLS port is refused
2. Least privilege
[ok] dashboard can read 100,000 rows
[ok] dashboard cannot insert / drop / read system.users
[ok] dashboard cannot raise its memory limit Code: 452 ... shouldn't be greater than
[ok] ingest can insert, cannot create tables
[ok] backup user cannot read other databases
3. Row policy and quota
[ok] analyst_eu sees only DE and FR rows (['FR', 'DE'], 50000)
[ok] dashboard is stopped after 300 queries a minute
ch-1 quota usage seen by admin: [('', 301, 300)]
[ok] ...but ch-2 keeps its own counter (quotas are per server)
4. Secrets
[ok] S3 secret is not visible in system.named_collections to dashboard
[ok] no query in query_log contains the S3 secret
17 of 17 checks passedHow it's set up
scripts/init.sql creates roles, not per-user grants:
writer:INSERT, SELECTonanalytics.*, foringest.reader:SELECTwith a settings profile capping memory (500 MB) and run time (30 s) withMAXconstraints, so a reader can't raise them, plus a quota of 300 queries a minute. Fordashboardandanalyst_eu.backup:BACKUP, restore rights onanalytics, and thech_backupsnamed collection, which holds the S3 keys so noBACKUPstatement (and noquery_logrow) ever contains them.
Users and roles live in Keeper, so they exist on all four nodes. Row policies go on the local table: a Distributed query runs as the same user on every shard, and the shards read local tables.
What the checks got wrong at first
Two checks failed on the first run, and neither was a security hole. Both were the lab testing the wrong thing.
"Plain HTTP to the TLS port is refused" failed: the login worked.
clickhouse-connect chooses HTTPS by itself when the port is 8443, even
with secure=False, so the "plain HTTP" attempt was really HTTPS. curl
over plain HTTP got no response. The check now sets interface="http"
explicitly. A security test that can't fail is worse than none.
The quota never triggered: 400 queries went through. Two reasons:
- The lab ran
SELECT 1. Quotas count queries that read a table; a query with no table isn't counted at all. ch-1 reported 0 queries used. - Quota counters live in each server's memory. Through HAProxy, the 400 queries were split across four nodes, 100 each. The quota really limits 300 queries a minute per server, so 1,200 across this cluster.
Once over quota, dashboard can't even read its own usage: that query
is refused too. The lab reads it as admin from system.quotas_usage.
And since the counter lasts for the rest of the minute, re-running the
lab straight away failed its first check; it now waits out the interval
at the end and at the start.
Per-server quotas are a real production surprise: behind a load balancer, a quota of N allows N times the number of nodes. Size them per node, or enforce the limit in front of ClickHouse.