Skip to content

Add normalized backup destination identity - #109083

Closed
pamarcos wants to merge 41 commits into
ClickHouse:masterfrom
pamarcos:backup-normalized-destination-identity-public
Closed

pamarcos wants to merge 41 commits into
ClickHouse:masterfrom
pamarcos:backup-normalized-destination-identity-public

Conversation

@pamarcos

@pamarcos pamarcos commented Jul 1, 2026 •

Copy link
Copy Markdown
Member

Adds BackupInfo::toNormalizedString and BackupInfo::freezeNamedCollection.

The normalized string is a deterministic, credential-free identity for a backup
destination. It normalizes S3, AzureBlobStorage, Disk, and File backup
destinations, excludes credential-only positional arguments and credential-only
key-value overrides, includes non-credential named-collection overrides that can
change the destination, and can resolve named collections with a Context when
needed.

This is infrastructure for deterministic resumable BACKUP FROM SNAPSHOT
identity in follow-up changes. There are no callers yet, so this PR does not
change user-visible backup behavior.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not for changelog.

Add `BackupInfo::toNormalizedString`, which produces a deterministic identity
string for a backup destination. `S3` identities are built from parsed URI
fields, `AzureBlobStorage` connection strings are normalized per component, and
`Disk` and `File` destinations normalize paths. Credential-only arguments and
credential key-value overrides are excluded from the identity.

Add `BackupInfo::freezeNamedCollection` to materialize named collection
arguments so the identity stays stable if the collection changes later. This is
infrastructure for resumable `BACKUP FROM SNAPSHOT`; it adds no callers and does
not change backup behavior.
@clickhouse-gh

clickhouse-gh Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [66f12f2]

Summary: ❌

job_name test_name status info comment
Build (arm_tidy) FAIL
Build ClickHouse FAIL cidb
Fast test (arm_darwin) DROPPED
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_debug) DROPPED
Build (arm_asan_ubsan) DROPPED
Build (arm_tsan) DROPPED

AI Review

Summary

This PR adds normalized, credential-free backup-destination identities plus named-collection freezing for future resumable snapshot work. Most of the earlier destination-alignment problems have been fixed, but one credential-redaction invariant is still inconsistent with the new logic: case-insensitive or ignored S3 override spellings are stripped from toNormalizedString yet can still be written verbatim into .backup metadata via withoutS3Credentials, so the patch is not ready to merge as-is.

Findings

❌ Blockers

  • [src/Backups/tests/gtest_backup_info.cpp:690] The PR now classifies S3 credential overrides case-insensitively for normalized identities, but BackupImpl still persists <base_backup> through BackupInfo::withoutS3Credentials, and that helper removes only exact lowercase spellings (src/Backups/BackupInfo.cpp:1088-1104). S3(collection, ACCESS_KEY_ID='KEYID') therefore still serializes KEYID into .backup, and the same exact-case gap leaves ignored URL= overrides able to persist presigned or userinfo secrets.
    Suggested fix: reuse the same lowercase credential-key classification (and url-key handling) in withoutS3Credentials, then add a focused regression asserting that case-mismatched ACCESS_KEY_ID and URL values are absent from the serialized base-backup locator.
Final Verdict
  • Status: ⚠️ Request changes

@pamarcos
pamarcos requested a review from Copilot July 1, 2026 18:25
@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Jul 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds infrastructure to compute a deterministic, credential-free “normalized identity” string for backup destinations (BackupInfo::toNormalizedString), including optional resolution of named collections (and a way to freeze them) to support future deterministic/resumable BACKUP FROM SNAPSHOT identity.

Changes:

  • Added BackupInfo::toNormalizedString (with and without ContextPtr) plus normalization helpers for S3/Azure/Disk/File destinations.
  • Added BackupInfo::freezeNamedCollection and a frozen_named_collection field to allow resolving named collections once and reusing the resolved collection.
  • Expanded gtest_backup_info coverage for normalization behavior (credential elision/redaction, canonicalization, context validation).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/Backups/BackupInfo.h Extends BackupInfo API with normalized identity methods and named-collection freezing support.
src/Backups/BackupInfo.cpp Implements normalization logic for backup destinations, including optional context-based validation and named-collection resolution.
src/Backups/tests/gtest_backup_info.cpp Adds gtest coverage for normalized identity determinism, credential redaction, and context-dependent validation.

Comment thread src/Backups/BackupInfo.cpp Resolved
Comment thread src/Backups/BackupInfo.cpp Resolved
Comment thread src/Backups/BackupInfo.cpp Resolved
Comment thread src/Backups/BackupInfo.cpp Resolved
pamarcos added 4 commits July 1, 2026 18:41
Strip arbitrary query parameters from direct `S3` backup URLs before parsing the
destination identity, while preserving `versionId`. This keeps non-presigned
query parameters out of the normalized identity and fixes the Fast test build
where the fragment helper was unused without `USE_AWS_S3`.
Apply the same query normalization to `S3` named-collection paths as direct
`S3` URLs. Only `versionId` affects the normalized identity; arbitrary query
parameters are ignored so they cannot leak into the identity string.
Use `std::filesystem::path` joining when resolving `S3` named-collection paths,
matching `registerBackupEngineS3`. This keeps normalized backup identity aligned
with the effective destination opened by the backup engine.
Move `File` and `Disk` backup destination validation into shared helpers used by
both `registerBackupEnginesFileAndDisk` and `BackupInfo::toNormalizedString`.
This keeps normalized backup identity validation aligned with the destination
validation performed by the backup engines.
@jkartseva jkartseva self-assigned this Jul 1, 2026
Comment thread src/Backups/BackupInfo.cpp Resolved
Comment thread src/Backups/BackupInfo.cpp Resolved
pamarcos added 2 commits July 6, 2026 15:58
Let `S3::URI` decide whether query parameters are part of the object key instead of stripping every non-`versionId` parameter first. This keeps non-presigned plain query parameters destination-significant while still omitting presigned credential parameters from the parsed identity.
Use exact override key names when building the no-context normalized identity for named-collection backups. This keeps `URL` distinct from `url`, matching the backup engines where overrides are consumed by exact lowercase names.
Comment thread src/Backups/BackupInfo.cpp Resolved
@alexey-milovidov

Copy link
Copy Markdown
Member

Updating the branch to fix the 04001_join_reorder_through_expression test, which was broken today in master.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread src/Backups/BackupInfo.cpp Resolved
pamarcos added 4 commits July 7, 2026 16:55
Reject invalid `S3`, `AzureBlobStorage`, `File`, and `Disk` locator shapes before building a normalized backup identity. Also validate skipped credential arguments and direct `S3` `extra_credentials`, so invalid locators cannot alias accepted destinations.
Stop `stripURLUserInfo` at query and fragment boundaries as well as paths. This avoids treating `@` inside a query string as userinfo when normalizing credential-free `S3` backup identities.
Clear ignored function arguments after resolving named-collection backup destinations, so the normalized identity validation continues to match the backup engines. Direct `S3` `extra_credentials` are still validated before normalization.
The Fast test build disables `USE_AWS_S3`, so the validation helper does not need the `ContextPtr` parameter in that configuration. Mark it as `[[maybe_unused]]` to keep the `S3`-enabled validation path unchanged while avoiding `-Wunused-parameter`.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread src/Backups/BackupInfo.cpp Resolved
Comment thread src/Backups/BackupInfo.cpp Resolved
Comment thread src/Backups/BackupInfo.cpp Resolved
pamarcos added 2 commits July 8, 2026 10:44
Correct the argument-count diagnostic for `AzureBlobStorage` normalized backup identity validation so it shows the intended `connection string/url` syntax.
Resolve backup named collections through `tryGetNamedCollectionWithOverrides` so normalized backup identity uses the same `isOverridable` and `allow_named_collection_override_by_default` checks as backup engine resolution. Add a regression test for rejecting a non-overridable `url` override.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/Backups/BackupInfo.cpp Outdated
Comment on lines +362 to +363
if (s.find(';') == String::npos)
return stripOneTrailingSlash(stripURLUserInfo(stripURLQuery(s)));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dismissed: uppercase-scheme URLs are not equivalent in the live generic Azure path. AzureBlobStorage::processURL uses the case-sensitive !candidate.starts_with("http") test, so HTTPS://... is treated as a connection string and rejected. The valid explicit-credential path is canonicalized by normalizePlainAzureStorageAccountURL before reaching this fallback. Changing the fallback would make normalization accept a locator the live engine rejects, so I am leaving this thread unresolved.

Comment on lines +339 to +341
#if USE_AZURE_BLOB_STORAGE
if (!s.starts_with("http"))
{

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dismissed for the same runtime-contract reason: normalizeAzureConnection intentionally mirrors the live 3-argument processURL classifier, which is case-sensitive and treats HTTPS://... as a connection string. Five-argument explicit-credential URLs are validated and canonicalized to lowercase before this function. Making this check case-insensitive would alias an invalid live locator with a valid one. Leaving unresolved.

Comment thread src/Backups/BackupInfo.cpp Resolved
Convert Poco and Azure URL parser failures into `BAD_ARGUMENTS` without empty catch blocks. Keep shape validation outside parser catches so its specific diagnostics are preserved.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Fail closed when generic Azure URLs or parsed connection-string endpoints retain fragments that the live engine keeps in the endpoint. Continue ignoring fragment characters that occur only inside SAS query credentials.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/Backups/BackupInfo.cpp Resolved
Require context or a frozen collection before accepting Azure connection overrides whose precedence and credential mode depend on stored state. Report malformed override structure without formatting literal values.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/Backups/BackupInfo.cpp Resolved
Replace invalid `extra_credentials` details with structure-only diagnostics, including validation exceptions and malformed placement. This preserves useful function shape without exposing literal values.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/Backups/BackupInfo.cpp Resolved
Comment thread src/Backups/BackupInfo.cpp Resolved
Wrap normalized S3 URL and path parsing with credential-free `BAD_ARGUMENTS` diagnostics. Successful parsing retains full `S3::URI` semantics, including version identifiers.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment on lines +321 to +334
S3::URI parseS3URIForNormalizedIdentity(const String & uri, std::string_view argument_description)
{
try
{
return S3::URI(uri, /* allow_archive_path_syntax = */ false);
}
catch (const Poco::Exception &)
{
throw Exception(
ErrorCodes::BAD_ARGUMENTS,
"Failed to parse S3 {} for normalized backup identity",
argument_description);
}
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dismissed: DB::Exception is declared as class Exception : public Poco::Exception in src/Common/Exception.h, so this catch already sanitizes both DB::Exception from S3::URI::validateKey and Poco URI parser failures. The tests explicitly exercise both paths (double-slash DB validation and malformed-percent Poco syntax) and verify the presigned secret is absent. Query parameters cannot be dropped before parsing because versionId is destination-significant. Leaving unresolved.

{
auto base = BackupInfo::fromString("S3(collection)");
auto with_credentials = BackupInfo::fromString(
"S3(collection, ACCESS_KEY_ID='KEYID', google_adc_client_id='CLIENTID', google_adc_client_secret='CLIENTSECRET', "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toNormalizedString now treats credential-like override keys case-insensitively, but BackupImpl still serializes <base_backup> through BackupInfo::withoutS3Credentials, and that helper only strips exact lowercase spellings in src/Backups/BackupInfo.cpp:1088-1104. As a result, the shape introduced in this test still leaks into metadata: S3(collection, ACCESS_KEY_ID='KEYID') keeps KEYID in .backup, and the same exact-case gap leaves ignored URL= overrides able to persist presigned or userinfo credentials. Please share the same case-insensitive key handling with withoutS3Credentials before relying on these redaction invariants.

@pamarcos
pamarcos marked this pull request as draft July 15, 2026 17:18
@pamarcos

Copy link
Copy Markdown
Member Author

Superseded by #110610, which moves destination identity into engine-owned BackupFactory callbacks and avoids duplicating backup-engine parsing in BackupInfo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants