From 371ad7e59e4cfc3b3c224d4c89c80770d19a415b Mon Sep 17 00:00:00 2001 From: Aaron Gibson Date: Tue, 10 Nov 2026 15:53:27 +0000 Subject: [PATCH] clickhouse: readonly = 2 for the users that only read (oonimeasurements, oonirun) #528 gave every SQL user readonly = 0. For users with only SELECT grants that changes nothing a query can do today (tested on 24.8 and 25.3: a readonly = 0 user with SELECT on ooni.* and oonitest.* is refused INSERT, ALTER, TRUNCATE, CREATE, DROP, temporary tables, url()/file(), SYSTEM and KILL with ACCESS_DENIED), but it drops the second lock: with readonly = 2 a grant added by mistake still can't make the user write. The ooniapi services that use these users never write to ClickHouse: oonimeasurements and oonirun call only query_click (ooni/backend ooniapi/services/*/src; oonirun reads url_priorities and runs a health check). Every ooniapi query carries a log_comment (common/dependencies.py, backend #1305), which readonly = 1 refuses (code 164); readonly = 2 allows it, and still refuses INSERT and SETTINGS readonly = 0. Production (SHOW ACCESS and system.settings_profile_elements on 2026-11-10): oonimeasurements data1: no profile, so readonly 2 from the default profile; data2: the same; data3: PROFILE readonly, so readonly 1, which refuses log_comment oonirun PROFILE write (readonly 0) on all three nodes So oonimeasurements gets what data1 and data2 have, and oonirun is tighter than production. Memory limits are unchanged (4 GiB and 61 GB). Tested with the role's tests (tests/run.sh, 24.8.6.70, nodes seeded like production): 1082 checks passed, among them, on every node, both users have readonly = 2, can set log_comment, can SELECT and cannot INSERT. --- ansible/group_vars/clickhouse/vars.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ansible/group_vars/clickhouse/vars.yml b/ansible/group_vars/clickhouse/vars.yml index 8e5bcb2d..15ed0a01 100644 --- a/ansible/group_vars/clickhouse/vars.yml +++ b/ansible/group_vars/clickhouse/vars.yml @@ -255,12 +255,16 @@ clickhouse_custom_users: # in force there and would fail queries the API makes today (e.g. aggregations # with more than 51000 rows). Nothing is CONST, as on data2: a query may set # these (the API's query helpers set max_execution_time on some queries). + # readonly = 2, as data1 and data2 have it (from the default profile): the API + # only reads, and 2 still lets every query set settings, which ooniapi needs for + # the log_comment it puts on each query (common/dependencies.py); readonly = 1 + # refuses that. A grant added by mistake still can't make it write. - name: oonimeasurements password_type: sha256_hash password: "{{ lookup('amazon.aws.aws_ssm', '/oonidevops/secrets/clickhouse_oonimeasurements_password', profile='oonidevops_user_prod') | hash('sha256') }}" networks: ["IP '0.0.0.0/0'"] settings: - - "readonly = 0" + - "readonly = 2" - "max_memory_usage = 4294967296" # 4 GiB, as on data2 - name: ooniprobe @@ -271,12 +275,15 @@ clickhouse_custom_users: - "readonly = 0" - "max_memory_usage = 61001001000" # 61 GB + # The oonirun service only reads ClickHouse (url_priorities, and a health check), + # with ooniapi's log_comment on every query: readonly = 2, as for oonimeasurements. + # Production has it on the write profile (readonly = 0). - name: oonirun password_type: sha256_hash password: "{{ lookup('amazon.aws.aws_ssm', '/oonidevops/secrets/clickhouse_oonirun_password', profile='oonidevops_user_prod') | hash('sha256') }}" networks: ["IP '0.0.0.0/0'"] settings: - - "readonly = 0" + - "readonly = 2" - "max_memory_usage = 61001001000" # 61 GB - name: oonitestlists