gabriel / muse public
fix patch auth dev
AI Agent gabriel · 144 days ago · Apr 27, 2026 · Diff

fix(auth): rotate atomically syncs hub — register new key, deregister old

Bug: muse auth rotate only incremented the local HD index in identity.toml. It never registered the new key with the hub or deregistered the old one, leaving local and remote in an inconsistent state after every rotation.

Fix: run_rotate now performs a four-step atomic sequence: 1. Derive new key at index+1 2. Register new key with hub via challenge-response (_post_challenge/_post_verify) 3. Deregister old key via DELETE /api/auth/keys/{handle}/{key_id} (_hub_delete) 4. Update identity.toml only after hub confirms the new key

If hub registration fails (step 2), identity.toml is not touched — local and remote stay in sync. _hub_delete failure is non-fatal (warns and continues) since the hub may have already expired or revoked the old key.

Also adds _compute_key_id() to derive the hub key_id from identity_id and public_key_b64, mirroring musehub.core.genesis.compute_key_id.

auth.py: _json_post_raw now loads the local dev CA cert for localhost HTTPS so muse auth register works against the local hub without system-wide cert install.

tests/conftest.py: _isolate_muse_home autouse fixture now uses muse_dir() from muse.core.paths instead of raw '/.muse/' string construction.

tests/test_auth_rotate.py: - isolated fixture stubs _json_post_raw + _hub_delete (hub-safe by default) - IV: hub-sync integration tests (register, deregister, toml-after-hub, fail-fast) - muse_dir() replaces raw '/.muse/' strings throughout

sha256:83386cdb9b53a8cb4e40d39838e89ed0788fc033cc9f746085b6fe289395f686 sha
+9 ~6 symbols
sha256:527a55acd32d5f304cceaa6322a1faae1147097557ccb4b4c0aee25ce6959e4b snapshot
+9
symbols added
~6
symbols modified
0
dead code introduced
Semantic Changes 15 symbols
~ muse/cli/commands/auth.py .py 2 symbols added, 1 symbol modified
+ _compute_key_id function function _compute_key_id L1307–1318
+ _hub_delete function function _hub_delete L531–544
~ tests/conftest.py .py 1 symbol modified
~ tests/test_auth_rotate.py .py 7 symbols added, 4 symbols modified
+ TestRotateHubSync class class TestRotateHubSync L347–518
+ _mock_hub_calls method method _mock_hub_calls L350–386
+ test_IV1_rotate_registers_new_key_with_hub method method test_IV1_rotate_registers_new_key_with_hub L388–414
+ test_IV2_rotate_deregisters_old_key_from_hub method method test_IV2_rotate_deregisters_old_key_from_hub L416–437
+ test_IV3_rotate_new_key_in_identity_toml_after_hub_sync method method test_IV3_rotate_new_key_in_identity_toml_after_hub_sync L439–476
+ test_IV4_rotate_fails_if_hub_registration_fails method method test_IV4_rotate_fails_if_hub_registration_fails L478–518
+ muse_dir import import muse_dir L70–70
← Older Oldest on dev
All commits
Newer → Latest on dev

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:83386cdb9b53a8cb4e40d39838e89ed0788fc033cc9f746085b6fe289395f686 --body "your comment"