`syn ensemble init` minted a keyphrase without a node and `syn init` then needed it back; `ensemble register` joined a store that had a node and no membership, which nothing ordinary makes any more. Both are gone: `syn init --new-ensemble [--format-a]` sets the node up in a new ensemble and prints its phrase once, and `syn init --keyphrase` (or the prompt) joins one. The two are parser alternatives, so contradictory flags are a usage error. `syn init` now also finishes an existing store whose node is in no ensemble, as the TUI's first run does, which gives NOT_IN_ENSEMBLE a recourse that exists. NO_REGISTRY_NODES no longer suggests `register`, which never worked on a node that already had a membership. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 KiB
Ensemble Reseed Design
Status
Implemented — rust/lib/src/ensemble/reseed.rs, driven by syn ensemble reseed <new-path>. The design below describes what was built; where the two
diverge, the code is authoritative.
This is a first, deliberately narrow step toward the "manifold key rotation"
TODO item in TODO.md — see that item and docs/KEY_MANAGEMENT.md's
"Deliberately Omitted: Key Rotation" section for the fuller context this fits
into.
Reseed does not revoke anything, by design (see Non-Goals). Removing a single
node from an ensemble while the ensemble key stays good is a separate feature
specified in docs/NODE_REVOCATION.md; the two overlap only in blob
re-encryption, which that document proposes to reuse from here.
Overview
Reseed is an operation that takes an existing, initialized store and a path to a new, not-yet-initialized store, and produces a brand new ensemble — new ensemble keypair, new node keypair, new delegation cert — whose local data is a copy of the old store's, with all blob content re-encrypted under keys derived from the new ensemble key.
syn ensemble reseed <new-path>
Conceptually: propagation, not rotation-in-place. The old ensemble is left completely untouched and remains fully valid; reseed only produces an independent new one seeded from the old one's content. What the user does with the old ensemble afterward (stop using it, decommission its nodes, manually tell other legitimate devices to move to the new keyphrase) is a separate, manual step this feature does not perform.
Motivating Scenario
The ensemble keyphrase (or its derived ensemble private key) is suspected
compromised, but the user still has software control of at least one node
holding a full local copy of their data. Reseed lets them stand up a fresh
ensemble identity without waiting for a general PKI/threshold/revocation
scheme (all still unimplemented — see KEY_MANAGEMENT.md).
Non-Goals
These are explicitly out of scope for this feature, not oversights:
- Revoking the old ensemble. There is no revocation mechanism in this codebase today (no chain-of-trust anchor, no DHT revocation record). The old ensemble's pkarr registry record and delegation certs remain cryptographically valid forever. Reseed does not change that; it only gives the user somewhere else to go. "Retiring" the old ensemble is a purely operational, manual act (stop running its nodes, stop publishing its registry, tell other legitimate devices the new keyphrase out-of-band).
- Unlinkability. Reseed does not try to hide that a new ensemble was derived from an old one. See "DocumentID stability" below for why this was considered and rejected as a goal for this feature.
- A distributed, multi-node rekey protocol. v1 is a single-node, local, offline copy operation. See "Multi-node ensembles" below for how the rest of an ensemble's nodes are expected to transition.
What Gets Copied, Regenerated, or Reset
A key simplifying fact about the current codebase: document/property/edge
data is not encrypted at rest today. Only blob content is
(stores/document.rs stores vault_id on documents and blob_refs purely "for
BLOB-compatibility if at-rest encryption is added later" — the columns
themselves are plaintext TEXT/JSON). So "re-encrypting the store" does not
mean touching every row; it means re-encrypting blob files and rewrapping
vault key(s). Everything else falls into one of three buckets:
| Data | Treatment | Why |
|---|---|---|
documents, properties, edges, document_tombstones, property_history, artifacts, artifact_stubs, artifact_tombstones |
Copied verbatim | Plaintext today; not a function of any key. documents.id is preserved unchanged (see below). |
Blob files (blobs/ directory) |
Decrypted under the old vault key, re-encrypted under the new vault key | Ciphertext is a function of the vault key; must be regenerated, not copied. |
blob_refs.blob_hash |
Rewritten via an old→new hash map built while re-encrypting | It's the ciphertext's content address (BLAKE3(ciphertext)), so it changes when re-encryption changes the ciphertext. plaintext_hash does not change and should be asserted equal as an integrity check. |
vault_keys (encrypted vault keys) |
Freshly derived from the new ensemble key and rewrapped under the new node key, one for each EnsembleDerived vault present in the old store |
Not copied — derived, per derive_ensemble_vault_key. Same label/version scheme is fine to reuse; a different ensemble key already produces a disjoint key regardless of version, so there's no need to also bump version as part of this. |
Node secret, delegation cert, ensemble membership (in settings) |
Freshly generated | These are the identity being replaced. |
peer_nodes, node_doc_status, node_content_status, content_release_log, sync_staging |
Not copied — start empty | Peer-swarm state scoped to the old node/ensemble identity; meaningless (and potentially misleading) under a new one. Repopulates naturally as the new node syncs with the (also newly re-registered) rest of the ensemble. |
Non-identity settings (theme, timezone, log verbosity, node name choice) |
Copied over | User preferences, not cryptographic material. |
Passphrase-keyed vaults, if any exist |
Not automatically migrated | Their key isn't derivable from the ensemble key; doing this transparently would need the passphrase re-entered. Out of scope for v1 — flag and skip, let the user handle separately. |
Blob Re-encryption
Traced every durable location a blob's content address is stored
(grep -rl 'BlobHash\|blob_hash' across documents/, stores/, p2p/,
agents/): it's exactly blob_refs.blob_hash (per-document reference) and
node_content_status's blob keys (peer-swarm cache, already being reset, not
migrated). PropertyValue (documents/property.rs) has no hash-shaped
variant, so there's no risk of a stray content address hiding inside a
generic text property. The blast radius is one column in one table.
This can be built out of the existing BlobStore API rather than
hand-rolling encryption:
- Open the old store's
BlobStore(resolves the old vault key from its ownVaultStore+ old node key automatically) and callload()for each distinctblob_hash/plaintext_hashpair referenced fromblob_refs— decryption is already handled. - Open the new store's
BlobStore(already seeded with the new vault key) and callstore(plaintext, vault_id)— it recomputesplaintext_hash, re-encrypts, and returns the newstored_hash. - Memoize on the old
blob_hashso a blob referenced by multiple documents is only decrypted/re-encrypted once. (Convergent encryption means twoblob_refssharing a blob today will still share exactly one blob after reseed.) - After processing all documents, rewrite each
blob_refs.blob_hashvia the memo map. Assertplaintext_hashis unchanged as a cheap correctness tripwire.
The risk here is procedural (don't miss a row; don't leave a half-migrated store on failure — build the new store in a temp directory and rename it into place only on success) rather than cryptographic, since the actual encrypt/decrypt logic is reused, not reimplemented.
DocumentID Stability
Decision: documents.id values are preserved unchanged across reseed.
This was considered and rejected as a place to try to buy unlinkability.
Regenerating IDs would require building an old→new ID map and rewriting it
consistently across documents.parent_id (self-referential),
edges.from_id/to_id, blob_refs.document_id,
property_history.document_id, and the three artifacts* tables'
document_id columns — real complexity for a security property this
feature can't actually deliver: the reseed is a faithful copy, so document
count, created_at/modified_at timestamps, edge-graph shape, and
property content (plaintext today) all still correlate the two stores
regardless of whether the ID strings match. An attacker positioned to notice
matching UUIDs is already looking at two databases with identical counts,
timestamps, and content. Changing the ID field alone would suggest an
unlinkability guarantee that isn't actually being provided, which is worse
than not attempting it.
If unlinkability ever becomes an actual goal, it needs to be designed as its own feature (timestamp perturbation, structural decorrelation, etc.), not folded into this one.
Multi-Node Ensembles
v1 scope: reseed is run once, on the node holding the fullest local copy
of the data, producing one new ensemble + one new node. The rest of the old
ensemble's nodes are not individually migrated by this tool — they're
discarded and replaced by fresh nodes set up with syn init (or a first-run
screen) and the new ensemble's keyphrase, which then backfill their data via the existing sync protocol
from the freshly-reseeded node. This avoids needing any distributed rekey
protocol or agreement between nodes; each replacement node just joins the
new ensemble the normal way.
Preconditions & Locking
The source store must be inactive (no daemon holding it open) for the
duration of the operation. This isn't new machinery — Store::open already
takes an exclusive StoreLock on the directory (stores/lock.rs), so a live
daemon on the source store makes the reseed tool's own Store::open fail
fast with StoreLockError::InUse, the same as any other second consumer.
Proposed Algorithm
- Validate preconditions: new path does not already contain a store; old path does contain one and isn't locked.
Store::openthe old store (this is also the "isn't locked" check).- Generate a new ensemble secret (same code path as
syn init --new-ensemble); print the new keyphrase to the user. Hold the derived ensemble key only in memory. Store::createthe new store, initially in a temp directory alongsidenew-path.- For every
EnsembleDerivedvault present in the old store'sVaultStore, derive the corresponding new vault key (samelabel,version) from the new ensemble key, wrap it under the new node key, and save it. For anyPassphrasevault found, warn and skip. - Bulk-copy
documents,properties,edges,document_tombstones,property_history,artifacts,artifact_stubs,artifact_tombstonesverbatim. - Walk
blob_refs, decrypt via the oldBlobStore, re-encrypt via the newBlobStore, build the old→new hash map (deduped). - Rewrite
blob_refs.blob_hashin the new store via the map; assertplaintext_hashunchanged per row. - Generate a new node secret, sign a new delegation cert against the new ensemble key, save ensemble membership. Copy over non-identity settings (theme, timezone, node name, log verbosity).
- Leave
peer_nodes,node_doc_status,node_content_status,content_release_log,sync_stagingempty in the new store. - Run a verification pass (see below).
- Rename the temp directory into place at
new-path. Print a summary (document count, blob count, new ensemble pubkey, reminder that the old ensemble is still fully valid and must be retired manually).
Verification
Suggested automated checks before considering the reseed successful (and before the temp→final rename in step 12):
- Document count in new store equals document count in old store.
- Set of
plaintext_hashvalues referenced byblob_refsis identical between old and new stores. - Every
blob_hashin the new store'sblob_refsresolves to an existing file in the new store'sblobs/directory. - Spot-decrypt some sample of blobs in the new store and compare plaintext
BLAKE3 against the recorded
plaintext_hash.
Residual Risks / Open Questions
- No revocation. Restated from Non-Goals because it's the most important caveat: after reseed, the old ensemble's pkarr record and delegation certs are not invalidated by anything. This needs to be prominent in any user-facing docs/output for this command so it isn't mistaken for a complete compromise-recovery story.
- CLI flag surface beyond the bare
<new-path>argument isn't decided — e.g.--format-afor keyphrase format (mirroringsyn init --new-ensemble), a--dry-run/verify-only mode, whether to require an explicit confirmation before treating the source as safe to retire. - Passphrase vaults are skipped rather than handled; if any exist in
practice, decide whether the CLI should refuse to proceed without
--skip-passphrase-vaultsor similar, rather than silently omitting them. - Only lightly explored: stores with more than the default vault, and
whether
origin_nodevalues on copied rows (which reference the old node's pubkey) need any special handling downstream in sync logic, or are fine as historical provenance.