iz
Clone
0 watching0 forksRustAGPL-3.0567.3 KiB3950aceTahinli27 days ago34 commits
Family contracts, v1
Status: normative. This file is copied byte for byte into im/docs/contracts.md, in/docs/contracts.md and
iz/docs/contracts.md. A change is made in all three repos in the same sitting, and the version line below is
bumped. The apps share no code. They share only the HTTP contracts written here.
Contract version: 1
1. The family
| Key | App | Role | Default listen |
|---|---|---|---|
im |
Account | OpenID Connect provider, people directory, service registry. Depends on nothing. | 127.0.0.1:7650 |
in |
Files | Personal drive. Blob store for the other apps. Depends on im. |
127.0.0.1:7655 |
iz |
Board | Task board. Depends on im, optionally on in. |
127.0.0.1:7654 |
Production origins are https://<key>.<domain> behind a TLS-terminating reverse proxy (Ferron). Apps bind
127.0.0.1 only.
1.1 Design rules
- No app is down because another is down. A signed-in user keeps working in
inandizwhileimis unreachable. Only new sign-ins needim. Nothing callsimon the request path of an ordinary page. - Standards first. Where a standard exists (OIDC Core, OIDC Discovery, OIDC RP-Initiated Logout, OIDC Back-Channel Logout, OAuth 2.0 client credentials, RFC 7009 revocation, RFC 7662 introspection), it is used as written. Extensions are named and listed here.
- Machine calls carry a short-lived JWT issued by
imthrough the client credentials grant, with an audience and scopes. Static shared bearer keys are not used. - Every machine API is versioned under
/api/v1/. A consumer accepts unknown JSON fields. A provider keeps v1 working for at least one release after v2 ships. - Errors are JSON with a real HTTP status (section 7).
2. Identity (OIDC)
im is the issuer. Its issuer URL is its public origin with no trailing slash, for example
https://im.example.com.
2.1 Discovery
GET /.well-known/openid-configuration returns standard metadata, including:
issuer,authorization_endpoint(/authorize),token_endpoint(/token),userinfo_endpoint(/userinfo),jwks_uri(/jwks.json),end_session_endpoint(/logout),revocation_endpoint(/revoke),introspection_endpoint(/introspect)response_types_supported: ["code"],grant_types_supported: ["authorization_code", "refresh_token", "client_credentials"]code_challenge_methods_supported: ["S256"],id_token_signing_alg_values_supported: ["EdDSA"]token_endpoint_auth_methods_supported: ["client_secret_basic", "client_secret_post"]backchannel_logout_supported: true,backchannel_logout_session_supported: truescopes_supported: ["openid", "profile", "email", "directory.read", "files.service"]
Clients fetch discovery once at boot and cache it. They may hard-code the paths above as a fallback.
2.2 Keys
- Signing algorithm: EdDSA (Ed25519).
jwks.jsonpublishes every key that is active or retired within the last 7 days, as{"kty":"OKP","crv":"Ed25519","x":...,"kid":...,"use":"sig","alg":"EdDSA"}. imrotates the signing key every 90 days and on admin demand. A new key is published 24 hours before it signs anything.- Clients cache the JWKS for 10 minutes, and refetch at most once a minute when a token names an unknown
kid.
2.3 Sign-in (authorization code + PKCE)
- App redirects the browser to
/authorizewithresponse_type=code,client_id,redirect_uri(exact match with a registered URI),scopecontainingopenid(andprofile email),state(≥128 bits),nonce(≥128 bits),code_challenge,code_challenge_method=S256. PKCE is mandatory. imsigns the user in (password, then TOTP or a recovery code if enrolled) and redirects back withcodeandstate. Codes live 60 seconds and are single use. A reused code revokes every token issued from it.- App posts to
/token(grant_type=authorization_code,code,redirect_uri,code_verifier), client auth byclient_secret_basicorclient_secret_post. Response:access_token(JWT, 10 min),id_token,refresh_token,token_type: "Bearer",expires_in. - App validates the
id_token: signature against JWKS,issexact,audequals itsclient_id,expin the future,iatnot more than 5 minutes in the future,nonceequal to the one it sent.
ID token claims: iss, sub (the user's ULID, stable forever), aud, exp, iat, auth_time, nonce,
sid (the im browser session id), email, email_verified (always true: im only stores confirmed
addresses), name, and the im extensions admin (bool), locale (en|tr), zoneinfo (IANA name, for
example Europe/Istanbul), picture_version (integer, bumps when the photo changes).
2.4 App sessions
After step 4 the app creates its own local session (its own table, its own __Host- cookie, its own CSRF
token), keyed by sub, and stores sid beside it. The app does not call im again for this session.
- Local session lifetime: at most 12 hours of absolute age. After that the app sends the browser through
/authorizeagain. While theimsession is alive this is an invisible redirect. - The app may keep the
refresh_tokenonly if it needs to call/userinfolater. Apps in this family do not. They discard it.
2.5 Sign-out and revocation
- App-initiated sign-out: the app deletes its local session, then redirects to
/logout?id_token_hint=...&post_logout_redirect_uri=<registered>&state=...(OIDC RP-Initiated Logout).imends theimsession and every app session tied to it (back-channel, below). - Back-Channel Logout (OIDC Back-Channel Logout 1.0): each client registers a
backchannel_logout_uri(<origin>/auth/backchannel-logout). When animsession ends (sign-out, admin revoke, password change or reset, user disabled or deleted, session expired by policy),imPOSTslogout_token=<JWT>(form-encoded) to every client that was used in that session. The token carriesiss,aud,iat,exp(2 min),jti,events: {"http://schemas.openid.net/event/backchannel-logout": {}}, andsid(andsub). For "disable" and "delete" it carries onlysub, which means "every session of this user". - The app validates it like an ID token (no
nonce; it must carryeventsand must not carrynonce), records eachjtifor 10 minutes (a repeat is already applied: it changes nothing and answers200), deletes the matching local sessions, and answers200with an empty body. Any other answer is a failure. imdelivers through a durable outbox: retries with backoff (10 s, 30 s, 1 min, 5 min, then every 15 min) for 24 hours. Combined with the 12-hour local session cap (2.4), a missed delivery cannot keep a revoked user signed in for longer than 12 hours, even if the app was down.- The directory stream (section 3) also carries
disabled: trueanddeletedevents. An app that sees one deletes the user's local sessions as well. Two independent paths; either one is enough.
2.6 Machine-to-machine tokens
- A client that calls another app's API asks
imfor a token:POST /tokengrant_type=client_credentials&scope=<scopes>&audience=<target key>with its client auth. (audienceis the RFC 8707-style extension parameter; its value is a family key such asin.) imchecks the scopes against the client's allowed scopes (set by the admin) and returns anaccess_tokenJWT:iss,sub=client:<client_id>,azp=client_id,aud= target key,scope(space separated),iat,exp(10 min),jti, plussvc= the caller's family key.- The receiving app verifies signature,
iss,audequals its own key,exp, and the scope it needs. It treatssvcas the caller's identity. Callers cache the token until 60 s beforeexp.
| Scope | Granted by default to | Lets the caller |
|---|---|---|
directory.read |
every family client | read the people directory and photos at im (section 3) |
files.service |
iz |
store and read its own objects in in (section 5) |
3. People directory (im)
All routes need a client-credentials token with aud = "im" and scope directory.read.
3.1 Member record
{
"sub": "01J...",
"email": "a@example.com",
"name": "Ayşe Yılmaz",
"admin": false,
"disabled": false,
"locale": "tr",
"zoneinfo": "Europe/Istanbul",
"picture_version": 3,
"updated_at": "2026-10-28T09:00:00.000000000Z"
}
3.2 Routes
GET /api/v1/directory→{"members":[<member>...], "cursor":"<opaque>"}. Every account, disabled ones included (disabled: true). Deleted accounts are absent.GET /api/v1/directory/stream→text/event-stream. OptionalLast-Event-ID(or?cursor=) resumes from a cursor. Events:event: member,data: <member>: a member was created or changed (including disabled/enabled).event: deleted,data: {"sub":"..."}: the account is gone.event: resync,data: {}: the cursor is too old; fetchGET /api/v1/directoryagain.- Each event has an
id:that is a cursor. Keep-alive comments every 30 s.imcloses the stream after 50 minutes; the client reconnects with its last cursor.
GET /api/v1/people/{sub}/photo→ image bytes with the storedContent-Type, or404when there is no photo.ETag: "p<picture_version>". With?v=<picture_version>matching,Cache-Control: private, max-age=31536000, immutable; otherwiseprivate, no-cache. HonorsIf-None-Matchwith304.
Apps mirror the directory into a local members table (full fetch, then the stream), so pages never call im
to show a name or an avatar. Apps proxy photos through their own origin and cache them on disk keyed by
(sub, picture_version); a browser never talks to im for a photo.
4. Service registry and switcher (im)
GET /api/v1/family(token withaud = "im", scopedirectory.read) →{"services":[{"key":"in","name":"Files","url":"https://in.example.com","healthy":true,"checked_at":"..."}]}in the admin's order.imis included as{"key":"im","name":"Account",...}.- The list is owned by
im's admin. A service row is created with its OIDC client (the admin gives a key, a name and the origin; the redirect and back-channel URIs are derived from the origin). Apps do not register themselves. improbes each row'sGET /healthzevery 60 s (2 s timeout) and reportshealthy. Apps fetch the list every 5 minutes and render the switcher from their copy; a stale copy is fine.
4.1 Health
Every app serves GET /healthz without auth: 200, body ok <build sha>, Content-Type: text/plain.
It checks that the process answers and that a SELECT 1 on its database succeeds within 1 s; otherwise
503 with fail <reason>.
5. Object store (in)
in stores bytes for other apps in a per-service namespace with its own quota. All routes need a
client-credentials token with aud = "in" and scope files.service. The namespace is the token's svc.
An object is named by the caller's external_id (1–128 chars of [A-Za-z0-9._-]).
| Method and path | Request | Success |
|---|---|---|
PUT /api/v1/objects/{external_id} |
Raw body; Content-Type (stored as given, re-sniffed for display); optional X-Object-Name (UTF-8, percent-encoded, ≤255 bytes); optional If-None-Match: * |
201 (created) or 200 (replaced), JSON {"external_id","size","sha256","content_type","created_at"} |
GET /api/v1/objects/{external_id} |
Optional Range: bytes=a-b (one range) |
200 or 206, the bytes, ETag: "<sha256>", Content-Length, Accept-Ranges: bytes |
HEAD /api/v1/objects/{external_id} |
— | Headers as GET |
DELETE /api/v1/objects/{external_id} |
— | 204; also 204 when already absent (idempotent) |
GET /api/v1/usage |
— | {"quota_bytes": n, "used_bytes": n, "objects": n} |
- Uploads stream to disk; the body is never held in memory. A body larger than the remaining quota is refused
with
413and error codequota_exceededbefore or while it is read. PUTis atomic: the new bytes are visible only after they are fully written and fsynced.- Service objects never appear in a person's drive and do not count against any person's quota.
- The quota per service is set in
in's admin page (default 10 GiB).
6. Users across apps
- The user id everywhere is
im'ssub(a ULID). Apps never invent their own user ids for people. - An app learns a user when they first sign in or when the directory names them. A member that the directory lists but who never signed in still exists in the app (so they can be assigned, mentioned, mailed).
- App-level roles (for example
izAdmin, Member, Viewer) belong to the app.im'sadminflag means "instance administrator" and every app treats it as its own top role.
7. Errors
Machine routes answer errors as:
{"error": "quota_exceeded", "message": "The service quota of 10 GiB is used up."}
with the matching status: 400 invalid_request, 401 invalid_token (with WWW-Authenticate: Bearer error="invalid_token"), 403 insufficient_scope, 404 not_found, 409 conflict, 413 quota_exceeded or
too_large, 429 rate_limited (with Retry-After), 500 internal, 503 unavailable. error is a stable
machine word; message is English for logs and may change. OAuth endpoints (/token, /revoke,
/introspect) use the OAuth error format from their RFCs instead.
8. Change log
- v1 (2026-10-28): first version.