Repository navigation
Conversation
`findBackupDatabaseSecretArguments` kept its own copy of the S3 argument
classification: a positional counter, a secret-key test and a url test beside
the shared `classifyS3Arguments` / `maskS3UrlArgument` / `maskS3PositionalsFrom`
that `BACKUP ... TO` uses. The copy did not skip `headers(...)` when counting
positionals, so `Backup('db', S3(url, 'secret', headers(...)))` counted three
positionals, took the valid-triple branch and wrote `secret` to
`system.query_log` and the server log, while `BACKUP ... TO` hid it.
The database path now runs `findBackupNameSecretArguments` on a finder over the
nested locator and only writes that result back as text. The formatter reaches
the nested `S3(...)` as an ordinary function, so it cannot apply the result by
itself; the outer result keeps the whole-argument replacement it had. A
`headers(...)` map on this path now keeps its keys, as on every other S3
surface.
The shared rule also counted a function in the last position as a positional,
while `BackupInfo::fromAST` reads it as the credential clause, so
`S3(url, 'secret', concat(...))` leaked on every backup-locator surface. That
function is now hidden and takes no positional slot.
Requested by kolsha on https://github.com/ClickHouse/clickhouse-private/issues/76267
("simplify findBackupDatabaseSecretArguments by reusing classifyS3Arguments").
Measured on 26.3.33.24, 26.8.10.6 and 26.9.1.1629: both leaks present.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A non-literal in a position other than the last (a function such as `concat(...)`, or an identifier) is rejected by `BackupInfo::fromAST` only after the statement is logged, so it was printed in the access key id or filename slot. It is now hidden, and it keeps its positional slot. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…positionals A function or an identifier among the positionals is rejected by `BackupInfo::fromAST` after the statement is logged. It was hidden but still counted, so `S3(url, 'secret', concat(...), headers(...))` kept `'secret'` visible (the `Backup` database path hid it before this PR). Such a locator now shows nothing after the url, which makes the separate trailing-function rule redundant, so it is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…its last argument A `headers(...)` or `extra_credentials(...)` map before the last argument takes no positional slot, but `BackupInfo::fromAST` accepts a function only in the last position and rejects the locator after the statement is logged. `S3(url, 'secret', headers(...), 'x')` therefore still looked like the valid triple and kept `'secret'` visible on both paths (the `Backup` database path hid it before this PR). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop the obvious doc line of the local write_as_written helper and state the Backup database writer's invariant precisely: it shows at most what BACKUP ... TO shows (it also hides arguments it cannot print). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 3 findings over 4 rounds, the last round clean).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20260928-225200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260928-221700 |
|
Workflow [PR], commit [013b199] Summary: ❌
AI ReviewSummaryThis PR moves most Findings❌ Blockers
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units124 translation units recompiled, 683 s compile time in total, 124 of them have a recent master baseline. |
Route `Backup` database `S3` locators through the existing backup masking rule and keep operator formatting at the locator owners. This preserves established output while removing duplicated credential classification. Add focused SQL and JSON AST coverage for masking and formatting. Related: ClickHouse#122776
Merge `master` to restore PR mergeability. Apply replacement masks before nested map handling so a secret in a computed map key cannot enter the AST dump. Add a regression test for direct and database backup locators. Related: ClickHouse#122776
Filter the `system.query_log` read by `current_database = currentDatabase()`, and flush it in a retry loop until all 12 rows have landed: the row of an HTTP query is written after its response is sent (ClickHouse#84364). Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Pushed 0493fd5 on top of your head: Separately, measured on cc1ccb1 with |
Choose the `Backup` secret rule by function name so client-supplied JSON AST kinds cannot bypass masking. Cover a locator with both kind tags removed in `05292`. Related: ClickHouse#122776
Preserve explicit secret masks before formatting nested maps and let the `S3` classifier handle named maps before the generic positional pass. Related: ClickHouse#123238
…N AST Secret masking of a backup locator dispatches on `ASTFunction::Kind::BACKUP_NAME`. The parser sets it on every locator slot, but the `clickhouse_json` readers took it from the client, so a JSON AST with that `kind` removed was logged with the secret: `BACKUP ... TO`, `RESTORE ... FROM`, `base_backup`, `BACKUP FROM SNAPSHOT`, `SYSTEM UNLOCK SNAPSHOT ... FROM` and `ALTER ... UNLOCK SNAPSHOT ... FROM`. The readers now set the kind themselves. `SYSTEM` and `ALTER` also require the locator to be a function, which is the only node the parser produces there. Extend 05292 with these slots. Related: ClickHouse#122776 Co-Authored-By: Claude Opus 5.5 <[email protected]>
| if (!function->hasArguments()) | ||
| return; | ||
|
|
||
| if (function_.name == "Backup") |
There was a problem hiding this comment.
This still only hardens the clickhouse_json path for the parser’s exact Backup / S3 spellings. ASTFunction::readJSON preserves whatever name the client sends, so a payload like CREATE DATABASE d ENGINE = backup('', s3('u', 'ak', 'SECRET')) (with or without the kind fields) never enters this new branch, and findDatabaseEngineSecretArguments() also returns without masking because it does not recognize backup. The statement is formatted/logged before DatabaseFactory rejects the engine name, so SECRET still reaches query_log / server logs. I think this needs a case-insensitive check here (and in the related ParserCreateQuery retagging) or an early rejection/canonicalization of non-parser spellings.
# Conflicts: # src/Backups/BackupInfo.cpp # src/Parsers/ASTFunction.cpp # src/Parsers/FunctionSecretArgumentsFinder.cpp # src/Parsers/FunctionSecretArgumentsFinder.h # src/Parsers/FunctionSecretArgumentsFinderAST.h
| { | ||
| if (auto * map = arguments[i]->as<ASTFunction>(); | ||
| map && map->arguments && secret_arguments.nested_maps.contains(map->name)) | ||
| if (auto replaced = secret_arguments.replaced_arguments.find(i); replaced != secret_arguments.replaced_arguments.end()) |
There was a problem hiding this comment.
EXPLAIN AST is still bypassing the Backup/backup-locator hardening this PR added. In this visitor the masking decision still comes from SecretArgumentsRegistry::instance().find(function->getKind(), ...), so an untagged clickhouse_json Backup(..., S3(...)) arrives here as an ordinary function again and DumpASTNode prints the raw secret_access_key.
Because FunctionSecretArgumentsFinderAST.h is already included in this file, I think this block needs to use findSecretArguments(*function) like ASTFunction::formatImpl and the other EXPLAIN masking paths do.
| { | ||
| ASTPtr ast = toAST(); | ||
| return ast->formatWithSecretsOneLine(); | ||
| return formatBackupInfo(*this, /* show_secrets= */ true); |
There was a problem hiding this comment.
BackupInfo::toString() is used outside logging (DatabaseBackup::getCreateDatabaseQueryImpl(), buildStoragePolicyName(), and the persisted .backup metadata), so switching it to formatBackupOrSnapshotLocator() changes the stable text form of valid locators. A Backup database with named overrides like S3('u', use_environment_credentials = 1) now serializes as S3('u', equals(use_environment_credentials, 1)), which changes SHOW CREATE DATABASE, metadata text, and the derived storage-policy hash even though this PR is supposed to be a logging-only fix.
I think only toStringForLogging() should go through the new helper; toString() needs to keep the normal AST formatter.
CI finish ledger - 013b199Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
CIDB has no other Session id: cron:our-pr-ci-monitor:20261012-150017 |
|
Changes became too complicated |
|
Understood. The leak itself is still on master ( |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a secret of an
S3backup destination being written in plaintext tosystem.query_logand the server log, by aBackupdatabase whose destination has aheaders(...)argument, and by a backup destination with a function argument, such asS3(url, 'secret', concat(...)). ABackupdatabase now masks its destination with the same rule asBACKUP ... TO.Description
Related: https://github.com/ClickHouse/clickhouse-private/issues/76267
Related: #117429
Requested by @ kolsha: reuse
classifyS3ArgumentsinfindBackupDatabaseSecretArguments.On 26.8 (also 26.3 and 26.9),
CREATE DATABASE d ENGINE = Backup('db', S3(url, 'secret', headers('a' = 'b')))writessecrettosystem.query_logand the server log, whileBACKUP ... TOmasks the same destination.S3(url, 'secret', concat(...))leaks on both.Root cause:
findBackupDatabaseSecretArgumentskept its own copy of the S3 argument classification. Its positional counter did not skipheaders(...), so a two-positional locator looked like the validurl, access_key_id, secret_access_keytriple and slot 1 stayed visible. Separately, the shared rule counted a function or an identifier as a positional, soS3(url, 'secret', concat(...)), whichBackupInfo::fromASTreads as a url, one positional and a credential clause, looked like the triple too.Change:
findBackupNameSecretArgumentson the nested locator and only writes its result back as text. The duplicated classification is removed.findBackupNameSecretArgumentshides every positional argument that is not a literal and shows the access key id only for three literal positionals and no function before the last argument, the only tripleBackupInfo::fromASTaccepts. This applies on every backup-locator surface.S3surface, aheaders(...)map on the database path now keeps its keys (values hidden), and the access key id of a valid triple stays visible when a map is present.Validation: new test
05291_database_backup_locator_headers_secret_mask: all 13 result lines red on master, green with the fix.04510changes one line (db_04510_hdr). A matrix of 31 locator shapes on both paths: 18 cells leak on master and none with the fix.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122776]