Repository navigation
Avoid storing S3 credentials in backup metadata - #107357
Merged
pamarcos merged 16 commits intoJun 29, 2026
Merged
Conversation
Incremental backup metadata could persist `S3` credentials in the `<base_backup>` locator of the `.backup` file: `getBaseBackupUnlocked` mutated the stored `base_backup_info` when `use_same_s3_credentials_for_base_backup` copied the credentials from the backup destination, and explicitly provided base backup credentials were serialized as is. Now the copied credentials are applied only to a local copy used to open the base backup, and `writeBackupMetadata` serializes the locator through `BackupInfo::withoutS3Credentials`, which removes the positional credential arguments, the authentication key-value arguments, the trailing `extra_credentials(...)` argument, and the credentials embedded in the URL itself (userinfo and presigned query parameters), evaluating non-literal `url` overrides with the context. When `use_same_s3_credentials_for_base_backup = 1` is used, a non-secret `<use_same_s3_credentials_for_base_backup>` marker is written next to the locator, so on restore the credentials are taken from the restore source locator automatically; otherwise they can be given to `RESTORE` with the `base_backup` setting. Existing backups with credentials embedded by older versions remain restorable, which the test verifies by rewriting the `.backup` file to imitate such a backup, first with invalid credentials to prove they are really read from the metadata, then with valid ones.
Contributor
|
Workflow [PR], commit [bca0806] Summary: ✅
AI ReviewSummary
Findings💡 Nits
Final Verdict
|
The credential stripping in `BackupInfo::withoutS3Credentials` recognized only identifier or
string-literal key-value argument keys, but the named collection opening path (`getKeyValueFromAST`
via `getParamsMapFromAST`) evaluates key expressions with the context. So an override such as
`S3(collection, concat('secret_', 'access_key') = '...')` or
`S3(collection, concat('u', 'rl') = concat('https://user:', 'password@host/base'))` was used when
opening the base backup while being persisted verbatim into the `.backup` metadata, keeping the
credential leak for that syntax. Resolve the key the same way (evaluating constant expressions with
the context, rejecting non-literal keys when no context is available) before classifying credential
arguments and redacting the `url` override. Covered by unit tests.
This was referenced Jun 29, 2026
robot-clickhouse-ci-2
added a commit
that referenced
this pull request
Jun 29, 2026
Cherry pick #107357 to 25.8: Avoid storing `S3` credentials in backup metadata
robot-clickhouse
added a commit
that referenced
this pull request
Jun 29, 2026
clickhouse-gh Bot
added a commit
that referenced
this pull request
Jun 29, 2026
Backport #107357 to 26.6: Avoid storing `S3` credentials in backup metadata
robot-ch-test-poll3
added a commit
that referenced
this pull request
Jun 30, 2026
Cherry pick #107357 to 26.3: Avoid storing `S3` credentials in backup metadata
robot-clickhouse
added a commit
that referenced
this pull request
Jun 30, 2026
robot-ch-test-poll3
added a commit
that referenced
this pull request
Jun 30, 2026
Cherry pick #107357 to 26.4: Avoid storing `S3` credentials in backup metadata
robot-clickhouse
added a commit
that referenced
this pull request
Jun 30, 2026
robot-ch-test-poll3
added a commit
that referenced
this pull request
Jun 30, 2026
Cherry pick #107357 to 26.5: Avoid storing `S3` credentials in backup metadata
robot-clickhouse
added a commit
that referenced
this pull request
Jun 30, 2026
pamarcos
added a commit
that referenced
this pull request
Jun 30, 2026
Backport #107357 to 26.3: Avoid storing `S3` credentials in backup metadata
pamarcos
added a commit
that referenced
this pull request
Jul 1, 2026
Backport #107357 to 26.4: Avoid storing `S3` credentials in backup metadata
pamarcos
added a commit
that referenced
this pull request
Jul 1, 2026
Backport #107357 to 26.5: Avoid storing `S3` credentials in backup metadata
pamarcos
added a commit
that referenced
this pull request
Jul 1, 2026
Backport #107357 to 25.8: Avoid storing `S3` credentials in backup metadata
1 task done
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…-credentials Avoid storing `S3` credentials in backup metadata
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.
Incremental
S3backup metadata could persist credentials in the<base_backup>locator of the.backupfile. With this change new incremental backups never contain base backup credentials in the metadata:getBaseBackupUnlockedcopies the credentials into a localBackupInfoused solely for opening the base backup, leaving the storedbase_backup_infounchanged (previouslyuse_same_s3_credentials_for_base_backupmutated it, and the copied credentials were persisted).writeBackupMetadataalways serializes the<base_backup>locator throughBackupInfo::withoutS3Credentials, which removes the positionalaccess_key_id/secret_access_keyarguments, the authentication key-value arguments (access_key_id,secret_access_key,session_token,role_arn,role_session_name,external_id), the trailingextra_credentials(...)argument, and the credentials embedded in the URL itself (userinfo and presigned authentication query parameters, keeping destination-significant parameters such asversionId). Non-literal argument keys andurloverrides are evaluated with the context, the same waygetNamedCollectiondoes, so evaluated credential arguments are stripped and the evaluated, redactedurlliteral is persisted.<base_backup_copy_s3_credentials_from_backup>true</...>marker is written next to the locator whenuse_same_s3_credentials_for_base_backup = 1was used, or when stripping the base locator removed the same positional inline credentials already present in this backup locator. On restore the marker takes credentials from the restore source locator automatically, so plainRESTORE ... FROM S3(url, key, secret)works without extra settings for those same-credential backups. The marker is ignored when the restore source has no copyable inline credentials (e.g. a named collection) or when the locator is overridden with thebase_backupsetting.RESTOREwith thebase_backupsetting, the same way they are given for the backup itself.Compatibility: backward compatibility is preserved — existing backups with credentials embedded by older versions are restored as before (covered by a test that rewrites the
.backupfile to imitate such a backup, first with invalid credentials to prove they are really read from the metadata, then with valid ones), and the metadata format needs no version bump since old servers ignore the marker. Forward compatibility is intentionally affected: new incremental backups no longer embed credentials, so older servers need the credentials passed at restore time.Closes: https://github.com/ClickHouse/clickhouse-private/issues/60577
Related: https://github.com/ClickHouse/clickhouse-private/pull/60612
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Incremental backups no longer store
S3credentials in the<base_backup>locator of the.backupmetadata file. Backups created withuse_same_s3_credentials_for_base_backup = 1, or with explicit base backup credentials matching this backup locator, store a non-secret marker and are restored without extra restore-time settings; for backups created with different explicit base backup credentials or extra base authentication arguments, pass them toRESTOREwith thebase_backupsetting. Backups created by older versions with embedded credentials remain restorable.Documentation entry:
Version info
26.7.1.263(included in26.7and later)26.6.2.14,26.5.5.13,26.4.5.90,26.3.17.10,25.8.26.8