Skip to content

spike(auth): the two-day Rust auth slice (argon2id, sessions, CSRF, API keys, one OIDC login) #38

Closed

Description

@aRustyDev

Context

Spike 0003 (.agents/plans/contrail/spikes/0003-identity-betterauth-rust.md, not started, 4 days) is a framework evaluation. It asks how to get "BetterAuth-quality identity" with a Rust backend and weighs three options (lines 11-17): A, better-auth-rs (a community alpha with a SeaORM adapter); B, TypeScript BetterAuth as a separate service-bound Worker; C, a hand-rolled Rust adapter. ADR-0050 still names BetterAuth as the intended basis (ADR-0050:42,78). Nothing in the tree logs anyone in: there is no login route, and a session exists only if /internal/seed created it (docs/src/architecture/infra.md:97-99). Handoff item A4.1 renames the spike to spikes/0003-auth-slice-rust.md.

Problem

  • BetterAuth is a TypeScript library. better-auth-rs is 1.0.0-alpha.3, and whether it builds for wasm32 is undocumented (research/0002 §2, lines 17-20).
  • Option A's SeaORM adapter conflicts with hand SQL on tokio-postgres (FR-07).
  • Option B adds a second language and a second deployable, against the Rust-only rule (ADR-0006).
  • The owner's P0 is user and password only (ADR-0050:43), with sessions in the database and no cache (ADR-0052:37,41, round 25). That is option C, so evaluating A and B spends spike days and keeps an alpha dependency on the path.
  • ADR-0050:78 still sets "KV/Redis secondary storage for sessions" as the spike bar, which contradicts ADR-0052 round 25.

Proposal

Rewrite the spike as handoff item A4.1 specifies. It gates ADR-0050 and ADR-0052. Build a two-day auth slice with option C only, on both targets, through the user-only Principal from #36:

  1. Passwords: argon2id with OWASP parameters (at least 19 MiB of memory, t=2, p=1) using the argon2 crate. Measure the CPU milliseconds per hash on the deployed Worker; they must fit the default 30 s CPU budget with margin.
  2. Sessions: a session row and an HttpOnly, Secure, SameSite cookie, with sign-out, sign-out-everywhere and a 30-day lifetime (ADR-0052 S1).
  3. CSRF: a double-submit token on cookie-authenticated mutations (ADR-0052:41; Plane's CSRFTokenEndpoint).
  4. API keys: a high-entropy token with a visible prefix, stored as a SHA-256 hash, shown once, and accepted as X-Api-Key (ADR-0052 K1).
  5. OIDC: one authorization-code login through the openidconnect crate against Zitadel or a mock IdP. On wasm32 its HTTP calls need a client built on worker::Fetch, which is not proven yet.

The plan side lands with the round-29 plan PRs: the spike rewrite, dropping options A and B in ADR-0050's round-29 note, and the answers to Q-0050.4 (the hand-rolled Rust adapter) and Q-0050.6 (User, Profile and Account tables are defined fresh; nothing is imported). This issue runs the slice.

Acceptance criteria

  • There is a contract test for each test listed in ADR-0052 (line 53), each with a control that must succeed: a revoked key is rejected on the next request with Plane's status, 403 for an invalid, expired or inactive key and 401 only for a missing one (ADR-0033 reproduces the oracle; ADR-0052 line 53 says 401 and is corrected with this issue), while an unrevoked key gets 200; a deactivated user's session is rejected; a mutation without the CSRF token is rejected (the same mutation with the token succeeds); no column holds a plaintext token or key.
  • One OIDC login completes against Zitadel or the mock on both targets, and a tampered state or nonce is rejected (the control).
  • The argon2id CPU time per hash on the deployed Worker is recorded together with its parameters.
  • scripts/contract-all.sh passes on all four targets, with the expected pass count updated so that the new tests cannot pass vacuously.
  • Results are written up in a research note, and ADR-0050 and ADR-0052 record the measured outcome.

References

  • Review: .agents/plans/contrail/reviews/2026-10-19-fable-architecture-review.md (FR-16)
  • Handoff: .agents/plans/contrail/reviews/2026-10-19-fable-handoff-PROMPT.md items A4.1, A4.2
  • .agents/plans/contrail/spikes/0003-identity-betterauth-rust.md:11-17; research/0002-rust-dioxus-fit.md:17-20
  • ADR-0050 (adrs/auth/0050-identity-oidc-zitadel-access.md:42,43,78), ADR-0052 (adrs/auth/0052-sessions-and-api-keys.md:37,41,53), ADR-0006, ADR-0141:26
  • Q-0050.4 (QUESTIONS.md:91), Q-0050.6 (QUESTIONS.md:93); docs/src/architecture/infra.md:97-99

Blocked by: #36

Finding: FR-16

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:appprio:p0review:fable-2026-10-19type:spike

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions