Merge branch 'design-oficina-id' into main
Spec Oficina ID slice 1: Home sign-in and Equipo Passkey and email sign-in at Home with recovery, seconds-lived audience-bound assertions to pinned consumers, explicit linking with fresh authentication. Equipo first; Contra in slice 2. Reviewed by Fable and Astra; rulings by Paul 2026-11-13.
2 files changed,
+111
−8
AGENTS.md+13 −8docs/superpowers/specs/2026-11-13-oficina-id-slice-1.md+98 −0
CI passed — run details
diff --git a/AGENTS.md b/AGENTS.md| index 14aeabb..fe6540c 100644 |
| --- a/AGENTS.md |
| +++ b/AGENTS.md |
| @@ -229,14 +229,19 @@ quietly ignored). |
| continuously, so a transiently readable write reaches the bucket before |
| any delete. `PRAGMA secure_delete` is on. |
| - **The session Subject is an opaque person ref, never an address.** |
| - `rastrillo/auth` as shipped sets `Subject: id.Address` and stores readable |
| - addresses in `auth_links.address` and, via `Subject: id.Address`, in |
| - `sessions.subject` — `auth_sessions` is no longer written at v0.22.0, its |
| - rows having been migrated into the shared `sessions` table, so the leak |
| - moved rather than closed. Verified at source, filed upstream as |
| - `rastrillo/rastrillo` #2. We hand-roll session minting until that lands, |
| - and take classification and the Keymail upgrade from **`keymaildev/signin` |
| - directly, not from `auth`** — corrected 2026-09-05: `auth`'s |
| + **Corrected 2026-11-13, verified at pin `29e4491`:** |
| + `rastrillo/auth.Config.SubjectFor` exists and can map a verified address |
| + to an opaque subject before session minting. Without that hook, auth |
| + defaults to the address in `sessions.subject`; `auth_sessions` stopped |
| + being written at v0.22.0 when rows moved to the shared sessions table. |
| + The hook does **not** fix link storage: `auth.New` still installs |
| + `Links: &linkStore{db: cfg.DB}`, which writes readable |
| + `auth_links.address`. The older claim that no subject-remapping hook |
| + exists is stale; the sealed-link-store requirement from upstream |
| + `rastrillo/rastrillo` #2 remains. Home keeps its sealed link store and |
| + opaque-subject session minting until both guarantees can be supplied |
| + upstream. Take classification and the Keymail upgrade from |
| + **`keymaildev/signin` directly, not from `auth`** — corrected 2026-09-05: `auth`'s |
| classification is reachable only through `auth.Begin`, which hardwires |
| `Links: &linkStore{db: cfg.DB}` and writes `auth_links.address`, so "use |
| `auth` only for the parts that hold nothing" was never a thing that could |
diff --git a/docs/superpowers/specs/2026-11-13-oficina-id-slice-1.md b/docs/superpowers/specs/2026-11-13-oficina-id-slice-1.md| new file mode 100644 |
| index 0000000..03d5063 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-13-oficina-id-slice-1.md |
| @@ -0,0 +1,98 @@ |
| +# 🤖 Oficina ID: slice 1 |
| + |
| +Status: revised design, 2026-11-13, applying Paul's rulings and Fable's READY AFTER FIXES review as supplied by Paul. Independently reviewed after these fixes by GPT-6 Astra (`gpt-6-astra`): acceptable as a spec, no blocking findings. Author: Codex. No implementation, deployment or merge approval. |
| + |
| +## Decision and boundary |
| + |
| +**Paul, 2026-11-13:** every Oficina app keeps its own sign-in **and** offers “Sign in with Oficina ID”. **Slice 1 is Home plus Equipo only.** Contra adopts in slice 2; Docs, Sheets and Slides follow. Local sign-in remains reachable without contacting Home, including for linked accounts. |
| + |
| +Slice 1 covers passkey/email sign-in, recovery, signed identity handoffs, explicit linking/unlinking and configured verification keys. Directory, provisioning, roster changes and preferences beyond display are outside it. Assertions grant no membership, invitation acceptance or item access. Existing roster rules remain binding where already used; Equipo gains no roster dependency here. |
| + |
| +This design extends [Home §4–5](2026-08-30-home-design.md) with standalone passkeys and Paul's recovery replacement ruling. Key publication is later work. The former cached-key proposal is withdrawn. |
| + |
| +## Evidence, domains and registration |
| + |
| +Checked against Home `14c83d7`, `connect`, `handoff`, the credential-return and transactional-link-resolution specs, suite README, Equipo's `auth.go` and `setup/session_handlers.go`, and pinned rastrillo `29e4491`. Home already implements P-256 assertions and explicit linking. Commit `462df84` records the primary-domain decision; `0dc863c` merged assertion exchange and `47301e8` tightened freshness. Older Ed25519 plans are historical. |
| + |
| +The issuer is [https://id.oficina.works](https://id.oficina.works), and the WebAuthn relying-party ID is exactly **id.oficina.works**, never the parent domain. The directory is [https://oficina.works](https://oficina.works); team apps use `<team>.<app>.oficina.works`. Credential pages never render account-authored strings. Cookies are host-only, Secure and HttpOnly; no parent-domain session cookie. |
| + |
| +Registration uses existing `HOME_CONSUMERS`: a JSON object mapping consumer IDs to exact canonical HTTPS origins. Equivalently, `HOME_CONSUMERS_BASE64` contains standard-base64 encoding of that JSON; set only one. Keep the required `directory` entry pointing at the configured directory origin and add Equipo's consumer/origin entry. The environment manifest permits 1–16 entries, at most 8,192 decoded bytes; IDs are 1–64 ASCII letters, digits, underscores or hyphens. Refuse collisions with existing database registrations. |
| + |
| +Each origin identifies one app instance, with fixed callback `/auth/assertion`. No wildcard, suffix trust, arbitrary return URL or automatic registration. Alias hosts are separate audiences. External HTTPS consumers need no domain move or shared cookies, but their pairwise-subject policy belongs to later slices. Native deep-link delivery is outside this browser slice. |
| + |
| +## Home sign-in and recovery |
| + |
| +Offer direct passkey and email sign-in. First registration verifies the mailbox through Keymail or an emailed link, then allocates/reuses an opaque person ref through Home's normalized, peppered index. The pepper stays at Home. Never resolve from an unverified address or use different normalization on return visits. |
| + |
| +Direct passkey sign-in uses a discoverable credential bound to the person ref. WebAuthn `user.id` is an opaque handle; `user.name` and `user.displayName` are generated identifiers, never an address or entered name. Require user verification, exact origin/RP checks, a five-minute browser-bound single-use challenge and the stored credential/person binding. Enrollment requires fresh authentication and request-forgery protection. Existing nondiscoverable credentials retain gated sign-in until a discoverable replacement is enrolled. Keep `LegacyRPID` unchanged. |
| + |
| +Keep Home's `keymaildev/signin.Flow`: Keymail upgrade, platform SMTP for emailed links, explicit email fallback after classification/Keymail failure. Rate-limit by IP and blinded address without disclosing account existence. SMTP failure never authenticates. GET displays confirmation; POST redeems once with existing browser protections. Email completed in another browser cannot finish the original app's handoff; restart there. |
| + |
| +Equipo keeps its existing `rastrillo/auth` local path and active-member/invitation checks. At pin `29e4491`, `auth.Config.SubjectFor` exists, but `auth.New` still installs the readable `auth_links.address` store. The corrected `AGENTS.md` records this: a subject hook alone is insufficient. Home keeps its sealed link store and opaque session subjects. |
| + |
| +Seal addresses before persistent link writes; expire the sealed state. No readable-address column, log, error, metric or queue payload. Keep `secure_delete` and scan SQLite, WAL, store objects and backups. Sessions, passkeys and codes key on person refs. |
| + |
| +After passkey enrollment, email/Keymail sign-in requires a passkey or recovery code. Issue ten hashed, single-use codes, shown once, each with **at least 80 bits of random entropy**. Code redemption is a protected form POST. Limit failed attempts persistently and atomically per account and IP: initially five per account and twenty per IP per fifteen minutes. Neither restart nor parallel requests resets the allowance. |
| + |
| +**Paul's ruling: email plus a recovery code is full account control.** It can replace the last lost passkey. Require fresh mailbox proof and an unused code bound to the same person and browser; provide an explicit replacement confirmation. Verify the new passkey ceremony, then atomically install that credential, consume the recovery proof, remove all previous passkeys, revoke **all Home sessions** and invalidate every remaining recovery code. Failure rolls back replacement; success requires a new sign-in with the new passkey. Generate replacement codes only after that proof. |
| + |
| +Send a replacement notice to the just-proven address held in memory, without storing it or adding it to a retry queue. Delivery failure must not undo revocation; allow a retry while the address remains available and report only a content-free failure. Recovery cannot satisfy unrelated passkey-only step-up. A working passkey survives mailbox loss; with no permitted recovery path, access is lost. No operator reset. Email/recovery work without scripts; WebAuthn requires its ceremony script. |
| + |
| +## Assertion and browser exchange |
| + |
| +Reuse `rastrillo/assertion` v1: P-256, context `rastrillo/assertion/v1`, `base64url(payload).base64url(signature)`. No JWT, algorithm negotiation or separate app verifiers. |
| + |
| +| Claim | Interpretation | |
| +|---|---| |
| +| `v`, `kid` | Fixed wire version and configured pinned verification key. | |
| +| `iss`, `aud` | Exact credential origin and registered app-instance origin. | |
| +| `sub` | Stable opaque Home person ref for Equipo; resolve through its explicit link. | |
| +| `iat`, `exp` | Mint for 120 seconds; require positive lifetime at most 120, `exp > now`, `iat <= now + 30 seconds`. No expiry grace. | |
| +| `jti`, `nonce` | Independent random replay identifier and browser-transaction nonce. | |
| +| `auth_time` | Actual authentication time, never refreshed by handoff; recency grants no authorization or factor strength. | |
| +| `ext` | Omit initially; future cosmetic values require closed enums already held by Home, unknown values treated as absent. | |
| + |
| +No email, role, grants, document list, encryption keys or authentication-strength claim. Existing roster hints remain separately reviewed, invalidation-only exceptions under Home §5.4. |
| + |
| +1. The app stores a short-lived transaction with independent browser secret, nonce, purpose and validated local return path/query. Set a `__Host-` pending cookie. Redirect to `/authorize` with exactly one `consumer`, one `nonce`, and optionally one `max_age=300`. No other parameters, duplicates or other `max_age` values; this matches `handleAuthorize`'s closed parser. Linking always includes `max_age=300`. Local accounts, documents and privileges stay app-side. |
| +2. Home validates the consumer and authenticates. For an ordinary existing session, **show a fixed-label Continue page before minting**; do not issue silently. Use operator-controlled service labels, no account-authored text. Linking always requires new authentication, regardless of session age. After Continue/authentication, deliver by form POST with optional static auto-submit and a manual button. Never put assertions in URLs or logs; use `no-store` and `strict-origin-when-cross-origin`, since `no-referrer` can null the POST Origin. |
| +3. Accept only a bounded form POST with exact issuer `Origin`. Verify signature, issuer, audience, types and times. Before storing a receipt, require its signed nonce to match a live pending transaction; check and insert atomically. Reserve `(iss,jti)` uniquely so repeated callbacks refuse. Unknown nonces and storage failures store nothing. |
| +4. Store a sealed, expiring inbox receipt, then redirect to `/auth/finish`. Its top-level GET receives the original SameSite=Lax cookie. Recheck the browser secret, nonce, expiry and account binding. Consume the pending/inbox proof, record replay use, resolve the current mapping/admission and mint the session atomically. Preserve the clock watermark and replay retention through expiry plus thirty seconds across restarts. Never mint at the cross-site POST. |
| + |
| +The final transaction boundary is a required adapter change: today's `handoff.Finish` commits before `Complete`. Do not leave a consumed proof in memory that can mint after unlink/relink. Reject swapped browsers, purposes or accounts; an assertion cannot silently replace another signed-in account. Only the callback bypasses ordinary cross-origin request-forgery checks. Bound pending/inbox rows and prune them; keep local return queries app-side. |
| + |
| +## Linking and unlinking |
| + |
| +The sibling stores `(issuer, person_ref) → immutable local account ID`, unique in both directions within its instance. Nothing about that account goes to Home. Email equality never creates, repairs or transfers a link. |
| + |
| +Start from the actual local session with request-forgery protection. **Equipo completes local reauthentication before creating the link transaction and starting the Home leg.** Record the transaction start server-side. Both proofs must be within five minutes at confirmation, and Home's `auth_time` must be **at or after that start**, with no backward allowance. Bind proofs to the original local account, session, nonce and purpose; never restart the clock by continuing a stale flow. |
| + |
| +`max_age=300` alone currently permits session reuse. For this slice, these requests must force a new Home authentication gesture, even with a recent session; a passive Keymail approval is insufficient. The consumer independently rejects an older `auth_time`. This tightens issuance behavior without adding request parameters. Show confirmation on Equipo, then consume both proofs and write the link in one transaction, rechecking existence/admission. Conflict refuses; never merge or overwrite. |
| + |
| +Retain `connect`/`linkstore`'s proof stages. Resolve Home subjects to Equipo's member identity before its active-member, invitation and session-epoch checks. Never pass a person ref to address-based helpers. An unlinked ID returns to local sign-in/linking; no duplicate account or implicit invitation acceptance. |
| + |
| +Unlink requires fresh local authentication and protected confirmation, and works while Home is down. In one transaction delete the mapping, every Home-derived session for it, and pending link/handoff proofs and receipts. Anonymous pending flows cannot yet be attributed: clear the instance's bounded pending/inbox/link-proof sets rather than add revision machinery. Other in-progress sign-ins may need restarting. Serialize callback receipt insertion, completion/session minting, linking and unlinking through the database writer; minting checks the live mapping in that same transaction. A later relink cannot revive deleted proofs or sessions. Keep local credentials, local sessions and data. Account deletion removes links transactionally; IDs are never reused. Address changes under today's address-bound bridge require fresh linking. |
| + |
| +## Pinned keys and rotation |
| + |
| +Use `connect`'s existing `EQUIPO_HOME_ISSUER`, `EQUIPO_HOME_CONSUMER_ID`, `EQUIPO_HOME_KEYS_BASE64` and `EQUIPO_HOME_DEK_BASE64`. The keys value is standard-base64 JSON mapping `kid` to standard-base64 65-byte uncompressed P-256 public keys, at most eight keys/4,096 decoded bytes. The dedicated 32-byte storage key protects handoff/link state, not content; keep it stable. Unknown `kid` fails closed without fetching. Private signing keys stay in credential-only configuration. |
| + |
| +Rotate by configuration: install old and new public pins in consumers first, activate that configuration, then switch Home's signer. Keep the old public pin for at least 150 seconds after its last assertion, then remove it through configuration. A consumer missing the new pin refuses ID sign-in until updated; local sign-in remains. Remove a compromised pin immediately and revoke affected Home-derived sessions separately. There is no cache-based revocation bound. Publication/discovery requires a later design; slice 1 has no key endpoint, refresh or cached-key policy. |
| + |
| +## Sign-out, outages and gates |
| + |
| +Capture the session’s authentication source before revocation. Every sign-out revokes locally and lands on the local signed-out page without waiting for Home. Local-authenticated sessions never redirect to Home. Only a Home-derived session may offer a separate optional Home sign-out hop from that page; this is best-effort and cannot gate local completion or local sign-in. Do not use `connect.Routes.Signout`'s unconditional redirect unchanged. No global logout guarantee. |
| + |
| +Home outage blocks new ID authentication/linking. Existing app sessions retain local expiry, revocation and admission checks; local sign-in and unlink continue. Failures offer deliberate retry or local sign-in without redirect loops. |
| + |
| +Required gates: RP/origin isolation and generated WebAuthn names; address-at-rest/log scans; both sign-in paths; recovery entropy, concurrent attempt limits, replacement revocation and notice privacy; expired/replayed/swapped assertions; unmatched nonce stores no receipt; closed authorize parameters; real cross-site scriptless return; concurrent link/unlink/relink/mint; pinned rotation; and identical Equipo admission through either sign-in path. Linking must reject an otherwise valid five-minute-old proof whose `auth_time` precedes transaction start, and demonstrate Home re-prompts. Sign-out/outage tests use an issuer that accepts connections and **hangs**, proving local landing/revocation/sign-in work; refused connections alone are insufficient. |
| + |
| +## Slice 2: Contra |
| + |
| +Paul ruled that Home mints for Contra **only after passkey-backed sign-in**, enforced at Home per consumer, never delegated to an assertion-strength claim. Recovery alone does not qualify. Linking is opt-in with disclosure of the new identity association; amend Contra's threat model before adoption. |
| + |
| +Contra receives a pairwise subject: a domain-separated HMAC of person ref and immutable consumer identity under a dedicated Home key. Never send the global ref; define key rotation/migration before use. Consumers outside `oficina.works` need this policy in their later slice too. No domain move is required. |
| + |
| +Move the adapter here: `connect.LookupPerson` expects a verified address label and integer ID, while Contra uses opaque IDs and no readable address. Preserve proof binding without inventing addresses. Oficina ID cannot supply vault keys, recover vault plaintext or bypass Contra's cryptographic proofs. |
| + |
| +**Open for slice 2:** what may a locked ID-authenticated session read or do? Default to nothing beyond the unlock screen. No Contra adapter or locked-session permissions are implemented in slice 1. |