Repository navigation
Sign and export integrity checkpoints - #80
Open
WiktorB2004 wants to merge 15 commits into
Open
WiktorB2004 wants to merge 15 commits into
WiktorB2004 wants to merge 15 commits into
Conversation
… key id collisions
A checkpoint now states the incarnation it was taken in. A signed fork explains a diverging checkpoint only when it starts a later incarnation, so a checkpoint taken after the fork still catches a truncated or rewritten tail.
…ions A stream with no row at a windowed fork has ceiling -1 in the verifier and in the sealer's window, so its first rows after the fork belong to the new incarnation.
Stamps and audit.scrubbed records are keyed by xid space. A stamp on an old row that fits both its own space and a scrub since the fork goes to whichever space's records account for it. The running-scrub window and the retired-receipt check apply per space.
The count reads at most id_count + 1 entries of the primary key, ordered by id, and runs only while the identity sequence is within id_count of the floor; past that the sequence check alone remains. The docstring records that retention weakens the count.
require_replicated reads synchronous_standby_names and needs the n standbys it asks for (FIRST n, ANY n, or a plain list) to flush the block. A configured standby that is not connected is waited for briefly before NO_SYNC_STANDBY, and any error after the commit is a ReplicationError with the seq and LSN.
WiktorB2004
force-pushed
the
add-integrity-retention
branch
from
November 27, 2026 02:37
9f876d7 to
9bb6864
Compare
WiktorB2004
force-pushed
the
add-integrity-checkpoints
branch
from
November 27, 2026 02:37
429cdb7 to
1259842
Compare
6 tasks done
This branch has not been deployed
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.
Summary
Signing, checkpoints and forks for the integrity chain. Closes #72.
Builds on #79 (retention). Everything stays private: nothing is exported from
audit_trailand there are no docs pages yet.Signer/SignatureVerifierprotocol; the core never imports a crypto library. Every block kind can be signed, andverify(verifier=..., require_signatures=...)reportsBAD_SIGNATUREandUNKNOWN_KEY. Withrequire_signatures, an unsigned checkpoint is refused too.Ed25519Signer/Ed25519Verifierin the newsqlalchemy-audit-trail[integrity]extra (cryptography). Keys use the C2SP vkey encoding, and a verifier holds several keys for rotation; two different keys with one key id are refused.export_checkpointappends acheckpointblock and returns it as a C2SP signed note wrapping the library's own statement{v, chain, seq, block_hash, xid_to, sealed_at, incarnation}(not a tlog-checkpoint). Notes with two signatures of one key, or control characters in a key name, are malformed.verify(checkpoints=[...])reportsTRUNCATED,CHAIN_MISMATCH, orANCHOREDwith anUNANCHORED_TAILnote.require_replicated. After the commit, the export readssynchronous_standby_namesand waits until as many standbys as it asks for (FIRST n,ANY n, plain list) have flushed the block's WAL. A configured standby that is reconnecting gets a short grace beforeNO_SYNC_STANDBY; any error after the commit is aReplicationErrorwith the seq and LSN.declare_forkwrites a closing seal of the old incarnation, then the fork block.pg_restoreinto a new cluster the fork records an id window, applied per incarnation by the sealer and the verifier. A stream with no row at the fork belongs to the new incarnation alone.ID_FLOOR_VIOLATIONwhen an identity sequence is behind the floor, or, while the sequence is withinid_countof it, when a stream has more rows at or below the floor than the fork counted (a bounded primary-key read).FORKEDnote. It explains a diverging checkpoint only if the checkpoint was taken in an earlier incarnation and the fork block is signed by a known key; with a verifier, an unsigned fork is aFORKED_UNSIGNEDnote.XID_REWIND.Golden vectors cover the note format (including the spec's example), the keys, a block signature and a checkpoint. A real
pg_dump/pg_restoretest in two containers covers the managed-service fork path. There is no test with a real synchronous standby; the no-standby case and the standby decision are tested.Test plan
uv run pytestpasses locally, including the PostgreSQL tests intests/dbAUDIT_TEST_PG_IMAGE=postgres:14) as well as the default imageruff check,ruff format --checkandmypypassCHANGELOG.mdUnreleasedbullet (nothing public yet)