Repository navigation
Enforce settings constraints and allow_feature_tier for access entities - #119472
Algunenano merged 41 commits into
Conversation
A statement on an access entity was checked by looking at the settings it names, so several statements that name no setting still changed which settings a user gets: granting a role that a settings profile is assigned to, dropping a role or a profile, and a replacement that discards a granted role. The same procedure also refused statements that change nothing, because the explicit `SETTINGS` elements were compared against the session of the administrator running the statement rather than against the target. The tier is now decided from the settings in effect. `resolveEffectiveSettings` resolves the settings every user ends up with over the whole access graph, with the entities a statement is about to write applied on top, and refuses the write when a setting of a disabled tier moved for anyone. That makes `GRANT`, `REVOKE`, `DEFAULT ROLE`, a profile's `TO` clause, `DROP ROLE`, `DROP SETTINGS PROFILE`, `ATTACH` and an override dropped by omission one case instead of many: none of them names a setting, and all of them change what is in effect. Users are compared by name, because `CREATE ... OR REPLACE` writes a new id for a user that keeps its name; a user the statement creates is compared against a blank user of that name, so a setting the server already puts in effect for everybody is not read as one the statement introduced; a user it drops is not compared, since dropping a user constrains nothing. Writing a setting of a disabled tier into an entity is still refused even when no user resolves to it yet, because the entity is what a later `GRANT` or `TO` clause would put in effect. That comparison is against the elements the entity already holds, so rewriting a value it already has is allowed whatever the administrator's own session says. The check hangs off the storage write in `AccessControl`, so it covers every route to an entity, and it is skipped entirely when `allow_feature_tier` is 0, which leaves the default configuration unchanged. Entities written by the configuration file or replayed from another replica do not go through it, as before. `collectRoles` and `substituteProfiles` move out of the caches so the resolution is the real one rather than a copy of it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…er-in-access-entities
Centralize access-entity validation and mutations, share effective settings resolution with the live caches, and preserve dependencies while moving entities between storages. Closes: ClickHouse#116126
Apply the shared tier, setting-read, assertion, and cleanup helpers throughout the existing integration tests, removing duplicated setup and checks. Related: ClickHouse#116126
…er-in-access-entities # Conflicts: # src/Core/ServerSettings.cpp
|
Workflow [PR], commit [a0df553] Summary: ✅
AI ReviewSummaryThis PR hardens settings-constraint and PR Metadata
Findings
Final Verdict
LLVM Coverage ReportMeasured on commit a0df553.
Changed lines: Changed C/C++ lines covered: 879/961 (91.47%) · Uncovered code |
…sible Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build profile diff (arm_release)Comparing Binary sizes
The official master build is compiled with Object file sizes
|
| Object file | Master | PR | Δ |
|---|---|---|---|
src/CMakeFiles/dbms.dir/Access/resolveEffectiveSettings.cpp.o |
new | 316.59 KiB | +316.59 KiB |
src/CMakeFiles/dbms.dir/Access/AccessControl.cpp.o |
544.21 KiB | 612.67 KiB | +68.46 KiB (+12.58%) |
src/CMakeFiles/dbms.dir/Access/SettingsConstraints.cpp.o |
232.74 KiB | 283.20 KiB | +50.46 KiB (+21.68%) |
src/CMakeFiles/dbms.dir/Processors/Transforms/Window/SlidingBlocks.cpp.o |
new | 34.98 KiB | +34.98 KiB |
src/CMakeFiles/dbms.dir/Access/SettingsProfilesCache.cpp.o |
446.37 KiB | 413.08 KiB | -33.29 KiB (-7.46%) |
src/CMakeFiles/dbms.dir/Processors/Transforms/WindowTransform.cpp.o |
160.67 KiB | 136.67 KiB | -24.00 KiB (-14.94%) |
src/CMakeFiles/dbms.dir/Interpreters/Context.cpp.o |
2.91 MiB | 2.93 MiB | +22.07 KiB (+0.74%) |
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.
Compile time of recompiled translation units
1368 translation units recompiled, 8404 s compile time in total, 1367 of them have a recent master baseline.
Median compile-time ratio to the baselines is ×0.94 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -447.4 s (-5%) in total before that adjustment.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…er-in-access-entities # Conflicts: # src/Access/SettingsConstraints.cpp
| if (!storage) | ||
| selected_storage = getStorageForInsertion(entity); | ||
| auto & storage_for_insertion = storage ? *storage : *selected_storage; | ||
| auto existing_id = storage_for_insertion.find(entity->getType(), entity->getName()); |
There was a problem hiding this comment.
existing_id and new_users_are_shadowed are inferred from storage_for_insertion.find(...), but for ReplicatedAccessStorage that lookup is only the local memory_storage cache. The actual insert(..., replace_if_exists = true) that follows goes to ZooKeeper and can still replace an entity another replica created before this cache refreshes.
In that window pending contains only the new entity, so CREATE ... OR REPLACE / RESTORE ... create_access='replace' is validated as a pure insert and never compared against the real replaced definition. That lets restricted tier changes slip through (and can also falsely reject a no-op replace) on replicated access storages. This path needs the same kind of replicated fallback that updateImpl has, or it needs to fail closed when the destination storage is replicated and the current definition is not locally available.
There was a problem hiding this comment.
🕵 Not fixing. A fresh cache would not close this either: another replica can write between the check here and the ZooKeeper commit, and a replica with a more permissive allow_feature_tier can change the shared entity directly anyway. Closing it would mean validating inside the ZooKeeper replace, like updateImpl does inside its compare-and-set callback, which is not worth it for replicas that share an access storage but disagree on the tier.
|
📊 Cloud Performance Report ✅ AI verdict: No query shows a performance change caused by this PR. Only ClickBench Q30 (+21.8%) and Q31 (+22.4%) were flagged, and both were held at not_sure because their PR medians (279 ms and 328 ms) fall inside the range master itself shows right now. CPU time barely moved (about +3% and +1%), so the extra wall time does not come from more work being done. Both PR benchmark runs also shared hardware with each other, which can slow wall-clock timings. The diff only changes access-entity storage locking, settings-constraint and feature-tier checks, how compatibility defaults are applied, and CI and docs files. None of that runs in the high-cardinality GROUP BY path these two queries exercise. clickbenchFlagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
…not its current value
|
|
||
| for (const auto & setting_name : names) | ||
| { | ||
| auto reason = getFeatureTierRestriction(access_control, setting_name, settingGetTier(setting_name)); |
There was a problem hiding this comment.
This before/after graph check only looks at getFeatureTierRestriction, so the indirect paths that now route through it still enforce only allow_feature_tier. A SQL-defined admin constrained by something like max_execution_time MAX 4 can still grant an existing role / profile that yields max_execution_time = 8, or switch DEFAULT ROLE, because no SettingsConstraints check ever runs on the resulting effective settings.
That contradicts the PR contract in the description (GRANT / REVOKE / indirect changes are supposed to be refused when they move a user outside the actor's bounds). The graph validator needs the actor's current constraints too, not just the tier gate.
There was a problem hiding this comment.
🕵 Not changing: constraints bound the values a statement writes and the settings it removes, and GRANT/REVOKE/DEFAULT ROLE write none. Checking another user's effective settings against the actor's own bounds would stop an admin with tight bounds for their own queries from managing users with heavier limits. Role and profile values are applied at login without a constraint check, as upstream always has; whoever created the role was allowed to write those values. Only allow_feature_tier applies to indirect changes, as the description says.
| if (auto old_entity = id ? storage->tryRead(*id) : nullptr) | ||
| checkRemovedSettings(old_entity, new_entity); | ||
| } | ||
| } |
There was a problem hiding this comment.
storage->find here still only sees the local cache of a ReplicatedAccessStorage, but the later insert(..., replace_if_exists = true) goes to ZooKeeper and can still replace a same-name entity another replica created before this cache refreshes.
In that window old_entity stays null, so CREATE USER/ROLE/SETTINGS PROFILE OR REPLACE skips checkRemovedSettings and lets a constrained actor drop settings it is not allowed to remove from the actual replaced entity. This needs the same kind of replicated fallback as updateImpl, or a fail-closed path when the destination storage is replicated and the current definition is not locally readable.
There was a problem hiding this comment.
🕵 Not fixing: the same window as the replicated OR REPLACE thread on AccessControl.cpp, and it was there before this change too (the global find read the same local cache). A fresher read only moves the window to the gap between the check and the ZooKeeper commit; closing it would mean validating inside the ZooKeeper replace. Refusing OR REPLACE whenever the destination is replicated would break normal use to guard against two replicas racing on the same name.
…pects-compatibility The conflicts are resolved to master's side in every file this branch touched: ClickHouse#119472 now makes `compatibility` skip a value the constraints refuse, which replaces this branch's post-apply checks of derived values, their rollback, the post-processor marks and the Arrow Flight batching. The fix is re-applied on top in the next commit.
…estriction A reset now re-derives the settings nothing assigned from the active `compatibility` after resetting the names, once per call, so the setting lands on the value of that version. It reuses `restrictSettingsChangedByCompatibility` from ClickHouse#119472, so a reset never takes a value from `compatibility` that the constraints refuse. Resetting `compatibility` itself reverts what it derived. The reset is checked against the value it lands on, learned by performing it on a copy of the context, as well as against the declared default: a readonly user whose profile assigns a setting its declared default could otherwise move it to the derived value, and a later change of `compatibility` moves a reset setting back to the declared default. Closes ClickHouse#116883. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@Algunenano — ClickGap found the following in this PR:
Could you review the test PR and add the |
…USERS before 26.10 Before 26.10, AccessControl::restoreFromBackup drains the access-change notifier before the deferred restore task inserts the entities, and those inserts never notify. The row-policy and settings-profile caches therefore miss restored entities until the next drain (SYSTEM RELOAD USERS, unrelated access DDL, or a restart). ClickHouse#119472 fixed this on master and in 26.10, so the note is scoped to earlier versions. Measured on official builds: right after RESTORE the restricted user reads 3 of 10 rows (policy enforced) and has max_result_rows = 3 on 26.11.1.1203 and 26.10.3.7, but 10 rows and 0 on 26.9.26.11 and 26.3.61.6, also 30 s later. DDL-created controls are enforced on all four, and SYSTEM RELOAD USERS applies the restored entities. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…users Since ClickHouse#119472, Context::setCurrentProfileWithLock passed actor_is_config_defined = isCurrentUserDefinedInConfigWithLock() when checking a selected settings profile. That flag is meant for access-entity DDL by a config-defined admin, who may write looser profiles for other users. On a profile switch it skipped the CONST/MIN/MAX/disallowed and writability checks of the actor's own session, so a user defined in users.xml could escape any constraint with SET profile, a SETTINGS profile = ... clause or the HTTP profile parameter (ClickHouse#128370). 26.9 checked the switch for every user; a SQL-defined user is still refused on master. Trust only a context without a user (background and buffer contexts, the distributed_ddl profile), which is what the helper returned for them. Access-entity DDL and login keep the config-defined-admin trust. Config-defined users now also get the writability check SQL users have: a profile restating a CONST setting's value without CONST is refused. Closes ClickHouse#128370 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Settings constraints and
allow_feature_tierwere enforced only while processing explicit setting changes. Access operations that named no setting could bypass them while still changing a user's effective settings through roles or settings profiles, and settings a user already stored were never re-checked.Writes to users, roles and settings profiles are now validated in
AccessControlby comparing the effective settings before and after the write using one access-graph snapshot:GRANT/REVOKE,DROP ROLE,DROP SETTINGS PROFILE, a profile'sTOclause,CREATE USER OR REPLACE, named access storages, moves, restores and replicated updates (preserving compare-and-set retries). Roles and settings profiles are also checked as carriers, so a restricted setting cannot be stored for later assignment. User, role and settings-profile writes are serialized while their snapshot is validated and committed, including storage I/O; quotas and row policies are unaffected.Profile elements are also checked against the constraints of the user running the statement, including inherited profiles, and
allow_feature_tierapplies to every element. A statement cannot remove a setting its author is constrained on, whether byDROP SETTINGS,DROP ALL SETTINGS,DROP ALL PROFILES,DROP PROFILES,ALTER ... SETTINGSreplacement orCREATE ... OR REPLACE. Users defined in the server configuration may still declare looser constraints, but not bypassallow_feature_tier.A user defined by SQL is now checked when it logs in: its own settings, its roles' settings and the profiles assigned to it (including by a profile's
TOclause) must satisfy the constraints andallow_feature_tierof a new session, otherwise the login is refused. Profiles and users defined in the server configuration are not re-checked. The same check applies whenEXECUTE ASor another path switches a context to that user, and it no longer depends on the caller's session.The
compatibilitysetting no longer applies a value that the user's settings constraints orallow_feature_tierrefuse; such a setting keeps its current value. The server-wideMergeTreesettings derived from the default profile'scompatibilitylikewise skip values that itsmerge_tree_constraints orallow_feature_tierrefuse.Closes: #116126
Related: #113156
Related: #116933
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Settings constraints and
allow_feature_tierare now enforced for users, roles and settings profiles defined by SQL. A statement is refused if it changes a restricted setting of some user indirectly (such asGRANT,DROP ROLE,DROP SETTINGS PROFILEorCREATE USER OR REPLACE), sets a value outside its author's constraints, or removes a setting its author is constrained on. A user defined by SQL whose stored settings, roles or assigned settings profiles violate the constraints orallow_feature_tiercan no longer log in. Thecompatibilitysetting no longer applies values that settings constraints orallow_feature_tierrefuse; such settings keep their current value.Workflow [PR]
Sync PR [sync-upstream/pr/119472]
Version info
26.10.1.1295-master(included in26.10and later)