Skip to content

Cherry pick #122697 to 26.9: Fix restoring a lightweight snapshot from Azure when the source disk has a key prefix - #124254

Merged
hanfei1991 merged 11 commits into
backport/26.9/122697from
cherrypick/26.9/122697
Oct 6, 2026
Merged

hanfei1991 merged 11 commits into
backport/26.9/122697from
cherrypick/26.9/122697

Conversation

@robot-clickhouse

Copy link
Copy Markdown
Member

Original pull-request #122697

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.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

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

garrettthomaskth and others added 10 commits September 28, 2026 15:33
…has a key prefix

The snapshot manifest records the source disk's object namespace, which
for Azure is `<container>/<prefix>` when the disk endpoint has a path
below the container (`AzureObjectStorage::getObjectsNamespace`), while
S3 records only the bucket. The Azure `snapshot_reader_creator` used that
namespace verbatim as a container name, so the reader's container-level
existence check went to `.../<container>/<prefix>/?restype=container`
and Azure rejected it with `400 InvalidUri`.

Split the namespace into `container_name` and `endpoint.prefix`, mark the
container as existing, and keep a connection-string account URL as is.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Move the namespace split out of the Azure backup engine's snapshot reader
creator into `makeSnapshotSourceConnectionParams` in
`BackupIO_AzureBlobStorage`, and cover it with a gtest: a prefixed
namespace is split into container and prefix, a plain container namespace
is unchanged, the backup's own connection params are not mutated, and a
connection-string account URL is kept.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
With connection-string auth `createForContainer` builds the client from
the connection string and ignores `storage_account_url`, so the recorded
`original_endpoint` cannot be applied; leaving it unused would silently
read the backup's account instead of the snapshot's. Compare the recorded
endpoint with the connection string's blob endpoint (SDK-canonical,
trailing slashes ignored) and throw `BAD_ARGUMENTS` when they name
different accounts.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Review: the lightweight-snapshot code path it covers is used only in Cloud,
so the test stays in the Cloud repo (sync PR) instead.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ction string

Review: the same account is reachable through several hosts (a private link
alias, Azurite by IP or by host name), so comparing the manifest endpoint with
the connection string's blob endpoint as URLs rejected valid restores. Compare
the account names instead: the connection string's AccountName (or the account
its blob endpoint names) against the account the manifest endpoint names, the
first host label for `<account>.blob.<suffix>` and `<account>.privatelink.blob.<suffix>`
hosts or the first path segment of a path-style endpoint. A URL that does not
reveal its account, such as a custom domain, is let through and a wrong account
fails at the first read.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…pshot endpoints that reveal none

storageAccountOfURL took any non-empty path as a path-style account name, so a host-style endpoint
that carries a path, e.g. https://acct.blob.core.windows.net/container/data/, named `container` rather
than `acct`, and a restore from the backup's own account was rejected as a cross-account one. The host
is now consulted first (`<account>.blob|dfs.<suffix>` and the privatelink aliases), and the first path
segment is only taken as the account when the host names none, which is how Azurite endpoints look.

With connection-string auth an endpoint that does not reveal its account (a custom domain) was let
through on the assumption that a wrong account fails at the first read. It does not: the container is
marked as existing, so nothing probes the source, and another account with the same container and key
layout would be restored from silently. Such an endpoint is now rejected with BAD_ARGUMENTS as well.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Review: a `storage_account_url` is recorded verbatim and may be a proxy whose
path prefix is not an account, so the first path segment of an arbitrary URL
proves nothing. Take it only when the host is an IPv4 address or a bare name
(Azurite, localhost); any other host that is not an Azure one reveals no
account and the connection-string check rejects it as unverifiable, instead of
reporting a mismatch against a made-up account. An emulator reached through a
dotted host name is rejected the same way; by IP or by a bare name it still
compares by account.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
The connection-string branch tried to prove that the connection string's own
endpoint is equivalent to the recorded one (URL equality, then account names,
then host and path rules), and every rule had a shape it got wrong: host
aliases, hosts that reveal no account, proxy path prefixes, service paths that
CreateFromConnectionString() drops. Stop proving equivalence instead:
CreateFromConnectionString() takes the endpoint from the connection string
alone, so point the connection string at the recorded endpoint by replacing
its BlobEndpoint and let the key or SAS it carries authorise the reads there,
or fail with Azure's refusal if it belongs to another account. That is what
every other auth method and the S3 reader already do through
storage_account_url.

The recorded endpoint is reduced to a service URL first: query parameters (a
SAS of the source disk) are dropped, and an endpoint recorded as a connection
string (a source disk configured with one) is reduced to its blob endpoint.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…pshot-reader-namespace-prefix

Fix restoring a lightweight snapshot from Azure when the source disk has a key prefix
@robot-clickhouse robot-clickhouse 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 labels Oct 6, 2026
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-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