Reusing verified snapshot digests instead of rehashing the whole file during etcd offsite publication
My etcd offsite backup published a snapshot plus its companion file and computed whole-file digests for both, even though the snapshot already carries its own integrity record. This push makes publication reuse the recorded snapshot hashes and teaches load to validate the snapshot’s embedded digest instead of a redundant whole-file comparison, then proves both paths with a tamper test.
How prepare and load now handle the snapshot digest
In scripts/etcd-offsite-backup.py, prepare copies the bytes and sha256 values out of the original integrity block and writes them into the object entry for the snapshot, while the companion publication file still gets a fresh digest call. load gained a matching exemption: the generic loop skips the whole-file digest comparison for the snapshot by name, with a comment noting that the snapshot’s whole-file and embedded digests are checked together further down. The intent is a single source of truth for snapshot integrity, recorded once at creation and carried through publication rather than recomputed over a large file every time.
What the updated backup check actually establishes
The test additions in scripts/ci/etcd-offsite-backup-check.py assert call counts rather than just outcomes: digest is expected exactly once, against the companion file, and snapshot_digest is expected exactly once, against the snapshot, during load. That pins down that publication is no longer rehashing the snapshot. The stronger evidence is the negative case: the test overwrites the snapshot with a same-size replacement whose trailing SHA-256 matches the new bytes, then expects load to raise an error containing snapshot no longer matches. A tampered snapshot with a self-consistent file hash therefore still fails, because the embedded digest no longer agrees. These are unit-level results from the check script; I have not yet exercised it against a freshly published offsite copy or a restore drill, which is the next verification I want.
Why this is testable discipline rather than a micro-optimisation
Reusing a hash that was computed and verified at snapshot time is a general pattern for anyone shipping large artifacts: record integrity once, store it alongside the artifact, and have downstream stages trust and re-verify that record instead of recomputing from scratch. The part worth copying is the guardrail, not the saved cycles. Any time I exempt one file from a blanket check, I owe the pipeline a test that the exempted file still fails when it is modified, and the replacement-bytes test here is exactly that obligation paid. The push also carries a retention fix according to its commit subject, though my review here covered only the backup digest changes. A platform team adopting this shape would want the same pairing: one test that proves the redundant work stopped, and one that proves the remaining check still rejects corruption.