Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jGVm0-0004zp-Mu for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Mar 2020 22:42:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jGVlz-0002Cn-Iu for pgsql-hackers@arkaria.postgresql.org; Mon, 23 Mar 2020 22:42:19 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jGVlz-0002Cg-8i for pgsql-hackers@lists.postgresql.org; Mon, 23 Mar 2020 22:42:19 +0000 Received: from tamriel.snowman.net ([96.255.250.162]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jGVlw-0005KA-40 for pgsql-hackers@postgresql.org; Mon, 23 Mar 2020 22:42:18 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id DB39A5F798; Mon, 23 Mar 2020 18:42:17 -0400 (EDT) Date: Mon, 23 Mar 2020 18:42:17 -0400 From: Stephen Frost To: Robert Haas Cc: Amit Kapila , Suraj Kharage , tushar , Rajkumar Raghuwanshi , Rushabh Lathia , Tels , David Steele , Andrew Dunstan , PostgreSQL Hackers , Jeevan Chalke , vignesh C Subject: Re: backup manifests Message-ID: <20200323224217.GN13712@tamriel.snowman.net> References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="fb42B6XxWAcmD3wU" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --fb42B6XxWAcmD3wU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Greetings, * Robert Haas (robertmhaas@gmail.com) wrote: > I think I forgot an initializer. Try this version. Just took a quick look through this. I'm pretty sure David wants to look at it too. Anyway, some comments below. > diff --git a/doc/src/sgml/protocol.sgml b/doc/src/sgml/protocol.sgml > index f139ba0231..d1ff53e8e8 100644 > --- a/doc/src/sgml/protocol.sgml > +++ b/doc/src/sgml/protocol.sgml > @@ -2466,7 +2466,7 @@ The commands accepted in replication mode are: > > =20 > > - BASE_BACKUP [ LABEL 'label' ] [ PROGRESS ] [ FAST ] [ WAL ] [ NOWAIT ] = [ MAX_RATE rate ] [ = TABLESPACE_MAP ] [ NOVERIFY_CHECKSUMS ] > + BASE_BACKUP [ LABEL 'label' ] [ PROGRESS ] [ FAST ] [ WAL ] [ NOWAIT ] = [ MAX_RATE rate ] [ = TABLESPACE_MAP ] [ NOVERIFY_CHECKSUMS ] [ MANIFEST manifest_option ] [ MANIFEST_CHECKSUMS checksum_algorithm ] > BASE_BACKUP > > > @@ -2576,6 +2576,37 @@ The commands accepted in replication mode are: > > > > + > + > + MANIFEST > + > + > + When this option is specified with a value of ye' > + or force-escape, a backup manifest is creat= ed > + and sent along with the backup. The latter value forces all fi= lenames > + to be hex-encoded; otherwise, this type of encoding is perform= ed only > + for files whose names are non-UTF8 octet sequences. > + force-escape is intended primarily for test= ing > + purposes, to be sure that clients which read the backup manife= st > + can handle this case. For compatibility with previous releases, > + the default is MANIFEST 'no'. > + > + > + > + > + > + MANIFEST_CHECKSUMS > + > + > + Specifies the algorithm that should be used to checksum each f= ile > + for purposes of the backup manifest. Currently, the available > + algorithms are NONE, CRC32C, > + SHA224, SHA256, > + SHA384, and SHA512. > + The default is CRC32C. > + > + > + > > > While I get the desire to have a default here that includes checksums, the way the command is structured, it strikes me as odd that the lack of MANIFEST_CHECKSUMS in the command actually results in checksums being included. I would think that we'd either: - have the lack of MANIFEST_CHECKSUMS mean 'No checksums' or - Require MANIFEST_CHECKSUMS to be specified and not have it be optional We aren't expecting people to actually be typing these commands out and so I don't think it's a *huge* deal to have it the way you've written it, but it still strikes me as odd. I don't think I have a real preference between the two options that I suggest above, maybe very slightly in favor of the first. > diff --git a/doc/src/sgml/ref/pg_basebackup.sgml b/doc/src/sgml/ref/pg_ba= sebackup.sgml > index 90638aad0e..bf6963a595 100644 > --- a/doc/src/sgml/ref/pg_basebackup.sgml > +++ b/doc/src/sgml/ref/pg_basebackup.sgml > @@ -561,6 +561,69 @@ PostgreSQL documentation > > > > + > + > + > + > + > + Disables generation of a backup manifest. If this option is not > + specified, the server will and send generate a backup manifest > + which can be verified using . > + > + > + How about "If this option is not specified, the server will generate and send a backup manifest which can be verified using ..." > + > + > + > + > + Specifies the algorithm that should be used to checksum each file > + for purposes of the backup manifest. Currently, the available > + algorithms are NONE, CRC32C, > + SHA224, SHA256, > + SHA384, and SHA512. > + The default is CRC32C. > + As I recall, there was an invitation to argue about the defaults at one point, and so I'm going to say here that I would advocate for a different default than 'crc32c'. Specifically, I would think sha256 or 512 would be better. I don't recall seeing a debate about this that conclusively found crc32c to be better, but I'm happy to go back and reread anything someone wants to point me at. > + > + If NONE is selected, the backup manifest will > + not contain any checksums. Otherwise, it will contain a checksum > + of each file in the backup using the specified algorithm. In add= ition, > + the manifest itself will always contain a SHA256 > + checksum of its own contents. The SHA algorit= hms > + are significantly more CPU-intensive than CRC32C, > + so selecting one of them may increase the time required to compl= ete > + the backup. > + It also seems a bit silly to me that using the defaults means having to deal with two different algorithms- crc32c and sha256. Considering how fast these algorithms are, compared to everything else involved in a backup (particularly one that's likely going across a network...), I wonder if we should say "may slightly increase" above. > + > + On the other hand, CRC32C is not a cryptograp= hic > + hash function, so it is only suitable for protecting against > + inadvertent or random modifications to a backup. An adversary > + who can modify the backup could easily do so in such a way that > + the CRC does not change, whereas a SHA collision will be hard > + to manufacture. (However, note that if the attacker also has acc= ess > + to modify the backup manifest itself, no checksum algorithm will > + provide any protection.) An additional advantage of the > + SHA family of functions is that they output > + a much larger number of bits. > + I'm not really sure that this paragraph is sensible to include.. We certainly don't talk about adversaries and cryptographic hash functions when we talk about our page-level checksums, for example. I'm not completely against including it, but I don't want to give the impression that this is something we routinely consider or that lack of discussion elsewhere implies we have protections against a determined attacker. > diff --git a/doc/src/sgml/ref/pg_validatebackup.sgml b/doc/src/sgml/ref/p= g_validatebackup.sgml > new file mode 100644 > index 0000000000..1c171f6970 > --- /dev/null > +++ b/doc/src/sgml/ref/pg_validatebackup.sgml > @@ -0,0 +1,232 @@ > + > + > + > + > + pg_validatebackup > + > + > + > + pg_validatebackup > + 1 > + Application > + > + > + > + pg_validatebackup > + verify the integrity of a base backup of a > + PostgreSQL cluster > + "verify the integrity of a backup taken using pg_basebackup" > + > + > + Description > + > + > + pg_validatebackup is used to check the int= egrity > + of a database cluster backup. The backup being checked should have b= een > + created by pg_basebackup or some other tool that i= ncludes > + a backup_manifest file with the backup. The backup > + must be stored in the "plain" format; a "tar" format backup can be ch= ecked > + after extracting it. Backup manifests are created by the server begin= ning > + with PostgreSQL version 13, so older backu= ps > + cannot be validated using this tool. > + This seems to invite the idea that pg_validatebackup should be able to work with external backup solutions- but I'm a bit concerned by that idea because it seems like it would then mean we'd have to be particularly careful when changing things in this area, and I'm not thrilled by that. I'd like to make sure that new versions of pg_validatebackup work with older backups, and, ideally, older versions of pg_validatebackup would work even with newer backups, all of which I think the json structure of the manifest helps us with, but that's when we're building the manifest and know what it's going to look like. Maybe to put it another way- would a patch be accepted to make pg_validatebackup work with other manifests..? If not, then I'd keep this to the more specific "this tool is used to validate backups taken using pg_basebackup". > + > + pg_validatebackup reads the manifest file = of a > + backup, verifies the manifest against its own internal checksum, and = then > + verifies that the same files are present in the target directory as i= n the > + manifest itself. It then verifies that each file has the expected che= cksum, > + unless the backup was taken the checksum algorithm set to "was taken with the checksum algorithm"... > + none, in which case checksum verification is not > + performed. The presence or absence of directories is not checked, exc= ept > + indirectly: if a directory is missing, any files it should have conta= ined > + will necessarily also be missing. Certain files and directories are > + excluded from verification: > + > + > + > + > + > + backup_manifest is ignored because the backup > + manifest is logically not part of the backup and does not include > + any entry for itself. > + > + This seems a bit confusing, doesn't it? The backup_manifest must exist, and its checksum is internal, and is checked, isn't it? Why say that it's excluded..? > + > + > + pg_wal is ignored because WAL files are sent > + separately from the backup, and are therefore not described by t= he > + backup manifest. > + > + I don't agree with the choice to exclude the WAL files, considering they're an integral part of a backup, to exclude them means that if they've been corrupted at all then the entire backup is invalid. You don't want to be discovering that when you're trying to do a restore of a backup that you took with pg_basebackup and which pg_validatebackup says is valid. After all, the tool being used here, pg_basebackup, *does* also stream the WAL files- there's no reason why we can't calculate a checksum on them and store that checksum somewhere and use it to validate the WAL files. This, in my opinion, is actually a show-stopper for this feature. Claiming it's a valid backup when we don't check the absolutely necessary-for-restore WAL is making a false claim, no matter how well it's documented. I do understand that it's possible to run pg_basebackup without the WAL files being grabbed as part of that run- in such a case, we should be able to detect that was the case for the backup and when running pg_validatebackup we should issue a WARNING that the WAL files weren't able to be verified (we could have an option to suppress that warning if people feel that's needed). > + > + > + postgesql.auto.conf, > + standby.signal, > + and recovery.signal are ignored because they = may > + sometimes be created or modified by the backup client itself. > + (For example, pg_basebackup -R will modify > + postgresql.auto.conf and create > + standby.signal.) > + > + > + > + Not really thrilled with this (pg_basebackup certainly could figure out the checksum for those files...), but I also don't think it's a huge issue as they can be recreated by a user (unlike a WAL file..). I got through most of the pg_basebackup changes, and they looked pretty good in general. Will try to review more tomorrow. Thanks, Stephen --fb42B6XxWAcmD3wU Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJeeTtJAAoJEO1sijiDR2RVTsEP/3YgvcXdcFuxBKjQwT3z/TKj IwMoSfX483JhsAjXsDmVx5kVkaZot2vnTSeSC3pwTtJwo65yGAlXqSKij3n+3psZ OiOBDxRB0/l8Fv+imq4kR/fv46xQLwL5q0zka+CKqObEcnHW5ka6lhH7bH45iDYJ CfW2HkMCklbE2kcWZ7u+tSywjyzmMBdDWjRs+bugZl9CGEgVLFgMFQsMTzNlwxWT IAikkvFUYTNXwoCLKE4/XsdTv+//2+OHXt/2xk/gEcoTOytLTN4Et1OT+IRce1JK EdDym2Jod8Xh35g0vftimE+neZ+CbWkTcK+yot4cxE4YgqXPyTVbjsVxxcWmSOVB iTEn7M5bWLS95buOlcf41fp0tF/mjQd/usZ1q7CkP4HFIwvGoC3yBDwZFNPUc7DC nJTX9sczNi5Taorq5nXk+CjdbOvt9sMISrnkj78mjNIZhvOx2ViQZhkvRDpV05dg /dvqNVAgUZwt7CEGbcmzB1PprZGSG16wbGOBIhejsMf+jGNngpW276I++6u7luxt gUYdqtec/OpxGyanDJq+Khqiq6DtVHaJeFBVvRi9Vo5VZi8z++L9ALf8ubyCfa1+ vapQD90W3ll3wYcZ2GC7YTYEF/+WztpyvtIrZZzmW16ttzO7JnwCZEBSc4HCEQMk B0Jb7A2WR86Uj9RlzFe5 =DPel -----END PGP SIGNATURE----- --fb42B6XxWAcmD3wU--