Skip to content

Cherry pick #107357 to 25.8: Avoid storing S3 credentials in backup metadata - #108840

Merged
robot-clickhouse-ci-2 merged 18 commits into
backport/25.8/107357from
cherrypick/25.8/107357
Jun 29, 2026
Merged

robot-clickhouse-ci-2 merged 18 commits into
backport/25.8/107357from
cherrypick/25.8/107357

Conversation

@robot-ch-test-poll

Copy link
Copy Markdown
Contributor

Original pull-request #107357

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

pamarcos and others added 17 commits June 12, 2026 18:27
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.
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.
…credentials

# Conflicts:
#	tests/queries/0_stateless/02843_backup_use_same_s3_credentials_for_base_backup.reference
#	tests/queries/0_stateless/02843_backup_use_same_s3_credentials_for_base_backup.sh
Use a metadata-only tag for copying `S3` credentials from the restore source to the base backup locator, so it cannot be confused with the user setting.

Also apply review nits and make the focused stateless test deterministic by not expecting an exact MinIO signature-error line.
Write the metadata marker only when copying this backup's inline `S3` credentials fully reconstructs the effective base backup locator. This avoids implicit credential copying for stripped non-copyable auth such as `extra_credentials`. Update the focused stateless test to cover this case.
The context-dependent expression checks instantiate the shared gtest context and leave an `ExternalLoader` periodic updater scheduled in the global thread pool. Later `ThreadPool.GlobalFull1` shrinks the same global pool and waits for it to become idle, which makes sanitizer unit-test jobs hit the 45-minute timeout. Keep these unit tests focused on literal redaction and fail-closed behavior without touching the shared context.
Run the context-dependent `withoutS3Credentials` expression checks as threadsafe death tests. This keeps coverage for evaluated `url` and credential-key expressions while isolating the shared gtest context and its `ExternalLoader` background work from later `ThreadPool.GlobalFull1` tests.
Cover the reviewed metadata-marker branches for `S3` incremental backups: full-backup metadata baseline, explicit restore-time `base_backup` override, different inline base credentials without `use_same_s3_credentials_for_base_backup`, and extra-auth metadata redaction. Add focused `BackupInfo` tests for the copy predicate invariant, idempotent credential stripping, and combined URL redaction.
Avoid storing `S3` credentials in backup metadata
@robot-ch-test-poll robot-ch-test-poll 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 pr-bugfix Pull request with bugfix, not backported by default labels Jun 29, 2026
…ypick/25.8/107357

# Conflicts:
#	tests/queries/0_stateless/02843_backup_use_same_s3_credentials_for_base_backup.reference
#	tests/queries/0_stateless/02843_backup_use_same_s3_credentials_for_base_backup.sh

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

This backport updates the backup/restore implementation to ensure incremental S3 backups do not persist S3 credentials in .backup metadata (specifically in the <base_backup> locator), while keeping restore compatibility with older metadata formats that did embed credentials.

Changes:

  • Add BackupInfo::withoutS3Credentials() to redact inline S3 credentials (positional args, auth key-value args, extra_credentials(...), and credentials embedded in URLs).
  • Update BackupImpl metadata writing/reading to serialize a redacted <base_backup> locator and (when applicable) persist a non-secret marker allowing restore-time credential copying from the restore source locator.
  • Add/adjust tests: new stateless query test for metadata behavior and new gtest coverage for redaction and credential-copy invariants.

Reviewed changes

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

Show a summary per file
File Description
tests/queries/0_stateless/04327_backup_s3_base_credentials_metadata.sh New stateless test validating <base_backup> metadata redaction and restore scenarios.
tests/queries/0_stateless/04327_backup_s3_base_credentials_metadata.reference Expected output for the new stateless test.
tests/queries/0_stateless/02843_backup_use_same_s3_credentials_for_base_backup.sh Removes metadata-rewrite helper that no longer matches the new behavior.
src/Backups/tests/gtest_backup_info.cpp New unit tests for credential stripping/redaction and copy invariants.
src/Backups/BackupInfo.h Adds canCopyS3CredentialsTo() and withoutS3Credentials() API.
src/Backups/BackupInfo.cpp Implements S3 credential stripping/redaction and canCopyS3CredentialsTo().
src/Backups/BackupImpl.h Adds a flag to track the restore-time “copy S3 creds from backup locator” marker.
src/Backups/BackupImpl.cpp Stops persisting creds into <base_backup>, writes/reads the marker, and avoids mutating stored base_backup_info.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +104
# Imitate old metadata with embedded credentials and no marker.
rewrite_backup_metadata inc_6 '<base_backup_copy_s3_credentials_from_backup>true</base_backup_copy_s3_credentials_from_backup>' ''
rewrite_backup_metadata inc_6 '<use_same_s3_credentials_for_base_backup>true</use_same_s3_credentials_for_base_backup>' ''
rewrite_backup_metadata inc_6 "S3('$(s3_url base)')" "S3('$(s3_url base)', 'test', 'testtest')"
check_base_backup_in_metadata inc_6
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit 0d22a20 into backport/25.8/107357 Jun 29, 2026
1 check passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/25.8/107357 branch June 29, 2026 19:38
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.

5 participants