Repository navigation
Do not let SET <name> = DEFAULT bypass the settings constraints - #115334
Conversation
`SET <name> = DEFAULT` resets a setting rather than assigning to it, so it does not
produce a `SettingChange` and never reached `SettingsConstraints`. Any constraint
could therefore be escaped by resetting the setting instead of assigning to it:
CREATE SETTINGS PROFILE p SETTINGS max_query_size = 1000 MAX 1000;
SET max_query_size = 2000; -- SETTING_CONSTRAINT_VIOLATION, as expected
SET max_query_size = DEFAULT; -- silently restored the default of 262144
A `CONST` constraint was just as escapable, and so was readonly mode, which is
enforced by the same check:
SET readonly = 2;
SET readonly = 0; -- READONLY, as expected
SET readonly = DEFAULT; -- silently left readonly mode
Describe the reset as the change it effectively is - to the value declared in the
source code, which is what `Context::resetSettingsToDefaultValue` restores - and run
the usual check on it before anything is applied, so that a violation leaves the
whole statement without effect. The in-query `SETTINGS <name> = DEFAULT` form goes
through the same interpreter and is covered too.
A reset that does not change the value is still allowed, because the check drops
changes whose new value equals the current one. Resetting a setting that was never
touched therefore keeps working under a `CONST` constraint and in readonly mode,
which is what the CI profiles that pin a setting to its default rely on. Settings
without a declared default are unaffected: a custom setting is dropped rather than
reset and cannot carry a constraint, and an unknown name stays silently ignored.
Co-Authored-By: Claude Fable 5 <[email protected]>
|
Workflow [PR], commit [b1c89e2] Summary: ✅
AI ReviewSummaryThis PR closes the Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 30/30 (100.00%) · Uncovered code |
|
@alexey-milovidov we should check for query parameters as well. They can be used to set setting values since 26.7 #108760 |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units1261 translation units recompiled, 7734 s compile time in total, 1261 of them have a recent master baseline. |
Centralize reset validation so SQL and Arrow Flight enforce constraints consistently, including readonly checks for existing custom settings. #115334
|
🕵 Reviewed query-parameter handling: both standalone |
|
@alexey-milovidov two more cases. The client can set settings via command line options. Is that also covered? What about distributed plans? I think settings are sent to remote nodes? |
…s-settings-constraints
The `readonly = 1` case of `05023_set_default_bypasses_settings_constraints` failed in CI: `readonly = 1` rejects every setting change, and the native client sends `send_logs_level` (and the test runner its randomized settings and `log_comment`) along with each statement, so one of those was rejected before the reset under test and the expected message never appeared. Do that check over HTTP with a session and a bare URL that carries nothing but the session id, so the only setting change in the request is the reset itself. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=115334&sha=5df0e26be9f9c6bacd206edbcd2b7f265303ecad&name_0=PR&name_1=Fast%20test PR: #115334
|
🕵 Checked both, and neither can carry a reset. Client command-line options. There is no Distributed plans. The wire format for settings is a list of name/value pairs; a reset has no representation there, so nothing resets a setting on a remote node. The initiator sends the values it ended up with, and after this change a reset that a constraint forbids never produces such a value in the first place — the statement is rejected before anything is applied. So the reset path is only reachable through |
…s-settings-constraints
|
🕵 Merged The single failure on @groeneai, please investigate the |
|
The fix is already merged: #114826 ( The abort is not on the new server. A concurrent Two consequences for this run:
Could you apply Two corrections to the CIDB reading. The master rows for that test name are all I have seen no recurrence since the merge (0 hits across 256 commits that ran this check), but that is ~24h against a base rate of about 9 events per 90 days here, so it is not yet meaningful. |
…settings constraints
Cherry pick #115334 to 26.5: Do not let SET <name> = DEFAULT bypass the settings constraints
…settings constraints
Cherry pick #115334 to 26.3: Do not let SET <name> = DEFAULT bypass the settings constraints
…settings constraints
Cherry pick #115334 to 26.6: Do not let SET <name> = DEFAULT bypass the settings constraints
…settings constraints
Cherry pick #115334 to 26.7: Do not let SET <name> = DEFAULT bypass the settings constraints
…settings constraints
Backport #115334 to 26.3: Do not let SET <name> = DEFAULT bypass the settings constraints
Backport #115334 to 26.5: Do not let SET <name> = DEFAULT bypass the settings constraints
Master gained an equivalent `SET <name> = DEFAULT` constraint check in #115334, under different names, so this branch no longer carries its own: * `SettingsConstraints::checkCanReset` is dropped for master's `SettingsConstraints::checkResetToDefault`. * `Context::checkSettingsConstraintsForDefaults` is dropped for master's `Context::checkSettingsConstraintsForSettingsReset`. * `Settings::getDefaultValue` is dropped; master reads the declared default from a local `Settings` instance instead. * The Arrow Flight reset branch and its test are master's. `src/Access/SettingsConstraints.*`, `src/Core/Settings.*`, `src/Interpreters/Context.*` and `src/Server/ArrowFlight/ArrowFlightServer.cpp` are now identical to master, and what is left is what master does not cover: * The constraint check on a `SETTINGS` clause nested in a subquery, a CTE or a view's inner query, in `QueryTreeBuilder::buildSelectExpression`. * The nested `SETTINGS <name> = DEFAULT` form, now checked through master's `checkSettingsConstraintsForSettingsReset`. * A setting assigned or reset after a `profile` change in the same `SET` statement. This is now `checkSettingsConstraintsAfterProfileChange`, a check on a scratch context that applies nothing, so it sits next to the two checks master already runs before the statement is applied and keeps the property that a rejected statement leaves the session untouched. Master's `05023_set_default_bypasses_settings_constraints` covers the top-level reset only, so `05019`, `05020` and `05021` stay.
Backport #115334 to 25.8: Do not let SET <name> = DEFAULT bypass the settings constraints
Backport #115334 to 26.6: Do not let SET <name> = DEFAULT bypass the settings constraints
Backport #115334 to 26.7: Do not let SET <name> = DEFAULT bypass the settings constraints
ACCESS: `SET <name> = DEFAULT` resets a constrained setting (e.g. readonly) to its built-in default -> security: settings constraints bypassed. Effect in the production build a394e92: reproduced by hand: `SET readonly = 2; SET readonly = DEFAULT` leaves readonly = 0 on the production build and 2 on official 26.8.8.8. Upstream patch unchanged, with its test(s): 05023_set_default_bypasses_settings_constraints. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ustom settings prefixes, reviewed dispatch sites, two open defects) The CAND4 (e7432ca) release gate reported, besides the open KD-D512-MIXED-GROUPBY-NULLABLE: - 3 skipped tests (04303, 04305, 04357: "no shard"): run_checks.sh passed --no-shard, a leftover from before the isolated server listened on 127.0.0.1-3 with the test clusters. Dropped, so clickhouse-test detects shard support from the server config as the triage runs do. - 05023 (ClickHouse#115334's test): the isolated server allowed only the custom_ settings prefix; it now allows SQL_,custom_ like the upstream test config (tests/config/config.d/custom_settings_prefixes.xml). isolated_ch.sh is vendored from the skill draft; VENDORED.sha256 updated. - 2 dispatch-scan candidates: the Int512 fast path of 7581066 (bothFitInt256/mulInt256Range); reviewed, not a gap. - 04411 (ClickHouse#108607's test): its three-index section recurses in equals() on every 26.3 build, including production and builds without the backport (FILE_DOESNT_EXIST, the bug ClickHouse#108607 fixes, is gone). New open KD-UP-TEXTINDEX-DIRECTREAD-3IDX (pre-existing upstream 26.3 bug, upstream fix not identified; workaround query_plan_direct_read_from_text_index = 0). - 04881 (ClickHouse#114624's test): its only differing line is the reference with the host name 'build' replaced by 'localhost' by clickhouse-test; the output is otherwise identical. New open KD-ENV-HOSTNAME-SUBSTITUTION (environment); the test and its reference are not edited. The fifth failure, 04409, is the missing dependency ClickHouse#106905 (previous commit). Registry: 147 entries, 3 open. Co-Authored-By: Claude Opus 5.5 <[email protected]>
SET x = DEFAULT restored the compiled default of x and ignored an active
compatibility setting, so the session reported the current version's default
while compatibility still claimed the old era - a state no new session with
the same compatibility could reach. That contradicts the documented contract
of compatibility ("only settings that have not been modified are affected"),
since after a reset the setting is by definition not modified.
SET x = DEFAULT is not a SettingChange: the parser puts the bare name into
ASTSetQuery::default_settings, and the reset reaches
BaseSettings::resetToDefault, which is not virtual. The whole chain therefore
bypasses SettingsImpl::set, the only compatibility-aware mutator and the sole
override of the single virtual in BaseSettings, so the derivation never re-runs.
SettingsImpl::resetToDefaultRespectingCompatibility resets and then calls the
existing applyCompatibilitySetting. Reading compatibility after the reset is
what makes SET compatibility = DEFAULT revert every setting it derived, with
no special case, because the value read is then the empty default. Calling the
existing walk rather than duplicating it filtered to one name keeps the reset
path from diverging from the fresh-session path, which matters because ClickHouse#114190
is editing that walk.
Only the four surfaces that implement SET <name> = DEFAULT are repointed;
every internal caller that wants the declared default keeps the raw reset.
Settings::setDefaultValue itself is deliberately not repointed: Connection.cpp
resets a setting purely to mark it unchanged so it is not resent and asserts
exactly that on the next line, and re-deriving assigns a value and so sets
changed, which was measured to fire that assert on an ordinary query whenever
the user profile activates compatibility. AsynchronousInsertQueue resets
async_insert to let the remote part decide, and async_insert has a live history
row, so re-deriving would take that decision away under compatibility <= 26.1.
MySQLHandler rewrites = DEFAULT to SQL text and re-enters the first surface, so
it is fixed with no edit.
SettingsConstraints::checkResetToDefault had to move with it. It was
centralized in ClickHouse#115334 on the premise that the defaults do not depend on the
session, which this change makes false: with a profile that both pins and
constrains a setting, the pin keeps it changed, compatibility leaves it alone,
and a reset would install the era value the constraint forbids. Measured on a
build carrying the reset change without this half, such a reset was accepted
silently and landed below the profile's declared minimum. The check now
replays the statement on a throwaway copy of the context the resets will
mutate and validates the values it lands on; enforcement stays on the checking
context, matching the ordinary-change check one line earlier, and the whole
statement is still left without effect on a violation.
Behaviour changes: a reset under an active compatibility now yields the era
value; SET compatibility = DEFAULT now reverts what it derived; and a reset
can now be rejected by a settings constraint where it previously succeeded.
Not addressed, pre-existing and wider: applyCompatibilitySetting writes through
BaseSettings::set, so SET compatibility = '<version>' installs era values for
every unchanged setting with no constraint check at all.
Closes: ClickHouse#116883
SET <name> = DEFAULTresets a setting rather than assigning to it, so it does not produce aSettingChangeand never reachedSettingsConstraints. Any constraint could therefore be escaped by resetting the setting instead of assigning to it:A
CONSTconstraint was just as escapable, and so was readonly mode, which is enforced by the same check:This describes the reset as the change it effectively is — to the value declared in the source code, which is what
Context::resetSettingsToDefaultValuerestores — and runs the usual check on it before anything is applied, so that a violation leaves the whole statement without effect. The in-querySETTINGS <name> = DEFAULTform goes through the same interpreter and is covered too.A reset that does not change the value is still allowed, because the check drops changes whose new value equals the current one. Resetting a setting that was never touched therefore keeps working under a
CONSTconstraint and in readonly mode — which is what CI profiles that pin a setting to its declared default rely on (max_parser_backtracksinlimit-recursion-settings.xml, for example). Settings without a declared default are unaffected: a custom setting is dropped rather than reset and cannot carry a constraint, and an unknown name stays silently ignored. The client only mirrors the reset into its own settings when the server accepted the statement, so its view does not drift.One consequence worth calling out: a profile that caps
max_threadsbelow the machine's core count now rejectsSET max_threads = DEFAULT, because the declared default resolves toauto(<cores>). That is the intended reading of the constraint, but it means the CI profiles that capmax_threadsat 128 would reject that reset on a machine with more than 128 cores.Verified locally against a build of this change: the four rejection paths above are rejected, the rejected statement leaves the value alone, and the no-op reset, custom-setting reset and unknown-setting reset all keep working.
04202_set_default_preserves_max_threads_autoand04078_settings_constraints_compatibility_conststill pass, and a sweep of every stateless test that uses= DEFAULTplus every test whose name mentions constraints/readonly/settings profiles produced no constraint or readonly error attributable to this change.Related: #115328
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a bypass of settings constraints:
SET <name> = DEFAULTreset a setting without checking the constraints from the user's profile, so aMIN/MAX/CONSTconstraint could be escaped by resetting the setting instead of assigning to it, and a session could leave readonly mode withSET readonly = DEFAULT.Workflow [PR]
Sync PR [sync-upstream/pr/115334]
Version info
26.8.1.1914(included in26.8and later)26.7.6.22,26.6.4.40,26.3.23.5