Skip to content
This repository was archived by the owner on Sep 5, 2026. It is now read-only.

feat: cogmem trust --rotate for safe key rotation - #12

Merged
dcondrey merged 1 commit into
mainfrom
feat/key-rotation
Jun 28, 2026
Merged

feat: cogmem trust --rotate for safe key rotation#12
dcondrey merged 1 commit into
mainfrom
feat/key-rotation

Conversation

@dcondrey

Copy link
Copy Markdown
Owner

Automates the key-rotation path so it no longer means manually deleting trust.json — and fixes a latent bug in the issuer pin while doing so.

The bug this also fixes

The TOFU pin (PR #11) trusted exactly one DID. Rotating the agent key would have bricked verification of all history: every past log entry and credential was signed by the old DID, which the pin would now reject as untrusted.

Design

cogmem trust --rotate is an explicit operator action — the only supported way to change the trusted identity, so a vault-content attacker (who can't run it) still can't re-root trust. It:

  • re-anchors to the current on-disk key,
  • retains the previous DID in a prior set so history signed by the retired key still verifies,
  • archives the old anchor to trust.json.prev,
  • is idempotent (no-op when the key already matches).

cogmem trust (no flag) shows the trusted + retired DIDs and warns on a key/anchor mismatch; cogmem doctor warns too.

What I did NOT do

No silent auto-re-pin on detected key change — that is the attack the pin defends against. Rotation stays deliberate.

Tests (38 provenance, +3)

  • test_rotation_preserves_history_and_accepts_new_key — old entry still verifies after rotation, new-key entry verifies too.
  • test_rotation_idempotent_when_key_unchanged
  • test_rotation_still_rejects_foreign_key — a never-trusted key is still rejected post-rotation.

End-to-end CLI flow (establish → mismatch warning → rotate → clean → idempotent) verified against a temp home. THREAT-MODEL §4.3 updated.

Changing the agent key previously meant manually deleting trust.json, and the pin
would have bricked verification of all history signed by the old key. Add an explicit
operator command that re-anchors to the current key while retaining prior DIDs (so
historical log/credentials still verify), archives the old anchor, and is idempotent.
doctor and 'cogmem trust' now warn on a key/anchor mismatch. A vault-content attacker
cannot run it, so the security property holds. Tests prove history survives rotation
and a foreign key is still rejected.
@dcondrey
dcondrey merged commit ced24ee into main Jun 28, 2026
2 checks passed
@dcondrey
dcondrey deleted the feat/key-rotation branch June 28, 2026 20:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant