Description
rotateProfileEncryptedColumns in key-rotation.ts is implemented but never called. There is no scheduled job or admin endpoint to trigger rotation. Stale encryption keys increase the blast radius of a key compromise.
Requirements and context
- Must be secure, tested, and documented where applicable
- Should stay reviewable and fit the current monorepo structure
- Relevant files:
apps/backend/src/lib/crypto/key-rotation.ts, apps/backend/src/lib/crypto/field-encryption.ts, apps/backend/src/app/api/cron/purge-expired-tokens/route.ts
Suggested execution
- Create branch:
issue-017-automate-encryption-key-rotation
- Keep changes scoped to the issue and reference the task IDs in the PR
Implement changes
- Create
apps/backend/src/app/api/cron/rotate-encryption-keys/route.ts
- Call
rotateProfileEncryptedColumns with the new key from env
- Guard the route with the existing
CRON_SECRET auth pattern
- Register in
vercel.json crons (weekly schedule)
Test and commit
- Add route tests: successful rotation, missing new key env var, partial failure
- Verify re-encrypted values can be decrypted with the new key
- Security note: old key must remain available until all rows are re-encrypted
Example commit message
feat(cron): add weekly encryption key rotation job
Guidelines
- Prefer small, reviewable PRs
- Keep naming and data contracts consistent with the spec docs
Description
rotateProfileEncryptedColumnsinkey-rotation.tsis implemented but never called. There is no scheduled job or admin endpoint to trigger rotation. Stale encryption keys increase the blast radius of a key compromise.Requirements and context
apps/backend/src/lib/crypto/key-rotation.ts,apps/backend/src/lib/crypto/field-encryption.ts,apps/backend/src/app/api/cron/purge-expired-tokens/route.tsSuggested execution
issue-017-automate-encryption-key-rotationImplement changes
apps/backend/src/app/api/cron/rotate-encryption-keys/route.tsrotateProfileEncryptedColumnswith the new key from envCRON_SECRETauth patternvercel.jsoncrons (weekly schedule)Test and commit
Example commit message
Guidelines