Skip to content

Dynamic disk restricting settings - #99138

Merged
kssenii merged 25 commits into
masterfrom
dynamic-disks-settings
May 13, 2026
Merged

kssenii merged 25 commits into
masterfrom
dynamic-disks-settings

Conversation

@kssenii

@kssenii kssenii commented Mar 10, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Backward Incompatible Change

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

Add a setting dynamic_disk_allow_from_env, dynamic_disk_allow_from_zk, dynamic_disk_allow_include to disallow usage of from_env, from_zk, include in dynamic disks. Backward Incompatible Change because prohibits by default the behaviour which used to be allowed by default.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Note

Medium Risk
Adds new access controls around dynamic disk configuration (from_env, from_zk, include) and changes MergeTree settings loading to use per-user query context; misconfiguration could block table creation or unexpectedly allow/deny storage configuration features.

Overview
Introduces three new settings—dynamic_disk_allow_from_env, dynamic_disk_allow_from_zk, and dynamic_disk_allow_include—to block dynamic disk config features by default and prevent reading env/ZooKeeper values or processing includes when defining disk() in table settings.

Enforces these checks in getDiskConfigurationFromASTImpl, returning ACCESS_DENIED unless explicitly enabled, while skipping the checks during ATTACH/server restart (is_attach=true) to keep existing tables loadable.

Updates MergeTree creation/attach to evaluate disk settings using the local (query) context so user settings profiles can control access, and adds stateless + integration tests covering default-deny and profile-enabled behavior.

Written by Cursor Bugbot for commit 3e4d90d. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.5.1.605 (included in 26.5 and later)
  • Backported to: 26.3.17.69

@clickhouse-gh

clickhouse-gh Bot commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [df020e2]

Summary: ✅


AI Review

Summary

This PR adds dynamic_disk_allow_* guards for dynamic disk() configuration, wires them through ATTACH/startup loading modes, and adds stateless/integration coverage. Verdict: changes are still required because the access gate remains bypassable from query/session settings.

Findings

❌ Blockers

  • [src/Access/SettingsConstraints.cpp:53-55; src/Core/Settings.cpp:4217-4228] The new security contract is profile-controlled default-deny for from_env/include/from_zk, but these settings are still regular query settings and are not source-restricted. SETTINGS_SOURCE_RESTRICTIONS still contains only max_sessions_for_user, so a restricted user can run SET dynamic_disk_allow_from_env = 1 and then CREATE TABLE ... SETTINGS disk = disk(endpoint = 'from_env ...'), bypassing the intended restriction.
    Suggested fix: add dynamic_disk_allow_from_env, dynamic_disk_allow_include, and dynamic_disk_allow_from_zk to SETTINGS_SOURCE_RESTRICTIONS with {SettingSource::PROFILE} (or make them non-query/server settings), and add a regression that SET dynamic_disk_allow_from_env = 1 is rejected for restricted_user.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Make dynamic_disk_allow_from_env, dynamic_disk_allow_include, and dynamic_disk_allow_from_zk non-overridable from query/session source.
  2. Add a focused regression proving a restricted user cannot bypass the gate via SET ... = 1.

@kssenii kssenii changed the title Add a setting to disallow from_env in dynamic disks Dynamic disk restricting settings Mar 10, 2026
@kssenii
kssenii force-pushed the dynamic-disks-settings branch from 0fd1284 to fc06e03 Compare March 10, 2026 17:15
kssenii and others added 2 commits March 10, 2026 18:17
For the `privileged_user` cases in `test_dynamic_disk_security_settings`,
replace the `query_and_get_error` + `ACCESS_DENIED not in error` pattern
with plain `node.query()` so the test verifies that `CREATE TABLE` truly
succeeds (no exception at all) when the profile permits the substitution.

To make the queries work end-to-end:
- Add `include_from_path.xml` / `include_from.xml` to node5 (needed for
  the `include` substitution test).
- Add `env_variables={"MINIO_SECRET": minio_secret_key}` to node5 (needed
  for `from_env`).
- Add `with_zookeeper=True` to node5 and pre-populate
  `/test_security_minio_secret` in ZooKeeper (needed for `from_zk`).

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Comment thread src/Core/SettingsChangesHistory.cpp Resolved
Comment thread src/Core/Settings.cpp
DECLARE(Bool, allow_drop_detached, false, R"(
Allow ALTER TABLE ... DROP DETACHED PART[ITION] ... queries
)", 0) \
DECLARE(Bool, dynamic_disk_allow_from_env, false, R"(

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.

dynamic_disk_allow_from_env (and the related toggles) are declared as regular query settings (DECLARE(..., 0)), so a user with CREATE TABLE can typically bypass the intended restriction by enabling them in session/query (SET dynamic_disk_allow_from_env = 1) before CREATE TABLE ... disk(...). That makes this security gate ineffective unless every user profile has explicit immutable constraints. Please move these toggles to a server-level setting or enforce non-overridable profile constraints, and add a negative test for restricted_user that tries to override the setting in-session.

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.

I re-checked this on the current HEAD, and the bypass is still possible.

dynamic_disk_allow_* are still regular query settings (DECLARE(..., 0)), and there is still no source restriction for them in SettingsConstraints (the SETTINGS_SOURCE_RESTRICTIONS map still only contains max_sessions_for_user). So a user can still do:

SET dynamic_disk_allow_from_env = 1;
CREATE TABLE ... SETTINGS disk = disk(... 'from_env ...');

and bypass the intended default-deny behavior.

Could you please make these settings profile-only / non-overridable from query/session (or move them to a server-level setting), then add a negative test that explicitly checks SET dynamic_disk_allow_from_env=1 fails for a restricted user?

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.

I re-checked this on current HEAD; this issue is still live.

dynamic_disk_allow_from_env, dynamic_disk_allow_include, and dynamic_disk_allow_from_zk are still regular query settings in src/Core/Settings.cpp, and SETTINGS_SOURCE_RESTRICTIONS in src/Access/SettingsConstraints.cpp still only contains max_sessions_for_user.

So a restricted user can still do:

SET dynamic_disk_allow_from_env = 1;
CREATE TABLE ... SETTINGS disk = disk(endpoint = 'from_env HOME', ...);

which bypasses the intended default-deny security gate. Please add these three settings to SETTINGS_SOURCE_RESTRICTIONS with {SettingSource::PROFILE} (or move them to non-query settings) and add an explicit negative test that SET ... = 1 is rejected for a restricted user.

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.

dynamic_disk_allow_from_env, dynamic_disk_allow_include, and dynamic_disk_allow_from_zk are still bypassable from a query/session context.

At HEAD, SETTINGS_SOURCE_RESTRICTIONS still only restricts max_sessions_for_user (src/Access/SettingsConstraints.cpp), while the three dynamic-disk toggles remain regular query settings in src/Core/Settings.cpp. That means a restricted user can still run:

SET dynamic_disk_allow_from_env = 1;
CREATE TABLE ... SETTINGS disk = disk(endpoint = 'from_env HOME', ...);

and bypass the default-deny protection.

Please add these three settings to SETTINGS_SOURCE_RESTRICTIONS with {SettingSource::PROFILE} (or make them non-query settings), and add a regression test that SET dynamic_disk_allow_from_env = 1 is rejected for a restricted user.

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.

I re-checked this on current HEAD; the bypass is still present.

dynamic_disk_allow_from_env, dynamic_disk_allow_include, and dynamic_disk_allow_from_zk are still regular query settings in src/Core/Settings.cpp, while SETTINGS_SOURCE_RESTRICTIONS in src/Access/SettingsConstraints.cpp still only restricts max_sessions_for_user.

So a restricted user can still do:

SET dynamic_disk_allow_from_env = 1;
CREATE TABLE ... SETTINGS disk = disk(endpoint = 'from_env HOME', ...);

and bypass the intended profile-controlled default-deny behavior.

Please add these three settings to SETTINGS_SOURCE_RESTRICTIONS with {SettingSource::PROFILE} (or make them non-query settings), and add a regression check that SET dynamic_disk_allow_from_env = 1 is rejected for restricted_user.

Comment thread src/Core/SettingsChangesHistory.cpp Resolved
@Algunenano Algunenano added pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-critical-bugfix labels Mar 13, 2026
kssenii and others added 2 commits March 17, 2026 18:00
…_metadata

The parameter was renamed to is_server_startup_attach in d86eca8, but
37a246d then established that the correct name for the concept is
isLoadingFromExistingMetadata (UNDROP TABLE also sets FORCE_ATTACH/
FORCE_RESTORE, not only server startup). Align the parameter names in
all loadFromQuery overloads and in getDiskConfigurationFromASTImpl to
match the helper.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@kssenii
kssenii marked this pull request as draft March 17, 2026 17:33
@kssenii
kssenii force-pushed the dynamic-disks-settings branch from eccd8c0 to 4efc892 Compare March 19, 2026 11:09
@kssenii
kssenii marked this pull request as ready for review March 23, 2026 12:45
@kssenii
kssenii requested a review from tavplubix March 24, 2026 14:16
Merged via the queue into master with commit 96393a1 May 13, 2026
165 checks passed
@kssenii
kssenii deleted the dynamic-disks-settings branch May 13, 2026 10:50
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label May 13, 2026
robot-ch-test-poll added a commit that referenced this pull request May 13, 2026
Cherry pick #99138 to 26.4: Dynamic disk restricting settings
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label May 13, 2026
@kssenii kssenii added the pr-backward-incompatible Pull request with backwards incompatible changes label May 13, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label May 13, 2026
@kssenii kssenii added v25.12-must-backport and removed pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Jun 24, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 24, 2026
@fm4v fm4v added v26.2-must-backport and removed pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore labels Jun 25, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 25, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jun 25, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 21, 2026
robot-ch-test-poll4 added a commit that referenced this pull request Jul 21, 2026
Cherry pick #99138 to 26.3: Dynamic disk restricting settings
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 21, 2026
kssenii added a commit that referenced this pull request Jul 23, 2026
Backport #99138 to 26.3: Dynamic disk restricting settings
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-backward-incompatible Pull request with backwards incompatible changes pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo v25.12-must-backport v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants