pg.ddx.io  pgbackrest/pgbackrest GitHub issues and pull requests  
help / color / mirror / Atom feed
[pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
19+ messages / 3 participants
[nested] [flat]

* [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-04 11:27 "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  0 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-04 11:27 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

repo-cipher-pass encrypts only archive.info, backup.info, and their copies. Every other file is encrypted with a key stored in one of them, so changing the passphrase rewrites four small files and no backups or WAL.

To change the passphrase, set repo-cipher-pass to the new passphrase and the new repo-cipher-pass-old option to the old passphrase on every host where repo-cipher-pass is configured. Then run stanza-rekey, remove repo-cipher-pass-old from those hosts, and run check. A host with no encryption settings gets both options from the repository host.

While repo-cipher-pass-old is set, an info file that cannot be read with repo-cipher-pass is retried with the old passphrase so commands keep working until the rekey runs. The retry is logged at debug level. verify also retries and reports the file at detail level. repo-get reads an info file directly and does not fall back to the old passphrase.

An info file is saved with the passphrase that decrypted it and only stanza-rekey changes it. Backups and archiving can continue while hosts are updated, and a host that has not been updated can still read the stanza until the rekey runs. check warns while repo-cipher-pass-old is set and reports whether the stanza has been rekeyed.

stanza-rekey has these behaviors:

- It does not connect to PostgreSQL and locks like stanza-upgrade.
- It checks the new passphrase like stanza-create, and the new passphrase must differ from the old one.
- It saves each info file and its copy with the new passphrase, so running it again after a crash finishes the job.
- It rekeys at every format and skips unencrypted repositories. It errors when no repository is encrypted. --repo limits it to one repository.

stanza-rekey also rotates the archive key of each encrypted repository at format >= 6, even when repo-cipher-pass-old is not set. There is no option to skip this. Format 5 has a single archive key, so a run with nothing to rekey there only warns. A backup set gets a new key with its next full backup.

Rotation protects only data written afterwards. If the old passphrase and the repository were both exposed, existing keys and data must be considered exposed. A full backup taken before the rekey stores its key in backup.info while backup.info is still encrypted with the old passphrase, and the rekey does not replace that key. After an exposure, take a full backup after the rekey.

The command and repo-cipher-pass-old are internal until format 6 is released.

The integration test runs the fallback and the rekey from pg1, which has no encryption settings. Before the rekey it runs a backup and checks that both info files are still encrypted with the old passphrase. The remaining backup and restore tests then run against the rekeyed repository.

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-04 11:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-04 11:41 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele requested a review.

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-04 11:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-04 11:41 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele assigned @dwsteele.

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-04 11:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-04 11:41 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele applied label "module [core]".

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-04 11:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-04 11:41 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele applied label "enhancement".

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-04 11:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-04 11:41 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele set milestone to "2.61.0".

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-04 15:07 ` "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: hunleyd (@hunleyd) @ 2026-11-04 15:07 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

(on src/command/stanza/rekey.c:140)

```
inline patch 1: src/command/stanza/rekey.c (+12/-11 lines) download inline-1.patchdiff --git a/src/command/stanza/rekey.c b/src/command/stanza/rekey.c index 110a619..e2095a6 100644 --- a/src/command/stanza/rekey.c +++ b/src/command/stanza/rekey.c @@ -138,33 +138,34 @@ cmdStanzaRekey(void) // Format of the repository. stanza-upgrade saves archive.info before backup.info. const unsigned int format = infoArchiveFormat(infoArchive); + // Warn when there is nothing to do. Format < 6 has a single archive key that cannot be rotated. + if (!rekey && format < REPOSITORY_FORMAT_6) + { + LOG_WARN("archive key rotation requires repository format " STRINGIFY(REPOSITORY_FORMAT_6) " or higher"); + + repoTotal++; + continue; + } + // Check the new passphrase if (rekey) stanzaCipherPassCheck(repoIdx, format, "rekey a stanza"); - // Rotate the archive key. Format < 6 has a single archive key that cannot be rotated. + // Rotate the archive key if (format >= REPOSITORY_FORMAT_6) { infoArchiveCipherRotate(infoArchive, cipherSpecGen(cipherType, format), time(NULL)); LOG_INFO_FMT("rotate archive key to id %s", strZ(cipherSpecMapIdCurrent(infoArchiveCipherSpecMap(infoArchive)))); } - // Else warn when there is nothing to do - else if (!rekey) - LOG_WARN("archive key rotation requires repository format " STRINGIFY(REPOSITORY_FORMAT_6) " or higher"); // Save the info files with the passphrase - if (rekey || format >= REPOSITORY_FORMAT_6) - { - infoArchiveSaveFile( - infoArchive, storageRepoIdxWrite(repoIdx), INFO_ARCHIVE_PATH_FILE_STR, cfgCipherSpecMainIdx(repoIdx)); - } + infoArchiveSaveFile(infoArchive, storageRepoIdxWrite(repoIdx), INFO_ARCHIVE_PATH_FILE_STR, cipherSpecMain); if (rekey) { infoBackupUpdatedSet(infoBackup); - infoBackupSaveFile( - infoBackup, storageRepoIdxWrite(repoIdx), INFO_BACKUP_PATH_FILE_STR, cfgCipherSpecMainIdx(repoIdx)); + infoBackupSaveFile(infoBackup, storageRepoIdxWrite(repoIdx), INFO_BACKUP_PATH_FILE_STR, cipherSpecMain); LOG_INFO("rekey info files with the new passphrase"); }
``` ^ permalink raw [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898 (changes requested): Add stanza-rekey command to change the repository passphrase.
@ 2026-11-04 15:07 ` "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: hunleyd (@hunleyd) @ 2026-11-04 15:07 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>



^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-04 16:12 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-04 16:12 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

(on src/command/stanza/rekey.c:140)

Looks good, but I'll raise you a further simplification, 92f5921232c. :)

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898 (approved): Add stanza-rekey command to change the repository passphrase.
@ 2026-11-05 14:04 ` "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: hunleyd (@hunleyd) @ 2026-11-05 14:04 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>



^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-06 10:04 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-06 10:04 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@hunleyd @pgstef I did some cleanup but also made a substantive change in d920ea29 (see commit for details).

I'd appreciate it if one of you could have a look before I merge this.

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898 (approved): Add stanza-rekey command to change the repository passphrase.
@ 2026-11-06 14:58 ` "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: hunleyd (@hunleyd) @ 2026-11-06 14:58 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>



^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-06 14:58 ` "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: hunleyd (@hunleyd) @ 2026-11-06 14:58 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

> @hunleyd @pgstef I did some cleanup but also made a substantive change in [d920ea2](https://github.com/pgbackrest/pgbackrest/commit/d920ea297072621ab22dd52230ecf85c87ec762a) (see commit for details).
> 
> I'd appreciate it if one of you could have a look before I merge this.

lgtm, re-approving

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-06 15:12 ` "pgstef (@pgstef)" <noreply+pgstef@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: pgstef (@pgstef) @ 2026-11-06 15:12 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

I haven't had time for an in-depth code review yet, but one thing concerns me about the current implementation.

While `repo-cipher-pass-old` is configured, a regular backup can already re-encrypt both `backup.info` and `archive.info` using the new passphrase. An `expire` can also rewrite `backup.info` with the new passphrase.
This effectively rekeys the info files before `stanza-rekey` is explicitly executed. If not every host has been updated with the new configuration yet, the remaining hosts would lose access to the repository. On a PostgreSQL host, this could cause `archive-push` to fail.

What concerns me is that this happens without any explicit indication at the usual logging levels. The fallback message is now logged at DEBUG, while the `check` warning only indicates that `repo-cipher-pass-old` is configured, not whether the info files have already been re-encrypted.

Wouldn't it make more sense to preserve the passphrase used to decrypt an info file when saving it, and leave the actual rekeying to `stanza-rekey`? That would make the command the explicit cutover point, as the documentation seems to suggest.

Am I missing something here?

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-06 16:27 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-06 16:27 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

> Wouldn't it make more sense to preserve the passphrase used to decrypt an info file when saving it, and leave the actual rekeying to stanza-rekey?

Well, yes, that would make a lot more sense! You are correct that the rekey should not happen as a side effect and I completely missed that.

Here's a better implementation at 6d189c9776f. This preserves the prior key on save and only rekey updates it. I'll have another look at it on Monday but I think this is the way to go.

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-06 20:48 ` "pgstef (@pgstef)" <noreply+pgstef@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: pgstef (@pgstef) @ 2026-11-06 20:48 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

> Here's a better implementation at [6d189c9](https://github.com/pgbackrest/pgbackrest/commit/6d189c9776f09807d78783b16134fdca482faa14). This preserves the prior key on save and only rekey updates it. I'll have another look at it on Monday but I think this is the way to go.

Yes, with this fix, it looks like a host configured with only the old passphrase can continue archiving and backing up, even after a backup or an `expire` that removes a backup is run on a host configured with both the new and old passphrases.

After `stanza-rekey`, the old host loses access as documented, and everything works again once its configuration is updated. The new `check` message also looks accurate.

Looks good to me now! :-)

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898 (approved): Add stanza-rekey command to change the repository passphrase.
@ 2026-11-06 20:49 ` "pgstef (@pgstef)" <noreply+pgstef@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: pgstef (@pgstef) @ 2026-11-06 20:49 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>



^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-13 14:49 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-13 14:49 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele merged this (commit c8c8da1cca47).

^ permalink  raw  [nested|flat] 19+ messages in thread

* Re: [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase.
@ 2026-11-13 14:49 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
  17 siblings, 0 replies; 19+ messages in thread

From: dwsteele (@dwsteele) @ 2026-11-13 14:49 UTC (permalink / raw)
  To: pgbackrest/pgbackrest <noreply+pgbackrest-pgbackrest@github.com>

@dwsteele closed this.

^ permalink  raw  [nested|flat] 19+ messages in thread


end of thread, other threads:[~2026-11-13 14:49 UTC | newest]

Thread overview: 19+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 11:27 [pgbackrest/pgbackrest] PR #2898: Add stanza-rekey command to change the repository passphrase. "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-04 11:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-04 11:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-04 11:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-04 11:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-04 11:41 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-04 15:07 ` "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
2026-11-04 15:07 ` Re: [pgbackrest/pgbackrest] PR #2898 (changes requested): Add stanza-rekey command to change the repository passphrase. "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
2026-11-04 16:12 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-05 14:04 ` Re: [pgbackrest/pgbackrest] PR #2898 (approved): Add stanza-rekey command to change the repository passphrase. "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
2026-11-06 10:04 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-06 14:58 ` Re: [pgbackrest/pgbackrest] PR #2898 (approved): Add stanza-rekey command to change the repository passphrase. "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
2026-11-06 14:58 ` "hunleyd (@hunleyd)" <noreply+hunleyd@github.com>
2026-11-06 15:12 ` "pgstef (@pgstef)" <noreply+pgstef@github.com>
2026-11-06 16:27 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-06 20:48 ` "pgstef (@pgstef)" <noreply+pgstef@github.com>
2026-11-06 20:49 ` Re: [pgbackrest/pgbackrest] PR #2898 (approved): Add stanza-rekey command to change the repository passphrase. "pgstef (@pgstef)" <noreply+pgstef@github.com>
2026-11-13 14:49 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>
2026-11-13 14:49 ` "dwsteele (@dwsteele)" <noreply+dwsteele@github.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox