Skip to content

Do not log the raw query text in the Arrow Flight and gRPC servers - #125716

Merged
alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-arrowflight-grpc-query-text-in-log
Oct 15, 2026
Merged

alexey-milovidov merged 3 commits into
ClickHouse:masterfrom
groeneai:fix-arrowflight-grpc-query-text-in-log

Conversation

@groeneai

@groeneai groeneai commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #125517

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):

Fixed the Arrow Flight interface writing the text of each query, including secrets such as IDENTIFIED BY passwords and storage keys, to the server log and system.text_log. The gRPC interface did the same for the first 64 characters of each query. Now queries from these interfaces are logged only with their secrets hidden.

Description

On 26.3.42.3 and 26.8.18.2, a query sent over Arrow Flight is logged at the information level with its secrets in plain text: DoPut is called for descriptor <FlightDescriptor cmd='CREATE USER ... IDENTIFIED BY '<password>''>. gRPC logs the first 64 characters of each query at the debug level. Found by the protocol randomization in #125517: Stress test (arm_debug) aborted on the test rule Detect passwords in tests while 05340_custom_disk_error_hides_secrets ran over Arrow Flight (report).

Root cause: the native protocol logs a query only in executeQuery, from formatForLogging, which hides secret arguments. The Arrow Flight server also logs the raw FlightDescriptor, ticket, FlightInfo, PollInfo and CancelFlightInfo request (nine lines), and gRPC's getQueryDescription logs a raw query prefix. With secrets display on, GetSchema logged secrets in field names.

Change: these lines now print only identifiers in the form the server generates (~TICKET-<uuid>, ~POLL-<uuid>), the compiled-in name of a known Flight SQL command, a table path, or the size of anything else; GetSchema prints the field count. gRPC prints the query size.

Not changed: HTTP's Request URI trace line masks query-string values by parameter name only, so a ?query= value is still printed there.

Validation: with the CI masking rule, the master binary aborts on both lines and the fixed one does not. An integration test in test_arrowflight_interface checks each line's new form and that the secret is absent, also with secrets display on; the stateless 05394_grpc_query_text_is_not_logged checks the gRPC line and system.text_log. Both fail on master and pass with the fix (10 repeats, 50 randomized runs).

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.2452-master (included in 26.10 and later)

The native protocol logs a query only in `executeQuery`, from `formatForLogging`,
which hides secret arguments. The Arrow Flight server additionally logged the
raw request before running it: `FlightDescriptor::ToString` (whose `cmd` is the
SQL text or a Flight SQL protobuf carrying it), the ticket (the SQL text when
it is not a generated `~TICKET-` id), and `FlightInfo`, `PollInfo` and the
`CancelFlightInfo` request, which embed that descriptor. gRPC's
`getQueryDescription` logged the first 64 characters of the query. So a
password in `CREATE USER ... IDENTIFIED BY`, a storage key in `s3` or `disk`
arguments, or an `encrypt` key was written to the server log and
`system.text_log` in plain text, even for a query that was then rejected.

These lines now print only identifiers generated by the server (a prefix and
a UUID, checked by form), the compiled-in name of a known Flight SQL command
(never the client's type URL), a table path, or the size of anything else.
gRPC prints the query size.

Found by the protocol randomization of the stress test in ClickHouse#125517, where the
test-only masking rule `Detect passwords in tests` aborted the server on the
`DoPut is called for descriptor` line while
`05340_custom_disk_error_hides_secrets` ran over Arrow Flight:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125517&sha=c1a332dfdd920abb5ceb3e4919fd6afe6eba0b72&name_0=PR&name_1=Stress%20test%20%28arm_debug%29
ClickHouse#125517

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding labels Oct 14, 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; 9 findings over 6 rounds) plus my own review.

Bounce cap reached: published as is. The fix for row 9 was checked by my own review and a mutation run, not by another second-model round. Residual findings are listed below (only the nit in row 11).

# Sev Finding Verdict Evidence / action
1 ⚠️ The Arrow Flight test did not reach the immediate-table PollFlightInfo return and did not pin the sanitized forms AGREE, fixed one exact fragment per changed line plus a CommandGetSqlInfo poll; fails when commandForLogging prints only sizes or that line is reverted
2 ⚠️ The gRPC test did not prove the size form AGREE, fixed moved to the stateless 05394_grpc_query_text_is_not_logged, which asserts the exact new line
3 ⚠️ The size-form expectations stopped at cmd=(, so a wrong size would pass AGREE, fixed expectations now carry the exact byte count; fails with a constant size
4 ⚠️ The test never sent a ~TICKET-/~POLL- lookalike or an unknown Flight SQL type, so the two guards' reject branches were untested AGREE, fixed same-length lookalikes and an unknown arrow.flight.protocol.sql.* type now must log as sizes; fails with a prefix-only check or the client's type name
5 ⚠️ CancelFlightInfo was only sent server-built FlightInfos, so its ticket sanitizing was untested AGREE, fixed a client-built FlightInfo with the query text as its ticket must log the ticket as a size; fails when the raw ticket is printed
6 ⚠️ Generated ~TICKET-/~POLL- ids were pinned by prefix only AGREE, fixed the test now asserts the exact ids the client received; fails when only the prefix is printed
7 ⚠️ A secret in endpoint app_metadata would be logged hex-encoded, invisible to the plaintext check AGREE, fixed app_metadata never carries query text and is not printed; the misleading sentinel is removed from the fixture
8 ⚠️ A UUID-shaped forged id is logged verbatim (syntax, not provenance) DISAGREE such a value is at most 32 client-chosen hex digits, is never executed as a query, and the client-chosen gRPC query_id is likewise logged verbatim; PR text now says "in the form the server generates"
9 ⚠️ The continuation ~POLL- id in each PollFlightInfo response line was not pinned AGREE, fixed each id the client received must appear intact in its response line; fails when that descriptor prints null
10 💡 commandSelector.cpp echoes the bytes of an unimplemented Flight SQL command in its error DISAGREE only reached by unimplemented or forged command types; the Flight SQL commands that carry SQL are dispatched earlier
11 💡 The new log lines omit non-secret fields such as app_metadata noted app_metadata of a CancelFlightInfo request is client-supplied, so it is not printed

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

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. A server with the CI masking rule and an Arrow Flight DoPut of the first statement of 05340_custom_disk_error_hides_secrets aborts on every run with the CI message; a gRPC CREATE USER ... IDENTIFIED BY 'P@ssw0rd' aborts a fresh server on Received initial QueryInfo.
b Root cause explained? The Arrow Flight server logs the raw descriptor, ticket, FlightInfo, PollInfo and CancelFlightInfo request, and gRPC a raw 64-character query prefix, before executeQuery logs the query with secrets hidden.
c Fix matches root cause? Yes. These lines no longer print request bytes: only identifiers in the form the server generates, compiled-in Flight SQL command names, table paths, or sizes.
d Test intent preserved / new tests added? An integration test in test_arrowflight_interface checks that each of the nine changed lines was written in its sanitized form, then that the secret is absent from the log. A stateless test checks that gRPC logs the query size and that no text_log line holds the encrypt key. No existing test changed.
e Both directions demonstrated? Both tests fail on master and pass with the fix (Arrow Flight 11/11, stateless 51/51 with randomized settings). Making every command print its size, reverting only the immediate-table PollFlightInfo line, printing a constant (0 bytes) instead of the real size, accepting any ~TICKET-/~POLL- value as a generated id, printing the client's own type name for an unknown Flight SQL command, printing the raw endpoint ticket of a CancelFlightInfo request, printing only the prefix of a generated identifier, or printing null for the continuation descriptor of a PollFlightInfo response makes the Arrow Flight test fail.
f Fix is general across code paths? All nine Arrow Flight log lines and the gRPC one. The native TCP, MySQL, PostgreSQL, SSH and web terminal handlers write no query text in their own log lines.
g Fix generalizes across inputs (params/datatypes/wrappers)? Plain-text commands, Flight SQL commands, a spoofed type URL prefix, unknown types, non-Flight-SQL protobufs, empty commands, generated and forged ~TICKET- values: checked on the fixed binary, none prints request bytes.
h Backward compatible? (maintainer-approved exception only) Yes. Only log message text changes; no setting, protocol or format change.
i Invariants and contracts preserved? The helpers are pure functions of their argument. request.info was already dereferenced unconditionally on the next line. Log arguments are evaluated only when the level is enabled.

Session id: cron:clickhouse-impl-slot-5:20261013-224600

@clickhouse-gh

clickhouse-gh Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [d56e423]

Summary: ✅


AI Review

Summary

The PR prevents Arrow Flight and gRPC protocol logs from exposing SQL secrets by logging safe identifiers, known command names, and payload sizes. The earlier GetSchema disclosure is fixed, including regression coverage with secrets display enabled. No unresolved findings remain.

Missing context / blind spots
  • ⚠️ Current-head CI is still pending, and no local ClickHouse build was available. The unchanged server implementation and Arrow Flight test passed the previous commit’s targeted integration check; the gRPC regression passed 50 CI repeats. Completion of current-head CI will confirm the final test-tag change.
Final Verdict

Status: ✅ Approve. No code changes requested.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... labels Oct 14, 2026
groeneai and others added 2 commits October 14, 2026 04:30
The field names of a query result are its projection names. The analyzer
hides secret arguments in them unless secrets display is enabled (server
setting `display_secrets_in_show_and_select`, query setting
`format_display_secrets_in_show_and_select` and the
`displaySecretsInShowAndSelect` privilege), in which case
`GetSchema returns schema` wrote, for example, the key of
`encrypt('aes-128-ecb', 'plaintext', '<key>')` to the server log. Showing
secrets in a result must not put them in the log, so this line now prints
only the number of fields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
In the DBReplicated job the two extra servers get no gRPC port override,
so all three listen on 9100 and the kernel spreads the connections between
them. When the query runs on a replica, the main server's `text_log`, which
the test reads, has no line for it, and the test fails with `0` instead of
`1`. The server logs of the failing runs show the query on
`clickhouse-server1` or `clickhouse-server2` every time:
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125716&sha=eb582abf613dbb60daa95ab8d32ea7d168f9e482&name_0=PR&name_1=Stateless%20tests%20%28arm_binary%2C%20s3%20storage%2C%20DBReplicated%2C%20parallel%2C%201%2F2%29

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Oct 15, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 15, 2026
Merged via the queue into ClickHouse:master with commit 7c7053a Oct 15, 2026
520 of 523 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 15, 2026
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-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... groeneai-origin-ci-master PR origin: master/nightly CI monitoring finding pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants