pgbackrest.git / summary / log / commit / refs

commit    7320d787e91ea4f9da8a93799ea73e8618ee071d
Author:   David Steele <david@pgbackrest.org>
Commit:   GitHub <noreply@github.com>
Date:     Sun Oct 25 11:36:31 2026 +0000

    Redact the backup passphrase from history and restored manifests.
    
    Each manifest stores the passphrase for the files in its backup set. The copy saved to backup.history is kept after the backup expires (forever by default) and it included this passphrase. Restore also writes the manifest to the data directory, unencrypted, so an interrupted delta restore can be restarted. That copy included the passphrase in plain text until the restore completed, and a failed restore left it in place.
    
    Nothing reads the passphrase from either copy, so it is now removed from both. History manifests are saved from the manifest in memory rather than copied from backup.manifest.


doc/xml/release/2020s/2027/2.61.0.xml | 3 +++ src/command/backup/complete.c.inc | 13 ++++--------- src/command/restore/restore.c | 6 ++++-- test/src/module/command/backupTest.c | 11 +++++++++++ test/src/module/command/restoreTest.c | 6 ++++++ 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/doc/xml/release/2020s/2027/2.61.0.xml b/doc/xml/release/2020s/2027/2.61.0.xml index 242669ad1..5ec51df5d 100644 --- a/doc/xml/release/2020s/2027/2.61.0.xml +++ b/doc/xml/release/2020s/2027/2.61.0.xml @@ -5,6 +5,9 @@ <commit subject="Use 256-bit subkeys for repository format 6."> <github-pull-request id="2879"/> </commit> + <commit subject="Redact the backup passphrase from history and restored manifests."> + <github-pull-request id="2881"/> + </commit> <release-item-contributor-list> <release-item-contributor id="david.steele"/> diff --git a/src/command/backup/complete.c.inc b/src/command/backup/complete.c.inc index 70e51ee13..5f4fce6da 100644 --- a/src/command/backup/complete.c.inc +++ b/src/command/backup/complete.c.inc @@ -194,15 +194,10 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest) storageNewWriteP( storageRepoWrite(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabel)))); - // Copy a compressed version of the manifest to history. If the repo is encrypted then the passphrase to open the manifest - // is required. We can't just do a straight copy since the destination needs to be compressed and that must happen before - // encryption in order to be efficient. Compression will always be gz for compatibility and since it is always available. + // Save a compressed copy of the manifest to history without the passphrase for the files in the backup. Compression will + // always be gz for compatibility and since it is always available. // ------------------------------------------------------------------------------------------------------------------------- - StorageRead *const manifestRead = storageNewReadP( - storageRepo(), strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabel))); - - cipherBlockFilterGroupAdd( - ioReadFilterGroup(storageReadIo(manifestRead)), cipherModeDecrypt, infoBackupCipherSpec(infoBackup)); + manifestCipherSpecSet(manifest, NULL); StorageWrite *const manifestWrite = storageNewWriteP( storageRepoWrite(), @@ -215,7 +210,7 @@ backupComplete(InfoBackup *const infoBackup, Manifest *const manifest) cipherBlockFilterGroupAdd( ioWriteFilterGroup(storageWriteIo(manifestWrite)), cipherModeEncrypt, infoBackupCipherSpec(infoBackup)); - storageCopyP(manifestRead, manifestWrite); + manifestSave(manifest, storageWriteIo(manifestWrite)); // Sync history path if required if (storageFeature(storageRepoWrite(), storageFeaturePathSync)) diff --git a/src/command/restore/restore.c b/src/command/restore/restore.c index 9c7982c72..cfb2efac7 100644 --- a/src/command/restore/restore.c +++ b/src/command/restore/restore.c @@ -90,7 +90,7 @@ cmdRestore(void) manifestValidate(jobData.manifest, false); // Get the cipher spec used to decrypt files in the backup - jobData.cipherSpecBackup = manifestCipherSpec(jobData.manifest); + jobData.cipherSpecBackup = cipherSpecDupP(manifestCipherSpec(jobData.manifest)); // Validate the manifest restoreManifestValidate(jobData.manifest, backupData.backupSet); @@ -127,7 +127,9 @@ cmdRestore(void) // Generate processing queues const uint64_t sizeTotal = restoreProcessQueue(jobData.manifest, &jobData.queueList); - // Save manifest to the data directory so we can restart a delta restore even if the PG_VERSION file is missing + // Save manifest to the data directory without the passphrase for the files so we can restart a delta restore even if the + // PG_VERSION file is missing + manifestCipherSpecSet(jobData.manifest, NULL); manifestSave(jobData.manifest, storageWriteIo(storageNewWriteP(storagePgWrite(), BACKUP_MANIFEST_FILE_STR))); // Create the parallel executor diff --git a/test/src/module/command/backupTest.c b/test/src/module/command/backupTest.c index 57bcf24b7..2e9bd9879 100644 --- a/test/src/module/command/backupTest.c +++ b/test/src/module/command/backupTest.c @@ -4089,6 +4089,17 @@ testRun(void) "[backup:target]\n" "pg_data={\"path\":\"" TEST_PATH "/pg1\",\"type\":\"path\"}\n", "compare file list"); + + // History manifest has no passphrase for the files + const InfoBackup *const infoBackup = infoBackupLoadFile(storageRepo(), INFO_BACKUP_PATH_FILE_STR, TEST_CIPHER_SPEC); + StorageRead *const read = storageNewReadP( + storageRepo(), STRDEF(STORAGE_REPO_BACKUP "/" BACKUP_PATH_HISTORY "/2019/20191108-080000F.manifest.gz")); + cipherBlockFilterGroupAdd(ioReadFilterGroup(storageReadIo(read)), cipherModeDecrypt, infoBackupCipherSpec(infoBackup)); + ioFilterGroupAdd(ioReadFilterGroup(storageReadIo(read)), decompressFilterP(compressTypeGz)); + + TEST_RESULT_UINT( + cipherSpecType(manifestCipherSpec(manifestNewLoad(storageReadIo(read), infoBackupCipherSpec(infoBackup)))), + cipherTypeNone, "history manifest has no file passphrase"); } // ------------------------------------------------------------------------------------------------------------------------- diff --git a/test/src/module/command/restoreTest.c b/test/src/module/command/restoreTest.c index 7c39d1cbd..b3759867f 100644 --- a/test/src/module/command/restoreTest.c +++ b/test/src/module/command/restoreTest.c @@ -3583,6 +3583,12 @@ testRun(void) // Make sure restore fails with the invalid file TEST_ERROR(hrnCmdRestore(), CryptoError, "raised from local-1 shim protocol: cipher header missing"); + TEST_RESULT_UINT( + cipherSpecType( + manifestCipherSpec( + manifestNewLoad(storageReadIo(storageNewReadP(storagePg(), BACKUP_MANIFEST_FILE_STR)), TEST_CIPHER_SPEC))), + cipherTypeNone, "manifest in data directory has no file passphrase"); + // Use detail log level to catch block incremental restore message harnessLogLevelSet(logLevelDetail); [parent: 7b160af0676d]