M2: Postgres-hardening slice (ADR-011) — drop Redis, PostgresOtpStore/SessionStore, advisory locks #120

Closed
opened 2026-11-08 13:39:13 +01:00 by amiryahaya · 3 comments
Owner

Umbrella for the M2 Postgres-hardening slice per ADR-011 (Postgres-only server state) — docs/redesign/2026-11-onboarding-passkey/02-architecture.md §17, dev plan v1.8 task 2.9.

Rationale (short): every 'per-process → M2 Redis hardening' TODO in the codebase collapses into a Postgres row/constraint/advisory lock; atomicity is native (no Lua); one stateful store shrinks the zero-knowledge audit surface (audits kept finding distributed-state bugs: #89, #93, bootstrap slot, TOTP guard); scale does not justify a second store pre-launch. Revisit triggers recorded in ADR-011.

Slices (each its own PR):

  1. PostgresOtpStore — atomic UPDATE…RETURNING consume; closes #89 (re-scoped) by deletion. Remove RedisOtpStore + fixtures.
  2. PostgresSessionStore — Drive-side sessions table (hash, user, device, expires_at) replacing the SDK's RedisSessionStore; IDA-06 device-revocation deletes unchanged; mfa: pending sessions unchanged semantically.
  3. Advisory locks + guard/budget rows — pg_advisory_xact_lock for the multi-instance invite-accept path (InvitationAcceptanceService per-invite semaphores); TotpSecurityGuard lockout state to rows; M2mAuthMiddleware failure budget to sliding-window rows.
  4. Cleanup — remove redis:7-alpine from compose.yml + compose.local.yml, RedisHealthCheck, ConnectionStrings:Redis wiring in Program.cs, StackExchange.Redis package ref; Redis testcontainers fixtures removed.

Acceptance: interleaved atomic-consume test green; suite green with no Redis containers in CI; compose files contain no redis service; #89 closed at slice 1; ADR-011 revisit triggers stay dormant (documented, not hypothetical claims).

Umbrella for the M2 Postgres-hardening slice per **ADR-011 (Postgres-only server state)** — docs/redesign/2026-11-onboarding-passkey/02-architecture.md §17, dev plan v1.8 task 2.9. Rationale (short): every 'per-process → M2 Redis hardening' TODO in the codebase collapses into a Postgres row/constraint/advisory lock; atomicity is native (no Lua); one stateful store shrinks the zero-knowledge audit surface (audits kept finding distributed-state bugs: #89, #93, bootstrap slot, TOTP guard); scale does not justify a second store pre-launch. Revisit triggers recorded in ADR-011. Slices (each its own PR): 1. **PostgresOtpStore** — atomic UPDATE…RETURNING consume; closes #89 (re-scoped) by deletion. Remove RedisOtpStore + fixtures. 2. **PostgresSessionStore** — Drive-side sessions table (hash, user, device, expires_at) replacing the SDK's RedisSessionStore; IDA-06 device-revocation deletes unchanged; mfa: pending sessions unchanged semantically. 3. **Advisory locks + guard/budget rows** — pg_advisory_xact_lock for the multi-instance invite-accept path (InvitationAcceptanceService per-invite semaphores); TotpSecurityGuard lockout state to rows; M2mAuthMiddleware failure budget to sliding-window rows. 4. **Cleanup** — remove redis:7-alpine from compose.yml + compose.local.yml, RedisHealthCheck, ConnectionStrings:Redis wiring in Program.cs, StackExchange.Redis package ref; Redis testcontainers fixtures removed. Acceptance: interleaved atomic-consume test green; suite green with no Redis containers in CI; compose files contain no redis service; #89 closed at slice 1; ADR-011 revisit triggers stay dormant (documented, not hypothetical claims).
Author
Owner

Slice 1 LANDED: PR #122 squash-merged as b5e90e3 (PR runs green, #89 closed). Remaining: slice 2 PostgresSessionStore, slice 3 advisory locks + guard/budget rows, slice 4 compose/health/wiring cleanup.

Slice 1 LANDED: PR #122 squash-merged as b5e90e3 (PR runs green, #89 closed). Remaining: slice 2 PostgresSessionStore, slice 3 advisory locks + guard/budget rows, slice 4 compose/health/wiring cleanup.
Author
Owner

Slice 2 LANDED: PR #124 squash-merged as 62c6528 (PR runs api-ci 12036 + security-ci 12037 green, suite 938/0/39, coverage 87.39%). PostgresSessionStore: sessions table (SHA-256 token hash at rest, sliding TTL, device fingerprint IDA-06, mfa values) + session_challenges (consume-once); SessionCleanupService sweep; AsNoTracking/set-based read paths. Scope deviation: RedisSessionStoreIntegrationTests (testcontainers) removed in this slice — the SDK Redis store has zero references left; slices 3-4 remain (advisory locks + guard/budget rows; compose/RedisHealthCheck/package cleanup).

Slice 2 LANDED: PR #124 squash-merged as 62c6528 (PR runs api-ci 12036 + security-ci 12037 green, suite 938/0/39, coverage 87.39%). PostgresSessionStore: sessions table (SHA-256 token hash at rest, sliding TTL, device fingerprint IDA-06, mfa values) + session_challenges (consume-once); SessionCleanupService sweep; AsNoTracking/set-based read paths. Scope deviation: RedisSessionStoreIntegrationTests (testcontainers) removed in this slice — the SDK Redis store has zero references left; slices 3-4 remain (advisory locks + guard/budget rows; compose/RedisHealthCheck/package cleanup).
Author
Owner

ALL SLICES LANDED — closing. Slice 1: PostgresOtpStore, atomic consume (#89 closed — PR #122, b5e90e3). Slice 2: PostgresSessionStore + session_challenges + sweep (PR #124, 62c6528). Slice 3: advisory invite locks + TotpSecurityGuard/M2M budget rows (PR #125, 2c26f9a). Slice 4: Redis leaves compose/health/packages/appsettings entirely (PR #126). Final state: suite 945/0/39 Release+Debug, coverage 87.77%, compose validated Postgres-only. ADR-011's revisit triggers remain documented and dormant. The 'M2 Redis hardening' concept is retired — Postgres-hardening shipped instead.

ALL SLICES LANDED — closing. Slice 1: PostgresOtpStore, atomic consume (#89 closed — PR #122, b5e90e3). Slice 2: PostgresSessionStore + session_challenges + sweep (PR #124, 62c6528). Slice 3: advisory invite locks + TotpSecurityGuard/M2M budget rows (PR #125, 2c26f9a). Slice 4: Redis leaves compose/health/packages/appsettings entirely (PR #126). Final state: suite 945/0/39 Release+Debug, coverage 87.77%, compose validated Postgres-only. ADR-011's revisit triggers remain documented and dormant. The 'M2 Redis hardening' concept is retired — Postgres-hardening shipped instead.
Sign in to join this conversation.
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
primatekuntech/failsulit#120
No description provided.