Skip to content

[M2.2b3] Serialize identity and credential mutations - #43

Merged
samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.2b3-identity-store
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.2b3-identity-store

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Task

M2.2b3, part of #21. Base: feat/m2.2b2-identity-schema; follows the identity schema PR.

What changed and why

Add the identity storage port, redacting domain records and Prisma adapter. Per-user row locks serialize sensitive mutations. Password changes increment the security version and revoke sessions and reset credentials; single-use token claims use conditional updates. Session activity advances monotonically across overlapping requests and cannot revive expired, revoked, disabled-owner or stale-version sessions.

Commands can share the transaction/audit boundary from #41. Driver errors from command transactions are replaced with an opaque availability error to keep bound data out of HTTP logs. A reusable integration fixture owns its PostgreSQL container, temporary KEK, Nest application and cleanup.

Validation

  • Workspace lint, type checks and TypeScript tests pass.
  • Seventeen PostgreSQL integration tests pass, including six repository tests covering concurrent mutations, consumed-token rollback with audit rollback, duplicate signup transactions, expired/future-created credentials, monotonic activity and security-version invalidation.
  • Existing schema, fleet and audit integration suites pass unchanged.

Security considerations

No HTTP endpoint is exposed yet. Application handlers must perform mutations and publish their events inside transaction or withUserLock; this PR supplies and tests that boundary. Password hashes returned by repositories are wrapped in Secret. Session activity is authentication telemetry, not a separate domain command. No new shell invocation or dynamic SQL identifier is introduced.

Checklist

  • M2.2b persistence acceptance met and checked; M2.2 account flows remain open
  • Lint, types and tests pass
  • Real PostgreSQL concurrency and failure cases covered
  • No new secret exposure path
  • Transaction and audit rollback verified
  • Threat model updated

@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.2b2-identity-schema branch from 035182a to 2090cbd Compare November 5, 2026 12:11
@samuelmbabhazi
samuelmbabhazi deleted the branch feat/m2.2b2-identity-schema November 5, 2026 12:11
@samuelmbabhazi samuelmbabhazi reopened this Nov 5, 2026
@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m2.2b2-identity-schema to main November 5, 2026 12:13
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.2b3-identity-store branch from 2a98306 to 6432448 Compare November 5, 2026 12:13
@samuelmbabhazi
samuelmbabhazi merged commit 5b16548 into main Nov 5, 2026
6 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.2b3-identity-store branch November 5, 2026 12:14
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
## Task

M2.2c1, part of #21. Depends on #43; base `feat/m2.2b3-identity-store`.

## What changed and why

Add account and session commands behind application ports. Signup
preserves existing credentials, verification/reset credentials are
single-use, login rotates the presented session, and password reset
invalidates all older sessions and reset links. Password proof is
checked again against the user's security version under a row lock to
prevent a concurrent reset from authorizing a stale login.

Every command mutation publishes an identity event in the same database
transaction. Session authentication verifies account status, security
version, idle/absolute expiry and a session-bound CSRF hash using a
timing-safe comparison. SMTP delivery, request limits, public HTTP
endpoints and MFA are intentionally separate remaining plan items; these
commands are not exposed over HTTP in this PR.

## Validation

- Twenty-five real PostgreSQL integration tests pass, including eight
complete command-flow tests.
- Coverage includes mailbox verification, duplicate signup,
expired/wrong-purpose links, concurrent reset attempts, session
rotation, CSRF binding, logout idempotency, reset-versus-login races,
generic credential rejection and injected audit failures.
- Workspace lint, types, TypeScript tests and builds pass.

## Security considerations

Credential values remain wrapped until hashing, storage or the mail
port. Password hashing and mail delivery occur outside database
transactions. A mail delivery failure leaves an unverified account
eligible for the explicit resend flow; it grants no session. Request
throttling and production delivery must land before exposing the
commands publicly. No new shell invocation or agent action is
introduced.

## Checklist

- [x] M2.2c1 acceptance checked; M2.2c remains open
- [x] Lint, types, tests and builds pass
- [x] Concurrency, replay, expiry and audit-failure tests added
- [x] No new secret logging or shell invocation
- [x] State changes audited atomically
- [x] Remaining HTTP, delivery, throttling and MFA work explicit in PLAN
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant