Repository navigation
Require the SOURCES grant for Disk(...) backup locations - #117406
Conversation
BackupFactory::createBackup authorizes a backup location through the per-engine SourceAccessFn hook, but the Disk engine's hook returned std::nullopt and checkSourceAccess early-returns on nullopt, so a Disk(...) location was never authorized. The sibling File engine demanded READ/WRITE ON FILE from the same shared creator_fn and resolveLocalBackupLocation, so only the authorization differed. backups.allowed_disk is an operator-wide allowlist rather than a per-user authorization, so a user holding BACKUP on their own database with SOURCES revoked could restore an operator's backup and read rows they were denied SELECT on. The exemption was justified by an allowlisted disk being local, S3- or Azure-backed, so that no single existing Source describes it. That is true, but the conclusion should have been to give the locator a source of its own rather than to skip the check. Two narrower alternatives were rejected on measurement. Deriving the source from the backing store fails twice over: getDataSourceDescription() reports only the local location while DiskObjectStorageTransaction forks writes to every enabled location, and it is node-local, so it cannot authorize ON CLUSTER (worker hosts do not re-run the check under the initiating user, since distributed_ddl_use_initial_user_and_roles defaults to false). Reusing Source::FILE would conflate independent capabilities, letting a user granted only READ ON FILE read every allowlisted backup disk including object-storage-backed ones. A whole-source Source::DISK target is a pure function of the query text, so it is identical on every host and independent of the disk's class, location set and future ObjectStorageType growth. It is whole-source because a disk name is not a URI. Since the lambda ignores its BackupInfo, authorization now strictly precedes location resolution, so checkDiskName and checkPath cannot leak allowlist membership to an unauthorized user, and checkSourceAccess stays free of I/O. GRANT SOURCES ON *.* covers the new source automatically, because AccessRightsElement::replaceDeprecated maps SOURCES to READ | WRITE with no parameter, so only users holding specific per-source grants need the new one. The Disk arms shipped in 04774 pinned the exemption as correct and are replaced, since the behaviour intentionally changed; the File arms are unchanged. 04775 is a uniformity guard over an S3-backed disk: the requirement provably cannot vary by backing store, so it exists to stop a future change special-casing object storage, and it asserts that READ ON S3 does not authorize an S3-backed backup disk. Co-Authored-By: Claude Opus 5 <[email protected]>
Disk('backups', ...) is the locator almost every existing backup test uses,
so making READ/WRITE ON DISK a prerequisite changes what those tests need.
Seven shipped tests back up or restore as a restricted user through such a
locator and would have failed: the integration suites test_backup_restore_new
(16 sites, its new_backup_name() returns a Disk(...) locator for the whole
file) and test_backup_restore_on_cluster (11 sites), plus the stateless
04027, 04401_remote_storage_engine_restore_access,
04489_remote_storage_engine_restore_tf_access,
04401_url_engine_s3_dispatch_engine_grant and
03315_query_log_privileges_backup_restore.
Each user gets the explicit direction its test needs, granted right after the
user is created. That placement preserves every message the tests already
assert: BACKUP checks the table-level privilege before opening the backup, so
its source denial would have arrived after the object-level one, while RESTORE
opens the backup before checking access for the objects inside it, so its
source denial would have arrived first and displaced the assertion. The
per-direction grant is deliberate rather than GRANT SOURCES ON *.*, which
confers every source and could mask an unrelated assertion. In
test_backup_restore_on_cluster the grant is repeated after REVOKE ALL, which
takes it away again.
Two of the assertions would have become vacuous rather than failing, because
their matchers are broad enough to accept the outer-locator denial in place of
the inner authorization they were written to test: 04027's grep for
ACCESS_DENIED and 04401_remote's grep for ACCESS_DENIED or Not enough
privileges. Both were replayed by hand to confirm they still fail for their
original reason, and a control with the grant removed shows the reason
changing to the DISK denial.
03315 needs no grant, since its user receives current grants from default and
so retains SOURCES. Its reference changes instead: a source grant a
BACKUP/RESTORE consumes is recorded in used_privileges, which 04774's own
audit arm already pins. The values are the observed output, and under a mutant
that keeps the new AccessType but reverts the lambda they collapse back to the
previous reference exactly, so the change is the behaviour and nothing more.
04775's no-replicated-database reason was inherited from 04774, where it is
accurate because of its Backup-engine arm; this file has none. The tag is kept
because the claim could not be settled: the DatabaseReplicated job's cluster
needs a Keeper ensemble across several servers, and under a single-server
stand-in 04774 passes without its tag too, so the control cannot discriminate.
Only the inaccurate mechanism is removed from the comment.
Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex) plus my own cold review of the
Resolved in the PR body before publication, so not listed above: the changelog entry now names the Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-48:20260831-200600 |
|
Workflow [PR], commit [4157d27] Summary: ❌
AI ReviewSummaryThis PR correctly wires top-level Findings❌ Blockers
Tests
Final VerdictChanges requested. The top-level LLVM Coverage ReportMeasured on commit 4157d27.
Changed lines: Changed C/C++ lines covered: 37/37 (100.00%) · Uncovered code |
Pre-PR validation gate (click to expand)
Anti-vacuity: with the Session id: cron:clickhouse-impl-slot-5:20260831-172900 |
|
cc @pufit @hanfei1991, could you review this? #114405 left the |
| auto disk_source_access_fn = [](const BackupInfo &, ContextPtr, IBackup::OpenMode open_mode) | ||
| -> std::optional<BackupFactory::SourceAccessTarget> | ||
| { | ||
| return BackupFactory::SourceAccessTarget{ | ||
| AccessTypeObjects::Source::DISK, "", backupSourceAccessFlagsForWriterUnlock(open_mode)}; |
There was a problem hiding this comment.
This still leaves a RESTORE ... ON CLUSTER bypass for incremental chains whose outer backup is readable but whose .backup metadata carries base_backup = Disk(...). checkAccessToExplicitBaseBackup() only preflights the query setting; when the base locator comes from the manifest, the initiator's CHECK_ACCESS_ONLY pass can succeed without opening it if the incremental layer already contains the .sql metadata. The actual base is then opened lazily in BackupImpl::getBaseBackupUnlocked() on the internal DDL worker context, which by default has no user, so this new READ ON DISK check runs with full access.
Could we authorize the metadata-carried base locator under the initiating user too, and add a focused regression here (for example: outer backup on File(...) or S3(...), base backup on Disk(...), metadata changed so the outer layer keeps the .sql, then RESTORE ... ON CLUSTER without READ ON DISK)?
There was a problem hiding this comment.
I am not folding this into this PR. Two measurements rather than a scope argument alone.
It is not introduced here. git diff fb85d8ee6e8a..HEAD -- src/Backups/BackupsWorker.cpp src/Backups/BackupImpl.cpp is empty, and both halves of the mechanism predate this branch. checkAccessToExplicitBaseBackup, with the is_internal early return and the restore_settings-only input you describe, arrived in 02289ea070a2f14; the lazy base open in BackupImpl::getBaseBackupUnlocked arrived in 37a9e8143b5a3ba. Both are ancestors of the base fb85d8ee6e8a.
It is also not Disk-shaped. That lazy open calls BackupFactory::createBackup, which runs checkSourceAccess for whichever engine the locator names. Six engines register such a hook, and the File, S3 and AzureBlobStorage hooks all landed in 02289ea070a2f14 as well, so a cross-engine chain reaches the same code with no Disk locator involved. This change is also strictly additive: one hook moves from std::nullopt, meaning no check at all, to returning a target, so it can only cause more locators to be authorized than before, never fewer.
I did not reproduce the clustered path, so I am not claiming your mechanism is wrong. I am claiming it is neither new nor specific to this diff, which is what decides whether it belongs here. The base-chain and retained-consumer area was deliberately left out of #114405 by @ pufit, so widening into it is not something I should decide alone, and a fix there would land in files this PR does not touch.
Recording it in this thread rather than in the description, since it is a property of the merged design rather than of this change.
GRANT READ ON Disk failed with a syntax error while GRANT READ ON DISK worked. Source names are matched case-sensitively: AccessTypeObjects validate() looks the name up in a std::map that holds the stringified enumerator plus the aliases declared in APPLY_FOR_SOURCE, and DISK declared none. Every other source whose user-facing name differs from its enumerator registers that name (File, PostgreSQL, AzureBlobStorage, and so on), and the ones with no alias are initialisms already spelled in uppercase (URL, S3, HDFS, ODBC, JDBC, NATS). DISK was the only non-initialism missing one, even though Disk(...) is exactly how the locator is written in BACKUP and RESTORE, so the natural spelling was the one that failed. The alias only widens the accepted input. unifySource normalizes it, so the grant is stored and displayed as DISK, and REVOKE READ ON DISK removes a grant made as Disk. system.privileges is unchanged, because its aliases column is built from the AccessType enum rather than from this table, so no privilege reference moves. Co-Authored-By: Claude Opus 5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units504 translation units recompiled, 3582 s compile time in total, 504 of them have a recent master baseline. |
`Stateless tests (amd_asan_ubsan, flaky check)` failed this PR's head with `Test runs too long (> 180s)` on 04774: 5 of 5 recorded runs over the gate (183.76 to 190.85 s), no passes. That gate is per test file and fires only in flaky-check mode (tests/clickhouse-test:3630-3646). The cost is per client process, not per statement. 04774 was 49 client invocations at 132.0 s p50 in ClickHouse#114405's slowest asan flaky-check job and is 75 here at 185.2 s p50: 2.69 and 2.47 s per invocation. Four interleaved local pairs give 0.179 s per invocation on all three arms. So the Disk section moves to 04776 with its own fixture, at 37 invocations. 04774 keeps the File coverage at 46 invocations, below the 49 it shipped with, and its change is a pure deletion: the two arms that asserted the old `Disk` exemption, plus the locator and admin backup only those arms used. The moved block is verbatim apart from the local database identifier and one added arm: `ENGINE = Backup` over a `Disk(...)` locator was asserted only in the denied direction, here and before the split, so a regression that stopped granting the new source on that path would not have been caught. `RESTORE` had that positive arm already. Equivalence is byte-exact rather than argued: dropping the two lines the new arm prints from 04776's reference and reinserting the rest at the seam in 04774's reproduces the published 04774 reference. With the `Disk` source hook reverted to `std::nullopt`, 04776 fails on 7 lines and 04774 passes; with it made to demand `WRITE` unconditionally, 04776 fails on the two positive arms.
Flaky-check runtime fix
So the The added arm is |
CI finish ledger - c30ed77Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
One Session id: cron:our-pr-ci-monitor:20260901-093000 |
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
CI finish ledger -
|
| Check / test | Reason | Owner / fixing PR |
|---|---|---|
Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) / Container memory budget exceeded (/docker) |
the shard's nested containers breach the /docker cgroup leaf, the kernel OOM-kills processes inside it and the job errors with no test attributed |
#117412 (external, merged 2026-09-01T11:31:33Z) |
Docs examples / Documentation examples |
the documented output of Function/toYYYYMM#0 was pinned to 202608, so the example self-broke at the month boundary |
#117459 (mine, merged 2026-09-01T13:55:50Z) |
Bugfix validation (functional tests and integration tests, amd64 / aarch64), Finish Workflow / Post Hooks |
both per-arch jobs abort on assert build_urls, "Could not find master builds in S3", so nothing could validate and new_tests_check.py then reds the post hook |
#117433 (mine, open) |
Performance Comparison (arm_release, master_head, 2/6) / Check Results |
10 errors, 8 too long: the report's error summary names insert_statistics_uniq_v2 and group_by_dynamic_keys as too slow to run as a whole, and one query of the latter as too slow to run, which aborts the shard |
#117447 (mine, open) |
The /docker breach is a job-level condition, not a test result. I measured #117412 ABSENT from the tree that ran, from the job's own environment rather than from git ancestry: this job was launched with CI_DIND_INIT_RESERVE=17179869184 (the 16 GiB share #117412 replaces), and so were all ten failing legs I read this tick. The probe discriminates, with a positive control: two shards launched at 14:53Z and 14:59Z carry CI_DIND_INIT_RESERVE=8589934592 (the flat 8 GiB reserve #117412 introduces) and both passed. So this is rule 3c and not rule 3d, and #117411 is not a co-owner: it was closed unmerged at 11:11:48Z in favour of #117412, whose own diff comment states the causal link.
The docs example is a trunk-wide, date-dependent break, not something specific to this PR: 226 distinct pull requests and 10 true-master runs carry it. I measured #117459 ABSENT from the tree that ran, from the failure text itself: the reported query is still the old toYYYYMM(now(), ...) form, and the string the fix introduces appears in 0 of the 164 Docs examples failure rows recorded in the last day. The control is master's own line - Docs examples is FAIL at d8aa6cab7800, which is 4 commits behind the fix and has 0 occurrences of the new string, and OK at 8627fa22f015, which is the fix's own merge commit.
The perf row is a harness condition, not a regression from this diff, which changes access checks for backup destinations and cannot alter how long a statistics or GROUP BY fixture takes to create and fill. #117447 bounds a profile run by the --profile-seconds budget it was given and catches TIMEOUT_EXCEEDED, which is the query-blows-the-cap half; #116491 (mine, open) is the reporting half that turns one failing perf test into the bare 10 errors label. Note there are 0 test-level rows for this check family in 7 days, so the condition exists only in the job result and its HTML report.
I have not merged master to pick those fixes up yet. It would not clear Mergeable Check on this head, because the Bugfix validation abort and the perf harness row both remain, and none of those fixes is merged, so a merge now would cost a full CI cycle and leave the head red on the same count. One master merge picks everything up once the remaining fixes land.
Mergeable Check reports Failed: 4 at this head, which counts only the jobs it gates on. The table above is the complete non-OK, non-SKIPPED node set of the head's praktika report, so it also covers the rows Mergeable Check does not gate.
CH Inc sync was pending at this head.
Session id: cron:our-pr-ci-monitor:20260901-163000
9061229
|
@nikitamikhaylov this PR should be backported as well maybe |
`GRANT READ ON DISK` is a syntax error on a branch without #117406, which is what made a Disk(...) backup location require it. No release branch has that source yet, and without it the location is not checked at all, so the grant is only needed where the privilege exists.
`GRANT READ ON DISK` is a syntax error on a branch without #117406, which is what made a Disk(...) backup location require it. No release branch has that source yet, and without it the location is not checked at all, so the grant is only needed where the privilege exists.
`GRANT READ ON DISK` is a syntax error on a branch without #117406, which is what made a Disk(...) backup location require it. No release branch has that source yet, and without it the location is not checked at all, so the grant is only needed where the privilege exists.
`GRANT READ ON DISK` is a syntax error on a branch without #117406, which is what made a Disk(...) backup location require it. No release branch has that source yet, and without it the location is not checked at all, so the grant is only needed where the privilege exists.
Backport #117406 to 26.8: Require the SOURCES grant for Disk(...) backup locations
A `Disk(...)` backup location is now authorized against the DISK source (ClickHouse#117406): the Disk backup engine's SourceAccessFn returns a real SourceAccessTarget, so writing a backup demands `WRITE ON DISK` and reading one demands `READ ON DISK`. This test's user holds neither, so after merging master every statement it issues as that user stopped at the location check before reaching the materialized-view target logic under test: six `allowed` lines flipped to `denied`, both assertions that the denial names the target went 1 -> 0, and the TimeSeries arm reported `forge failed`. Grant both halves to the test user, the spelling ClickHouse#117406 used for its own tests. The DISK source says nothing about a view target, so the oracle is unchanged: with the grants in place the forged restore is denied with `SELECT, INSERT ON <db>.dst` again, and with the RestorerFromBackup change reverted the same test file still fails on six assertion lines.
Related: #114405
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
BACKUP ... TO Disk(...),RESTORE ... FROM Disk(...)andCREATE DATABASE ... ENGINE = Backup(..., Disk(...))now authorize the location against the user'sSOURCESgrants, like the other backup engines already do. A newDISKsource is added for this: writing needsWRITE ON DISKand reading needsREAD ON DISK. Previously aDisk(...)location was subject to no access check at all, so a user holdingBACKUPbut notSOURCEScould write a backup to, and read one from, any disk listed inbackups.allowed_disk. Users grantedSOURCESare unaffected; a user who holdsBACKUPwithoutSOURCESand uses an allowlisted disk must now be grantedREAD/WRITE ON DISK.Description
#114405 made each backup engine declare the grant its location requires, checked in
BackupFactory::createBackupbefore any I/O. TheDiskengine was left returningstd::nullopt, andcheckSourceAccessearly-returns onnullopt, soDisk(...)locations were never authorized, while the siblingFileengine demandedREAD/WRITE ON FILE. Both engines sharecreator_fnandresolveLocalBackupLocation; only the authorization differed.backups.allowed_diskis an operator-wide allowlist, not a per-user authorization, so a user withBACKUPon their own database andSOURCESrevoked could restore an operator's backup.#114405 exempted
Diskbecause an allowlisted disk may be local, S3- or Azure-backed, so no single existingSourcedescribes it. Deriving it from the backing store does not work:getDataSourceDescription()reports only the local location of a multi-location disk and is node-local, so it cannot authorizeON CLUSTER. A whole-sourceDISKtarget is a pure function of the query text, identical on every host; whole-source because a disk name is not a URI.GRANT SOURCES ON *.*covers it automatically, so admin grants need no update.04776_backup_disk_source_grantscovers both directions on the local-backed disk and pins that neither grant authorizes the other locator;04775_backup_disk_source_grants_object_storagerepeats that on an S3-backed disk and assertsREAD ON S3does not authorize it.04774_backup_destination_source_grantskeeps theFilecoverage, less the two arms that asserted the old exemption.Disk('backups', ...)is the locator most existing backup tests use, so the suites that back up as a restricted user are updated:test_backup_restore_new,test_backup_restore_on_clusterand five stateless tests. Azure- and HDFS-backed disks are uncovered: CI has no allowlisted disk of those types and the requirement does not depend on the type.Workflow [PR]
Sync PR [sync-upstream/pr/117406]
Version info
26.8.3.37