Skip to content

Hide a named-collection credential override whose key is not a plain literal - #121467

Closed
groeneai wants to merge 4 commits into
ClickHouse:masterfrom
groeneai:mask-unreadable-keys-redis-arrowflight-ytsaurus
Closed

groeneai wants to merge 4 commits into
ClickHouse:masterfrom
groeneai:mask-unreadable-keys-redis-arrowflight-ytsaurus

Conversation

@groeneai

@groeneai groeneai commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix a credential written in cleartext to system.query_log and the server log by the Redis and ArrowFlight table engines, the arrowFlight table function and the YTsaurus table engine: the value of a named-collection override whose key is written as an expression rather than as a plain literal was not masked. Redis(creds, concat('pass', 'word') = 'secret') sets the password, because the parser evaluates the key, but the masker recognized only a literal key; the YTsaurus oauth_token override was not masked in either spelling.

Description

On v26.8.10.6-lts, CREATE TABLE t (k String, v String) ENGINE = Redis(creds, concat('pass', 'word') = 'S7') PRIMARY KEY k is accepted, authenticates to Redis with S7, and writes S7 in cleartext to system.query_log.query and the server log, because the masker recognizes an override key only when it is a plain literal.

getKeyValueFromASTImpl evaluates an override's key as a constant expression, while FunctionSecretArgumentsFinder reads it only via tryGetStringFromArgument. classifyS3Arguments and the MySQL TLS keys already hide the value of any override whose key they cannot read; these three finders did not. findYTsaurusStorageTableEngineSecretArguments also had no named-collection branch at all, and the Redis finder returned after its first readable hit.

This adds that fail-closed scan to the three finders and deletes the early return. Every edit adds a mark and none is moved, so the change cannot un-hide anything; a 61-statement corpus rendered on a master binary and on this one changes exactly the 14 rows expected and leaves the other 47 byte-identical. The new test carries the credential into system.query_log on a master binary and is clean here.

A bare positional written after a collection name still shifts the hidden slot, and is not fixed here: StorageRedis folds positionals through evaluateConstantExpressionOrIdentifierAsLiteral, so Redis('127.0.0.1:6379', 0 = 1, 'S9', 16) is a valid table and a formatter cannot separate the two shapes. mongodb and remote have the same gap and are handled separately.

Found while sweeping this file for #121257. The sibling PR #121425 lifts the same markNamedArgumentsWithUnreadableKeys helper out of findTLSCredentialsSecretArguments byte for byte and applies it to jdbc/odbc, RabbitMQ and Kafka, so whichever merges second resolves that hunk by keeping one copy.


Workflow [PR]
Sync PR [sync-upstream/pr/121467]

groeneai and others added 2 commits September 22, 2026 00:42
…literal

The named-collection parser does not require the key of a `key = value`
override to be a plain literal: `getKeyValueFromASTImpl` evaluates it as a
constant expression. `FunctionSecretArgumentsFinder` works on the AST alone and
reads a key only through `tryGetStringFromArgument`, so an override written with
a computed key is applied by the server and invisible to the masker, and its
value is rendered into `query_for_logging`.

On v26.8.10.6-lts,

    CREATE TABLE t (k String, v String)
    ENGINE = Redis(creds, concat('pass', 'word') = 'S7') PRIMARY KEY k

is accepted, the table is created, the server authenticates to Redis with `S7`
(measured on the wire: the RESP handshake sends `AUTH S7`, not the collection's
own password), and `S7` is written in cleartext to `system.query_log.query` and
to the server log. The literal spelling `password = 'S7'` of the same override
on the same engine is already hidden, so the guarantee exists and only this
spelling escapes it.

`classifyS3Arguments` and the MySQL TLS keys already hide the value of any
override whose key they cannot read. Give the `Redis` and `ArrowFlight` finders
the same fail-closed scan, and add to `findYTsaurusStorageTableEngineSecretArguments`
the named-collection branch it never had, which is why even a plain readable
`oauth_token = '...'` leaked there. Its positional `markSecretArgument(2)` stays
first and unconditional: master hides that argument whatever argument 0 is, and
`YTsaurus(identifier, ..., 'token')` is rejected only after it has already been
formatted for the log.
Also delete the `return` after the `Redis` finder's readable-key scan: the
parser applies every override in turn, so the first credential found is not a
reason to stop looking, and that `return` would have made the new call dead.

Every edit adds a mark and none is moved, so masking is monotone and the change
cannot un-hide anything. A 61-statement corpus rendered on a master binary and
on this one changes exactly the 14 rows expected and leaves the other 47
byte-identical, including the positional forms, the valid folded positional
`Redis('127.0.0.1:6379', 0 = 1, 'S9', 16)`, a secret in the left operand of an
`equals` at the password slot, and the `s3`/`url`/`mysql`/`mongodb`/`remote`
calls this does not touch.

Not addressed here: a bare positional argument written after a collection name
still shifts the slot the masker hides. Those parsers fold every positional
through `evaluateConstantExpressionOrIdentifierAsLiteral`, so an `equals` is a
legal positional value and no formatter can tell the two shapes apart. The
`mongodb` and `remote` carriers have the same unreadable-key gap and are handled
separately; `ExternalDistributed`'s finder has it too, but that engine was
removed in eac5e98.

Co-Authored-By: Claude Opus 5 <[email protected]>
Condensed the argument-2 masking note in the YTsaurus finder to a one-line invariant.
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-follow-up PR origin: groeneai's own out-of-scope finding during its PR work labels Sep 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex): 2 gate findings plus 6 from my own cold
reads, 2 fix rounds, third round clean on both sides.

# Sev Finding Verdict Evidence / action
1 ⚠️ The comment on YTsaurus's unconditional markSecretArgument(2) claims getConfiguration falls back to the positional form when an identifier does not name a collection (FunctionSecretArgumentsFinder.cpp:1010, same sentence in the tests and the commit message) AGREE, fixed @ 5dc8c085d7ff3 It does not: StorageYTsaurus.cpp:133 passes throw_unknown_collection=true, so the lookup throws NAMED_COLLECTION_DOESNT_EXIST. The mark is still right, because master hides that argument whatever argument 0 is and the call is rejected only after being formatted for the log; comments and commit message reworded, no masking line, assertion or reference row changed
2 ⚠️ Two gtest assertions cannot fail: EXPECT_NE(masked.find("nc"), npos) is satisfied by concat('pass', 'word') in the same query (gtest_Parser.cpp:404, :455) AGREE, fixed @ 5dc8c085d7ff3 "concat".find("nc") == 2, so both passed with the collection name removed; replaced with the dispatched call prefix and proved by a mutation that reddens each one while the old blind form stays green on the same mutant
3 ⚠️ A comment states a false server behaviour: both Redis arms are said to be accepted with the table created, but only the computed string key is (05236_*.sh:30-32) AGREE, fixed @ 7c6149644de90 A numeric key evaluates to UInt64 and checkAndGetLiteralArgument<String> throws BAD_ARGUMENTS outside the try that guards the value, so Redis(nc, 0 = 'secret') is rejected; the arm and its reference row are correct and unchanged, since masking a rejected statement is the point when formatting precedes validation
4 ⚠️ The same claim, generalised over all seven Redis arms in the file header (05236_*.sh:2-9) AGREE, fixed @ 7c6149644de90 False for the numeric-key arm per row 3, and vacuous for the three positional arms, which read no collection (StorageRedis.cpp:400-413)
5 💡 The helper's header doc says "key is not a plain literal", but a numeric literal key is masked too DISAGREE That line is byte-identical to the same line in #121425 deliberately, so whichever lands second resolves the hunk by keeping one copy; rewording it here turns a take-either-side conflict into a real one, and the precise predicate is stated on the definition (FunctionSecretArgumentsFinder.cpp:318-323)
6 💡 Redis(nc, 0, 'S9') and arrowFlight(nc, 'ds', 'usr', 'S9') with a non-collection identifier were said to reach the positional form and leak an in-use credential DISAGREE My own claim, disproved by the chain in row 1: both parsers pass throw_unknown_collection=true (StorageRedis.cpp:379, StorageArrowFlight.cpp:50), so such a call is rejected rather than executed, leaving only the pre-existing face this PR declares out of scope
7 💡 The fail-closed comment above the YTsaurus group says "such a call is rejected", but the first row it heads is the plain positional form (05236_*.sh:60-61, gtest_Parser.cpp:492-493) AGREE, fixed @ 7c6149644de90 Self-scoped by its own opening clause, so not misleading; reworded only because row 3 reopened the same file two lines away
8 💡 Two @groeneai PRs add the same markNamedArgumentsWithUnreadableKeys helper AGREE, in the description #121425 lifts it out of findTLSCredentialsSecretArguments byte for byte for jdbc/odbc, RabbitMQ and Kafka, so the later merge keeps one copy

Also checked, no finding: a census over all 17 functions using isNamedCollectionName leaves only carriers
that are already fail-closed, already filed, or in #121425. Monotonicity is structural as well as measured,
since every added call sets argument_is_named and the merge step can only clear that flag. The changelog
category was re-tested against the released v26.8.10.6-lts sources, where all three finders are still in
their pre-fix shape.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per
finding.

Session id: cron:clickhouse-review-self-slot-58:20260922-004700

@groeneai groeneai added the groeneai-origin-follow-up PR origin: groeneai's own out-of-scope finding during its PR work label Sep 22, 2026
@clickhouse-gh clickhouse-gh Bot closed this Sep 22, 2026
@clickhouse-gh clickhouse-gh Bot reopened this Sep 22, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. One command, no server, 100% of runs: printf '%s' "CREATE TABLE t (k String, v String) ENGINE = Redis(creds, concat('pass', 'word') = 'S7') PRIMARY KEY k" | clickhouse format --oneline. Master echoes 'S7'; this branch prints '[HIDDEN]'.
b Root cause explained? Yes. getKeyValueFromASTImpl evaluates an override's key as a constant expression, so a computed key names password; FunctionSecretArgumentsFinder reads a key only via tryGetStringFromArgument and so never matches it, and the value is rendered into query_for_logging.
c Fix matches root cause? Yes. The three finders get the fail-closed unreadable-key rule classifyS3Arguments and the MySQL TLS keys already have, at the site that decides what the log shows. No setting, no parser change, no widened bound, no guard at a symptom.
d Test intent preserved / new tests added? Yes. 4 new gtest arms in gtest_Parser.cpp and a new stateless test (21 reference lines) covering all 6 dispatched names. No existing test weakened and no existing reference changed.
e Both directions demonstrated? Yes. Two servers from one tree: the new stateless test is [ FAIL ] on a master binary with the credential in system.query_log (canary count 11) and [ OK ] here (0). Reverting each carrier separately fails exactly that carrier's gtest arm and no other; restoring only the deleted return fails the readable-key-then-computed-key assertion.
f Fix is general across code paths? Yes. All three finders in the class are fixed together. Every other named-argument site in the file was censused with its disposition and owner; grep -c 'if (findSecretNamedArgument' is 2 before and 1 after. mongodb, remote, Azure/URL and XDBC are owned elsewhere and left untouched.
g Fix generalizes across inputs? Yes, per carrier: expression key, numeric key, readable key, readable-then-expression, override at index 1 and later, non-secret override, positional form, valid folded positional 0 = 1, secret in an equals left operand, identifier-then-positional. No data-type wrappers apply: this code reads AST argument kinds, not types.
h Backward compatible? Yes. No setting, no SettingsChangesHistory entry, no serialization format, no on-disk metadata. SHOW CREATE TABLE can only gain [HIDDEN], which the corpus check proves.
i Invariants and contracts preserved? Yes. Every edit adds a mark and none is moved, so masking is monotone: a 61-statement corpus token-aligned across both binaries changes exactly the 14 rows declared in advance, 0 rows hide less. None of the three finders sets result.replacement, so markSecretArgument's chassert is untouched, and that call is bounds-checked, so the unconditional YTsaurus mark is a no-op on a short argument list.

Session id: cron:clickhouse-impl-self-slot-57:20260922-001900

@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f33cb5b]

Summary: ✅


AI Review

Summary

This PR extends the existing fail-closed masking rule for unreadable named-collection override keys to the Redis engine, the ArrowFlight engine and table function, and the missing named-collection branch in the YTsaurus finder. I did not find any remaining correctness or coverage issues in the current diff or in the resolved review thread.

Missing context / blind spots
  • ⚠️ I did not run the new tests locally in this environment because this checkout has no build directory or ready binary. Running the new parser gtests and the new stateless query test locally would close that remaining runtime gap.
Final Verdict

✅ No new review findings.

LLVM Coverage Report

Measured on commit f33cb5b.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.40% +0.00%

Changed lines: Changed C/C++ lines covered: 13/13 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 22, 2026
`CLICKHOUSE_TEST_UNIQUE_NAME` is `${CLICKHOUSE_TEST_NAME}_${CLICKHOUSE_DATABASE}`,
so it is unique per run only while the runner creates a database per test. The
database is pinned whenever `clickhouse-test` is given `--database` (`stress.py`
passes `--database=test_<i>` for every odd worker) and it defaults to `test` when
the script runs outside the runner, and two runs then build the same `query_id`s.

Measured on a pinned database, with the arms of this test neutered so that the
invocation executed no statement at all: the oracle still reproduced its whole
reference output from the previous run's rows and the test reported OK, which is
what would let it certify a leaking binary. With a run-local part in the prefix
the same probe fails with all 20 arm rows missing, while the test still passes
50/50 in the default per-test-database shape.

Reported by clickhouse-gh[bot] on this pull request.

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing f33cb5b48 with master 365470f5a (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

15 translation units recompiled, 54 s compile time in total, 15 of them have a recent master baseline.

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 1c1200a

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Performance Comparison (arm_release, master_head, 1/6) / order_by_read_in_order #1 shard verdict 4 too long, 1 slower; 1 confirmed regression(s) on the performance dashboard. Not attributable to this diff: the change is confined to FunctionSecretArgumentsFinder, which runs when a query is formatted for the log, and the flagged fixture issues no table function with credentials. Fleet-wide over the last 3 days this fixture is reported slower on 158 distinct PRs (418 rows), which is the master_head dashboard-verdict gate misfiring rather than a per-PR regression #121090 (mine, open) and #121189 (mine, open)
Mergeable Check, PR praktika rollups of the row above, no independent failure #121090 and #121189

Session id: cron:our-pr-ci-monitor:20260922-073125

@clickhouse-gh clickhouse-gh Bot added the comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. label Sep 22, 2026

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Superseeded by #122770. One missing case is a7_redis_left_operand, which I'll fix there and add a test

@Algunenano Algunenano closed this Sep 28, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

I ran my masking corpus (220 statements through clickhouse format, the system.query_log render) against #122770 at aa5a089f and against its base a32c4c20. The only rows where it hides less than master are the identifier-first ones the bot raised there ('x' = 'y' at the secret slot of redis(localhost, ...), YTsaurus(proxy, ...), ytsaurus(proxy, ...)). Two Remote/remote shapes named in its changelog entry are still logged in cleartext, as on master:

-- nc: CREATE NAMED COLLECTION nc AS host = '127.0.0.1', port = 9000, database = 'system', table = 'one', user = 'u', password = 'orig'
CREATE TABLE t (dummy UInt8) ENGINE = Remote(nc, concat('pass', 'word') = 'S7')
-- logged as Remote(nc, concat('pass', 'word') = 'S7'); the literal key gives Remote(nc, password = '[HIDDEN]')
SELECT * FROM remote(password = 'S7', '127.0.0.1:9000', 'system', 'one', 'u')
-- logged as remote(password = 'S7', '[HIDDEN]', '[HIDDEN]', '[HIDDEN]', '[HIDDEN]')

The first is a valid table and its override is used: reading it sends S7 in the client hello (captured by a listener on the collection's port), and SHOW CREATE TABLE and system.tables.engine_full print it as well. RemoteSecure renders the same. Both come from findRemoteFunctionSecretArguments, which is not on the findPositionalAndNamedSecretArguments path: it reads password only when argument 0 is an identifier, from index 1, and never calls markNamedArgumentsWithUnreadableKeys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-sql-syntax SQL/grammar parsing, AST nodes, syntax-level features. groeneai-origin-follow-up PR origin: groeneai's own out-of-scope finding during its PR work pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants