Repository navigation
Check access rights before loading a dictionary or reading its definition - #122678
Conversation
The `dictionary` table function, `dictGet`-family functions and `naiveBayesClassifier` loaded the dictionary first and checked `dictGet`/`SELECT` access afterwards, so a query without the required grants still triggered the load. The injective `dictGet` optimization of `GROUP BY` in the old analyzer loaded the dictionary without any check. Add `ExternalDictionariesLoader::getDictionaryID`, which returns the dictionary ID from the loaded dictionary or from its configuration without loading it, and use it to check access before the load. The injective `GROUP BY` optimization is skipped when `dictGet` is not granted; the query then fails at the regular check. `DESCRIBE TABLE dictionary(...)` now also requires `dictGet` or `SELECT`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [09b6e5e] Summary: ✅
AI ReviewSummaryReviewed PR #122678 at Findings❌ Blockers
Missing context / blind spots
Final VerdictStatus: |
…ccess Co-Authored-By: Claude Opus 5.5 <[email protected]>
A user with `SELECT` on a `Dictionary` table but without `dictGet` or `SELECT` on the underlying dictionary triggered the dictionary load before getting `ACCESS_DENIED`. Check access on the dictionary ID obtained without loading. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes20 object files changed (-23.23 KiB total), 0 added.
711 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 units112 translation units recompiled, 1334 s compile time in total, 112 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.08 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
LGTM. |
…nctions `dictGet`-family functions and `dictGetKeys` read the dictionary structure, and `naiveBayesClassifier*` read the layout, to infer the result type before any access check. A user without the `dictGet` grant could learn attribute names, types and the layout from the result type or the error messages. Check `dictGet` access before reading the definition. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`CREATE TABLE ... ENGINE = Dictionary(d)` loaded the dictionary to validate the columns, without checking access to the dictionary. Validate the columns against the dictionary definition without loading it, and require `dictGet` or `SELECT` on the dictionary, the same rule as for reading it. The rule is now in `StorageDictionary::checkDictionaryAccess`, shared by `StorageDictionary::read`, the `Dictionary` engine and the `dictionary` table function. Test joins against a `Dictionary` table as a user without access to the dictionary, too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`CREATE VIEW ... AS SELECT ... JOIN` against a `Dictionary` table only analyzes the query, so `StorageDictionary::read` is not called, but the direct join planning of both analyzers still loaded the dictionary without checking access to it. `StorageDictionary::getDictionary` now takes the query context and checks access before loading; the unchecked overload is removed. Remove the unused `trySetStorageInTableJoin`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The direct join planning of the old analyzer loaded the dictionary a second time through `FunctionDictHelper`, which requires `dictGet`, so a user with only `SELECT` on the dictionary could not join against a `Dictionary` table, unlike with the analyzer and when reading the table. Reuse the dictionary returned by `StorageDictionary::getDictionary`, which accepts `dictGet` or `SELECT`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test started a client for every query and took more than 180 seconds in the flaky check with ASan. Send the queries over HTTP instead. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122678&sha=3725558c0b5667ba74e6c58f3e17a7e9b1abfbf0&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 ClickHouse#122678 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…onary` At `CREATE` time the `Dictionary` engine resolved the dictionary name with the global context, while reading the table resolves it with the query context, so an unqualified name could point to different dictionaries, and `CREATE TABLE ... ENGINE = Dictionary(d)` with a non-default current database failed with `Dictionary not found`. Use the query context for the access check and the validation of the columns. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fter the access check The access check now runs before the dictionary is loaded, so loading it to validate the columns is fine for a user who may read it. Keep the previous behavior for such users, including failing early when the dictionary cannot be loaded. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Dear @diegomestre2, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
…-before-load Co-Authored-By: Claude Opus 5.5 <[email protected]>
`dictGet*`, `dictGetKeys`, `naiveBayesClassifier*`, the `dictionary` table function and `ENGINE = Dictionary` check access with the ID returned by `ExternalDictionariesLoader::getDictionaryID`, which threw `Dictionary ... not found` for a missing dictionary before the check ran. A user without access could therefore tell a missing dictionary from an existing one. For a missing dictionary, `getDictionaryID` now returns the ID the dictionary would have, so such a user gets `ACCESS_DENIED`, and a user with access still gets the not-found error from the lookup that follows. ClickHouse#122678 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
…access check Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflicts of the cherry-pick of #122678 to 26.10. The conflicts come from master-only changes next to the PR's hunks: the `modernize-use-nodiscard` sweep (disabled on 26.10), `getSignatureString` in the naive Bayes functions, and the `SubcolumnCodecs.h` include. They take the 26.10 side; the PR's own changes are kept, including the removal of `assertDictionaryStructureExists`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #122678 to 26.10: Check access rights before loading a dictionary or reading its definition
…onary or reading its definition
Resolve the conflicts of the cherry-pick of #122678 to 26.9. - 26.9 has no `predictXGBoost`, so the changes to `FunctionPredictXGBoost.cpp` and the test `05620_dictionary_access_check_predict_xgboost` are dropped. - 26.9 has neither `ExternalDictionariesLoader::ResolvedDictionaryName` nor `addDistributedPlanLocalObject`: the struct is added for `resolveDictionaryNameUnchecked`, which qualifies the name the same way as `resolveDictionaryNameFromDatabaseCatalog`, the 26.9 string resolvers stay as they are, and `resolveDictionary` records nothing. - The analyzer is mandatory on 26.9, so the `enable_analyzer = 0` cases are removed from `05291_dictionary_access_check_before_load`. - Other conflicts come from master-only changes (the `modernize-use-nodiscard` sweep, `getSignatureString` in the naive Bayes functions, the `SubcolumnCodecs.h` include) and take the 26.9 side. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #122678 to 26.9: Check access rights before loading a dictionary or reading its definition
…nary or reading its definition
Backport #122678 to 26.10: Check access rights before loading a dictionary or reading its definition
Backport #122678 to 26.9: Check access rights before loading a dictionary or reading its definition
Resolve the conflicts of the cherry-pick of #122678 to 26.3. - 26.3 has no `predictXGBoost`, so the changes to `FunctionPredictXGBoost.cpp` and the test `05620_dictionary_access_check_predict_xgboost` are dropped. - `naiveBayesClassifier` on 26.3 reads its models from the server configuration, not from a dictionary, so `FunctionNaiveBayesClassifier.cpp` keeps the 26.3 version, the naive Bayes cases are removed from `05291`, `05292` and `05497`, and the PR's `getDictionaryLayoutType` additions are dropped (26.3 has no `getDictionaryLayoutType`). - 26.3 has neither `ExternalDictionariesLoader::ResolvedDictionaryName` nor `addDistributedPlanLocalObject`, and resolves names only with the string form of `resolveDictionaryNameFromDatabaseCatalog`: the struct is added for `resolveDictionaryNameUnchecked`, which takes the key from that function and qualifies the name the same way, the check that skips databases without their own tables (`isExternal`) moves into that function, and `resolveDictionary` records nothing. - `trySetStorageInTableJoin` is still used on 26.3 (`PlannerJoinTree.cpp`), so it is kept; it now takes the query context and gets the dictionary through the access-checked `StorageDictionary::getDictionary`. - 26.3 has no `SYSTEM UNLOAD DICTIONARY`, so `05291` and `05498` reset the dictionary with `DETACH DICTIONARY` and `ATTACH DICTIONARY`, with `check_table_dependencies = 0` because the `Dictionary` tables depend on it and a `Replicated` database detaches permanently. - Other conflicts come from master-only changes (the `modernize-use-nodiscard` sweep, include changes) and take the 26.3 side. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Resolve the conflicts of the cherry-pick of #122678 to 26.8. - 26.8 has no `predictXGBoost`, so the changes to `FunctionPredictXGBoost.cpp` and the test `05620_dictionary_access_check_predict_xgboost` are dropped. - 26.8 has neither `ExternalDictionariesLoader::ResolvedDictionaryName` nor `addDistributedPlanLocalObject`, and resolves names only with the string form of `resolveDictionaryNameFromDatabaseCatalog`: the struct is added for `resolveDictionaryNameUnchecked`, which takes the key from that function and qualifies the name the same way, the check that skips databases without their own tables (`isExternal`) moves into that function, and `resolveDictionary` records nothing. - Other conflicts come from master-only changes (the `modernize-use-nodiscard` sweep, `getSignatureString` in the naive Bayes functions, the `SubcolumnCodecs.h` include) and take the 26.8 side. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry pick #122678 to 26.8: Check access rights before loading a dictionary or reading its definition
Cherry pick #122678 to 26.3: Check access rights before loading a dictionary or reading its definition
…nary or reading its definition
…nary or reading its definition
Backport #122678 to 26.8: Check access rights before loading a dictionary or reading its definition
Backport #122678 to 26.3: Check access rights before loading a dictionary or reading its definition
Since ClickHouse#122678, analyzing `dictGet` checks the `dictGet` grant, and an ALTER re-validates the default expressions of every column of the table as the altering user. Once `c_dict ALIAS dictGet(d, 'v', id)` exists, every later ALTER by a user without `dictGet ON d` therefore fails with ACCESS_DENIED, whatever column it adds. Adding `c_dict` last keeps each arm about its own expression. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`timeSeriesSamples`, `timeSeriesTags`, `timeSeriesTimeRanges` and
`timeSeriesMetricFamilies` (and the aliases `timeSeriesData`,
`timeSeriesMetrics`) look up the TimeSeries table and its target in
`parseArguments` and then return the target's columns, but nothing in the
class checks a privilege on the TimeSeries table. A user with only
`SHOW TABLES` on `db.ts` (or no grant on it at all) therefore got the
target's columns from `DESCRIBE TABLE timeSeriesSamples('db', 'ts')` and
`DESCRIBE (SELECT ...)`, and could `SELECT` from the target, also through a
`remote()` local shard or parallel replicas, while `DESCRIBE TABLE db.ts`
is denied.
Check `SHOW COLUMNS` on the resolved TimeSeries table id before the lookup,
the privilege `DESCRIBE TABLE db.ts` checks at the same point, through the
existing `ITableFunction::checkSourceTableAccess` helper. `parseArguments`
runs before every use of the function, so one check covers every spelling
and all four functions. A table-level `SELECT` or `INSERT` on the TimeSeries
table implies `SHOW COLUMNS`, so ordinary readers and writers are unaffected;
a missing table now gives `ACCESS_DENIED` to a user without the grant, as a
direct `DESCRIBE` does. The Prometheus `/api/v1/metadata` endpoint reads
through `timeSeriesMetricFamilies` as the request's user and inherits the
check.
`timeSeriesSelector`, `prometheusQuery` and `prometheusQueryRange` are not
changed: they are the PromQL engine's read path, can be persisted with
`CREATE TABLE ... AS`, and their access design is the owner's open work
(ClickHouse#120267).
Closes ClickHouse#133495 (the `dictionary(...)` half was fixed by ClickHouse#122678).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The
dictionarytable function, thedictGet-family functions,naiveBayesClassifier*andDictionarytables loaded the dictionary first and checkeddictGet/SELECTaccess afterwards. A query without the required grants failed withACCESS_DENIED, but the dictionary had already been loaded: its source was queried and its status insystem.dictionarieschanged fromNOT_LOADEDtoLOADED.CREATE TABLE ... ENGINE = Dictionary(d)and, with the old analyzer, the injectivedictGetoptimization ofGROUP BY(optimize_injective_functions_in_group_by) loaded the dictionary without any access check. In addition, inferring the result type of these functions read the dictionary definition before any check, so a user withoutdictGetcould learn attribute names, types and the layout from the result type or from error messages.This PR adds
ExternalDictionariesLoader::resolveDictionary, which resolves a dictionary name once, without loading the dictionary. It returns the key the loader stores the dictionary under (the UUID for a dictionary in anAtomicdatabase) and the dictionary ID, taken from the loaded dictionary if there is one, otherwise from the dictionary configuration, so the access key is the same as before. Access is checked on that ID, and the dictionary or its definition is then read by the same key, so a dictionary renamed in between cannot be read instead of the one that passed the check. For a dictionary that does not exist, it returns the ID the dictionary would have in the current database, so a user without access getsACCESS_DENIEDand cannot tell a missing dictionary from an existing DDL dictionary. An XML dictionary is checked as<no_database>.d, so the denial message for it still differs from the one for a missing name. The access check now runs before the dictionary is loaded or its definition is read:dictionarytable function,Dictionarytables (including joins against them) andCREATE TABLE ... ENGINE = Dictionary:dictGetorSELECTon the dictionary is required, the same rule as for reading aDictionarytable before (StorageDictionary::checkDictionaryAccess). ForCREATE TABLE ... ENGINE = Dictionary, the check runs before the dictionary is loaded to validate the columns.dictGet-family functions,dictGetKeysandnaiveBayesClassifier*:dictGetis required, also for inferring the result type.dictGetinGROUP BY: the optimization is skipped whendictGetis not granted, and the query fails at the regular check during execution.Behavior changes:
dis a dictionary andwis a table withENGINE = Dictionary(d). "Access" meansdictGetfor thedictGet-family functions,dictGetKeysandnaiveBayesClassifier*, anddictGetorSELECTondfor thedictionarytable function andDictionarytables.dSELECT * FROM dictionary('d'),dictGet('d', ...),dictHas,naiveBayesClassifier('d', ...), reading or joiningw,GROUP BY dictGet('d', ...)withenable_analyzer = 0dwas loaded, thenACCESS_DENIEDACCESS_DENIED,dis not loadeddDESCRIBE TABLE dictionary('d')dwas loaded and its structure shownACCESS_DENIEDdCREATE TABLE ... ENGINE = Dictionary(d),CREATE VIEW ... AS SELECT ... JOIN wdACCESS_DENIEDdDESCRIBE/EXPLAINof a query withdictGet('d', ...), queries where no rows reachdictGet,CREATE VIEWwithdictGet('d', ...), a column withDEFAULT dictGet('d', ...)dACCESS_DENIEDdddoes not existDictionary ... not found, which told a missing dictionary from an existing oneACCESS_DENIED, like for an existing DDL dictionarySELECTondwwithenable_analyzer = 0dwas loaded, thenACCESS_DENIED(requireddictGet)CREATE TABLE ... ENGINE = Dictionary(d)with an unqualified name and a non-default current databaseDictionary (d) not founddis resolved in the current database, like when the table is readA table created
ASa table function with an explicit column list, e.g.AS view(SELECT dictGet('d', ...)), creates its storage on first use with the global context, so the query ofviewis analyzed with full access. A follow-up PR handles that case.Users with access see no difference. If a query or DDL now fails with
ACCESS_DENIEDfor a dictionary, grantdictGeton it (orSELECTfor thedictionarytable function andDictionarytables) to the user running it.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Check access rights before loading a dictionary or reading its definition in the
dictionarytable function,dictGet-family functions,naiveBayesClassifier,Dictionarytables andCREATE TABLE ... ENGINE = Dictionary. Queries without the required grants no longer trigger the dictionary load, and queries or DDL that reference a dictionary now require access to it even when they do not read it, e.g.DESCRIBE,CREATE VIEWor aDEFAULT dictGet(...)column.Workflow [PR]
Sync PR [sync-upstream/pr/122678]
Version info
26.11.1.2728-master(included in26.11and later)26.10.8.7,26.9.33.16,26.8.42.17,26.3.67.31