Skip to content

fix: prevent orphaned API keys in secure-storage profile mutations#239

Draft
bukinoshita wants to merge 1 commit intomainfrom
fix/atomic-credential-mutations-5198
Draft

fix: prevent orphaned API keys in secure-storage profile mutations#239
bukinoshita wants to merge 1 commit intomainfrom
fix/atomic-credential-mutations-5198

Conversation

@bukinoshita
Copy link
Copy Markdown
Member

@bukinoshita bukinoshita commented Apr 9, 2026

Summary by cubic

Fixes orphaned API keys by making secure-storage profile mutations atomic with compensating rollbacks. Addresses Linear BU-636.

  • Bug Fixes
    • Atomic writes in writeCredentials via temp file + renameSync to prevent partial credentials.json updates.
    • storeApiKeyAsync: if the file write fails after storing the secret, delete the new secret from the secure backend.
    • removeApiKeyAsync: cache the existing secret and restore it if the file update fails.
    • removeAllApiKeysAsync: cache all secrets and restore them if credentials.json deletion fails.
    • renameProfileAsync: copy secret to the new name, commit the file rename, then delete the old secret; revert the new secret if the file rename fails.

Written for commit 92bcda3. Summary will update on new commits.

- Make writeCredentials() atomic via temp file + rename to prevent
  partial writes from corrupting credentials.json
- Add compensating rollback to storeApiKeyAsync: if writeCredentials
  fails after backend.set(), immediately backend.delete() the
  just-stored secret
- Add compensating rollback to removeApiKeyAsync: cache the existing
  secret before backend.delete(); if removeApiKey() fails, restore it
  with backend.set()
- Add compensating rollback to removeAllApiKeysAsync: cache all
  existing secrets before deletion; if file unlink fails, restore them
  all with backend.set()
- Reorder renameProfileAsync: copy secret to newName, commit file
  rename, then delete oldName; if file rename fails, delete newName
  to restore original state
- Add tests for all rollback scenarios

Co-authored-by: Bu Kinoshita <bukinoshita@users.noreply.github.com>
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.

2 participants