Auth Worker Migration
Auth Worker Migration
Section titled “Auth Worker Migration”This runbook covers migration from:
workers/cosmos/auth
to:
workers/bookmarks/auth
with minimal user disruption and a fast rollback path.
Difficulty and timeline
Section titled “Difficulty and timeline”- Estimated difficulty: medium-high (7/10)
- Recommended timeline: 1-2 weeks (fork-and-trim approach)
Bookmarks currently depends on auth for:
/api/auth/login/api/auth/register/api/auth/password/reset-request/api/auth/password/reset-confirm/api/auth/refresh/api/auth/verify/api/v1/verify(token verification used by Bookmarks API middleware)
Success criteria
Section titled “Success criteria”- No increase in login/refresh failure rate after cutover.
- Session expiry continues to auto-redirect to login in app.
- Verification and reset emails still deliver and links resolve.
- Rollback can be completed by binding change only.
Migration strategy
Section titled “Migration strategy”- Clone
cosmos-auth-workertobookmarks-auth-worker. - Clone
cosmos-mail-workertobookmarks-mail-worker. - Keep endpoint contracts identical during first cut.
- Use dedicated Bookmarks auth + mail D1/KV/queue resources.
- Keep secrets/config parity.
- Validate in staging with Bookmarks API bound to new auth worker.
- Cut over production by changing only
AUTH_SERVICEbinding inworkers/bookmarks/api. - Monitor, then remove legacy dependency after stabilization.
Phase 1: Create worker
Section titled “Phase 1: Create worker”- Copy
workers/cosmos/authtoworkers/bookmarks/auth. - Update
wrangler.tomlnames/bindings/database names for Bookmarks. - Keep route paths unchanged.
- Keep auth token and verify behavior unchanged.
Phase 1b: Create dedicated mail worker
Section titled “Phase 1b: Create dedicated mail worker”- Copy
workers/cosmos/mailtoworkers/bookmarks/mail. - Update worker/package names to
bookmarks-mail-worker. - Provision dedicated Cloudflare resources for Bookmarks mail:
- KV namespace
- D1 database
- queue + DLQ
- Replace inherited IDs in
wrangler.tomlwith Bookmarks-specific IDs. - Deploy and validate
POST /api/send-email.
Phase 2: Environment parity
Section titled “Phase 2: Environment parity”Set equivalent vars/secrets in bookmarks-auth-worker:
JWT_SECRETENCRYPTION_KEYAPP_URL=https://bookmarksapp.cosmosdigitalservices.com- Access verification config (
ACCESS_TEAM_DOMAIN,ACCESS_AUD,ACCESS_ISSUER) - Turnstile settings, if enabled
MAIL_SERVICEbinding ->bookmarks-mail-worker
Phase 3: Data + token plan
Section titled “Phase 3: Data + token plan”Choose one path:
- Hard cut (simpler): users re-login once after cutover.
- Soft continuity (preferred): preserve token verification compatibility during rollout by keeping token signing/verification compatible until refresh churn completes.
Recommended:
- Keep JWT verification compatibility at cutover.
- Accept old refresh tokens for a grace window if feasible.
- Force rotate tokens after grace window.
Phase 4: Staging validation
Section titled “Phase 4: Staging validation”- Deploy
bookmarks-auth-workerto staging. - Deploy
bookmarks-mail-workerstaging. - Point
bookmarks-auth-workerstagingMAIL_SERVICEtobookmarks-mail-worker-staging. - Point staging
workers/bookmarks/apiAUTH_SERVICEtobookmarks-auth-worker. - Run smoke tests:
- register/login/logout
- refresh flow
- password reset request + confirm
- email verify redirect to
/verify-email /v1/me- websocket auth to
/v1/clubs/:clubId/stream
- Confirm app/session behavior:
- token refresh works
- expired sessions auto-redirect to login
- app resume reconnect still works
Phase 5: Production cutover
Section titled “Phase 5: Production cutover”- Deploy
bookmarks-auth-workerproduction. - Deploy
bookmarks-mail-workerproduction. - Ensure
bookmarks-auth-workerMAIL_SERVICEbinds tobookmarks-mail-worker. - Update
workers/bookmarks/api/wrangler.toml:[[services]] binding = "AUTH_SERVICE"->bookmarks-auth-worker
- Deploy
bookmarks-api-worker. - Monitor:
- auth error rate
- refresh failures
- password reset failures
- verification redirect errors
Rollback plan
Section titled “Rollback plan”If regressions occur:
- Re-point
workers/bookmarks/apiAUTH_SERVICEback tocosmos-auth-worker. - Redeploy
bookmarks-api-worker. - Re-run auth smoke tests.
Rollback target time: under 15 minutes (binding + deploy only).
Post-cut cleanup
Section titled “Post-cut cleanup”- Update docs and runbooks to remove
cosmos-auth-workerreferences for Bookmarks flows. - Remove temporary compatibility paths after stabilization window.
- Archive migration metrics and incident notes.
Checklist
Section titled “Checklist”-
bookmarks-auth-workercreated fromcosmos-auth-worker - D1 database created and schema applied
-
bookmarks-mail-workercreated fromcosmos-mail-worker - Mail worker KV/D1/queue resources created
- Secrets and vars configured
- Auth
MAIL_SERVICEbound tobookmarks-mail-workerand tested - Staging binding switched and validated
- Production binding switched
- Monitoring clean for 48 hours
- Legacy dependency references removed