Skip to content

Avoid storing S3 credentials in backup metadata - #107357

Merged
pamarcos merged 16 commits into
ClickHouse:masterfrom
pamarcos:fix/backup-base-s3-credentials
Jun 29, 2026
Merged

pamarcos merged 16 commits into
ClickHouse:masterfrom
pamarcos:fix/backup-base-s3-credentials

Conversation

@pamarcos

@pamarcos pamarcos commented Jun 12, 2026 •

Copy link
Copy Markdown
Member

Incremental S3 backup metadata could persist credentials in the <base_backup> locator of the .backup file. With this change new incremental backups never contain base backup credentials in the metadata:

  • getBaseBackupUnlocked copies the credentials into a local BackupInfo used solely for opening the base backup, leaving the stored base_backup_info unchanged (previously use_same_s3_credentials_for_base_backup mutated it, and the copied credentials were persisted).
  • writeBackupMetadata always serializes the <base_backup> locator through BackupInfo::withoutS3Credentials, which removes the positional access_key_id/secret_access_key arguments, the authentication key-value arguments (access_key_id, secret_access_key, session_token, role_arn, role_session_name, external_id), the trailing extra_credentials(...) argument, and the credentials embedded in the URL itself (userinfo and presigned authentication query parameters, keeping destination-significant parameters such as versionId). Non-literal argument keys and url overrides are evaluated with the context, the same way getNamedCollection does, so evaluated credential arguments are stripped and the evaluated, redacted url literal is persisted.
  • A non-secret <base_backup_copy_s3_credentials_from_backup>true</...> marker is written next to the locator when use_same_s3_credentials_for_base_backup = 1 was 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 plain RESTORE ... 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 the base_backup setting.
  • Backups created with explicit base backup credentials that differ from this backup locator, or use extra authentication arguments, are restored by giving the credentials to RESTORE with the base_backup setting, 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 .backup file 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):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Incremental backups no longer store S3 credentials in the <base_backup> locator of the .backup metadata file. Backups created with use_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 to RESTORE with the base_backup setting. Backups created by older versions with embedded credentials remain restorable.

Documentation entry:

  • Documentation is not required for this change.

Version info

  • Merged into: 26.7.1.263 (included in 26.7 and later)
  • Backported to: 26.6.2.14, 26.5.5.13, 26.4.5.90, 26.3.17.10, 25.8.26.8

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.
@pamarcos
pamarcos requested a review from Copilot June 12, 2026 18:28
@clickhouse-gh

clickhouse-gh Bot commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bca0806]

Summary: ✅


AI Review

Summary
  • This PR prevents incremental S3 backup metadata from persisting base-backup credentials by redacting stored S3 locators and using a metadata marker only when restore can reconstruct the effective base locator from the restore source credentials. The current code addresses the earlier credential-leak and marker-overreach findings; I found no new blocking code issues.
Findings
💡 Nits
  • [src/Backups/BackupImpl.cpp:455] The PR description still says the metadata tag is <use_same_s3_credentials_for_base_backup>, but the implementation writes <base_backup_copy_s3_credentials_from_backup>. This already has an open inline thread: Avoid storing S3 credentials in backup metadata #107357 (comment)
    Suggested fix: update the PR description to name <base_backup_copy_s3_credentials_from_backup>.
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Jun 12, 2026
Comment thread src/Backups/BackupInfo.cpp Resolved

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

pamarcos added 2 commits June 15, 2026 13:10
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.

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 9 out of 9 changed files in this pull request and generated no new comments.

@pamarcos
pamarcos requested a review from Copilot June 15, 2026 17:01

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread src/Backups/BackupImpl.h Resolved
Comment thread src/Backups/BackupImpl.cpp Resolved
Comment thread src/Backups/BackupImpl.cpp Resolved

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 9 out of 9 changed files in this pull request and generated 6 comments.

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
Comment thread src/Backups/BackupInfo.h Resolved

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 9 out of 9 changed files in this pull request and generated no new comments.

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
clickhouse-gh Bot pushed 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-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 29, 2026
@pamarcos pamarcos removed the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jun 30, 2026
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-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label 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-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-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label 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
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…-credentials

Avoid storing `S3` credentials in backup metadata
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants