You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cli: key-gen --force regenerates node.secret before the eth keystore with no rollback — failure leaves a mismatched half-rotated key pair #844
Surfaced by a full-repository review (2026-06-09).
Finding
With --force, key_gen (crates/cli/src/commands/key_gen.rs:59-69) archives the old node.secret, writes a fresh node key via load_or_generate, and only then runs generate_and_persist for the eth keystore. If keystore generation fails (disk full, encryption error), the node identity has already been replaced while the keystore is archived/stale — a confusing partial-success state on the very rotation path the archiving exists to make safe. The no-force pre-flight (lines 23-36) deliberately avoids partial writes; the force path reintroduces the hazard. (The password is read before any write, so the most likely failure is already excluded — the window is real but narrow.)
Fix
Generate both key materials into temp files first, then commit (archive-old + rename-new) for both only after both succeed.
The --force path in key_gen (crates/cli/src/commands/key_gen.rs:59-69) performs a non-atomic two-step write: it archives and replaces node.secret (lines 60–64) before invoking generate_and_persist for the eth keystore (line 67). If keystore generation fails after the Ed25519 key is already committed, the node ends up with a new node.secret but no corresponding keystore.json — exactly the mismatched state the archival runbook is designed to prevent. The password is read before any write (mitigating the most common interactive failure), but disk-full and encrypt errors are real edge cases.
📊 Assessment
Dimension
Value
Reasoning
Type
Bug
Confirmed: partial-success state on the key rotation path.
Labels
bug, medium, cli (unchanged)
Already accurate; security is borderline but this is an atomicity/reliability bug on the force path, not an exploitable surface.
Coding agent
Suitable
Fix is clearly specified (generate both to temp, then commit both), scope is one function in one file, and success criterion is unambiguous.
💡 Notes and suggestions
Root cause walk-through
key_gen --force
└─ move_aside(key_path) # node.secret → node.secret.bak.<ts> [COMMITTED]
└─ load_or_generate(output_dir) # writes new node.secret [COMMITTED]
└─ generate_and_persist(...) # ← fails here (disk full / encrypt)
└─ move_aside(keystore_path) # keystore.json → keystore.json.bak.<ts> [may have run]
└─ encrypt_keystore(...) # ← actual failure point
After the failure: node.secret is new, keystore.json is either archived or absent — neither matches.
Suggested fix (in key_gen.rs)
The cleanest approach, consistent with how generate_and_persist already handles atomicity internally (temp file → chmod → rename):
Refactoridentity::load_or_generate to have a lower-level variant (e.g. generate_to_temp(data_dir) -> (SecretKey, TempPath)) that writes to a random temp name in data_dir without touching node.secret.
Refactoreth_identity::generate_and_persist similarly — accept an explicit temp path, or expose a generate_to_temp helper that returns (Address, TempPath) without archiving the live keystore.
generate_new_eth_keystore_to_temp() → (address, eth_temp) (both succeed before committing)
move_aside(key_path)
rename(node_temp, key_path)
move_aside(keystore_path)
rename(eth_temp, keystore_path)
Alternatively, a simpler but equivalent approach: run generate_and_persist (step 3 in the original code) first (its own temp→rename is already atomic at the file level), skip its internal archive by passing a new archive: false flag, then do both move_aside calls and the node key write only after generate_and_persist succeeds. The ordering in the current code's comment ("mirrors decdn run startup") is not a hard constraint.
Checklist
Extract temp-write helper(s) from load_or_generate / generate_and_persist
Rewrite --force path in key_gen.rs to: gen-both-to-temp → archive-both-old → rename-both-new
Verify cleanup on partial failure (temp files removed if any step fails after generation)
Add test: simulate a failure after node key write but before keystore write; assert node.secret and keystore.json remain unchanged (i.e. archives are restored or originals never touched)
Update appendix-operator-key-rotation.md if the observable archive timing changes
Activity
github-actions commentedon Jun 9, 2026
🎯 Triage report
The
--forcepath inkey_gen(crates/cli/src/commands/key_gen.rs:59-69) performs a non-atomic two-step write: it archives and replacesnode.secret(lines 60–64) before invokinggenerate_and_persistfor the eth keystore (line 67). If keystore generation fails after the Ed25519 key is already committed, the node ends up with a newnode.secretbut no correspondingkeystore.json— exactly the mismatched state the archival runbook is designed to prevent. The password is read before any write (mitigating the most common interactive failure), but disk-full and encrypt errors are real edge cases.📊 Assessment
bug,medium,cli(unchanged)securityis borderline but this is an atomicity/reliability bug on the force path, not an exploitable surface.💡 Notes and suggestions
Root cause walk-through
After the failure:
node.secretis new,keystore.jsonis either archived or absent — neither matches.Suggested fix (in
key_gen.rs)The cleanest approach, consistent with how
generate_and_persistalready handles atomicity internally (temp file → chmod → rename):identity::load_or_generateto have a lower-level variant (e.g.generate_to_temp(data_dir) -> (SecretKey, TempPath)) that writes to a random temp name indata_dirwithout touchingnode.secret.eth_identity::generate_and_persistsimilarly — accept an explicit temp path, or expose agenerate_to_temphelper that returns(Address, TempPath)without archiving the live keystore.key_gen.rs --forcepath, sequence:generate_new_node_key_to_temp()→(key, node_temp)generate_new_eth_keystore_to_temp()→(address, eth_temp)(both succeed before committing)move_aside(key_path)rename(node_temp, key_path)move_aside(keystore_path)rename(eth_temp, keystore_path)Alternatively, a simpler but equivalent approach: run
generate_and_persist(step 3 in the original code) first (its own temp→rename is already atomic at the file level), skip its internal archive by passing a newarchive: falseflag, then do bothmove_asidecalls and the node key write only aftergenerate_and_persistsucceeds. The ordering in the current code's comment ("mirrorsdecdn runstartup") is not a hard constraint.Checklist
load_or_generate/generate_and_persist--forcepath inkey_gen.rsto: gen-both-to-temp → archive-both-old → rename-both-newnode.secretandkeystore.jsonremain unchanged (i.e. archives are restored or originals never touched)appendix-operator-key-rotation.mdif the observable archive timing changesAdd this agentic workflows to your repo
To install this agentic workflow, run
fix(cli): make staged commit() fail-safe on install-rename failure (#844
fix(cli): surface restore-failure on commit; dedupe via install_stage…
fix(cli): make key-gen --force rotation atomic across both key files (#…