Skip to content

Enforce settings constraints and allow_feature_tier for access entities - #119472

Merged
Algunenano merged 41 commits into
ClickHouse:masterfrom
Algunenano:enforce-feature-tier-in-access-entities
Oct 2, 2026
Merged

Algunenano merged 41 commits into
ClickHouse:masterfrom
Algunenano:enforce-feature-tier-in-access-entities

Conversation

@Algunenano

@Algunenano Algunenano commented Sep 11, 2026 •

Copy link
Copy Markdown
Member

Settings constraints and allow_feature_tier were 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 AccessControl by comparing the effective settings before and after the write using one access-graph snapshot: GRANT/REVOKE, DROP ROLE, DROP SETTINGS PROFILE, a profile's TO clause, 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_tier applies to every element. A statement cannot remove a setting its author is constrained on, whether by DROP SETTINGS, DROP ALL SETTINGS, DROP ALL PROFILES, DROP PROFILES, ALTER ... SETTINGS replacement or CREATE ... OR REPLACE. Users defined in the server configuration may still declare looser constraints, but not bypass allow_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 TO clause) must satisfy the constraints and allow_feature_tier of a new session, otherwise the login is refused. Profiles and users defined in the server configuration are not re-checked. The same check applies when EXECUTE AS or another path switches a context to that user, and it no longer depends on the caller's session.

The compatibility setting no longer applies a value that the user's settings constraints or allow_feature_tier refuse; such a setting keeps its current value. The server-wide MergeTree settings derived from the default profile's compatibility likewise skip values that its merge_tree_ constraints or allow_feature_tier refuse.

Closes: #116126
Related: #113156
Related: #116933

Changelog category (leave one):

  • Backward Incompatible Change

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

Settings constraints and allow_feature_tier are 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 as GRANT, DROP ROLE, DROP SETTINGS PROFILE or CREATE 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 or allow_feature_tier can no longer log in. The compatibility setting no longer applies values that settings constraints or allow_feature_tier refuse; such settings keep their current value.


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

Version info

  • Merged into: 26.10.1.1295-master (included in 26.10 and later)

Algunenano and others added 11 commits September 9, 2026 19:00
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]>
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
@clickhouse-gh

clickhouse-gh Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a0df553]

Summary: ✅


AI Review

Summary

This PR hardens settings-constraint and allow_feature_tier enforcement across access-entity writes, login, compatibility, and several multi-storage paths. The main remaining gap is CREATE ... OR REPLACE on replicated access storages: its pre-overwrite constraint check still trusts the local cache, so it can miss the real replaced entity and bypass the new "do not remove settings outside the actor's bounds" contract.

PR Metadata
  • The Changelog entry no longer matches the implementation for compatibility: the code and docs now keep the default value when a compatibility-derived setting is refused, not the current value. Replace the last sentence with: The compatibility setting no longer applies values that settings constraints or allow_feature_tier refuse; such settings keep their default value.
Findings
  • ❌ Blockers
    • [src/Interpreters/Context.cpp:3855] checkSettingsConstraintsForOverwrite resolves the overwritten entity via storage->find / storage->tryRead, which for ReplicatedAccessStorage only sees the local cache. The later insert(..., replace_if_exists = true) still goes to ZooKeeper and can replace a same-name user/role/profile created on another replica before this cache refreshes, so CREATE ... OR REPLACE can skip checkRemovedSettings and drop bounds the actor is not allowed to remove. Suggested fix: validate against the ZooKeeper-backed current definition with a replicated compare-and-set fallback like updateImpl, or fail closed whenever the destination storage is replicated and the replacement target is not locally readable.
Final Verdict
  • Status: ⚠️ Request changes
  • Minimum required actions: close the replicated OR REPLACE hole in checkSettingsConstraintsForOverwrite, and align the changelog wording for the compatibility fallback semantics.

LLVM Coverage Report

Measured on commit a0df553.

Metric Baseline Current Δ
Lines 88.30% 88.30% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 879/961 (91.47%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 11, 2026
Comment thread src/Access/AccessControl.cpp Resolved
Comment thread src/Access/resolveEffectiveSettings.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. label Sep 11, 2026
Comment thread src/Access/AccessControl.cpp Resolved
Comment thread src/Access/resolveEffectiveSettings.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a0df55399 with master 28dc98b1f (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 0982e5a39; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes.

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.

Object file sizes ⚠️

136 object files changed (+447.33 KiB total), 2 added.

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.

Job report

Comment thread src/Access/AccessControl.cpp Resolved
Comment thread src/Access/AccessControl.cpp Resolved
Algunenano and others added 3 commits September 15, 2026 16:13
…er-in-access-entities

# Conflicts:
#	src/Access/SettingsConstraints.cpp
Comment thread src/Access/resolveEffectiveSettings.cpp Resolved
Comment thread src/Access/AccessControl.cpp Outdated
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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 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.

Comment thread src/Access/AccessControl.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 37 queries analysed

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.

clickbench

⚠️ 2 inconclusive

Flagged queries (2 of 43)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 30 not_sure 229 279 +21.8% <0.0001 aggregation: The +21.8% median stays inside master's current range, and CPU time rose only about 3%. This PR changes access-control and settings-constraint code, not GROUP BY execution.
⚠️ 31 not_sure 268 328 +22.4% <0.0001 aggregation: The +22.4% median stays inside master's current range, and CPU time rose only about 1%. Nothing in the diff touches the aggregation path this query runs.

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
  • StressHouse run: a9d0ef88-202b-40b7-8ef9-084098f45094
  • MIRAI run: b47e4087-733c-4e22-9923-2de4545974b7
  • PR check IDs:
    • clickbench_2773533_1790878136
    • clickbench_2773546_1790878137
    • clickbench_2773552_1790878137
    • tpch_adapted_1_official_2773563_1790878137
    • tpch_adapted_1_official_2773590_1790878136
    • tpch_adapted_1_official_2773604_1790878136


for (const auto & setting_name : names)
{
auto reason = getFeatureTierRestriction(access_control, setting_name, settingGetTier(setting_name));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 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.

Comment thread src/Interpreters/Context.cpp Resolved
if (auto old_entity = id ? storage->tryRead(*id) : nullptr)
checkRemovedSettings(old_entity, new_entity);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 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.

@Algunenano
Algunenano enabled auto-merge October 2, 2026 08:06
@Algunenano
Algunenano added this pull request to the merge queue Oct 2, 2026
Merged via the queue into ClickHouse:master with commit 326c44e Oct 2, 2026
149 checks passed
@Algunenano
Algunenano deleted the enforce-feature-tier-in-access-entities branch October 2, 2026 15:25
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 2, 2026
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 2, 2026
…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.
groeneai added a commit to groeneai/ClickHouse that referenced this pull request Oct 2, 2026
…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]>
@clickgapai

Copy link
Copy Markdown
Contributor

@Algunenano — ClickGap found the following in this PR:

Could you review the test PR and add the can be tested label if it looks good?
Close anything that's wrong or already addressed.

leshikus pushed a commit to leshikus/ClickHouse that referenced this pull request Oct 13, 2026
ylw510 pushed a commit to ylw510/ClickHouse that referenced this pull request Nov 4, 2026
…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]>
Algunenano pushed a commit to Algunenano/ClickHouse that referenced this pull request Nov 11, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-rbac Authorization: roles, grants, quotas, row-level security, access checks. pr-backward-incompatible Pull request with backwards incompatible changes pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

allow_feature_tier is not enforced when a role or settings profile changes which settings apply

4 participants