Repository navigation
Fix DROP WORKLOAD and DROP RESOURCE removing an entity of the other kind with Keeper workload storage - #131688
Conversation
…r kind Workloads and resources share one name space in `WorkloadEntityStorageBase::entities`, and `removeEntity` looked the name up without checking that the stored entity is of the requested kind. With Keeper workload storage (`workload_zookeeper_path`), `removeEntityImpl` rewrites the single znode without that name, so `DROP WORKLOAD cpu` removed the resource `cpu` and `DROP RESOURCE x` removed the workload `x`. The interpreters only check the privilege of the statement's own kind, so a user granted only `DROP WORKLOAD` could remove resources and vice versa. Disk storage was safe only because its file name is kind-specific (`workload_<name>.sql` / `resource_<name>.sql`), so the same statement failed with "Workload entity 'cpu' doesn't exist". Treat an entity of the other kind as missing in the base class, which every storage goes through: the statement now fails the same way on every storage, and `IF EXISTS` is a no-op. The check sits inside the retry loop, so it is re-done after a Keeper version conflict. The sibling write path `storeEntity` already rejects a kind mismatch for `CREATE OR REPLACE`. Reported by the AI review on ClickHouse#131653 (ClickHouse#131653 (comment)). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (round 1): CLEAN, no blocker or major
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261114-204102 |
|
Workflow [PR], commit [a4dfb87] Summary: ❌
AI ReviewSummaryThe PR adds a shared entity-kind check to Findings❌ Blockers
Tests
Missing context / blind spots
Final Verdict❌ Block. Make session renewal preserve the validation/version invariant and cover it deterministically. If this pre-existing path is deferred, link a dedicated tracking issue that explicitly records the remaining privilege bypass and stale-payload data loss. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 14 s compile time in total, 7 of them have a recent master baseline. |
… writing `WorkloadEntityKeeperStorage::storeEntityImpl` and `removeEntityImpl` serialized the definitions from the in-memory cache and only then called `getZooKeeper`. When the cached session had expired, `getZooKeeper` opened a new one and `refreshEntities` replaced the cache and advanced `current_version` to the znode's current version, so the following `trySet(..., current_version)` passed its version check and committed the payload built from the stale cache: definitions written by other replicas meanwhile were deleted (or a dropped workload resurrected), and the validation in `WorkloadEntityStorageBase::storeEntity/removeEntity` (references, cycles, parent kind, unique resources) had run against the stale cache as well. Call `getZooKeeper` first and return `OperationResult::Retry` when it changed `current_version`, so the caller re-runs the validation on the refreshed state (the same contract the `ZBADVERSION` path already uses); serialize only after that check. The integration test expires the Keeper session of `node` with `SYSTEM RECONNECT ZOOKEEPER` right after its watching thread refreshed (it then sleeps for up to 10 s and ignores SESSION events), lets `node2` change the definitions, and runs a DDL on `node` as the first user of the new session: `DROP WORKLOAD` must see the new child, `CREATE WORKLOAD` must keep `node2`'s definition. Related: ClickHouse#131688 Co-Authored-By: Claude Opus 5.5 <[email protected]>
7615344
Backport #131688 to 26.10: Fix `DROP WORKLOAD` and `DROP RESOURCE` removing an entity of the other kind with Keeper workload storage
Backport #131688 to 26.9: Fix `DROP WORKLOAD` and `DROP RESOURCE` removing an entity of the other kind with Keeper workload storage
Backport #131688 to 26.8: Fix `DROP WORKLOAD` and `DROP RESOURCE` removing an entity of the other kind with Keeper workload storage
Backport #131688 to 26.3: Fix `DROP WORKLOAD` and `DROP RESOURCE` removing an entity of the other kind with Keeper workload storage
…OURCE` removing an entity of the other kind with Keeper workload storage
Related: #131653
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
DROP WORKLOADremoving a resource with the same name andDROP RESOURCEremoving a workload with the same name when workload entities are stored in Keeper (workload_zookeeper_path). A user with only one of the two privileges could remove the other kind of entity.Description
On 26.8 LTS (26.8.37.168, also 26.3.63.123) with
workload_zookeeper_pathset, a user granted onlyDROP WORKLOADcan runDROP WORKLOAD cpuand remove the resourcecpu, and a user granted onlyDROP RESOURCEcan remove a workload the same way. The definition is gone from Keeper for every replica. Found by the AI review of #131653 (comment).Workloads and resources share one name space, and
WorkloadEntityStorageBase::removeEntitylooked the name up without checking the kind of the stored entity. The Keeper storage then rewrites its single znode without that name. The interpreters check only the privilege of the statement's own kind. Disk storage was not affected only because its file names are kind-specific.removeEntitynow treats an entity of the other kind as missing, for every storage: the statement fails withWorkload entity 'x' doesn't existandIF EXISTSis a no-op, which is what disk storage already did.storeEntityalready rejects a kind mismatch forCREATE OR REPLACE.The new test in
test_scheduler_io(Keeper-backed) fails without the fix and passes with it (20/20); the rest oftest_scheduler_io,test_backup_restore_workload_entitiesand the workload stateless tests pass.#122761 (still open) rewrites this function with
{kind, name}keys and would remove the bug on master with the same behaviour; this one-line change is the version that can be backported.Workflow [PR]
Sync PR [sync-upstream/pr/131688]
Version info
26.11.1.2475-master(included in26.11and later)26.10.5.44,26.9.31.10,26.8.39.9,26.3.66.11