Skip to content

[M2.2c3a] Deliver identity mail through encrypted durable jobs - #46

Merged
samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.2c3a-private-mail-queue
Nov 5, 2026
Merged

samuelmbabhazi merged 1 commit into
mainfrom
feat/m2.2c3a-private-mail-queue

Conversation

@samuelmbabhazi

Copy link
Copy Markdown
Collaborator

Task

M2.2c3a, part of #21. Depends on #45; base feat/m2.2c2-auth-throttling.

What changed and why

Enqueue identity emails atomically with account/credential/audit changes using pg-boss and its upstream Prisma transaction adapter. Email addresses, credentials and expiration are envelope-encrypted with authenticated data tied to the job id. A separate worker retries delivery up to five times with capped backoff, skips expired credentials and sanitizes every persisted worker error.

Add the pg-boss lifecycle owner with bounded database connections and graceful shutdown. The MIT-licensed dependency is pinned to 12.38.0 and implements the queue already chosen in ADR 0004. Production SMTP wiring follows in M2.2c3b; no endpoint is exposed by this PR.

Validation

  • Thirty-four real PostgreSQL integration tests pass.
  • Four queue tests cover transaction rollback, ciphertext-only persistence, restart delivery, transport failures and retries, opaque persisted errors, expired credentials and tampered ciphertext.
  • Workspace lint, types and builds pass; existing account, limiter, repository, schema, audit and fleet integration suites pass.

Security considerations

Queue and schema names are fixed. The upstream Prisma adapter executes pg-boss SQL with separately bound values inside the current transaction; request values never form SQL identifiers or query text. Only ciphertext reaches queue tables. Worker exceptions omit transport responses and validation details. Plaintext buffers are cleared after encryption/decryption. SMTP transport is an injected port, exercised separately in the next PR.

Checklist

  • M2.2c3a acceptance checked; SMTP and HTTP flows remain open
  • Lint, types, builds and PostgreSQL integration tests pass
  • Restart, rollback, tampering and secret-disclosure tests added
  • No shell invocation or plaintext job persistence
  • Delivery enqueue joins command/audit transactions
  • Architecture and threat model updated

@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.2c2-auth-throttling branch from bef50e9 to 2a43b7b Compare November 5, 2026 12:15
@samuelmbabhazi
samuelmbabhazi changed the base branch from feat/m2.2c2-auth-throttling to main November 5, 2026 12:15
@samuelmbabhazi
samuelmbabhazi force-pushed the feat/m2.2c3a-private-mail-queue branch from 38054d9 to 0c74633 Compare November 5, 2026 12:15
@samuelmbabhazi
samuelmbabhazi merged commit 7018cf8 into main Nov 5, 2026
9 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the feat/m2.2c3a-private-mail-queue branch November 5, 2026 12:15
samuelmbabhazi added a commit that referenced this pull request Nov 5, 2026
## Task

M2.2c3b, part of #21. Depends on #46; base
`feat/m2.2c3a-private-mail-queue`.

## What changed and why

Add SMTP delivery over implicit TLS with mandatory
certificate-chain/hostname verification and TLS 1.2 minimum. Configure
the SMTP host, sender, optional credentials and optional public CA
bundle through validated/redacting application configuration. A
ten-second inactivity timeout and twenty-second total deadline bound
delivery; sockets close on both success and failure.

Emails link to a clean verification/reset page and provide a separate
code to paste, keeping bearer credentials out of URLs. Public API URLs
must be bare origins and use HTTPS in production. emailjs is pinned to
MIT-licensed version 5.0.4. Providers must support implicit TLS
(normally port 465); STARTTLS/plaintext SMTP is outside this
implementation.

## Validation

- Thirty-eight integration tests pass, including four tests against a
real loopback TLS SMTP server: successful authenticated delivery,
untrusted certificate rejection, hostname mismatch rejection and header
injection/expired credential handling.
- Unit tests enforce the total deadline, transport-error redaction,
socket cleanup and SMTP/public-origin configuration constraints.
- Workspace types, builds and TypeScript tests pass; lint passes after
fixture type checks.
- No message was sent to an external email service; TLS keys and the
test CA are generated at runtime and cleaned up.

## Security considerations

There is no TLS verification bypass. SMTP credentials are exposed only
to the transport and protocol logging is disabled. Untrusted
certificates fail before SMTP authentication. Transport errors are
opaque before the durable worker sees them. Production signup endpoints
still await HTTP integration in M2.2c4.

## Checklist

- [x] M2.2c3 delivery acceptance checked; HTTP flows remain open
- [x] Lint, types, builds, unit and integration tests pass
- [x] Real TLS negative tests and deadline tests included
- [x] No shell invocation, committed key/certificate or credential URL
- [x] Durable delivery remains coupled to audited commands
- [x] Configuration example, SPEC and threat model 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