Repository navigation
insights.query works where log_queries is pinned, and no logged error quotes the scope key - #428
Merged
Merged
Conversation
… quotes the scope key ClickHouse Cloud pins log_queries for the service's users, so the analyst entity statements (sent with log_queries=0) and the analyst profile (log_queries = 0 CONST) were refused and insights.query stayed unavailable. The statements that carry the key or the password now run with log_queries_cut_to_length = 1, which any user may set and which logs the statement as only its removed length; the analyst profile pins the same, and the printed analyst SQL sets it first. Under forced logging the probe's unsigned read logs an error that quotes the whole policy, so the HMAC pads are written as decrypt() of themselves sealed under the key, which ClickHouse prints as [HIDDEN]. The HMAC is unchanged. ENTITY_VERSION is 2. CI's ClickHouse pins log_queries read-only for Loom's user, as Cloud does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…f the deploy delta, and name CI's log_queries pin - The canary test writes the policy under a random key, so the probe's signed read fails on the signature instead of a decrypt error. - The tests rebuild policies with the domain's policy_sql. - Both query-log tests tie their counts to rows that prove the case ran. - The deploy delta leaves loom_analyst's statements out. - The CI/compose mount test names log_queries_readonly.xml as CI's own. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…t a refused statement logs - printed_statements puts the log cut first, so the CLI only prints. - The setting is TEXT_CUT_FROM_LOG, used by the integration tests too. - The doc says a refused statement's error can quote the whole statement, and that the probe's refused reads add error rows. - A unit test pins the deploy delta's analyst filter. - The key test also reads formatted_query. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… names and wording Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…query-log settings in CI Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…he pads themselves stay out - The architecture page's stored-data table names query_log and the server log: a refused statement's error can quote an allowlisted value, kept for ClickHouse's log retention, which erasure does not reach. - The key test also looks for the two pads the decrypt arguments evaluate to. - hmac_sql is public; the deploy delta binds the analyst user. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e cut in one value - A refused statement that throws on a row value, in the select list, WHERE or PREWHERE, with short-circuiting off and PREWHERE moves forced, quotes the caller's own row and none from another org or namespace, in the answer and in system.query_log. - LOG_CUT_BYTES is the one cut value; the profile pin and the printed SET use it. - The entity statements change none of the three settings Cloud pins. - The deploy delta test checks the analyst user is bound. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…g cut once - The stored-data notes say an analyst error reaches system.query_log and the server log on every install, with no TTL by default, and name the operator step that bounds them. - TEXT_CUT_SQL is the one SQL spelling of the cut; the profile and the printed SET use it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ed read of this run Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…cope-filter read in the tests Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e new cases - An escape and the text test try SETTINGS log_queries_cut_to_length; its text stays cut whether ClickHouse runs or refuses it. - The isolation proof lists the cut and the errors that quote only the caller's own row. - One dict and one SQL spelling of the cut (LOG_TEXT_CUT, LOG_TEXT_CUT_SQL); the AES key length is checked where the policy is built. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…gs of the cut from one pair Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…still matters Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
- The lift test also sets log_formatted_queries and counts formatted_query. - The escape case that could not fail on its own is dropped; the lift test is the check. - Reads with no secret lose the cut setting, and the key test's docstring says what it checks. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
ClickHouse's log_queries_cut_to_length does not reach query_log's formatted_query: with log_formatted_queries on, the full text is logged. Entity statements now also send log_formatted_queries = 0, the analyst profile pins both CONST, and the printed SQL sets both. The lift test tries each setting on its own. AES256 checks the key length where the policy is built. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… its two pins Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ll covers Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Cloud refuses CREATE USER with a password missing an upper case letter or a symbol, and the analyst's was drawn as lowercase hex. A new draw puts a fixed Aa1- in front of 192 random bits. A stored password without them, whose user Cloud never created, is drawn again under the same key when no analyst user exists, at a version from the clock; a password in use is kept. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
The hex draw came after the last release, so only deployments built from main hold such a row; with no analyst user, deleting the row lets the next boot draw a fresh pair. New draws keep every character class. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…rapped Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ssword Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…test helper Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…er names in two tests Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…list in the CI file Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… a clear pad On an upgrade the older profile still pins log_queries = 0; replacing it before the policies would log, for a moment, a refused read that quotes a policy holding the pads in clear. The pins now follow every policy, the canary's included, and still precede every grant. Also: the quoting test searches its errors for the key, the plain text read must answer 200, the password test checks the draw itself, and the isolation proof no longer claims a printed-SQL run. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…s reason Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
After the cross-boot, both builds answer insights.query on the entities N wrote over N-1's, and system.query_log holds none of the scope key's spellings. The write order's two halves each name their reason. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…, and names a missing key apart Also regenerates the op reach manifest for the gate's insights.query call, and rewraps the write-order bullet. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…o search the server log - The gate reads the stored version, polls N before N-1, and binds its needles as a parameter like the integration test. - The key test searches text_log's error lines too; a missing key literal fails with its own message. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…ndency, and the gate's search keeps itself out of the log - server.insights.domain.analysis.key_spellings is the one list the unit test, the integration tests and the gate search for. - The gate reads names and the version from the domain, and sends the log cut with the request: a SETTINGS clause does not cut its own logged text. - An error-quoting case sets format_display_secrets_in_show_and_select. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… key; one _pads builds the HMAC pads Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…the gate - The gate puts this checkout on sys.path, reads the version unquoted, and checks the probe's refused reads were logged before it searches them. - The statement-text test keeps each statement's accepted answers with it. - The isolation proof names the format_display_secrets case. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… with sql_string; policy_spellings has a unit test Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…sed read reached the log N-1's version 1 probe errors reached text_log with the pads in clear, as on any version 1 install, so the gate searches from once both builds answer, waits for a refused read to reach the log (the probe runs every 5 s in the gate), and only then counts key spellings. The integration test checks the same positive count. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…e-error match takes SQL_loom_ literally Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…LITERAL pattern
decrypt(encrypt(pad, key), key) evaluates to the pad, folds to a constant
before the read, and ClickHouse prints the whole call as
decrypt('aes-256-ecb', '[HIDDEN]') (checked on 26.4, 26.5 and 26.10, and
across a restart on replicated access storage). The cryptography
dependency and the PKCS7 code go.
Also: the app's scrubber and policy_spellings share the domain's
KEY_LITERAL, the gate's checks are split and say what they check without
naming a version, and the structure digest pin moves with the policy text.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…es its rule in the present Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…rite order protects Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…the exact list Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…row names both logs Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
zlareb1
force-pushed
the
fix/insights-cloud-log-queries
branch
from
November 9, 2026 07:23
21c8eb1 to
9412afa
Compare
… alone With LOOM_CH_LOG_COMMENT_STATEMENT_DIGEST, log_comment held a statement's first 200 characters: the analyst's CREATE USER password, and a caller's SQL. Now that those statements are logged, a statement under uncaptured() or run as the analyst gets the literal-masked shape only. The isolation tests and the gate also search log_comment. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…analyst statement logs its shape alone Also splits ch_statement_text's helpers so the whitespace collapse runs once per call. Regenerated: configuration.md, status.md, the settings schema and loom.example.yaml. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
….py names its flag shape_only Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This was referenced Nov 9, 2026
Merged
8 of 9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #436
Changelog category (leave one):
Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):
insights.querynow works on ClickHouse Cloud, where it stayed unavailable withSetting log_queries should not be changed. The analyst's scope key and password stay out ofsystem.query_logthere too, including the error text of a read a row policy refuses.Why
ClickHouse Cloud pins
log_queries(andlog_query_settings,log_queries_min_type) asCONSTin the profile of the service's users. Loom sent every analyst entity statement withlog_queries = 0and pinnedlog_queries = 0 CONSTin the analyst's profile, so the first statement was refused (code 452) and the analyst user was never written.Dropping the setting alone would have put the key in the log: the policies hold the key's HMAC pads as hex literals, and ClickHouse logs a
CREATE ROW POLICY's text in full. Two things checked on ClickHouse 26.10 decided the design:IDENTIFIED BY. It does not mask a row policy's expression inquery_log, and query parameters are substituted into the logged text, so neither the policy literal nor a parameter keeps the key out.log_queries_cut_to_lengthis not constrained on Cloud. A read-only probe as the service'sdefaultuser (Loom's user there),SELECT name, readonly FROM system.settings WHERE name IN (...), showsreadonly = 0for it and for every other setting the analyst profile pins:readonly,final,apply_row_policy_after_final, the overflow modes,use_query_cache,use_query_condition_cache,allow_introspection_functions,send_logs_level,max_concurrent_queries_for_user, the caps, andlog_formatted_queries.system.settings_profile_elementslistslog_queries,log_queries_probability,log_queries_min_typeandlog_query_settingsasCONSTin itsdefaultprofile. At1, ClickHouse logs the statement as(removed N characters), insystem.query_logand in the server log's statement line.So every statement that carries a secret runs with
log_queries_cut_to_length = 1andlog_formatted_queries = 0. The cut does not reachformatted_query: checked on 26.10, a top-levellog_formatted_queries = 1logs the full text there even with the cut. The analyst profile pins bothCONST, and the printed analyst SQL starts withSET log_queries_cut_to_length = 1, log_formatted_queries = 0. On Cloud, ClickHouse also traces a share of statements intosystem.opentelemetry_span_log(opentelemetry_start_trace_probabilityis 0.05 there). Itsdb.statementhonours the same cut: spans of statements carrying the cut read(removed N characters), andquery_logon Cloud shows the same.With logging forced on, a second leak showed up in the new integration test: the probe's unsigned read (which proves each table carries a policy) fails with
UNKNOWN_SETTING, and ClickHouse's error quotes the whole policy filter, pads included, inquery_log.exception. ClickHouse prints the arguments ofdecryptas[HIDDEN]in error messages and inSHOW CREATE. Each pad is now written in SQL asdecrypt('aes-256-ecb', encrypt('aes-256-ecb', <pad>, <key>), <key>). ClickHouse evaluates it back to the pad and prints the whole call asdecrypt('aes-256-ecb', '[HIDDEN]'), so no Python crypto or new dependency is needed. The HMAC and the signatures Loom sends do not change, and the on-disk access storage keeps the real arguments, so a restart reads the same policies.system.row_policiesstill shows the arguments in full to an admin, as before.A second refusal waited behind the first. Cloud applies complexity rules to a database user's password, and the analyst's password was drawn as lowercase hex, so
CREATE USER loom_analystwould have been refused next (Invalid password ... contain at least 1 uppercase character, contain at least 1 special character, reproduced with ClickHouse'spassword_complexityrules). The password is now drawn with a fixedAa1-prefix in front of 192 random bits. No release drew a hex password (the draw is in no release tag; the newest, v1.1.0, does not contain it), so nothing rewrites stored rows. A deployment built frommainthat stored one on Cloud, and so has no analyst user, recovers by deleting itsloom.analysis_secretsrow: the next boot draws a fresh pair.Rejected options: making
log_queries = 0conditional on the server allowing it, which means two entity shapes and two digests for one version. Reading the key from a dictionary or table inside the policy, which needs a grant the analyst could use directly.Scope and risk
ENTITY_VERSIONgoes from 1 to 2, since the policy text changed. A build N-1 beside N sees a newer version, writes nothing, and keeps answering, because the signature is identical.query_logrow without their text: user, timing, rows read and settings, the signed scope among them. A signature reads rows only with the analyst's password, for its own query id, before its expiry. A refused statement logs its error message, which can quote the whole statement (an unknown column's error quotes the query it was looked up in). Both are in the architecture page.log_queries,log_queries_probability,log_query_settingsandlog_queries_min_typeread-only for every user on its default profile, Loom's included, (dev/clickhouse-ci/log_queries_readonly.xml, mounted only bydev/ci_start_clickhouse.sh), so every integration pass runs under Cloud's constraint. The bundled compose config does not change.tests/unit/test_ci_clickhouse_matches_dev_compose.pynames it as CI's second intended difference.toUInt64(title)quotes the title). The value is one of the caller's own allowlisted metadata columns (a key, a title, a user id), never a memory value or document text, andtest_an_error_quotes_no_value_from_another_scopeshows it is never another scope's.mainthat error already went to the server log andsystem.text_logat Error level, whateverlog_queriessaid. Checked on 26.10 with alog_queries = 0profile:text_logheld it,query_logdid not.system.query_log.exception, on every install, because Loom writes one profile shape and Cloud pinslog_queries_min_type.<ttl>toquery_logandtext_log. Erasure reaches neither. The architecture page's stored-data table says so.mainthe same values already persisted intext_logwith no TTL, out of erasure's reach, so this adds a second copy of data that was already kept, not a new kind. Avoiding it would take a second profile shape per server (rejected above). The bound is a system-log TTL for both logs, tracked in The bundled ClickHouse bounds how long query_log and text_log keep rows #436.loom_analystrows per probe (its refused reads, and the start and finish of each read that succeeds), about 33 KB of text uncompressed counting theSettingscolumn. At the default 60 s interval that is about 34,000 rows and 48 MB uncompressed a day per web process, before ClickHouse's compression. Eachinsights.querystatement adds two rows.log_comment: with the opt-inLOOM_CH_LOG_COMMENT_STATEMENT_DIGEST,log_commentcarries a statement's shape and its first 200 characters. A statement underuncaptured()(it carries a password or a key) or run as the analyst now carries the literal-masked shape alone. Checked with the setting on: no entity-write row holds the password, and the isolation tests also searchlog_comment.loom_analyst's statements out of its shapes. They are callers' SQL, and they are now logged without their text.Compatibility, rollout and rollback
mainthat stored a hex analyst password on ClickHouse Cloud (it has no analyst user) deletes itsloom.analysis_secretsrow once, and the next boot draws a fresh pair. Where Loom's user has access management, the first boot on this build rewrites the analyst entities at version 2. Where it does not and the analyst SQL was printed for an admin, the version 1 entities stay until the admin rerunsloom ch-setup --print-analyst-sql, which is optional: version 1 still pinslog_queries = 0on the self-managed servers that accepted it. The printed file runs with plainclickhouse-client --multiquery --queries-file <file>, because it sets the cut itself.log_queries = 0holds until no policy has the pads in clear. A unit test pins the order. The mixed-version gate (scripts/gates/mixed_version.py) now checks the upgrade itself: base build N-1 writes version 1, this build rewrites it to version 2 on the same ClickHouse, both builds answerinsights.query, and nothing logged afterwards holds any spelling of the key. It does not exercise the few statements between the policies and the profile'sALTER; the unit test covers that order. Run locally againstorigin/main, every check of the gate passed.Tests
<log_queries><readonly/></log_queries>on Loom's user, the server onmainlogged the sameSETTING_CONSTRAINT_VIOLATIONandtests/integration/test_analysis_isolation.pyanswered503 ANALYSIS_UNAVAILABLE. The new unit tests failed onmain(nolog_querieschange in any statement or profile, the statements sent with the cut, the printed SQL'sSETfirst, and an error that quotes the policy quotes no key, through clickhouse-local).test_analysis_isolation.pypassed against an auth-on server. That includestest_the_scope_key_stays_out_of_the_query_log, which looks up every hex literal of the live policy inquery_log.queryand.exception. Before thedecryptchange it found 183 rows.test_an_error_quotes_no_value_from_another_scope: seven statements that throw onmemory_keyin the select list,WHEREorPREWHERE, also withshort_circuit_function_evaluation = 'disable',optimize_move_to_prewhere(_if_final) = 1,query_plan_merge_filters = 1andformat_display_secrets_in_show_and_select = 1. Each is refused, its logged error quotes the caller's own row, and none quotes another org's or namespace's, in the answer or inquery_log.test_analysis_isolation.pypasses in full underlog_queries,log_queries_probability,log_query_settingsandlog_queries_min_typepinned read-only.clickhouse local), a refused read of the generated policy prints both pads as[HIDDEN], with nounhex(and no key bytes.EXPLAIN actions = 1of aloom.memoryread under the policy filter has neitherencryptnordecryptin its plan, because ClickHouse folds the constant calls before the read.password_complexityrules, a hex password is refused (BAD_ARGUMENTS). From an emptyanalysis_secrets, a boot draws a password that passes and creates the user, and the isolation file passes in full under those rules. A unit test checks the draw has every character class; it fails on the old hex draw.replicateduser directory still reads after a restart. The signed read returns its row, and a changed scope reads none.clickhouse-clientunder the constraint. Afterwardsquery_logheld no policy literal and noIDENTIFIED BY.make format lint typecheck. The full unit suite passed: 31794 tests, 0 failures.test_ci_clickhouse_matches_dev_compose.pywas updated to name the CI-only mount as its second intended difference.AI assistance in the code (leave one; writing this description with AI is fine):
AI-generated (an agent wrote most of the diff): Claude Code. The ClickHouse behaviour each design point rests on was checked on a local ClickHouse 26.10, and the integration suite was run under the constraint.
I can explain every line of this diff and how it interacts with the rest of Loom.
Checklist
make format-check,make lint,make typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.server/operations/reach_manifest.py(the gate now calls insights.query).main; no merged migration is edited. (none)frontend/changed. (unchanged)docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code