Add trusted identity: passkeys, sessions, recovery and admin approval (#9) #42

Merged
amiryahaya merged 14 commits from feat/9-identity-implementation into main 2026-10-22 16:46:51 +02:00
Owner

Implements issue #9 (F04): app-managed passkey identity for controlled on-premises use, following the design and plan. Group-aware policy enforcement across protected operations stays with #10.

This does not authorize operational or classified data. The identity source, proofing, passkey classes, relay, session/CSRF/recovery profiles, administrative separation and revocation deadline still need the decision-issue #2 approvals. Production startup stays blocked; synthetic development only.

What it adds

  • Trusted account, membership and entitlement records; only the authorization crate can turn a current, active session into a VerifiedSubject.
  • Invitations and self-registration through a durable mail outbox. Both end in pending_approval; an administrator must explicitly approve, and approval can only reduce what an invitation proposed.
  • webauthn-rs passkey registration, sign-in and add/remove, with required user verification and server-side challenge state. Sign-in for unknown, pending or suspended addresses returns indistinguishable decoy options.
  • Opaque server-side sessions: __Host- HttpOnly Secure SameSite=Strict cookie with matching Max-Age, rotation on each sign-in, /auth/me, logout, and an ActiveSubject extractor that rereads the canonical account on every request.
  • CSRF token plus exact-origin checks on every cookie-authenticated change.
  • One-use recovery codes (stored as digests), administrator-reviewed passkey replacement, per-address rate limiting.
  • Administrator routes (groups, invitations, approvals, delivery status, recoveries), re-verified as a current, recently signed-in administrator on every call.
  • React flows: sign-in, request access, mailed-link enrollment, awaiting approval, account, recovery, administration. Nothing about an account, session, grant or code is kept in browser storage.
  • Migrations 0004 to 0006, operations guide docs/operations/identity.md.

Verification (this branch, local PostgreSQL 17)

  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets --locked -- -D warnings: clean.
  • cargo test --workspace --locked: 46 passed, 57 ignored (the PostgreSQL suites).
  • bash scripts/test-postgres.sh --local: 30 identity, 14 foundation, 9 recovery, 4 administrator tests passed.
  • bash scripts/coverage.sh rust: 88.45% line coverage (gate 80%).
  • web/: npm run typecheck, npm test (22 tests), npm run build clean; line coverage 96.7% (gate 80%).
  • Behavior changes were written test-first; new tests were seen failing before implementation.

Known gaps

  • No real-browser passkey run against the real API. Passkeys need https and the API pins an https origin, so tests use a simulated authenticator and scripted servers. Needs a TLS-fronted run before anyone relies on it.
  • No email on recovery completion (the outbox is invitation-specific); it is only an audit event.
  • Recovery and enrollment tokens live in browser memory only, so a mid-flow reload restarts the flow.
  • Rate limiting is per address digest only; per-source limiting belongs at the ingress.
  • No list or remove screen for passkeys (no credential-listing endpoint yet).
  • Approval grants a placeholder Read action until policy administration (#14); no compartments or need-to-know are assigned here.
  • Group ancestry and classification enforcement across protected operations are #10.
  • No independent review yet; the plan requires one before merge.

Admin sessions must be signed in within IDENTITY_ADMIN_REAUTH_MAX_AGE_SECONDS (default 300), so administrators will be asked to sign in again often.

Refs #9, #2, #10.

🤖 Generated with Claude Code

Implements issue #9 (F04): app-managed passkey identity for controlled on-premises use, following the [design](docs/superpowers/specs/2026-10-22-identity-groups-and-recovery-design.md) and [plan](docs/superpowers/plans/2026-10-22-trusted-identity.md). Group-aware policy enforcement across protected operations stays with #10. **This does not authorize operational or classified data.** The identity source, proofing, passkey classes, relay, session/CSRF/recovery profiles, administrative separation and revocation deadline still need the decision-issue #2 approvals. Production startup stays blocked; synthetic development only. ## What it adds - Trusted account, membership and entitlement records; only the authorization crate can turn a current, active session into a `VerifiedSubject`. - Invitations and self-registration through a durable mail outbox. Both end in `pending_approval`; an administrator must explicitly approve, and approval can only reduce what an invitation proposed. - `webauthn-rs` passkey registration, sign-in and add/remove, with required user verification and server-side challenge state. Sign-in for unknown, pending or suspended addresses returns indistinguishable decoy options. - Opaque server-side sessions: `__Host-` HttpOnly Secure SameSite=Strict cookie with matching `Max-Age`, rotation on each sign-in, `/auth/me`, logout, and an `ActiveSubject` extractor that rereads the canonical account on every request. - CSRF token plus exact-origin checks on every cookie-authenticated change. - One-use recovery codes (stored as digests), administrator-reviewed passkey replacement, per-address rate limiting. - Administrator routes (groups, invitations, approvals, delivery status, recoveries), re-verified as a current, recently signed-in administrator on every call. - React flows: sign-in, request access, mailed-link enrollment, awaiting approval, account, recovery, administration. Nothing about an account, session, grant or code is kept in browser storage. - Migrations 0004 to 0006, operations guide `docs/operations/identity.md`. ## Verification (this branch, local PostgreSQL 17) - `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets --locked -- -D warnings`: clean. - `cargo test --workspace --locked`: 46 passed, 57 ignored (the PostgreSQL suites). - `bash scripts/test-postgres.sh --local`: 30 identity, 14 foundation, 9 recovery, 4 administrator tests passed. - `bash scripts/coverage.sh rust`: 88.45% line coverage (gate 80%). - `web/`: `npm run typecheck`, `npm test` (22 tests), `npm run build` clean; line coverage 96.7% (gate 80%). - Behavior changes were written test-first; new tests were seen failing before implementation. ## Known gaps - No real-browser passkey run against the real API. Passkeys need https and the API pins an https origin, so tests use a simulated authenticator and scripted servers. Needs a TLS-fronted run before anyone relies on it. - No email on recovery completion (the outbox is invitation-specific); it is only an audit event. - Recovery and enrollment tokens live in browser memory only, so a mid-flow reload restarts the flow. - Rate limiting is per address digest only; per-source limiting belongs at the ingress. - No list or remove screen for passkeys (no credential-listing endpoint yet). - Approval grants a placeholder `Read` action until policy administration (#14); no compartments or need-to-know are assigned here. - Group ancestry and classification enforcement across protected operations are #10. - No independent review yet; the plan requires one before merge. Admin sessions must be signed in within `IDENTITY_ADMIN_REAUTH_MAX_AGE_SECONDS` (default 300), so administrators will be asked to sign in again often. Refs #9, #2, #10. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
feat(identity): verify passkeys and manage credentials
Some checks failed
CI / Web checks (push) Successful in 1m0s
CI / Rust checks (push) Has been cancelled
3200ed663f
Add webauthn-rs backed registration, login and passkey add/remove
ceremonies with server-side challenge state, plus the HTTP routes:
login begin/finish (sets a __Host- session cookie), add begin/finish
and remove (session cookie and exact Origin required).

Login begin returns indistinguishable HMAC-derived decoy options for
unknown, pending and suspended addresses so responses do not reveal
account existence. Requires IDENTITY_DECOY_KEY_HEX.

Cookie expiry, rotation and CSRF tokens are deferred to Task 5.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
feat(identity): enforce current sessions and CSRF
All checks were successful
CI / Web checks (push) Successful in 55s
CI / Rust checks (push) Successful in 7m50s
6c7e12eede
Add the browser session boundary: GET /auth/me (state, expiry and a
session-derived CSRF token only), POST /auth/logout, and the
ActiveSubject extractor that reloads session, account, memberships and
entitlement generation from PostgreSQL on every request (401 when
stale, 503 when storage is unavailable).

Login cookies now carry Max-Age matching the server session. Logout and
credential changes require the exact origin plus an X-CSRF-Token
header. Development mode refuses non-loopback binds before any
database connection. The shared session freshness rule moves into the
authorization crate.

Administrator HTTP routes remain unmounted.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Move the disposable-database, service, passkey-browser and HTTP helpers
into tests/common so new suites reuse them. No behavior change: the
same 30 identity and 14 foundation tests pass.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
feat(identity): add reviewed passkey recovery
Some checks failed
CI / Web checks (push) Successful in 44s
CI / Rust checks (push) Has been cancelled
9a82031d57
One-use recovery codes (130-bit random, stored only as SHA-256 digests)
start a single administrator-reviewed request; they never create a
session. An independent, recent administrator with a verification
record approves; a full WebAuthn ceremony then installs the replacement
passkey and, in one transaction, revokes every old credential, session
and unused code and issues fresh codes.

Failures are uniformly generic and rate limited per address digest
(known or not). Code issuance needs a recent passkey sign-in plus
session, origin and CSRF. Startup now rejects widened recovery-table
privileges. Migration 0006 adds the ticket digest, one-open-request
index and attempt counters.

No completion email is sent and approval has no HTTP route yet; both
are documented gaps.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
feat(identity): mount administrator routes
All checks were successful
CI / Web checks (push) Successful in 32s
CI / Rust checks (push) Successful in 10m32s
7e17ca7986
Add the administrator HTTP surface: list/create groups, invite,
list/approve pending accounts, delivery status, and list/approve
recoveries. Authority comes only from the server-side session,
re-verified as a current, recently signed-in administrator on every
call; changes also need the exact origin and CSRF token. Bodies reject
unknown fields so actor, role or organization claims cannot ride along.
Delivery status never exposes links or tokens. Approval can only reduce
what an invitation proposed; the server adds policy version, validity
and a placeholder Read action from configuration.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The browser needs to know whether to offer the administration screens.
The flag is a display hint only: every administrator route still
re-verifies a current, recently signed-in administrator server-side.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
feat(web): add passkey enrollment and approval flows
All checks were successful
CI / Web checks (push) Successful in 55s
CI / Web checks (pull_request) Successful in 49s
CI / Rust checks (push) Successful in 8m44s
CI / Rust checks (pull_request) Successful in 11m27s
5f15fc458c
Gate the workspace on a server-confirmed session and add the browser
flows for the identity design: passkey sign-in, request access, the
mailed-link enrollment page (token removed from the address bar), the
awaiting-approval state, account (add a passkey, one-time recovery
codes), recovery from code to replacement passkey, sign-out and expiry,
and administration (groups, invitations, approvals that can only reduce
the proposal, delivery status, recovery approval).

Nothing about an account, session, grant or code is stored in the
browser; mutations carry the server-issued CSRF token. Failures are
generic. Frontend line coverage is 96.7%.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign in to join this conversation.
No description provided.