Repository navigation
Cherry pick #107357 to 26.4: Avoid storing S3 credentials in backup metadata - #108842
Merged
robot-ch-test-poll3 merged 18 commits intoJun 30, 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.
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
…ve/pr108842-26.4 # 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
Contributor
There was a problem hiding this comment.
Pull request overview
Backport of #107357 to the 26.4 branch to prevent incremental backup metadata from persisting S3 credentials inside the <base_backup> locator in the .backup file, while preserving restore compatibility behavior through a non-secret marker and additional redaction logic.
Changes:
- Ensure base backup opening uses a local
BackupInfocopy souse_same_s3_credentials_for_base_backupno longer mutates the persistedbase_backup_info. - Serialize
<base_backup>throughBackupInfo::withoutS3Credentials, stripping inlineS3credentials (positional, key-value,extra_credentials, and URL-embedded credentials) and optionally writing a<base_backup_copy_s3_credentials_from_backup>marker. - Add coverage via a new stateless query test and new
gtestcoverage forBackupInfocredential stripping/redaction behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/04327_backup_s3_base_credentials_metadata.sh | New stateless test validating that .backup metadata does not store base-backup S3 credentials and that old-credential metadata remains restorable. |
| tests/queries/0_stateless/04327_backup_s3_base_credentials_metadata.reference | Expected output for the new stateless test (counts of relevant tags and credential-string presence). |
| tests/queries/0_stateless/02843_backup_use_same_s3_credentials_for_base_backup.sh | Removes the old metadata-rewrite helper now covered more comprehensively by the new test. |
| src/Backups/tests/gtest_backup_info.cpp | New unit tests for BackupInfo::withoutS3Credentials redaction/stripping behavior (including expression evaluation with context). |
| src/Backups/BackupInfo.h | Adds canCopyS3CredentialsTo and withoutS3Credentials APIs with documentation. |
| src/Backups/BackupInfo.cpp | Implements redaction logic for S3 locators (positional creds, auth kv args, extra_credentials, and URL userinfo/presigned params) and canCopyS3CredentialsTo. |
| src/Backups/BackupImpl.h | Adds state to track the new restore-time marker for copying credentials from the restore source locator. |
| src/Backups/BackupImpl.cpp | Uses local base-backup info when copying credentials; writes redacted base locator plus optional marker; honors the marker on restore when base locator comes from 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.
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job