Skip to content

[M2.2a] Add bounded authentication security primitives - #40

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

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.2a-identity-primitives

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

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

  • Workspace lint, type checks, builds and TypeScript tests pass.
  • Eight identity tests cover exact idle/absolute expiry, revoked sessions, malformed mailboxes, Unicode passwords, real salted Argon2id verification, missing accounts, malformed hashes, queue exhaustion/recovery, RFC 6238 vectors and TOTP replay/window boundaries.
  • Go tests and protobuf lint/format checks pass.
  • Semgrep custom-rule scan passes.

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

  • M2.2a acceptance documented and checked in the plan; parent milestone remains open
  • Lint, types, builds, tests and protobuf checks pass
  • Invalid-input and overload cases covered
  • No new shell invocation or logging of secrets
  • No state-changing command introduced
  • SPEC and threat model updated

@samuelmbabhazi
samuelmbabhazi merged commit 765c32b into main Nov 5, 2026
10 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.2a-identity-primitives branch November 5, 2026 12:10
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
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