Skip to content

feat: DB password rotation drill with pool credential refresh + safety guardrails (Closes #718) - #801

Open
laurentketterle-hub wants to merge 2 commits into
RevoraOrg:masterfrom
laurentketterle-hub:feat/db-password-rotation-drill
Open

feat: DB password rotation drill with pool credential refresh + safety guardrails (Closes #718)#801
laurentketterle-hub wants to merge 2 commits into
RevoraOrg:masterfrom
laurentketterle-hub:feat/db-password-rotation-drill

Conversation

@laurentketterle-hub

Copy link
Copy Markdown
Contributor

Summary

Implements database password rotation with runtime pool credential refresh, a rehearsal drill script, and comprehensive tests.

Changes

src/db/pool.ts — Added rotatePoolCredentials():

  • Gated behind DB_ROTATION_ENABLED=true (safe-by-default, no-op otherwise)
  • Smoke-tests new credentials with SELECT 1 before swapping the active pool
  • Drains old pool gracefully (5s delay for in-flight queries to complete)
  • Event listener system (onCredentialsRotated) for rotation/failure notifications
  • Metric counters: db.pool.credential_rotation (success) and db.pool.credential_rotation_failed

scripts/drill-db-password-rotation.sh — Rehearsal script:

  • Refuses to run against production URLs
  • Pre-rotation connection verification
  • Triggers rotation via admin endpoint (with fallback to direct psql smoke test)
  • Post-rotation staging health verification

src/db/pool.rotation.test.ts — 8 test cases:

  • No-op when disabled, smoke-test path, failure counter + exception
  • Listener notification (success & failure), listener error swallowing
  • Config override over env vars, clearRotationListeners cleanup

Safety Guardrails

  • DB_ROTATION_ENABLED must be explicitly set for rotation to take effect
  • Drill script refuses production URLs
  • Smoke-test prevents swapping to bad credentials
  • Old pool connections drain before closing

Closes #718

…y guardrails

- Add rotatePoolCredentials() to src/db/pool.ts:
  - DB_ROTATION_ENABLED safety gate (no-op by default)
  - Smoke-test query before swapping pool
  - Graceful old-pool drain (5s timeout)
  - Event listeners for rotation/failure notifications
  - Metric counters: db.pool.credential_rotation / _failed
- Add drill script scripts/drill-db-password-rotation.sh:
  - Production URL guard (refuses prod)
  - Pre/post rotation connection verification
  - Staging health endpoint check
- Add pool.rotation.test.ts with 8 test cases
  - No-op when disabled, smoke-test, failure counter,
    listeners, env fallback, config override, cleanup

Closes RevoraOrg#718
@laurentketterle-hub

Copy link
Copy Markdown
Contributor Author

I claim this bounty. PR ready for review.

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.

Secrets rotation: DB password rotation drill with connection-pool refresh test

1 participant