Repository navigation
Mask session_token and Google ADC secrets in the explicit-url S3 form - #109768
Merged
Merged
Conversation
106855 removed table caching because it didn't respect session credentials, so this is dead code
The explicit-url branches of the S3 function/table-engine/database-engine secret finders masked only secret_access_key, so session_token and the Google ADC secrets (google_adc_client_secret, google_adc_refresh_token) passed as named arguments leaked in plaintext into SHOW CREATE, system.query_log and server logs. Only the named-collection branch masked all four. Route the explicit-url named-argument handling through the same shared secret_keys set so every S3 form masks the same secrets. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [b2e108c] Summary: ✅
AI ReviewSummaryThis PR consolidates secret masking for the S3 and URL carriers and for the query-tree / Findings❌ Blockers
Final VerdictChanges required. The main masking refactor looks solid otherwise, but the two dismissed named-collection paths above still leak credentials on current code. |
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The BACKUP destination secret finder (findBackupNameSecretArguments) masked only secret_access_key in the explicit-url form, so session_token and the Google ADC secrets leaked in plaintext in the logged query text. Route it through the same shared helper as the other S3 forms. Extend the regression test to cover the s3() function and BACKUP ... TO S3 forms via the logged query text. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
extra_credentials(role_arn = ..., external_id = ...) carries S3 assume-role auth material but was printed verbatim in SHOW CREATE and the logged query text for s3, ENGINE = S3 and BACKUP ... TO S3. Mask all its values like headers, and add external_id to the shared S3 secret-key list so the named-collection form masks it too. Strengthen the regression test to prove both explicit-url forms (s3 function and BACKUP ... TO S3) are individually logged and masked, and that no form leaks any secret. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The Backup database engine reconstructs its nested S3 destination to mask
secrets. A nested extra_credentials(...) matched none of the reconstruction
branches and hit the bail-out return, discarding all masking, so
CREATE DATABASE ... ENGINE = Backup('', S3('url','ak','sk', extra_credentials(external_id='...')))
left secret_access_key and external_id verbatim in SHOW CREATE / logged queries.
Reconstruct extra_credentials with every value hidden.
Extend the regression test with the Backup(..., S3(..., extra_credentials(...))) form.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Named-collection S3 carriers (s3, ENGINE = S3, DATABASE S3, BACKUP ... TO S3) route through findS3NamedCollectionSecretArguments, which only scanned top-level key = value overrides. An extra_credentials(...) override passed alongside a collection, e.g. s3(my_collection, extra_credentials(external_id = '...')), was printed verbatim. Mask it there too. Add a named-collection + extra_credentials regression. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Two leak paths in the S3 secret formatter: - When extra_credentials(...) sits between two named secret overrides, it was swept into the min..max named span and formatted as a key = value argument, emitting a malformed 'external_id = SECRET = [HIDDEN]' that leaked the first nested value. Format a nested secret map (headers/extra_credentials) before the secret-span branch so it is always masked as a map, keys kept, values hidden. - findBackupDatabaseSecretArguments reconstructs the nested S3 locator and bailed out with a verbatim leak when it met an argument it could not rebuild (e.g. a headers(...) tail). Fail closed: hide such arguments instead. Extend the regression to cover the interleaved extra_credentials and the headers-tail Backup forms. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…dentials keys - The explicit-key S3 form accepts a positional session_token as the 4th argument (s3/ENGINE = S3), which was left visible in SHOW CREATE and logged query text. Mask it, mirroring the storage's positional disambiguation: hide the 4th argument when the 2nd is an access key (not NOSIGN/format) and the 4th is not itself a format name. This also masks the session_token slot in the ambiguous S3(url, id, key, X, format) signature, updating 03273. - findBackupDatabaseSecretArguments reconstructed extra_credentials(...) but bailed out with a verbatim leak when an inner key was not a plain literal (a constant expression the parser still accepts). Fail closed: hide the whole map instead. Extend the regression with positional session_token and expression-key forms. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The backup S3 locator only accepts url, access_key_id, secret_access_key positionally. A further positional argument (e.g. a session token) is rejected by the backup engine, but the query is formatted and logged first, so the extra positional leaked verbatim in the logged query text. Fail closed: hide every positional beyond secret_access_key. Extend the regression with the BACKUP ... TO S3(url, ak, sk, tok) form. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The Backup database engine reconstructor (findBackupDatabaseSecretArguments)
hid only positional index 2, so a further positional in the explicit-url form,
e.g. CREATE DATABASE db ENGINE = Backup('', S3('url', 'ak', 'sk', 'tok')), was
emitted verbatim in the logged query text before the backup engine rejects it.
The locator accepts no positional beyond secret_access_key, so hide everything
from position 2 on, mirroring findBackupNameSecretArguments.
Extend the regression with the Backup('', S3(..., 'tok')) form.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
findS3DatabaseSecretArguments masked named overrides, extra_credentials and
positional index 2, but left a further positional literal visible. The S3
database engine (DatabaseS3) accepts no positional beyond secret_access_key,
so CREATE DATABASE db ENGINE = S3('url', 'ak', 'sk', 'tok') logged the extra
value verbatim before validation. Fail closed on extra positionals, using
excludeS3OrURLNestedMaps so trailing named overrides such as
use_environment_credentials = 1 stay visible.
Extend the regression with the extra-positional form and a
use_environment_credentials override that must remain visible.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- findSecretNamedArgument and the named-collection scan recorded only the first
occurrence of each secret key, so a malformed query like
s3('url', session_token = 'a', session_token = 'b', ...) (formatted for
logging before duplicate-key validation) left the later copy visible. Mark
every occurrence.
- Generalize maskS3ExtraCredentials to maskS3NestedSecretMaps, masking both
headers(...) and extra_credentials(...) on every S3 form. The named-collection
path previously masked extra_credentials but not headers, leaking header
values (e.g. Authorization). This also masks non-trailing headers(...) on the
explicit-url form, which the trailing-only excludeS3OrURLNestedMaps missed
(updates 02968). The helper and excludeS3OrURLNestedMaps are idempotent.
- Use a unique {CLICKHOUSE_DATABASE_1:Identifier} for the lazy S3 database in
the regression test so parallel runs do not collide on a global name.
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The masker re-implemented the S3 parser's argument model as several independent mechanisms doing raw-AST-index arithmetic (trailing-only nested map strip, per-key named scans, hardcoded positional indices, a min/max named span). The parsers instead normalize first: headers(...)/extra_credentials(...) are stripped from any position and key = value arguments are separated before positional slots are assigned. Each divergence between the two models was a leak (maps before the positional session_token shifting it out of the masked slot, malformed nested map children formatted verbatim). Replace them with classifyS3Arguments, a single pass that mirrors the parser: it records nested maps at any position, masks secret named arguments (every occurrence), and returns the raw indices of the positional slots; all S3 finders now run their slot logic on that view. Make the formatter fail closed: a nested-map child that is not key = value prints '[HIDDEN]' instead of verbatim, and a non-equals argument swept into a named span prints only '[HIDDEN]' instead of echoing itself as a bogus key (a pre-existing leak). Move the implementation out of the header into a new .cpp: the class uses virtual dispatch, not templates, so nothing required it to be header-only, and the header was transitively rebuilt by a large part of the codebase on every masking change. Restructure the regression test to one row per form (marker, masked, leaked) and add coverage for maps before the positional token, malformed map children, and a positional argument inside a named secret span. Co-Authored-By: Claude Fable 5 <[email protected]>
Harden classifyS3Arguments and the backup locators against malformed inputs that are logged before validation rejects them: - A positional after the first key = value argument is rejected by the S3 parsers, so mask it (the intended slot is unknowable). The backup locators are the exception: BackupInfo::fromAST collects positionals independently of named overrides, so they opt out and the named-collection filename stays visible in any position. - A key = value argument whose key is a constant expression can name any secret key (the parsers evaluate it); mask its value without evaluating. - The explicit-url backup locator accepts exactly one or three positionals; the valid triple carries its secret at slot 2, any other count is invalid, so everything after the url is hidden. Same rule in the Backup database reconstructor, which now counts positional slots instead of raw indices. Rework the regression test to assert the exact logged text of every query in execution order: the reference now shows each masked query verbatim, with the non-secret parts (urls, formats, filenames, non-secret overrides) visibly intact, instead of opaque per-marker booleans. Co-Authored-By: Claude Fable 5 <[email protected]>
…token slot
The storage evaluates constant expressions at CREATE, so SHOW CREATE stores
and shows the evaluated literal: a format expression like concat('TS', 'V')
stays visible, and a token expression is stored evaluated and masked. In the
logged text of the original query the unevaluated expression is
indistinguishable from a session token (which would print its pieces
verbatim), so it is hidden there: fail closed. Pin both surfaces in the
regression reference.
Co-Authored-By: Claude Fable 5 <[email protected]>
robot-clickhouse
added a commit
that referenced
this pull request
Jul 28, 2026
…n the explicit-url S3 form
robot-ch-test-poll2
added a commit
that referenced
this pull request
Jul 28, 2026
Cherry pick #109768 to 25.8: Mask session_token and Google ADC secrets in the explicit-url S3 form
robot-clickhouse
added a commit
that referenced
this pull request
Jul 28, 2026
…n the explicit-url S3 form
robot-ch-test-poll2
added a commit
that referenced
this pull request
Jul 28, 2026
Cherry pick #109768 to 26.3: Mask session_token and Google ADC secrets in the explicit-url S3 form
robot-clickhouse
added a commit
that referenced
this pull request
Jul 28, 2026
…n the explicit-url S3 form
Algunenano
added a commit
that referenced
this pull request
Jul 29, 2026
DatabaseS3.cpp/.h still had addTable() and a loaded_tables-based cache in getTableImpl(), which the PR's own hunk left dangling once it removed the loaded_tables field (undeclared identifier). Removed them, matching master's "not cached across sessions" design. The new 04510_s3_explicit_url_named_secret_mask test also exercised use_environment_credentials on the S3 database engine, which this branch's DatabaseS3 does not support; dropped that assertion.
Algunenano
added a commit
that referenced
this pull request
Jul 29, 2026
DatabaseS3.cpp/.h still had addTable() and a loaded_tables-based cache in getTableImpl(), which the PR's own hunk left dangling once it removed the loaded_tables field (undeclared identifier). Removed them, matching master's "not cached across sessions" design. The new 04510_s3_explicit_url_named_secret_mask test also exercised use_environment_credentials on the S3 database engine, which this branch's DatabaseS3 does not support; dropped that assertion.
Algunenano
added a commit
that referenced
this pull request
Jul 29, 2026
04510_s3_explicit_url_named_secret_mask exercised use_environment_credentials on the S3 database engine, which this branch's DatabaseS3 does not support; dropped that assertion. #112323
Algunenano
added a commit
that referenced
this pull request
Jul 29, 2026
QueryAnalyzer.cpp lost its transitive include of <boost/algorithm/string/predicate.hpp> when the include of the old, inline-bodied Parsers/FunctionSecretArgumentsFinder.h was swapped for the new declarations-only Analyzer/FunctionSecretArgumentsFinderTreeNode.h, breaking the pre-existing, unrelated boost::iequals ORDER BY ALL check. Added the include explicitly, matching master's QueryAnalyzer.cpp. The new 04510_s3_explicit_url_named_secret_mask test also exercised use_environment_credentials on the S3 database engine, which this branch's DatabaseS3 does not support; dropped that assertion. #112333
Algunenano
added a commit
that referenced
this pull request
Jul 29, 2026
…e table functions
A duplicated key-value argument such as
s3('http://...', format = 'CSV', format = 'TSV') is user-controlled input,
but parseKeyValueArguments threw LOGICAL_ERROR on the duplicate-key emplace.
LOGICAL_ERROR aborts debug builds and is treated as a critical failure by
stress and fuzzer checks, so a user typo must not produce it.
Backport of 4939661 (already applied to the
26.4 private backport), needed here too since the new secret-masking tests
from #109768 exercise this exact duplicate-key path.
Closes: #104267
Algunenano
added a commit
that referenced
this pull request
Jul 29, 2026
…e table functions
A duplicated key-value argument such as
s3('http://...', format = 'CSV', format = 'TSV') is user-controlled input,
but parseKeyValueArguments threw LOGICAL_ERROR on the duplicate-key emplace.
LOGICAL_ERROR aborts debug builds and is treated as a critical failure by
stress and fuzzer checks, so a user typo must not produce it.
Backport of 4939661 (already applied to the
26.4 private backport), needed here too since the new secret-masking tests
from #109768 exercise this exact duplicate-key path.
Closes: #104267
Algunenano
added a commit
that referenced
this pull request
Jul 29, 2026
…tion
A duplicated key-value argument such as
s3('http://...', format = 'CSV', format = 'TSV') is user-controlled input,
but parseKeyValueArguments threw LOGICAL_ERROR on the duplicate-key emplace.
LOGICAL_ERROR aborts debug builds and is treated as a critical failure by
stress and fuzzer checks, so a user typo must not produce it. On this branch
the helper still lives in Storages/ObjectStorage/S3/Configuration.cpp
(pre-dates the shared ObjectStorage/Utils.cpp refactor).
Backport of 4939661 (already applied to the
26.4 private backport), needed here too since the new secret-masking tests
from #109768 exercise this exact duplicate-key path.
Closes: #104267
Algunenano
added a commit
that referenced
this pull request
Jul 30, 2026
Backport #109768 to 26.3: Mask session_token and Google ADC secrets in the explicit-url S3 form
Algunenano
added a commit
that referenced
this pull request
Jul 30, 2026
Backport #109768 to 26.5: Mask session_token and Google ADC secrets in the explicit-url S3 form
Algunenano
added a commit
that referenced
this pull request
Jul 31, 2026
findS3FunctionSecretArguments only special-cased the named-collection
form for non-cluster functions (isNamedCollectionName(0)), so
s3Cluster('cluster', named_collection, ...) fell through to the
positional url/secret classification meant for the literal-url form,
leaving the named collection's secret_access_key (and session_token,
Google ADC secrets) unmasked. Ported master's findS3NamedCollectionSecretArguments
helper and its use in findS3FunctionSecretArguments, findS3TableEngineSecretArguments
and findS3DatabaseSecretArguments, matching the fully merged state of #109768.
This is what test_mask_sensitive_info/test.py::test_table_functions_object_storage_cluster
caught on this backport (amd_asan and amd_tsan integration runs).
#112333
Algunenano
added a commit
that referenced
this pull request
Jul 31, 2026
BACKUP TABLE ... TO S3('https://user:pass@localhost:11111/x?...', 'ak', 'sak') relied on the one-character bucket name being rejected by S3 URI validation before any network access, matching master's comment for this case. On this branch BACKUP's S3 destination locator parses the url without going through S3::URI: the userinfo confuses its ad-hoc host:port parsing into a bogus endpoint ("user:0"), and the resulting request is misclassified as retryable, so BackupsWorker retries it (s3_retry_attempts = 1000) instead of failing fast. The client hung for the full 600s test timeout, and the background backup task then kept the server from shutting down cleanly. The masking behavior itself already works (the query is logged with the userinfo and signature correctly hidden before the hang); only the "fails before any network access" assumption doesn't hold here. #112333
Algunenano
added a commit
that referenced
this pull request
Jul 31, 2026
findTableEngineSecretArguments's S3-family dispatch (S3, COSN, OSS, DeltaLake, Hudi, Iceberg, IcebergS3, S3Queue) was missing GCS and DeltaLakeS3, even though both exist as table engines on this branch (StorageObjectStorageDefinitions.h) and are included in master's merged state of #109768. Engines that fell through this dispatch got no masking at all: SHOW CREATE TABLE and the query log showed their secret_access_key in plaintext, as caught by 04510_s3_explicit_url_named_secret_mask's ENGINE = GCS(...) case. #112333
Algunenano
added a commit
that referenced
this pull request
Jul 31, 2026
The `Backup` database engine (`ENGINE = Backup(database_name, S3(...))`) reconstructs its nested `S3(...)` destination for logging, since that destination isn't itself recognized as an S3 engine when the formatter recurses into an argument rather than `function`. This whole function, its dispatch entry, the `quote_replacement` field it needs on `Result` (to emit the reconstructed call as raw SQL text instead of a quoted string), and the matching ASTFunction.cpp formatting change all exist in #109768's own commits (42bda2e, ced7e82) and in master's merged state, but were dropped entirely in this cherry-pick: on this branch, `CREATE DATABASE ... ENGINE = Backup('db', S3('url','ak','sk'))` showed the secret access key in plaintext in SHOW CREATE and the query log, and nothing in the trimmed 25.8 test file caught it. Ported the function, wiring, and the corresponding SQL/reference test cases from 04510_s3_explicit_url_named_secret_mask (skipping the two cases with a userinfo-bearing localhost:11111 URL, which hit the same BACKUP-destination-parsing hang already worked around for the plain BACKUP TO S3 case), plus the integration test case in test_mask_sensitive_info::test_create_database. #112333
Algunenano
added a commit
that referenced
this pull request
Aug 3, 2026
Backport #109768 to 25.8: Mask session_token and Google ADC secrets in the explicit-url S3 form
Algunenano
added a commit
that referenced
this pull request
Aug 3, 2026
Backport #109768 to 26.6: Mask session_token and Google ADC secrets in the explicit-url S3 form
This was referenced Sep 28, 2026
26.3: S3 table with
role_arn spends ~77 s in STS retries on CREATE and at every server start
#122680
Closed
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.
Follow-up to #106855.
The S3 secret masking in
FunctionSecretArgumentsFinderre-implemented the S3 parsers' argument model as several independent mechanisms doing raw-AST-index arithmetic, and every divergence between the two models leaked credentials intoSHOW CREATE,system.query_logand the server logs. This PR restructures the masking around a single argument-classification pass that reads an S3 argument list the way the parsers do (nested maps stripped from any position, named arguments separated, positional slots assigned on the remainder), moves the implementation out of the widely-included header into a.cpp, and makes both the finder and the formatter fail closed on anything unclassifiable.The positional credential slots are now selected by argument count and
with_structureexactly likeS3StorageParsedArguments::fromAST, instead of guessing slot roles by value; this closes leaks in longer signatures such as a five-positionalNOSIGNengine form and asession_tokenthat happens to spell a registered format name.Newly masked, across the explicit-url and named-collection
s3/s3Clustertable functions, theS3/GCS/COSN/OSS/DeltaLake/DeltaLakeS3/Hudi/Iceberg/IcebergS3/Paimon/PaimonS3/S3Queuetable engines, theS3database engine,BACKUP ... TO S3and theBackupdatabase engine:session_tokenand the Google ADC secrets (google_adc_client_secret,google_adc_refresh_token), named or positionalextra_credentials(...)andheaders(...)values at any argument position, failing closed on malformed childrenSecret redaction on the query-tree surfaces is made display-only and consistent for every secret-aware function, not only S3:
EXPLAIN QUERY TREEmasking now runs after the analysis passes, so redaction can never change how a query is analyzed, and descends into every carrier so a table function under aUNIONor a scalar subquery is maskedencrypt/decrypt/HMAC key such asleftPad('...', 16, '*'), including one inlined from a SQL UDF body) has every literal inside it hidden. The display mask carries into projection names,EXPLAIN QUERY TREEand theEXPLAIN actions = 1ActionsDAG in both the pretty (default) and legacy plan formats; the pretty format previously printed the constant value straight from its columnThe regression tests assert the exact logged text of every query in execution order, so the reference documents each masked form verbatim.
Also removes dead table-caching code from
DatabaseS3that #106855 left unused (the cache was dropped because it did not respect session credentials).Closes: #109731
Closes: #111536
Related: #106855
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix credential leaks in
SHOW CREATE,system.query_log, server logs andEXPLAINoutput. EveryS3locator form now maskssession_tokenand Google ADC secrets,extra_credentials/headersvalues at any argument position, duplicated or expression secret keys, invalid positional forms (fail closed), and credentials embedded in S3 URLs; this covers the explicit-url and named-collections3/s3Clustertable functions, the S3-backed table engines (S3,GCS, the data-lake engines,S3Queue), theS3database engine,BACKUP ... TO S3and theBackupdatabase engine. In addition, secret arguments ofencrypt/decrypt/HMAC that are built by an expression (including ones inlined from a SQL UDF) are now hidden in projection names,EXPLAIN QUERY TREEandEXPLAIN actions.Version info
26.7.2.32,26.6.2.148,26.5.6.87,26.3.17.89,25.8.29.47