Skip to content

feat: hulak env rotate-key — identity rotation (#146)#187

Merged
pthapa1 merged 8 commits intomainfrom
146-hulak-env-rotate-key-master-key-rotation
May 1, 2026
Merged

feat: hulak env rotate-key — identity rotation (#146)#187
pthapa1 merged 8 commits intomainfrom
146-hulak-env-rotate-key-master-key-rotation

Conversation

@xaaha
Copy link
Copy Markdown
Owner

@xaaha xaaha commented Apr 30, 2026

Summary

  • Add hulak env rotate-key (alias: rotate-identity) — generates new age keypair, swaps in recipients.txt, re-encrypts store, backs up old key to identity.txt.old
  • Add import-identity / export-identity aliases for consistency
  • Identity-first write order for crash recovery: backup → new identity → store.age → recipients.txt
  • Interrupted rotation detection: re-running rotate-key after a crash resumes from where it left off
  • Refuses to run when HULAK_MASTER_KEY is set (directs user to import-key first)

Files changed

File What
pkg/vault/keys.go IdentityOldPath, BackupIdentity, LoadIdentityOld
pkg/vault/recipients.go SwapRecipientKey
pkg/userFlags/env_rotate_key.go runRotateKey + helpers (new)
pkg/userFlags/env_rotate_key_test.go 8 integration tests (new)
pkg/userFlags/subcommands.go Command registration + aliases

Test plan

  • Single-recipient happy path — new key decrypts, old key doesn't
  • Multi-recipient — teammate's key and name untouched after rotation
  • Refuses when HULAK_MASTER_KEY set — error mentions import-key
  • Refuses extra arguments
  • Store data preserved after rotation (strings, numbers)
  • identity.txt.old overwritten on second rotation
  • Interrupted rotation recovery — crash after identity write, re-run completes
  • Both keys dead — error when neither identity nor .old can decrypt
  • mise check passes (lint + all tests)

Closes #146

@xaaha xaaha linked an issue Apr 30, 2026 that may be closed by this pull request
@xaaha xaaha requested review from pthapa1 April 30, 2026 21:28
@pthapa1 pthapa1 merged commit c9cfbe8 into main May 1, 2026
2 checks passed
@pthapa1 pthapa1 deleted the 146-hulak-env-rotate-key-master-key-rotation branch May 1, 2026 14:54
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.

hulak env rotate-key — master key rotation

2 participants