Skip to content

Cherry pick #114405 to 26.5: Authorize backup destinations against the SOURCES grant model - #114743

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

robot-ch-test-poll2 wants to merge 7 commits into
backport/26.5/114405from
cherrypick/26.5/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

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