Repository navigation
Cherry pick #117406 to 26.8: Require the SOURCES grant for Disk(...) backup locations - #118091
Merged
Merged
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]>
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]>
`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 #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.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Require the SOURCES grant for Disk(...) backup locations
This was referenced Sep 4, 2026
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #117406
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job