Repository navigation
remote: send each new key epoch to the server and fetch a newer one another machine published - #2110
Merged
Merged
Conversation
…nother machine published
…newer key instead of ending
fujibee
force-pushed
the
feat/epoch-fence-recovery
branch
from
November 29, 2026 15:09
c2d723b to
8c0c2d2
Compare
…st that epochs are sent in order
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.
What
On a team that uses a server's key escrow, a key rotation made with
key.sh rotatenow reaches the server, and a second machine that has not got the new key gets it from there. Nothing in agmsg rotates a key on its own:key.sh rotateis the only thing that writes an epoch after the first one (checked:key.shis the only script that appends a rotation to the journal; the new code only sends and fetches).remote.sh escrow-sync <team>, which sends the newest epoch's key and snapshot toPOST <address>/v1/keys/epochs, with the same body and checks as the first epoch from the escrow connect (same key and same public key already held = a repeat, a different key = a stop that says so). The first epoch at connect now takes the same path (the epoch is read from the team's latest key snapshot instead of being fixed at 1). A team connected with its own key sends nothing: the command asks the server what it holds and leaves the team alone when it holds nothing.GET <address>/v1/keys/bundle, opens it with this machine's device key, and imports it through the same checks aspull(unlock --authenticated-bundle-stdin). The running engine then reloads its configuration and goes on; the same happens when the engine starts on such a team. Messages waiting to be sent are never dropped while it waits.key.sh rotateon a device-approved team no longer tells only "distribute it out of band": it says the key reaches the server once the rotation is confirmed, and still prints the command that shows the key for a team that holds its own.Not in this PR: any rotation on device removal, any handling of a fenced write (nothing fences in 1.10).
Stops and recovery (review-criteria section 10)
remote.sh escrow-install <team>, thenremote.sh sync start <team>), records the wait whereremote.sh statusshows it (a refusal record with codekey-import-required, cleared by the next good cycle), and goes on asking once a minute. It never ends on this error and the queue is untouched. At engine start the same fetch is tried 10 times and then the start fails with that error naming the same two commands. Tested with the engine's own default classifiers (a run of 45 failing cycles: 45 fetches, six one-minute waits, one stated line, no exit).pull).remote.sh escrow-sync <team>). Running it again continues from the server's next epoch, so a run that stopped between epochs is finished in order; the engine also tries at its next rotation or start.Process spawns
Measured by shimming external commands in a throwaway sandbox install against the reference server.
escrow-sync(send) with nothing missing: about 90 external launches (onenodecall more than before, which returns the public half of an epoch's key) (23 sed, 16 sqlite3, 12 rm, 11 mktemp, 6 cat, 5 chmod, 4 curl, ...) against 23 forremote.sh statusin the same setup, about 2.3 s more (2.6 s vs 4.9 s, both from a sandbox start). It reads the server's epochs once, then sends each missing epoch (one body build and one request each) or, with none missing, repeats the newest. It runs once per confirmed rotation and once at engine start for a team that has rotated, never per cycle or per message. Connect now also reads the server's epochs once before it sends (one more request).pull's import when a newer epoch exists; one request when it does not.Tests
tests/remote_sync_fence.test.mjs(6): the engine fetches on a missing key and asks again without a long wait; reloads its configuration after an install without sleeping; after the 40 quick tries it says what to run once, records the wait forstatus, and keeps asking each minute (default classifiers); sends a newly effective epoch once; passes only the team and--fetchon the child's command line with no token or identity in its environment; startup fetch is bounded and other errors pass through.tests/test_remote_escrow.bats(+7, 26 in all): no external command (sqlite3, node, curl, age, ...) is started with the team's private key in its arguments, checked by spying on every launch through a connect and a send (red when the body is read throughsqlite3again); the epochs are sent in order from the server's next one, and after a failure on epoch 3 a rerun sends only epoch 3 (red when only the newest epoch is sent); a repeat of the newest epoch is not a second epoch; an own-key team sends nothing;--fetchwith no newer epoch installs nothing and exits 0; a team not joined by device approval is left alone and an unknown option is refused; thekey.sh rotatetext on a device-approved team.AGMSG_HOMEandAGMSG_INSTALL_HOMEunset. The four.github/scripts/check-*.shpass at their baselines.Run against the reference server (accounts profile, key escrow with a key file)
On a throwaway PostgreSQL 14 cluster on a loopback port, two sandboxed installs of this branch, nothing outside the sandbox changed.
connectby device approval; the server holds epoch 1.pullby device approval; the key bundle came from the server and B synced.key.sh rotate. The engine confirmed it and sent epoch 2; the server then held epochs 1 and 2 for the team.remote.sh escrow-syncregistered epochs 2 and 3, in that order.escrow-installwas refused (401, "the server did not accept this machine's device key"), and A kept writing under the same key.The first rotation attempt also showed that a second machine started on a rotated team ended with a fatal error and no recovery; that is the start-up fetch above.
Not run: Windows, a server behind TLS, a concurrent rotation by two machines (the second to send is told the server holds a different key for that epoch and is pointed at
escrow-install).Notes for the release
key.sh rotateis sent to the server, and another machine fetches the new key from it. No key is rotated automatically.