Skip to content

Reject unknown key-value arguments of the s3 table function and engines - #132354

Open
groeneai wants to merge 8 commits into
ClickHouse:masterfrom
groeneai:groeneai/s3-reject-unknown-key-value-arguments
Open

groeneai wants to merge 8 commits into
ClickHouse:masterfrom
groeneai:groeneai/s3-reject-unknown-key-value-arguments

Conversation

@groeneai

@groeneai groeneai commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #132003
Related: #107670

Changelog category (leave one):

  • Backward Incompatible Change

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

The s3, s3Cluster, gcs, oss, cosn and S3 data lake table functions and the S3, S3Queue, GCS, OSS, COSN and S3 data lake table engines now reject a key = value argument they do not read with BAD_ARGUMENTS instead of silently ignoring it, so a misspelled or wrong-case key such as secret_acess_key or SECRET_ACCESS_KEY is no longer dropped. Keys such as compression, http_client and google_service_account_key are accepted only through a named collection. Tables created before keep loading, but a view, refreshable materialized view or other stored query that passes such a key now fails when it runs. Closes #132003.

Description

s3(..., SECRET_ACCESS_KEY = '...') or foo_bar = '...' were accepted, the key was dropped, and the request went out without it.

S3StorageParsedArguments::fromAST collects every key = value argument but reads only the 13 keys it knows and never checked the rest. I copied the check the Azure parser already has (#122707): an unread key now throws BAD_ARGUMENTS naming the accepted keys.

Stored definitions keep loading: the check is skipped for a definition replayed from metadata, using the existing is_replayed_definition that the object storage engines already set. S3Queue/AzureQueue now set it too, and CREATE TABLE ... AS s3(...) gets it at load, short ATTACH, RESTORE and replicated replay; this also gives them the existing replay rule for a named collection's NOT OVERRIDABLE 'auto' format/structure. A fresh CREATE or full-syntax ATTACH stays strict.

DatabaseS3 passed use_environment_credentials = 1 to the s3() call it builds. The positional parser never read that key (environment credentials are its default), so it now builds s3(url).

Not changed: secret masking (a rejected query is logged as written, with only the known keys masked), and the SETTINGS disk = ... data lake form. 04510 and 05242 passed keys the S3 engine never read.

Validation: the new test fails on master and passes here (50/50 randomized runs). ENGINE = S3, S3Queue and AS s3(...) tables with an unknown key, created by a master build, load and can be detached, attached, restored from a backup and dropped.

🤖 Generated with Claude Code


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

groeneai and others added 2 commits November 17, 2026 11:55
`S3StorageParsedArguments::fromAST` collected every `key = value`
argument but read only the keys it knows, so a misspelled, wrong-case or
named-collection-only key (`SECRET_ACCESS_KEY`, `secret_acess_key`,
`compression`, `google_service_account_key`, ...) was silently ignored and
the request went out without it (issue ClickHouse#132003). Reject such a key with
BAD_ARGUMENTS, naming the accepted keys, like the Azure parser already does.

A stored definition created before this change must keep loading, so the
check is skipped for a replayed definition, using the existing
`is_replayed_definition` flag and `isReplayedTableDefinition` predicate:
- the object-storage engines already set it; S3Queue/AzureQueue now set it too;
- `CREATE TABLE ... AS s3(...)` is re-parsed through `TableFunctionFactory::get`
  at load, short ATTACH, RESTORE and replicated replay; those three callers now
  pass the predicate, and the object-storage table functions copy it into their
  configuration. A fresh CREATE or full-syntax ATTACH stays strict.

`DatabaseS3` passed `use_environment_credentials = 1` to the `s3` function it
builds; the positional parser never read that key (environment credentials
are its default), so it now builds `s3(url)`, which parses identically.

Tests: `04510` and `05242` passed keys the `S3` engine positional form never
read; `05242` now checks the masking in the query log of the rejected CREATE.
Masking itself is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`http_client` and `google_service_account_key` are accepted only through a named collection; assert that the explicit form rejects them, like `compression`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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; 3 findings, 0 on the re-review of the fix) plus my own review.

# Sev Finding Verdict Evidence / action
1 ⚠️ No test asserts that http_client / google_service_account_key are rejected in the explicit form (the 05242 case checks masking only and also passes on master) AGREE, fixed @ d38352e two rejection lines added to 05814; both return rows on master
2 ⚠️ No cross-version evidence that stored definitions keep loading DISAGREE measured locally: ENGINE = S3, S3Queue and AS s3(...) tables with an unknown key created by a master build load (async and async_load_databases = 0), query, detach, short-attach, restore from a master backup and drop; full-syntax ATTACH stays strict; passing false at each new call site re-breaks its path
3 💡 Changelog omits the GCS, OSS, COSN engines AGREE, fixed entry lists them
4 ⚠️ Changelog did not say that a stored query (view, refreshable MV) passing such a key now fails when it runs AGREE, fixed entry says so

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. 05814_s3_unknown_key_value_argument fails on master every run: s3(..., foo_bar = 'x') returns 4 rows and the ENGINE = S3 / AS s3(...) / S3Queue CREATEs with an unknown key succeed.
b Root cause explained? S3StorageParsedArguments::fromAST collects every key = value argument but reads only the 13 keys it knows and never checked the leftovers, so any other key was dropped.
c Fix matches root cause? Yes. The leftovers are rejected where they become known, with the check the Azure parser already has (#122707). Masking is not touched.
d Test intent preserved / new tests added? New 05814 (8 rejected queries incl. wrong-case, misspelled, NOSIGN forms and the named-collection-only keys compression, http_client, google_service_account_key, 3 rejected CREATEs, positive controls for all 13 accepted keys). 04510 and 05242 keep their masking checks; 05242 checks the query log of the now-rejected CREATE.
e Both directions demonstrated? 05814: master FAIL, this PR OK. Stored definitions from a master build load with this PR; passing false at the DatabaseOnDisk site breaks the startup load, at the two interpreter sites breaks RESTORE and short ATTACH.
f Fix is general across code paths? Every user of the S3 positional parser: table functions (incl. cluster and data lake variants), engines, S3Queue/AzureQueue, AS table functions on every replay path, DatabaseS3. Azure and named collections were already strict; HDFS, Local and Web take no key-value arguments.
g Fix generalizes across inputs (params/datatypes/wrappers)? Wrong case, typo, named-collection-only key, NOSIGN form, positional plus key-value mix, data lake function, engine and queue forms; every accepted key still works. Type wrappers do not apply (argument names).
h Backward compatible? (maintainer-approved exception only) Stored tables keep loading: replayed definitions (startup, also with async_load_databases = 0, short ATTACH, RESTORE, replicated replay) are not checked. Queries with an unknown key now fail, as requested on #132003; category Backward Incompatible Change.
i Invariants and contracts preserved? The check throws before any argument is consumed. is_replayed_definition keeps its one meaning and predicate; fresh CREATE and full-syntax ATTACH stay strict (measured). DatabaseS3 builds a call that parses identically (measured on master: the dropped key was never read).

Session id: cron:clickhouse-impl-slot-40:20261117-112300

@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5097627]

Summary: ✅


AI Review

Summary

Rejects unknown key = value arguments in the s3 family of table functions and engines while preserving replay of stored table definitions. No actionable findings at head 50976279b4de. The previously reported replay-probe blocker is fixed and its thread correctly remains resolved.

Missing context / blind spots
  • ⚠️ Current-head builds and tests are still pending. The completed flaky-check report for dd9c5e1dad67 passed all 50 repetitions each of 05814_s3_unknown_key_value_argument, 04510_s3_explicit_url_named_secret_mask, and 05242_s3_gcp_service_account_key. Completion of current-head CI will validate the latest merge reconciliation; no local tests were run in this review job.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-backward-incompatible Pull request with backwards incompatible changes label Nov 17, 2026
@PedroTadim PedroTadim self-assigned this Nov 17, 2026
@PedroTadim

Copy link
Copy Markdown
Member

@groeneai what about other table function and engines such as Azure?

@groeneai

Copy link
Copy Markdown
Collaborator Author

Measured on master (9b107508c683) and on this PR, with foo_bar = 'x' as the extra argument:

  • Azure is already strict, since Fix loading AzureBlobStorage tables whose engine arguments end with partition_strategy = 'none' #122707: azureBlobStorage, ENGINE = AzureBlobStorage, AzureQueue, icebergAzure and deltaLakeAzure throw BAD_ARGUMENTS (Unexpected key-value argument), also for a wrong-case key. extra_credentials(...) rejects an unknown name for both S3 and Azure. This PR copies that check into the S3 parser.
  • Named collection overrides of s3, azureBlobStorage, url, mysql, postgresql and remote already throw Unexpected key ... in named collection.
  • hdfs, file, url, icebergLocal and ENGINE = HDFS take no key-value arguments in the positional form: foo_bar = 'x' is evaluated as an expression and fails with UNKNOWN_IDENTIFIER. In the SETTINGS disk = ... data lake form an extra key falls into a positional slot and fails (Argument 'compression_method' must be a literal).
  • Same bug, not covered here: the named collection form of HDFS and Local. hdfs(nc, foo_bar = 'x'), icebergHDFS(nc, foo_bar = 'x') and CREATE TABLE ... ENGINE = HDFS(nc, formt = 'CSV') succeed and the key is never read; icebergLocal(nc, ...) and deltaLakeLocal(nc, ...) get past argument parsing the same way. Their fromNamedCollection never calls validateNamedCollection, unlike S3 and Azure. That check also covers the keys stored in the collection itself, so it has its own compatibility question. I'll send it as a separate PR and link it here.

@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. labels Nov 17, 2026
groeneai and others added 2 commits November 17, 2026 15:15
`getSourceEngineOfTableFunction` (from master) parses the `AS` table function to find the engine whose
`TABLE ENGINE` grant is required. It parsed it as a fresh definition, so after the merge with master a
definition stored by an older version with an unknown key-value argument, e.g.
`AS s3(..., foo_bar = 'x')`, could no longer be replayed: short `ATTACH` and `RESTORE` failed in the
probe of `getTablePropertiesAndNormalizeCreateQuery`, and a `Replicated` database replica replaying
such a log entry failed in the probe of `getRequiredAccess` (the entry is not retriable, so the table
was never created on that replica).

The probe now takes the same `isReplayedTableDefinition` flag as the later parses of the table
function. The grant check itself is unchanged: a replayed short `ATTACH` still requires
`TABLE ENGINE ON S3`. Fresh `CREATE`, full `ATTACH` and `CREATE TABLE copy AS src` stay strict.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

The HDFS and Local named collection forms are fixed in #132410. It is based on this PR, because CREATE TABLE ... AS hdfs(...) needs the replay flag added here; its own change is the last commit.

@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 50976279b with master cd11f22d8 (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

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

Job report

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 17, 2026
…named-collection-unknown-override-keys

Brings in ClickHouse#132354's dbec745, which passes the replay flag to the source-engine
probe of `CREATE TABLE ... AS`, so a stored `AS hdfs(nc, foo_bar = 'x')` /
`AS icebergLocal(...)` definition still loads on short `ATTACH` and `RESTORE`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The engine-form `CREATE TABLE t_04510` passed `extra_credentials(role_arn = ...)`, so building
its S3 client wrapped the credentials in the STS assume-role provider, and the AWS SDK signers
fetch credentials while the client is constructed: three AssumeRole calls to
`sts.amazonaws.com`, four attempts each. On CI runners that cannot reach it every attempt waits
for the 1 s connect timeout, so the statement takes about 11 s. The flaky check runs many copies
of the test at once, and they all get the same cached provider (same role, external id,
endpoint and base credentials), whose reload holds a writer lock and is retried on every call
while it keeps failing. The copies therefore wait for each other: in the flaky check of this
PR the CREATE took 105 s at the median and up to 491 s, so runs failed with "Test runs too
long" or the 300 s receive timeout.

Drop `role_arn` from that CREATE and assert that it stays visible in the function-form
`url_basic` statement instead. That statement fails while its arguments are parsed, before any
client exists. Both forms go through the same `classifyS3Arguments` ->
`maskHeadersAndExtraCredentials` path, so the masking coverage is unchanged.

Locally (sts.amazonaws.com unreachable), with `--flaky-check -j 20`: before, 12 of 20 runs
failed and run times grew from 31 s to 529 s; after, 50 of 50 runs passed in under 1 s each,
and the server log shows no AssumeRole attempt.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 17, 2026
…named-collection-unknown-override-keys

Picks up e712844 (test-only: keeps 04510_s3_explicit_url_named_secret_mask
off the network), which fixes the flaky-check timeouts of 04510 on this PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - e712844

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, AsyncInsert, s3 storage, parallel) / 05629_explain_analyze_join_side_q_error flaky, not from this PR: the runner's diagnosis isolates the randomized MergeTree settings index_granularity 968, min_bytes_for_wide_part 0. With them, a hash join sharded by primary-key ranges skips the left rows of a range with no right rows, so the left side reports 999 rows instead of 1000. Reproduced on a master build (1 0 with query_plan_join_shard_by_pk_ranges = 1, 1 1 with 0). Same test failed on 3 other PRs in 30 days #132149 (mine, open)
Mergeable Check, PR praktika rollups of the row above #132149 (mine, open)

All five Stateless tests (*, flaky check) jobs passed, including 04510_s3_explicit_url_named_secret_mask. CH Inc sync is green.

Session id: cron:our-pr-ci-monitor:20261117-233020

@PedroTadim

Copy link
Copy Markdown
Member

@groeneai, please investigate the CI failures in this PR (commit 316ea61) and fix them, or link existing fixes.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=132354&sha=316ea61170a0e92612a068c0020b2ba90879061f&name_0=PR

Failures without a known issue:

  • 05829_autopr_skip_index_on_read_in_subquery in Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) (history)
  • 05829_autopr_skip_index_on_read_in_subquery in Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) (history)
  • 05829_autopr_skip_index_on_read_in_subquery in Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) (history)
  • 04353_text_index_explicit_tokenizer_argument in Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) (history)
  • 01710_projection_with_mixed_pipeline in Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) (history)
  • 05034_lazy_materialization_column_function_set_capture in Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) (history)

@PedroTadim
PedroTadim added this pull request to the merge queue Nov 19, 2026
@PedroTadim

Copy link
Copy Markdown
Member

The CI failure is unrelated

@PedroTadim
PedroTadim removed this pull request from the merge queue due to a manual request Nov 19, 2026
@groeneai

groeneai commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 316ea61

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, ParallelReplicas, plan-based, s3 storage, parallel) / 05829_autopr_skip_index_on_read_in_subquery fails with plan-based parallel replicas, with and without random settings (97/97) #132867 (mine, merged after this head's master merge)

The job report also lists 3 NOT_FAILED rows (04353_text_index_explicit_tokenizer_argument, 01710_projection_with_mixed_pipeline, 05034_lazy_materialization_column_function_set_capture). They are not failures: these tests are intended entries of tests/parallel_replicas_plan_based_blacklist.txt, and NOT_FAILED alone never fails this job (over the last 3 days, 234 runs with NOT_FAILED rows and no FAIL row, all green; the job owner's ruling), so no fix is needed.

Both merge-queue runs failed Stateless tests (amd_binary, flaky check) on new tests of PRs ahead of this one in the queue: 05507_parquet_object_storage_next_file_read_ahead (#129495, report) and 05512_parquet_metadata_cache_offset_index (#129430, report). Both PRs are mine, are out of the queue now, and are being fixed. This PR's tests (05814, 04510, 05242) passed every flaky-check repetition in both runs.

Session id: cron:clickhouse-premium-slot-28:20261120-014400

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 22, 2026
…-named-collection-unknown-override-keys

Conflicts in the code of ClickHouse#132354: master (ClickHouse#133420) renamed
`InterpreterCreateQuery::getSourceEngineOfTableFunction` to
`getRequiredAccessOfTableFunction`, which returns the whole required grant, and
made `ITableFunction::getSourceAccessObject` public. The replay flag of ClickHouse#132354
is passed to the renamed function at both call sites.
@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - dd9c5e1

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, iceberg_s3, 2/3) crash: during ie_join_selectivity_key_choice, the shard's last test, the right server died of SIGILL with no stack trace and no <Fatal> record of its own (the watchdog logs Child process was terminated by signal 4, report). This is the silent arm_release death that follows #131784: a failed return address authentication inside a stack capture raises SIGILL, which the signal handler does not recover. The job is red only for this run error; its 3 too long, 1 unstable entries do not gate the iceberg configurations #132186 (mine, open)

Session id: cron:our-pr-ci-monitor:20261122-153022

groeneai added a commit to groeneai/ClickHouse that referenced this pull request Nov 23, 2026
…-named-collection-unknown-override-keys

Master ClickHouse#115581 added the same replayed-definition plumbing this branch carries from ClickHouse#132354
(`TableFunctionFactory::get(..., is_replayed_definition)` and `ITableFunction::setReplayedDefinition`),
storing the flag in `arguments_from_stored_definition`. Take master's version of `ITableFunction.h`,
`TableFunctionFactory.h`, `InterpreterCreateQuery.h` and `DatabaseOnDisk.cpp`, read the flag from
`arguments_from_stored_definition` in `TableFunctionObjectStorage::parseArgumentsImpl`, and keep the
replay decision in `InterpreterCreateQuery::getRequiredAccess`, which runs on every execution, including
a secondary DDL replay.
…unknown-key-value-arguments

Master added the same replayed-definition flag for table functions (`ITableFunction::setReplayedDefinition`,
member `arguments_from_stored_definition`) and renamed `getSourceEngineOfTableFunction` to
`getRequiredAccessOfTableFunction`. Take master's versions, read the flag from `arguments_from_stored_definition`
in `TableFunctionObjectStorage`, and keep passing `isReplayedTableDefinition` in `getRequiredAccess`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. pr-backward-incompatible Pull request with backwards incompatible changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

s3 table function silently ignores unknown key = value arguments (and logs their values unmasked)

2 participants