Skip to content

Automate field-level encryption key rotation for profiles table #491

@temma02

Description

@temma02

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

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions