Skip to content

fix(dg): keep a master key on logout and the sync key when the keychain fails - #771

Merged
PastaPastaPasta merged 1 commit into
masterfrom
fix/dg-key-safety-wave9
Nov 27, 2026
Merged

PastaPastaPasta merged 1 commit into
masterfrom
fix/dg-key-safety-wave9

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Problem

  1. dg auth logout deleted dg's main-slot key file and keychain entries outright. A dg auth login --full-key file (or a master key an older dg put in the keychain) was gone, with no copy.
  2. dg: a failing keychain leaves the settings-sync key unstored (no file fallback) #768: when the OS keychain is there but fails, Storer::write stopped for Slot::Sync instead of falling back to a file, so a wallet sign-in left the settings-sync key unstored.

Fix

Logout keeps master keys. Before removing an identity key (main, pending, or the keychain entry --identity names), store::remove copies it if it:

  • holds a master key or recovery words, or
  • can't be opened to check: a sealed file this run didn't unlock, or one that changed after it was unlocked.

The copy goes to <name>.bak-<UTC time> (0600, via the existing keep_file) or to a .bak-<UTC time> keychain entry (the same pattern keep_keychain_entry uses). Logout prints one line per copy and adds keptAt to --json (schema regenerated).

While removing, remove holds the identity lock. It trusts the key logout opened only while the key file (a regular file only, never a pipe) still holds the same bytes. A key it can't read or copy stays where it is, and logout fails, listing any copies already made. Limited keys and the sync key are removed as before.

I chose a backup over refusing: logout still does its job (the default identity is cleared and dg's slots are emptied), and the master key isn't lost.

Sync key fallback (#768). After any keychain failure for the sync key, dg reads the entry again:

  • no entry: the key goes to the sealed .key.sync file;
  • the entry already holds this key: keychain;
  • any other entry, or the read fails: dg refuses, as before. A file next to that entry would be hidden by it.

user_sync::key::load reads the file whenever the keychain has no entry or errors, so the fallback file is found. When the keychain failed, the passphrase prompt now gives that as the reason instead of "there is no OS keychain here".

User-visible lines

  • kept a copy at <path>: it holds this identity's master key (--identity uses it; delete it once you keep the master key elsewhere)
  • kept a copy at <path>: dg could not open it to check that it holds no master key (delete it once you no longer need it)
  • note: the OS keychain failed (<error>), so the settings-sync key is kept in <path> (dg and git read it when DASH_FORGE_PASSPHRASE is set)

Compat

No format changes. The backups use the existing names and formats, which older dg can already read through --identity. Sign-ins with a working keychain, or no keychain, behave as before.

Closes #768

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 38 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 241b337f-6170-480e-a484-80a7e0eede32
Commits

Reviewing files that changed from the base of the PR and between a15614b and af53fcc.

Files selected for processing: 6

  • crates/dg/src/auth/mod.rs
  • crates/dg/src/auth/store.rs
  • crates/dg/src/auth/wallet.rs
  • docs/guides/identity-and-keys.md
  • docs/schemas/dg/auth-logout.schema.json
  • docs/schemas/generate.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…in fails

`dg auth logout` deleted dg's key file and keychain entries outright, so a
`--full-key` file (or an older dg's master key in the keychain) was lost.
It now copies an identity key that holds a master key or recovery words,
or that it could not open to check, to `<name>.bak-<UTC time>` (0600) or a
`.bak-` keychain entry before removing it, prints where, and reports the
copies as `keptAt`. It holds the identity lock while it removes, and trusts
the key it opened only while the (regular) key file still holds the bytes
it opened. A key it cannot read or copy stays in place.

When the OS keychain failed to take the settings-sync key, `Storer::write`
gave up. It now reads the entry again: with none there, the key goes to
the sealed `.key.sync` file (which the loader reads when the keychain has
no entry or errors) and dg says so; an entry that would hide the file, or
one that cannot be read, still stops it.

Closes #768

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PastaPastaPasta
PastaPastaPasta merged commit 90a36c6 into master Nov 27, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dg: a failing keychain leaves the settings-sync key unstored (no file fallback)

1 participant