Skip to content

Hide the arguments of a table function or function with secrets called with the wrong letter case - #124862

Merged
Algunenano merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/wrong-case-function-name-hides-secrets
Oct 15, 2026
Merged

Algunenano merged 3 commits into
ClickHouse:masterfrom
groeneai:groeneai/wrong-case-function-name-hides-secrets

Conversation

@groeneai

@groeneai groeneai commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Improvement

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

The arguments of a table function or function with secrets are now hidden in system.query_log and the server log also when the call uses the wrong letter case, such as S3(...) instead of s3(...), MySQL(...) instead of mysql(...), or ENCRYPT(...). Such a call is still rejected.

Description

On 26.8.18.2, SELECT * FROM S3('https://b.s3.amazonaws.com/k', 'AKID', 'secret', 'CSV') is rejected with Unknown table function S3. Maybe you meant: ['s3'], but only after the statement, secret included, was written to system.query_log and the server log. The same holds for MySQL, URL, REMOTE, PostgreSQL, AzureBlobStorage, IcebergS3, INSERT INTO TABLE FUNCTION S3(...), CREATE TABLE ... AS S3(...) and ENCRYPT/Decrypt: the engine spelling in a table-function position is the natural mistake.

SecretArgumentsRegistry::find looks an ordinary function up in TableFunctionFactory and FunctionFactory under each factory's own case rule. A wrong-case name finds no spec, so nothing is hidden and executeQuery logs the raw text before the factory rejects the name. #123364 already fails closed for an unregistered engine; this is the converse direction.

Now, when the name equals, ignoring case, a table function or function whose spec has argument secrets, and is not itself a registered function, find takes the existing fail-closed path and hides every argument. Any other unknown function stays visible. TableFunctionFactory keeps the lowercase names with secrets at registration; FunctionFactory scans its six secret specs.

The new test 05340_wrong_case_function_name_hides_secrets checks clickhouse-format and the query_log row. It fails on master 895d8b8 (the secrets are printed) and passes with the fix. No registered function equals a secret table function up to case.

Not covered: wrong-case argument names inside a correctly spelled call (s3(..., SECRET_ACCESS_KEY = '...')) and arbitrary misspellings, the typo family left to query_masking_rules. A SQL UDF named like such a function up to case (CREATE FUNCTION S3 ...) gets its logged arguments hidden; its result is unchanged.

🤖 Generated with Claude Code


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

Version info

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

groeneai and others added 2 commits October 9, 2026 08:25
…on with secrets

`SecretArgumentsRegistry::find` looks an ordinary function up in
`TableFunctionFactory` and `FunctionFactory` under each factory's own case
rule. A call such as `SELECT * FROM S3(...)` (the engine spelling in a
table-function position), `MySQL(...)` or `ENCRYPT(...)` finds no spec, so
nothing is hidden: `executeQuery` writes the statement, credentials included,
to the server log and `system.query_log` before the factory rejects the name
with UNKNOWN_FUNCTION. ClickHouse#123364 made an unregistered engine fail closed; this
is the converse direction.

When the name equals, ignoring case, a table function or function whose spec
has argument secrets, and is not itself a registered function, `find` now
takes the existing fail-closed path and hides every argument. Every other
unknown function keeps its arguments visible, so UDF calls are unaffected
unless the UDF is named like such a function up to case.

`TableFunctionFactory` records the lowercase names with argument secrets at
registration; `FunctionFactory` scans its six secret specs. The cost per
spec-less function is one lowercase copy, one hash lookup and that scan,
below run-to-run noise when formatting a 50,000-call query.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the fail-closed rationale from the ORDINARY_FUNCTION branch comment; the comment at maskEveryArgument already states it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-self PR origin: self-found defect (impact-bar validated) labels Oct 9, 2026
@groeneai

groeneai commented Oct 9, 2026

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

Pre-publication review by an independent model (engine: codex; 1 finding; one full pass).

# Sev Finding Verdict Evidence / action
1 ❌ A wrong-case call in the OVER form (ENCRYPT(...) OVER ()) or the parametric form (S3('p')('a')) still prints its literals (SecretArgumentsRegistry::find) DISAGREE The canonical encrypt(...) OVER () and s3(...)(...) print the same literals on master. Window calls are excluded from the finder for every name (FunctionSecretArgumentsFinderAST.h:98-111), and parameters are formatted without it (ASTFunction.cpp:1039-1043). A separate syntax-form carrier, not part of this change.

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

Session id: cron:clickhouse-review-self-slot-58:20261009-082700

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT * FROM S3('https://b.s3.amazonaws.com/k', 'AKID', 'secret', 'CSV') under --send_logs_level=debug prints the secret every time on master 895d8b8 and on 26.8.18.2; same for MySQL, URL, REMOTE, PostgreSQL, AzureBlobStorage, IcebergS3, INSERT INTO TABLE FUNCTION S3, CREATE TABLE ... AS S3, ENCRYPT, Decrypt.
b Root cause explained? SecretArgumentsRegistry::find looks an ordinary function up under each factory's case rule. A wrong-case name finds no spec, so nothing is hidden and executeQuery logs the raw text before the factory rejects the name.
c Fix matches root cause? Yes. The name-to-spec step in find now sends a name that equals a secret-bearing table function or function up to case (and is not itself a registered function) to the existing fail-closed path. No guard at a log site.
d Test intent preserved / new tests added? New 05340_wrong_case_function_name_hides_secrets: clickhouse-format cases plus controls, and the end-to-end system.query_log row. Existing masking tests unchanged.
e Both directions demonstrated? Yes. The new test fails on master 895d8b8 (secrets printed, raw query_log row) and passes with the fix; server Build-IDs checked on both. 50/50 randomized and 50/50 plain runs green.
f Fix is general across code paths? One function serves the AST, query tree and ActionsDAG views. Engine kinds already fail closed. All table-function positions (FROM, INSERT INTO TABLE FUNCTION, CREATE TABLE ... AS) are measured.
g Fix generalizes across inputs (params/datatypes/wrappers)? Measured over every secret-bearing family listed in (a). Controls stay visible: a wrong-case table function without secrets (NUMBERS), an unknown name, a case-insensitive function (UPPER), the canonical spelling. Census: no registered function equals a secret table function up to case. Type wrappers: N/A (names, not values).
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or stored-data change; only the logged text of a rejected call changes. Side effect: a SQL UDF named like such a function up to case has its logged arguments hidden, and its result is unchanged (measured).
i Invariants and contracts preserved? find still returns the spec-driven result for every registered name. The new name set is written only during single-threaded registration, before any lookup, like the existing maps. Formatting cost per call stays within noise (50,000-call query, same build type).

Session id: cron:clickhouse-impl-self-slot-57:20261009-071500

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [e1c170b]

Summary: ✅


AI Review

Summary

The PR hides every argument of otherwise unregistered calls whose names differ only in case from secret-bearing functions or table functions. No actionable findings in the current diff. The focused regression test covers formatter output and system.query_log, supported by the author's recorded before/after validation.

Missing context / blind spots
  • ⚠️ Current-head stateless CI jobs are still pending. No local build was available; execution evidence comes from the author's validation of the original implementation. The full-feature CI run should confirm 05340_wrong_case_function_name_hides_secrets on the merged head.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). labels Oct 9, 2026
@Algunenano Algunenano self-assigned this Oct 9, 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.

Changes look good, but this should not be considered a bugfix. It's an improvement to help keep things tidy on a known bad case, but I don't think it's realistic to expect us to handle every possible syntax error

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks, agreed. I changed the changelog category to Improvement and rewrote the changelog entry accordingly.

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit e1c170b76592582af061e1fc88ba8cac014e422b was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 0376a14

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
Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 1/2) / 05316_secret_arguments_declared_by_engines test regression from merged #123364, not from this PR: under DatabaseReplicated the final query_log count returns 0 2 instead of 0 1 (the password stays hidden; the CREATE DICTIONARY row is counted twice). It passes in the 6 other lanes that ran it on this head; 22/22 reruns pass; the same diff is on 33 PRs in this lane today a fix task is created (investigating at full effort, fixing-PR link to follow here)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05233_string_filters_fixed_string_constant flaky, not from this PR: the last query_log ProfileEvents check reads 0 instead of 1; under parallel replicas the scan events can land only in the remote replica's row, which the current_database = currentDatabase() filter drops. 192/192 reruns pass #124911 (mine, open)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05210_lightweight_update_materialized_cte_in_ignore flaky, not from this PR: Code: 60 UNKNOWN_TABLE for the initiator-local _materialized_cte_c_* table when a follower replica takes a read (issue #112642). 1/145 reruns fail; 11 PRs in 30 days #123121 (mine, open)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, sequential) / 03254_system_prewarm_mark_cache flaky, not from this PR: the first read's LoadedMarksCount > 0 check reads 0 on the initiator's query_log row, the same parallel-replicas oracle shape as the 05233 row. 114/114 reruns pass; first failure in 30 days a fix task is created (investigating at full effort, fixing-PR link to follow here)
Mergeable Check, PR praktika rollups of the four rows above, no independent failure #124911, #123121; a fix task is created (05316, 03254)

Session id: cron:our-pr-ci-monitor:20261009-140011

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for 05316_secret_arguments_declared_by_engines (DatabaseReplicated 0 1 -> 0 2) from the CI finish ledger above: #124928 (external, open).

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

Fixing PR for 03254_system_prewarm_mark_cache (ParallelReplicas) created: #124942

nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Oct 11, 2026
In the ParallelReplicas configuration the single segment of these tests'
tables is read by whichever of the three replicas gets it. When a remote
replica reads it, the mark and primary index load counters land on that
replica's own query_log row (is_initial_query = 0, current_database =
'default'), which the current_database = currentDatabase() filter drops, so
the initiator row shows 0. parallel_replicas_local_plan = 1 does not help:
the local plan is used but gets nothing to read.

Sum the counters over all rows whose initial_query_id is one of the test's
queries, as in 02417_load_marks_async (ClickHouse#123825). All replicas share one
server's caches and each load is counted once, so the exact references are
unchanged, and nothing changes without parallel replicas.

Failing job: 03254_system_prewarm_mark_cache in Stateless tests (arm_binary,
ParallelReplicas, s3 storage, sequential) on PR ClickHouse#124862.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements and removed pr-bugfix Pull request with bugfix, not backported by default labels Oct 14, 2026
@Algunenano
Algunenano added this pull request to the merge queue Oct 15, 2026
Merged via the queue into ClickHouse:master with commit ccdc5da Oct 15, 2026
176 checks passed
@robot-ch-test-poll robot-ch-test-poll 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-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). groeneai-origin-self PR origin: self-found defect (impact-bar validated) pr-improvement Pull request with some product improvements 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