Repository navigation
Description
Goal
After this phase the provider's binding decisions are recorded in ADR 0119 before any client can register, a partner subdomain such as compute.nemar.org is no longer trusted as a NEMAR origin, the app session cookie has a __Host- name with a safe dual-read window, and every account has an opaque, never-reused oidc_subject.
Nothing OIDC is served yet.
Routing
- Readiness: ready
- Implementer: Sonnet
- Opus checkpoint: review before merge (ADR, origin checks, cookie matrix)
- Depends on: none ; Unblocks: Phase B2: OIDC client registry, signing keys and discovery #2016, Phase B3: OIDC authorization and consent #2017, Phase B4: OIDC token, userinfo, revocation and introspection #2018, Phase B5: OIDC revocation cascades and back-channel logout #2019, Phase B6: Sign in with NEMAR docs and conformance #2020
- Repository and base branch: nemarOrg/nemar-cli, epic branch; plus one website PR into
stagingfor the cookie reader
Scope
In: ADR 0119; shared/partner-hosts.ts and its two exclusions; the cookie rename with dual read in both repositories; migration 0120; the reserved-prefix username rule.
Out: any /oauth route, client or key table (#2016); turning the cookie flag on in production (the owner, after the website release).
Design references
Design section 3; ADR 0056, 0079, 0043, 0048, 0106; .context/decisions/0000-template.md.
Changes
- Create
.context/decisions/0119-nemar-is-an-openid-connect-provider-and-orcid-stays-the-upstream-identity.md, statusproposed: every binding rule of design section 3, plus token prefixesnmo_at_andnmo_rt_(API keys arenm_),subasnmu_plus 32 lowercase hex, sign-in rulesactive_accountandperson_proven_orcid("proven" is anoauth_identitiesORCID row matchingusers.orcid; an ADR 0106 attestation does not count), first-party refused for a client with a partner-host redirect, and "general provider" (compute facts come from the API, never the ID token). Credential-ending table: admin revocation and owner soft delete end all grants and tokens and send back-channel logout; account merge (manual, ADR 0043) does the same for the loser through an owner command; compute suspension ends grants with acompute.scope and notifies only those clients; ORCID unlink or relink ends grants ofperson_proven_orcidclients; client disable revokes everything and sends no logout; role demotion, key revocation and sign-out leave OIDC grants alone, each with its reason. A "not decided" list (public clients,private_key_jwt, connected-apps page). Add the README index line and an AGENTS.md "Load-bearing ones" line. test/adr-index.unit.test.tsdemands gapless numbers: iforigin/devlacks 0118, addTOLERATED_GAPS = new Set([118])with a comment to delete it in the PR that adds 0118.- Create
shared/partner-hosts.ts(import-free):PARTNER_HOSTS = ["compute.nemar.org"],isPartnerHost(hostname)(exact or subdomain, lowercase). MakeisNemarWebOrigin(backend/src/services/cors-origins.ts) andisAllowedOrigin(backend/src/services/web-session.ts) return false for a partner host first; the api cors,routes/zarr-data.tsandroutes/mcp.tsinherit the first. backend/src/services/web-session.ts:SESSION_COOKIE_NAME = "__Host-nemar_session",LEGACY_SESSION_COOKIE_NAME,readSessionCookie(header)(new first) andsessionCookieHeaders(env, value, {maxAgeSeconds})returning an array:HOST_PREFIXED_SESSION_COOKIEunset gives today's header byte for byte;"1"gives the new name withSecure; HttpOnly; SameSite=Lax; Path=/, noDomain, plus legacy clears with and withoutDomain. Readers:middleware/webSession.tsandresolveCookieUserinmiddleware/auth.ts. Writers (append):routes/auth-web.tsverify, logout and the/meslide;routes/auth-orcid.tsboth issuances. Optional binding intypes/bindings.ts;"1"only in[env.dev.vars]ofbackend/wrangler-sccn.toml.- Website PR (base
staging):src/lib/auth.ts(new name,readSessionCookie),src/middleware.ts(presence check before the cross-host redirect,applySession, forwarded-cookie fallback),src/pages/api/auth/logout.ts(defensive clear of both), and tests naming the cookie (also comments inauth-proxy.tsandapi/v1/[...path].ts).auth-dev.tskeeps the legacy name; proxies mirror Set-Cookie unchanged. backend/src/db/migrations/0120_users_oidc_subject.sql(style of0096_...): add the column with a format CHECK, backfill every row including tombstones with'nmu_' || lower(hex(randomblob(16))), unique indexidx_users_oidc_subject, an AFTER INSERT trigger filling NULL, a BEFORE UPDATE OF trigger aborting any change to a non-NULL value.shared/oidc-subject.ts(OIDC_SUBJECT_PREFIX,isOidcSubject),backend/src/services/oidc-subject.ts(userIdForOidcSubject),validateUsernameFormatinservices/username.tsrefusing a leadingnmu_(codeusername_reserved; map every consumer ofUsernameFormatError), and owner-onlyGET /admin/users/by-oidc-subject/:subinroutes/admin/users.tspinned intest/admin-route-inventory.unit.test.ts.
Tests (write these first)
- Partner exclusion through real routes:
Origin: https://compute.nemar.orggets no CORS allowance from the api, zarr and mcp forks, and a cookie-authenticated admin write is 403origin_not_allowed. Mutation: drop the partner test from either check. Alsox.compute.nemar.orgexcluded, app.nemar.org unchanged. - Cookie matrix: flag off is byte-identical at all five writers; flag on sets the new name without
Domainand both clears; a legacy-only request authenticates; with both, the new one wins and an invalid new one is not rescued by a valid legacy one. Mutation: swap the read order. - Migration 0120 (template
backend/test/upstream-repull-dispatches-migration.test.ts): backfill unique and well-formed, insert gets one, update or duplicate aborts, the tombstone mask keeps it. - The subject is in no body of
/users/me,/auth/meor admin user detail;validateUsernameFormat("nmu_abc")is refused andnemar_xis not. - The ADR index test passes with and without the tolerated gap.
Acceptance criteria
- ADR 0119 is indexed and carries design section 3's binding rules.
- Both origin checks exclude partner hosts and change nothing else.
- The website PR is merged to
stagingwith tests green before the flag is set anywhere. -
oidc_subjectexists on every row, cannot change, and is not exposed.
Gates
bun run typecheck, bun run lint, bunx biome check backend/src shared test, the new tests, test/adr-index.unit.test.ts, test/admin-route-inventory.unit.test.ts, backend/test/cors-origins.test.ts, bun run migrations:d1-check, full bun test. Website: bun run lint, bun run typecheck, bun run test.
Rules that bite here
- The cookie stays host-only on purpose (ADR 0056);
__Host-forbidsDomain, so never route the new name throughWEB_SESSION_COOKIE_DOMAIN. - Two readers of the cookie exist; do not add a third copy.
- The repository is public: no private host details.
Escalate to the owner if
- A production username already starts with
nmu_(the owner checks before release). - SDSC's answer to design question 13 makes the subject format unusable.
When merged
Tell the owner the order: website release, API release, then HOST_PREFIXED_SESSION_COOKIE in production. Mark design section 3 "decided in ADR 0119".
Activity
neuromechanist commentedon Nov 4, 2026
Merged into the epic branch by #2031 (squash
f7233e8a), 2026-11-04, after a round-1 panel review, the Opus checkpoint and its delta; every accepted finding fixed. Gates: phase tests, typecheck, lint and the D1 migration check pass; the full CI run is the epic gate.Still open from this phase's acceptance criteria: the website cookie reader nemarOrg/website#499 is green and waiting for the owner's approval to merge into
staging(an integration branch). The flag stays off everywhere in production until that release is live. Release order: website tostagingand released, then the API release, thenHOST_PREFIXED_SESSION_COOKIEin production. The ADR isproposeduntil the owner settles the points listed on #2031.