How do Principals authenticate, and what may each do? #54
Notifications
Due Date
No due date set.
Depends on
#45 How is hAPI reachable on the network?
bobby/hapi
Reference: bobby/hapi#54
Reference in new issue
Block a user
Part of #44
Question
How does each kind of Principal prove identity to hAPI, and how is access controlled? Decide Person authentication (passkeys, OIDC with a self-hosted IdP, etc.), Bot authentication (API keys, client credentials, mTLS), token lifetimes and revocation, how the Owner manages Principals, and the authorization model (scopes per domain, per-resource checks).
Input from Who owns data: a Person, the household, or both?: authorization has to express Owner-given Household grants for Bots, Person-granted and revocable Bindings (Bot → one Person's Personal data), Household membership, and Owner authority over Principals that does not cover reading others' Personal data. See ADR-0001.
Constraint from How is hAPI reachable on the network? (ADR-0002): Bots share the public surface with Persons and have no network-level gate, so Bot credentials must be per-Bot, scoped, individually revocable, and stored hashed. A long-lived JWT that can't be revoked is out; use an opaque API key, or trade a revocable secret for short-lived tokens. Owner administration (Principals, credentials, Household grants) is CLI-only inside the pod, not an HTTP route. Persons grant Bindings through the public API. Uptime Kuma is a Bot with a health-only scope.
Resolution
Decided in a grilling session on 2026-11-24 and recorded as ADR-0005. It amends ADR-0004 and adds glossary terms.
Authentication
kindthat resolves to the same Principal.hapi_<public-id>_<256-bit secret>. Only a SHA-256 of the secret is stored, and each request looks it up in the DB, so revocation is instant. We chose this over JWT plus refresh tokens, and over mTLS.--no-expiryis allowed only for Bots, and the CLI warns about such Tokens. A Principal can hold several live Tokens for rotation.last_used_atis written about once an hour, and the CLI flags Tokens that are expiring or have been unused for 90 days.Authorization
<domain>:read|write, plushealth) through Household grants (from the Owner, via the CLI) or Bindings (from a Person, via the API, per domain)./v1/<domain>/<things>/{id}and keeps that URI when it moves to the Household. Records exposeownerandrecorded_by. Lists filter with?owner=me|household|<id>. Creating a record takesowner, which Bots must supply for Personal data. We rejected a header naming the acting Person and nested owner paths.hapi.principal_idis always the authenticated Principal. RLS now covers Personal and Household data: owner, active Binding, Household member, or Household grant.USINGchecks the read Scope andWITH CHECKchecks the write Scope. Routes also declarerequire_scopeso callers get a clean 403.Self-service, lifecycle, errors
401. A missing Scope returns403. A record the caller can't see returns404. Auth decisions and changes to Tokens, grants and Bindings are logged; secrets never are. There's no app-level rate limiting (anything per-IP belongs at the Gateway).Glossary: added Token, Scope and Household grant; Binding is now per domain.