Repository navigation
[M2.2a] Add bounded authentication security primitives - #40
Merged
Merged
Conversation
6 tasks done
samuelmbabhazi
added a commit
that referenced
this pull request
Nov 5, 2026
## Task M2.2b1, part of #21. Depends on #40; base `feat/m2.2a-identity-primitives`. ## What changed and why Add a request-local Prisma unit of work and make the audit repository participate in the current command transaction. Identity commands can now roll back their state change when audit persistence fails. Nested commands share their caller's transaction; concurrent requests remain isolated. Existing repositories retain their behavior until they explicitly adopt this unit of work. ## Validation - Real PostgreSQL integration test rejects an audit insert with a database constraint and verifies that the command write is rolled back. - Concurrent transaction test commits one command and rolls back another, including nested audit writes, and verifies the async context is cleared afterwards. - All six API integration tests pass; workspace lint, type checks and TypeScript tests pass. - The unchanged Go/protobuf contracts passed in #40. ## Security considerations No endpoint, role, credential or external delivery is added. Transaction callbacks must await their work and allow failures to propagate; password hashing and external I/O remain outside transactions. The synchronous audit subscriber is the only current event consumer; future external consumers must use an outbox rather than emit side effects inside a database transaction. ## Checklist - [x] M2.2b1 acceptance met and checked in PLAN; M2.2 remains open - [x] Lint, type checks, tests and PostgreSQL integration pass - [x] Failure and concurrency tests added - [x] No shell invocation or new secret exposure path - [x] Audit participates in the command transaction - [x] Architecture documentation updated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task
M2.2a, part of #21. Base:
main. This PR establishes identity primitives; account endpoints and persistence follow in separate PRs. It does not complete M2.2.What changed and why
Add pure email/password/session rules, bounded Argon2id hashing, purpose-separated random-token hashes, RFC 6238 TOTP counter validation and recovery-code generation. The hashing adapter caps native memory work at two concurrent calls and limits queued callers to prevent unbounded resource use. Missing accounts still perform password verification work; malformed stored hashes cannot choose arbitrary Argon2 parameters.
Document the security parameters and the remaining M2.2 subdivisions. Dependencies are pinned MIT-licensed argon2 0.44.0 and otpauth 9.4.1, with only the required Argon2 native build allowed.
Validation
Security considerations
Secret wrappers redact credentials and provisioning URIs. No public endpoint, persistent write, shell invocation or audit-producing command is introduced. Accepted TOTP counters are deliberately returned for atomic storage claims: callers must not authorize from validation alone. Provisioning URIs are secret response data, not navigation URLs.
Checklist