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-party | Connected app | |
|---|---|---|
| Who | Your own web app, apps, CLIs and machines | Other companies’ apps, with the user’s consent |
| Token | Bound to a key, or a secure cookie for page loads | Short-lived, one audience, limited scopes |
| May change passkeys, sessions or recovery | Yes, after a fresh login | No |
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.
Authenticatedand its fields:rust/formats/core/src/proof.rs.DecisionandWrite:rust/formats/core/src/store.rs.- The reasons for the strict rules: decision 001.
Glossary
| Term | Meaning | In the code |
|---|---|---|
| Realm | One set of users, one passkey domain (RP ID), one login origin | Config |
| Tenant | An organization or customer inside a realm. Each session belongs to one tenant. Without tenants, everything is in the root tenant | Tenant, Tenant::ROOT |
| Membership | Permission for a user to enter a tenant, with your own columns such as a role | Membership, Member |
| Passkey | A key on a person’s device, checked with WebAuthn | Passkey row, passkey flow |
| Device key | A key that a CLI, app or machine holds. A user device acts as its user; a machine acts as itself | Device, Subject::Machine |
| Session | A lasting login: a cookie for page loads, or a key-bound token | Session |
| DPoP | Demonstration of Proof of Possession: the client signs each request with the session’s key, so a stolen token is useless alone | dpop crate |
| Fresh login | A passkey use within the last few minutes. Risky actions require it | FreshLogin<SECS>, step_up_required |
| First-party | Your own clients | Level::FirstParty, FirstParty |
| Connected app | Another company’s app that a user allowed | Level::Connected, ConnectedApp |
| API key | A secret for a program that can only send a header. Off by default and discouraged | ApiKey |
| Flow | A function that decides one step and does no I/O | crates in rust/flows/ |
| Decision | What a flow returns: an output and writes | Decision { out, writes } |
| Write | A row change with a condition | Write |
| Commit | Storing a list of writes, all or nothing | Store::commit |
| Ceremony | A two-request step (start, finish) whose state travels in a sealed token | ceremony_invalid |
| Policy | Extra requirements; the strictest value wins | Policy |
| Hook | A point where your application decides or adds its own writes | Hooks |
| Event | An audit row for each change to an account | Event |
| Outbox | Work that runs after a commit, such as sending mail, at least once | Outbox, work |
| Place | The location of a tenant’s or user’s data when it is outside the users’ database | Place, Placement |
| Envelope | An encrypted copy of an end-to-end encryption secret that one passkey (PRF) or the recovery key opens | Envelope |
| Recovery key | A long random key that the person stores, used to regain access | RecoveryKey |
| Hold | A period after a recovery when old passkeys cannot be removed, so the owner can undo a theft | hold_until |
| Profile | The fixed set of algorithms and limits of a release | AC1 in the spec |
| † | A proposed value that needs a security review | spec |