Skip to content

fix(id): persist restored-key rotation markers durably #12420

Closed

Description

@dezren39

Summary

id key import and id key import-seed install the restored private key before flag_restored() writes .id-key-restored or .id-key-client-restored. restored_key::mark_restored currently uses std::fs::write directly on the marker, so it truncates an existing marker in place and does not durably publish the new contents.

If the process or machine stops during/after that write, the restored key may remain installed while the marker is absent, empty, or partial. restored_key() interprets an empty marker as None; pending() only warns when the marker names an active key. A missing/empty or incomplete marker can therefore make later id serve and keyset operations omit the restore-and-rotate warning for a key that was restored from backup.

This is a crash-safety defect in the implemented restore-rotation flag, not a request to add restore/rotation behavior. The marker is intentionally advisory; this issue concerns losing that warning state.

Evidence

Verified on fresh origin/main b03284079be68158b737d7bd8ceccb95f4a0e52e:

  • pkgs/id/crates/id-directory/src/restored_key.rs:46-50: mark_restored calls std::fs::write(marker, format!("{public_key}\n")) directly.
  • restored_key.rs:57-62: an empty marker is converted to None, the same result as a missing marker.
  • restored_key.rs:100-111: pending() only returns the marker's key when it is still an active admin key.
  • pkgs/id/crates/id-cli/src/commands/key.rs:85-124: import writes/replaces the private key before calling flag_restored; the marker write follows the key installation.
  • pkgs/id/crates/id-cli/src/commands/serve.rs:1398-1404 and commands/keyset.rs:139-145 use the marker to display the warning.
  • id-directory already depends on id-core; id_core::durable_write::write_durable provides a sibling-temp, file-sync, rename, and parent-directory-sync pattern used by other pkgs/id state files.

Dedupe

Acceptance criteria

  • Persist both server and client restore markers through a durable atomic-write path (or an equivalent helper): sync complete marker contents before replacing the target, then sync the containing directory.
  • Preserve useful path context and ensure a failed marker write does not leave a truncated/empty marker in place.
  • Add focused regression coverage for replacing an existing marker and for the durable-write failure boundaries, including that a marker remains readable as the prior or new complete key rather than an empty/partial value.
  • Existing restored-key status, serve-warning, and keyset-rotation tests pass.

No source change was made in this audit.

Activity

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/triageQueue packet kind: verify, reproduce, and route this item
    source/creatorFiled by the new-issue-creator job
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/xsTrivial: expected under 30 minutes of work
    on Nov 22, 2026
  2. developing-today commented on Nov 22, 2026

    @developing-today
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/xsTrivial: expected under 30 minutes of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:donetask/triageQueue packet kind: verify, reproduce, and route this item

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions