Skip to content

Cherry pick #114405 to 26.7: Authorize backup destinations against the SOURCES grant model - #114745

Closed
robot-ch-test-poll2 wants to merge 7 commits into
backport/26.7/114405from
cherrypick/26.7/114405
Closed

robot-ch-test-poll2 wants to merge 7 commits into
backport/26.7/114405from
cherrypick/26.7/114405

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #114405

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 7 commits August 11, 2026 23:18
BACKUP, RESTORE and ENGINE = Backup never authorized the backup location
against the user's SOURCES grants, unlike the matching table functions
(s3(), file(), azureBlobStorage()). A user holding BACKUP but not SOURCES
could therefore write a backup to, and read one from, any location the
server can reach.

Each backup engine now declares the SOURCES grant its location requires
through a SourceAccessFn registered with BackupFactory. The check performs
no I/O, so besides running in createBackup() before the creator opens
anything, it also serves as a preflight at each place that is the last
point still executing as the real user:

  - BackupsWorker, for an explicitly requested base_backup: a base opens
    lazily and on the workers, so on ON CLUSTER the initiator may never
    open it at all. Measured without this preflight, a RESTORE by a
    SOURCES-revoked user succeeds and returns the base backup's rows.
  - InterpreterCreateQuery::execute, because is_create_database returns
    from executeQueryOnCluster before DatabaseFactory runs.
  - RestorerFromBackup::checkAccessForObjectsFoundInBackup, for an
    ENGINE = Backup definition embedded in a restored manifest. Under
    CHECK_ACCESS_ONLY the creating host is a different one, so a local
    existence answer cannot stand in for it.
  - registerDatabaseBackup, for a newly introduced definition rather than
    one replayed from this server's own metadata.

Per-engine dispositions: S3 and AzureBlobStorage authorize a
regex-filterable URI normalized the same way ITableFunction does, and both
route UNLOCK through a reader. File requires the whole-source FILE grant,
matching file(), which has no path-filter semantics; path containment
remains the operator's backups.allowed_path. Disk is exempt because an
allowlisted disk may be local, S3- or Azure-backed, so no single Source
describes it, and backups.allowed_disk already bounds it. Memory and Null
have no external location.

A named collection is authorized whole-source rather than on the URL it
currently resolves to, since it can be re-pointed after the check. It is
still resolved, because that is where NAMED_COLLECTION is enforced.

Each of the five check sites was verified by reverting it alone and
confirming a test reddens.
A user holding BACKUP but not the matching SOURCES grant now gets
ACCESS_DENIED, so the requirement has to be discoverable. The backup
overview gains a table of the required direction per destination, the
regex-filter and named-collection behaviour, the Disk exemption and the
controlling server setting; the SOURCES grant reference no longer claims the
privilege applies only to table engines and table functions; and the Backup
database engine's own documentation states its READ requirement.
Two mistakes in the section added by the previous commit. The check does not
depend on enable_read_write_grants: that setting selects between the
READ/WRITE split and the legacy whole-source syntax, and the location is
authorized either way, so the note now describes the legacy spelling instead
of implying the check can be turned off. And an AZURE filter is matched
against the blob path inside the container, not a URL carrying the account
and container, which is the same string the azureBlobStorage table function
authorizes; verified by granting WRITE ON AZURE('backups/.*') and observing
that a backup to backups/az1 is allowed while other/az2 is denied.
The Azure case only granted whole-source privileges, so it would have passed
even if the hook always returned an empty URI: an empty URI can only be
satisfied whole-source, so the case could not distinguish a working filter
from no filter at all. It now grants a path-filtered privilege and asserts
both the matching and the non-matching destination, which also pins which
string the filter is matched against - the blob path inside the container,
the same one the azureBlobStorage table function authorizes.

Neither engine had an archive locator, so the field that captures the URI
before a trailing archive filename is stripped from it was untested. The new
S3 case grants exactly the archive path and asserts that a sibling archive in
the same directory is refused. Verified as a live oracle: authorizing the
stripped URI instead makes it fail.
Requested by the reviewer. The backup/restore overview section, the SOURCES
grant reference edit and the Backup engine's own note are all removed, so the
change carries source and tests only. The grant reference linked the anchor the
overview section defined, so keeping either alone would leave a dangling link.
BackupStarter runs the new destination check on a copy of the query context,
and makeQueryContext resets that copy to a fresh QueryPrivilegesInfo, so the
grant the check consumed never reached system.query_log. RestoreStarter already
shares the originating tracker for exactly this reason; the BACKUP side now does
the same.

Measured on a single node with an audit user granted BACKUP and WRITE ON FILE:
used_privileges was ['BACKUP ON default.t'] before and
['WRITE ON FILE','BACKUP ON default.t'] after. The stateless test asserts it,
and removing the line flips that assertion alone.
…source-grants

Authorize backup destinations against the SOURCES grant model
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Aug 14, 2026
@groeneai

Copy link
Copy Markdown
Collaborator

All five cherry-picks (#114741 25.8, #114742 26.3, #114743 26.5, #114744 26.6, #114745 26.7) conflict for one reason: #110610 ("Add factory-owned backup destination identity", merged 2026-07-23) is on master but is an ancestor of no release branch. #114405 builds directly on it. The RegisteredEngine struct and the destination_identity_fn parameter of registerBackupEngine both come from #110610, and #114405 adds source_access_fn alongside them. getDestinationIdentity has 37 hits on master and 0 on all five release branches.

What I measured, reproducing the automation's merge shape (merge-tree --merge-base=<merge commit>^1 <branch> <merge commit>):

branch conflicts now with #110610 applied first
26.7 7 files 0, clean
26.6 7 files #110610 itself conflicts (3 files)
26.5 8 files same
26.3 9 files same
25.8 9 files same

The synthesized 26.7 tree is not vacuous: it carries checkSourceAccess, BackupSourceAccess.h and 04774_backup_destination_source_grants.sh, with no conflict markers.

On the older four, #110610 itself conflicts in registerBackupEngineS3.cpp, registerBackupEngineAzureBlobStorage.cpp and registerBackupEnginesFileAndDisk.cpp, because the S3 credential-restriction series it sits on (3b7f7be, 5ba2141, 664299b, 75ca869, 4273b1b) is present on 26.7 only.

Not blockers: the SOURCES grant API (AccessTypeObjects, checkAccessWithFilter) is present on all five branches, test number 04774 is free on all five, and #114405 does not touch SettingsChangesHistory.cpp.

@pufit, your call, since I will not hand-resolve release branches or push to the robot's branches:

  1. Label Add factory-owned backup destination identity #110610 for backport first, then recreate these. 26.7 then lands with no manual resolution.
  2. Or narrow to v26.7-must-backport and close the other four.
  3. For 25.8/26.3/26.5/26.6, the question is whether the prerequisite series is wanted there at all. It is a behaviour change that starts rejecting backups a user could previously run.

One clock worth noting: the automation pings after 3 days of inactivity and closes these PRs automatically after 7.

@pufit

pufit commented Aug 14, 2026

Copy link
Copy Markdown
Member

@groeneai should we revert #114405 PR and redo it so it would be easy backportable? How hard is it to do?

@groeneai

Copy link
Copy Markdown
Collaborator

@pufit reverting #114405 would not make it backportable. The blocker is not its shape: #110610 ("Add factory-owned backup destination identity", merged 2026-07-23) is an ancestor of no release branch and has no backport label, and #114405 adds source_access_fn next to the destination_identity_fn parameter and RegisteredEngine struct that #110610 introduced. On a branch without #110610, the context my change sits on does not exist. Re-measured against the current tips: 9/9/8/7/7 conflicts on 25.8/26.3/26.5/26.6/26.7.

26.7 needs no redo at all. #110610 applies there cleanly, and with it applied #114405 merges with zero conflicts, producing a tree that carries checkSourceAccess, BackupSourceAccess.h and test 04774 with no conflict markers.

The other four are harder for a reason unrelated to #114405: #110610 itself conflicts there in the three registerBackupEngine* files, because the S3 credential-restriction series it builds on is present on 26.7 only.

On how hard a redo would be: the conflict surface is confined to the engine-registration plumbing. Holding those seven files at their pre-#114405 content, the rest of the change merges with zero conflicts on 26.6 and 26.7, and one or two on 26.5, 26.3 and 25.8. So a variant that registers the per-engine source-access callback separately, rather than as a fourth parameter of registerBackupEngine, should avoid the collision. I have not built it, so I will not call it easy, and it would leave release branches with a different implementation from master.

What I would do instead: label #110610 for backport and let the robot recreate these, which gets 26.7 with no manual resolution, or narrow #114405 to v26.7-must-backport and close the other four. A revert costs the fix on master while a rewrite is developed, and does not remove the prerequisite. If you want 25.8/26.3/26.5/26.6 specifically, tell me and I will write the adapted variant against the pre-#110610 factory API.

This branch was successfully deployed

1 active deployment
staging - docs — 0eb65899 Deployed Aug 14, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants