Repository navigation
Require permission to override named collections - #123133
Conversation
Check stored keys and aliases before applying query arguments, backup arguments, or `SETTINGS`. Allow adding missing keys and preserve explicit `NOT OVERRIDABLE` restrictions. Dictionary sources may only add missing keys because background loading does not retain the caller's access context. Make `allow_named_collection_override_by_default` obsolete. Update the documentation and affected tests, and add regression coverage for scoped grants, roles, revocation, aliases, headers, XML paths, and engine settings. Validated with a debug build, five functional tests, and three dictionary integration tests. Closes: ClickHouse/clickhouse-private#53768 Related: ClickHouse/clickhouse-private#53768 (comment)
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [f121547] Summary: ✅
AI ReviewSummaryThis PR centralizes named-collection override checks and extends them to engine/table-function Findings
Final Verdict
LLVM Coverage ReportMeasured on commit f121547.
Changed lines: Changed C/C++ lines covered: 262/269 (97.40%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes39 object files changed (+19.46 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units91 translation units recompiled, 615 s compile time in total, 91 of them have a recent master baseline. |
There was a problem hiding this comment.
🤖 Correctness review. Three findings below are in files outside this diff, so they are in this body instead of inline comments. The inline comments cover stored keys re-parsed as overrides, Kafka key aliases, and loading existing metadata.
src/TableFunctions/TableFunctionPostgreSQL.cpp:120
The postgresql table function does not check SETTINGS overrides.
parseArguments removes the ASTSetQuery and calls StoragePostgreSQL::getConfiguration without the settings argument (:120). It then applies the settings with loadFromQuery (:125). This replaces the values loaded from the collection (StoragePostgreSQL.cpp:803-804). The result reaches the pool constructor (:130-136). Neither SHOW NAMED COLLECTIONS SECRETS nor NOT OVERRIDABLE is checked.
Example, as a user without the privilege:
SELECT * FROM postgresql(nc, SETTINGS postgresql_connection_pool_size = 1)With postgresql_connection_pool_size = 2 stored in the collection, this works. It also works if the stored setting is NOT OVERRIDABLE.
The engine path is correct. StoragePostgreSQL.cpp:886-887 passes args.storage_def->settings.
Suggested fix: pass the retained settings AST to StoragePostgreSQL::getConfiguration before applying it. Please add tests for a missing grant, an explicit NOT OVERRIDABLE lock, and a positive case with the grant.
src/Dictionaries/MongoDBDictionarySource.cpp:49-53
The new dictionary rule also breaks trusted XML dictionaries and existing DDL dictionaries after the upgrade.
The config-based overload passes nullptr as the context, so every override of a stored key is rejected (NamedCollectionsHelpers.cpp:156-157, 286).
- The MySQL, PostgreSQL, ClickHouse, HTTP and YTsaurus sources call it only when
created_from_ddlis true (for exampleMySQLDictionarySource.cpp:141andPostgreSQLDictionarySource.cpp:263). - This file ignores
created_from_ddl. An XML dictionary such as<mongodb><name>mymongo</name><collection>my_dict</collection></mongodb>that overrides a stored key stops loading after the upgrade. - A DDL dictionary created before the upgrade with an override stops loading too. Examples are
SOURCE(MYSQL(NAME nc PORT 3306)), andSSL_CA_PEMover a storedssl_ca.
The setting is obsolete, so there is no way back. The integration cases that covered this (test_storage_mysql: dict_ssl_override, mysql_ssl_empty_override_dictionary) were deleted, not migrated.
Dictionaries load lazily by default, so the failure happens at load time, not at startup.
Suggested fix: pass created_from_ddl or an explicit trusted-config flag, and allow overrides for config-defined dictionaries. Optionally check SHOW NAMED COLLECTIONS SECRETS of the creator at CREATE DICTIONARY time. If the current design stays, please state this impact in the Backward Incompatible changelog entry. Please also restore tests for the DDL dictionary override cases.
docs/concepts/features/configuration/settings/settings-users.mdx:315-317 and programs/server/users.xml:117-127
show_named_collections_secrets is still described as only controlling the reading of stored values. It now also controls overriding stored keys. Please add one sentence about this in both places.
|
@groeneai prioritize addressing these comments |
|
Acknowledged, I am working on these comments. I cannot push to |
|
@groeneai I though it was your PR, just reply to threads and write comments in this PR. I'll push the changes. |
…std::array` Add parameter-name comments to the bare `true` / `nullptr` arguments in the calls that pass `settings`, and declare the equivalent keys table with `std::to_array` instead of a C array. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@antonio2368 I replied in the inline threads instead of sending the PR I mentioned above. The three findings from the review body and the CI fixtures are below. All of this comes from reading the code at 982cee9; I did not run it.
configuration.emplace(StoragePostgreSQL::getConfiguration(
args, context, &postgresql_settings, /*table_id=*/ nullptr, settings_ast ? settings_ast->as<ASTSetQuery>() : nullptr));Tests, added to
MongoDB dictionary source (
MutableNamedCollectionPtr tryGetNamedCollectionWithOverrides(
const Poco::Util::AbstractConfiguration & config, const std::string & config_prefix, ContextPtr context, bool trusted_config = false);
...
checkNamedCollectionOverride(*collection, key, trusted_config ? context : nullptr);Mongo then passes
CI fixtures. Two tests are red in
|
…base` / `url_base` resolution ClickHouse appends the inferred `format` and `structure` to named collection arguments (for example in `addInferredEngineArgsToCreateQuery` and for `*Cluster` secondary queries) and parses them again. Replacing a stored `'auto'` value of these keys neither hides a stored value nor redirects credentials, so it no longer requires `SHOW NAMED COLLECTIONS SECRETS`. The `NOT OVERRIDABLE` lock still applies. Resolving a relative `url` stored in a named collection against the `s3_base` or `url_base` session setting replaces the stored `url`, and could send the stored credentials to another host. It now goes through the same check as an explicit `url` override, which also keeps the materialized `url` argument consistent. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… locks at load Dictionary sources are loaded in the background with the global context, so the previous code rejected every override of a stored key there. This broke trusted config-defined dictionaries (`MongoDB` reads a named collection from the XML config) and DDL dictionaries created before the upgrade. Use the same model as table engines: the `SHOW NAMED COLLECTIONS SECRETS` privilege is checked with the user's context when the dictionary is created, attached or restored (in `registerStorageDictionary`), and loading the source only enforces `NOT OVERRIDABLE`. The lock check is now a separate function, so a null context no longer means "reject" implicitly. Restore the integration cases with dictionary overrides that were removed, and add a test for dictionary overrides and for tables whose override was locked after creation, which are rejected on `ATTACH`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`KafkaConfigLoader` sets librdkafka properties from nested named collection keys (`kafka.<property>`, `kafka.consumer.<property>`, `kafka.producer.<property>`) and then overwrites them with the non-empty flat settings such as `kafka_security_protocol` or `kafka_sasl_password`. The override check did not relate the two forms, so a flat setting in `SETTINGS` could replace a stored nested value without `SHOW NAMED COLLECTIONS SECRETS`, even when the nested key was `NOT OVERRIDABLE`. `areEquivalentKeys` now maps both forms to the librdkafka property for the flat settings that overwrite nested values. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `postgresql` table function applies its `SETTINGS` clause after the settings loaded from a named collection, but did not pass the clause to `StoragePostgreSQL::getConfiguration`. So a user without `SHOW NAMED COLLECTIONS SECRETS` could replace a stored setting such as `postgresql_connection_pool_size`, also when it was `NOT OVERRIDABLE`. Pass the clause, as the `PostgreSQL` table engine does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ride stored keys These tests intentionally override keys stored in a named collection, which now requires the `SHOW NAMED COLLECTIONS SECRETS` privilege: - `test_dictionaries_ddl::test_secure` overrides `secure` of `nc_secure_0`. - `test_s3_client_refresh` overrides `url` of `refresh_env`. - `test_storage_dict` overrides `format` of `urldict2`. - `test_storage_iceberg_schema_evolution`, `test_storage_iceberg_concurrent` and `test_storage_iceberg_with_spark_cache` use `iceberg_utils`, which overrides `url` of the `s3` collection. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123133&sha=52e14f769c75857c59b6c9e2ea76da124c516a57&name_0=PR PR: #123133 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Dictionary sources can override stored keys with the `SHOW NAMED COLLECTIONS SECRETS` privilege, which is checked when the dictionary is created, attached, or restored. When the dictionary is loaded, only keys marked `NOT OVERRIDABLE` are enforced. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…::test_secure` `default` has `allow_databases`, which makes the users config parser revoke all non-global flags, including the `NAMED_COLLECTION`-level ones. So `show_named_collections_secrets` in its config had no effect and overriding the stored `secure` key of `nc_secure_0` was denied. Remove the ineffective settings from `default`, enable them for `admin` (which has no `allow_databases`), check that `default` is denied, and create the dictionary as `admin`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123133&sha=1d125f8813382e5ff74b6819cfe25295d6dbaa14&name_0=PR PR: #123133 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Cherry pick #123133 to 26.8: Require permission to override named collections
Cherry pick #123133 to 26.9: Require permission to override named collections
Cherry pick #123133 to 26.3: Require permission to override named collections
Backport #123133 to 26.9: Require permission to override named collections
Backport #123133 to 26.8: Require permission to override named collections
Backport #123133 to 26.3: Require permission to override named collections
Backport #123133 to 26.7: Require permission to override named collections
) The v26.3.53.4 bump pulls in upstream backport ClickHouse#123133 "Require permission to override named collections", which removes the old allow_named_collection_override_by_default=true default. Touching a named collection now requires the show_named_collections_secrets grant. Two Antalya-specific tests were not covered and fail with `Code: 497 … necessary to have the grant SHOW NAMED COLLECTIONS SECRETS`: - test_storage_iceberg_with_spark/test_export_partition_iceberg.py: the cluster nodes loaded only allow_export_partition.xml (which grants nothing); add the existing users.xml (that carries both flags) to every node's user_configs. - test_storage_iceberg_multistorage: its users.xml had named_collection_control but was missing show_named_collections_secrets. Test-config only; validated by CI on this PR, not locally. Co-Authored-By: Claude Opus 4.8 <[email protected]>
…eaaf Source: ClickHouse/ClickHouse@c5f2466 Master as of 2026-09-30, the commit ClickHouse/ClickHouse#123133 was branched from.
…ride stored keys These tests intentionally override keys stored in a named collection, which now requires the `SHOW NAMED COLLECTIONS SECRETS` privilege: - `test_dictionaries_ddl::test_secure` overrides `secure` of `nc_secure_0`. - `test_s3_client_refresh` overrides `url` of `refresh_env`. - `test_storage_dict` overrides `format` of `urldict2`. - `test_storage_iceberg_schema_evolution`, `test_storage_iceberg_concurrent` and `test_storage_iceberg_with_spark_cache` use `iceberg_utils`, which overrides `url` of the `s3` collection. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123133&sha=52e14f769c75857c59b6c9e2ea76da124c516a57&name_0=PR PR: ClickHouse/ClickHouse#123133 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…::test_secure` `default` has `allow_databases`, which makes the users config parser revoke all non-global flags, including the `NAMED_COLLECTION`-level ones. So `show_named_collections_secrets` in its config had no effect and overriding the stored `secure` key of `nc_secure_0` was denied. Remove the ineffective settings from `default`, enable them for `admin` (which has no `allow_databases`), check that `default` is denied, and create the dictionary as `admin`. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=123133&sha=1d125f8813382e5ff74b6819cfe25295d6dbaa14&name_0=PR PR: ClickHouse/ClickHouse#123133 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Require explicit permission to override stored named collection parameters. Update documentation and tests.
Changelog category (leave one):
Changelog entry:
Overriding a key that is stored in a named collection now requires
SHOW NAMED COLLECTIONS SECRETSon that collection. This also applies to overrides through an alias (including flatkafka_*settings over nestedkafka.*keys), through aSETTINGSclause of a table engine or table function, and through keys in a dictionary source (checked when the dictionary is created). Resolving a relativeurlstored in a named collection againsts3_baseorurl_basealso counts as an override ofurl. Adding a key that the collection does not store remains allowed, and keys markedNOT OVERRIDABLEcannot be overridden. Theallow_named_collection_override_by_defaultsetting is obsolete. Existing tables whoseSETTINGSor alias arguments override aNOT OVERRIDABLEkey cannot be loaded after the upgrade, and the server does not start: before upgrading, recreate such tables without the override, or make the key overridable.Workflow [PR]
Sync PR [sync-upstream/pr/123133]
Version info
26.10.1.1574-master(included in26.10and later)26.9.20.16,26.8.28.15,26.7.32.7,26.3.52.12