Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Concepts

Summary: the model behind auth-chad in seven ideas, and the vocabulary that the code and the spec use.
Key terms: flow, decision, write, commit, Authenticated, tenant, realm, policy, DPoP, ceremony, envelope.
Related: Data · Flows · Interfaces · spec 01

Every account change in auth-chad follows the same pattern. A pure function, called a flow, reads the database and returns a decision: the result plus the list of rows to write. The application commits those rows in one transaction, and only then is the result real. Every request carries a key proof, and the library alone turns a valid proof into an Authenticated value that handlers can use. Configuration can make the rules stricter and has no setting that weakens them.

The seven ideas

1. Login is proof of a key

A person proves a passkey. A program proves a device key. A browser session or an app signs every request with its session key (DPoP). A copied database row, log line or token cannot log anyone in.

2. A flow decides, the application commits

Each step (signup, login, device approval) is a flow: a function that reads, applies the rules and returns a decision. A decision has an output and a list of writes. The writes are committed together in one transaction, and the output is valid only after that commit succeeds. The application can add its own writes to the same transaction.

use auth_chad::{Decision, Store};

async fn finish<S: Store, T>(store: &S, decision: Decision<T>) -> Result<T, auth_chad::Error> {
    store.commit(decision.writes).await?; // all or nothing
    Ok(decision.out)                      // valid only after the commit
}

3. Every write has a condition

Another request can change a row between the read and the commit. Each write therefore states what it expects: “no row with this key exists”, or “the row is still at version 7”. If any condition fails, the commit stores nothing and the request fails with conflict. When two requests use the same single-use token, exactly one succeeds.

4. Only the library makes a proof

When a request passes the checks, the library creates an Authenticated value. It records who the caller is, the tenant, the client level (first-party, connected app or API key), the key, and the last passkey use. Application code cannot construct one. A handler declares in its signature what it needs, and requests that lack it are rejected before the handler runs.

use auth_chad::axum::{FirstParty, FreshLogin, Refused};

async fn notes(who: FirstParty) -> Result<String, Refused> {
    Ok(format!("notes of {}", who.user()?))
}

async fn delete_account(_fresh: FreshLogin<300>) -> &'static str {
    "the passkey was used in the last 5 minutes"
}

5. Two levels of client

First-partyConnected app
WhoYour own web app, apps, CLIs and machinesOther companies’ apps, with the user’s consent
TokenBound to a key, or a secure cookie for page loadsShort-lived, one audience, limited scopes
May change passkeys, sessions or recoveryYes, after a fresh loginNo

6. Rules only get stricter

One profile fixes the algorithms, checks and upper limits. An instance, a tenant and a route can each add a policy. Policies combine, and the strictest value wins. No setting turns a check off.

7. All effects come from outside

Time, random bytes, storage, network and mail reach the library through traits. The library writes no logs. It returns audit events as writes in the same commit, so a change cannot be stored without its event. Every flow can be tested with a fake clock and fake random bytes.

Where the details are

  • The exact model (realms, tenants, users, credentials, proofs, policies): spec 01.
  • The contract of a flow (protected reads, writes, single use, effects, audit): spec 02.
  • Authenticated and its fields: rust/formats/core/src/proof.rs. Decision and Write: rust/formats/core/src/store.rs.
  • The reasons for the strict rules: decision 001.

Glossary

TermMeaningIn the code
RealmOne set of users, one passkey domain (RP ID), one login originConfig
TenantAn organization or customer inside a realm. Each session belongs to one tenant. Without tenants, everything is in the root tenantTenant, Tenant::ROOT
MembershipPermission for a user to enter a tenant, with your own columns such as a roleMembership, Member
PasskeyA key on a person’s device, checked with WebAuthnPasskey row, passkey flow
Device keyA key that a CLI, app or machine holds. A user device acts as its user; a machine acts as itselfDevice, Subject::Machine
SessionA lasting login: a cookie for page loads, or a key-bound tokenSession
DPoPDemonstration of Proof of Possession: the client signs each request with the session’s key, so a stolen token is useless alonedpop crate
Fresh loginA passkey use within the last few minutes. Risky actions require itFreshLogin<SECS>, step_up_required
First-partyYour own clientsLevel::FirstParty, FirstParty
Connected appAnother company’s app that a user allowedLevel::Connected, ConnectedApp
API keyA secret for a program that can only send a header. Off by default and discouragedApiKey
FlowA function that decides one step and does no I/Ocrates in rust/flows/
DecisionWhat a flow returns: an output and writesDecision { out, writes }
WriteA row change with a conditionWrite
CommitStoring a list of writes, all or nothingStore::commit
CeremonyA two-request step (start, finish) whose state travels in a sealed tokenceremony_invalid
PolicyExtra requirements; the strictest value winsPolicy
HookA point where your application decides or adds its own writesHooks
EventAn audit row for each change to an accountEvent
OutboxWork that runs after a commit, such as sending mail, at least onceOutbox, work
PlaceThe location of a tenant’s or user’s data when it is outside the users’ databasePlace, Placement
EnvelopeAn encrypted copy of an end-to-end encryption secret that one passkey (PRF) or the recovery key opensEnvelope
Recovery keyA long random key that the person stores, used to regain accessRecoveryKey
HoldA period after a recovery when old passkeys cannot be removed, so the owner can undo a thefthold_until
ProfileThe fixed set of algorithms and limits of a releaseAC1 in the spec
†A proposed value that needs a security reviewspec