Skip to content

Remove Cognito auto-refresh and PII from database - TEST#209

Merged
nomadicrogue merged 4 commits into
testfrom
dev
Mar 5, 2026
Merged

Remove Cognito auto-refresh and PII from database - TEST#209
nomadicrogue merged 4 commits into
testfrom
dev

Conversation

@nomadicrogue
Copy link
Copy Markdown
Collaborator

Summary

  • Drop email and name columns from the users table — PII now lives exclusively in Cognito
  • GET /me fetches email live from Cognito using the caller's own access token (same pattern as the frontend's GetUserCommand) — nothing stored, retrieved at execution
  • cognito_service uses ECS task role instead of explicit AWS credentials (which were never set and caused 2500+ UnrecognizedClientException errors per 12h window)
  • Remove auto-refresh-from-Cognito code path that was the source of those errors
  • Delete account flow preserved: DB cascade + Cognito AdminDeleteUser (production only, per PR Delete Cognito user only in production; skip in dev/test #202)
  • Clean up dead code: get_user_by_email, UserCreate/UserUpdate/UserLogin schemas, AWS_ACCESS_KEY_ID/SECRET/TOKEN config, email sync in auth pipeline

Companion Infra changes (Morpheus-Infra)

  • IAM policy grants AdminDeleteUser + GetUser on the Cognito user pool (task role)
  • Removed AWS_ACCESS_KEY_ID/SECRET_ACCESS_KEY/SESSION_TOKEN from ECS task definition secrets

Migration

Alembic migration drop_email_name_2026 drops email and name columns and the ix_users_email_nonunique index. Reversible (downgrade adds columns back as nullable).

nomadicrogue and others added 4 commits March 5, 2026 13:29
…ors/12h

The auto-refresh-from-Cognito code path attempted to call AdminGetUser
on every request for users without email, but AWS credentials were never
configured — generating constant cognito_user_info_error noise. Since
Dec 2 2025 (c848bf2), email is optional metadata and cognito_user_id is
the sole identity key; aggressively chasing email server-side contradicts
that design. Email is still opportunistically captured from the JWT when
present.

Removed:
- Both auto-refresh blocks in dependencies.py (new-user + existing-user)
- update_user_from_cognito() in crud/user.py (only caller was auto-refresh)
- get_user_info() in cognito_service.py (only caller was the above)
- cognito_service import from dependencies.py

Kept:
- cognito_service.delete_user() (used by account deletion endpoint)
- JWT-based email update (passive, no server-side AWS call)

Made-with: Cursor
… time

- Drop email and name columns from users table (alembic migration)
- GET /me now fetches email live from Cognito via user's access token
  (same pattern as the frontend's GetUserCommand)
- cognito_service uses ECS task role instead of explicit AWS credentials
- Remove email sync logic from auth pipeline (dependencies.py)
- Remove get_user_by_email, UserCreate, UserUpdate, UserLogin schemas
- Remove AWS_ACCESS_KEY_ID/SECRET/TOKEN from config (task role provides creds)
- Clean up all email/name references in cache, logging, and local testing

Cognito is now the single source of truth for PII.  The database only
stores cognito_user_id and application-level fields.

Made-with: Cursor
- Changed the method of determining the database host and port by retrieving connection details from a dedicated AWS Secrets Manager secret.
- Updated the DATABASE_URL format to include the port for PostgreSQL connections.
- Improved comments for clarity regarding environment determination and database credential retrieval.

This refactor enhances the maintainability and clarity of the build workflow configuration.
feat: remove PII from database, resolve email from Cognito live
@nomadicrogue nomadicrogue merged commit 78f4634 into test Mar 5, 2026
5 checks passed
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.

1 participant