Skip to content

chore(oidc): remove annex-auth, harden the client after review, port e2e to the new sign-in - #26

Merged
CubityFirst merged 12 commits into
oidc/3-admin-deletion-syncfrom
feat/oidc-client-auth-split
Nov 19, 2026
Merged

CubityFirst merged 12 commits into
oidc/3-admin-deletion-syncfrom
feat/oidc-client-auth-split

Conversation

@CubityFirst

Copy link
Copy Markdown
Owner

Final layer: nothing depends on annex-auth any more, so it goes, along with the fixes from review and the e2e port.

  • Removes packages/auth (annex-auth). Docs (CLAUDE.md, memories/Identity-Client.md, README, CONTRIBUTING, docs/oauth) describe Annex as a client of auth.cubityfir.st; memories/Identity-Client.md holds the cutover runbook.
  • Review hardening: login-CSRF-proof handoff, per-sign-in state and handoff cookies, deletion tombstones that win over caches and late refreshes, tombstone-guarded billing upserts, no Stripe customer deletion without evidence, live admin checks for deletion, Stripe receipt email kept in step on every mirror write, deletion-sync paging fixes.
  • Fixes annex-api failing to start: src/index.ts exported a plain constant, which workerd loads as an entrypoint. A test now guards the entry module's exports.
  • e2e: every suite signs in with the localhost-only dev quick login (e2e/signIn.ts); the admin worker gets the same double-gated dev route. The 2FA, change-email and change-password suites are deleted. On Chromium locally: 84 pass; the 14 failures are existing UI drift on main in code this stack doesn't touch (missing "New document" header button, changed toast copy, site-delete dialog, avatar variant).

Before deploying (see memories/Identity-Client.md): register the docs and admin clients disabled, set OIDC_CLIENT_SECRET on annex-api/annex-admin, move the Stripe secrets to annex-api, apply migration 0065, freeze old sign-ups, export → import → deploy, replay Stripe, reconcile deletions and additions (accounts registered on old Annex after the identity import need an additions-only import with their original ids on the identity side), then enable the clients.

Stack (merge in order; each PR's diff is only its own commits):

  1. API: sign-in, users mirror, account data moved into cubedocs-main ← base main
  2. Frontend: sign-in/out through auth.cubityfir.st, retire annex-auth's provider surface
  3. Admin panel as its own OIDC client, deletion sync
  4. Remove packages/auth, review hardening, docs, e2e port

Reviewed with sol-loop: 9 rounds with gpt-6.2-sol. Sol verdict: approved

Identity lives on auth.cubityfir.st and everything Annex-specific moved
into the api worker, so the annex-auth worker package goes: root
dev/build/deploy/typecheck/test scripts, the auth migrations step,
d1-local's "auth" database and e2e's auth-DB calls (account data is in
cubedocs-main now). The cubedocs-auth schema survives as a fixture for the
one-time import script. Admin + admin-frontend tests join the root
`pnpm test`, and `dev:stripe` forwards to the api worker.

Adds e2e/signIn.ts (dev quick-login) for porting the e2e suites, which
still drive Annex's old registration and login forms.
CLAUDE.md's auth section, schema notes, admin deletion, worker config and
local-dev notes now describe the OIDC client model: Annex sessions and the
users mirror in cubedocs-main, the IDENTITY RPC and IDENTITY_OIDC bindings
(and why same-zone fetches must use the binding), the deletion sync, and
the e2e suites that still need porting. New memories/Identity-Client.md
covers the flow, client registration and the cutover steps;
.dev.vars.example files show how to point local dev at a local identity
worker. Ink-Stripe, Api-Keys, Collab, Worktree-Dev, README and
CONTRIBUTING drop the auth worker.
…eview

- The single-use handoff code now travels only in an HttpOnly,
  SameSite=Strict cookie (never in a URL), so a crafted /auth/complete
  link can't sign anyone in (login CSRF).
- A recorded or persisted identity deletion wins over the standing cache,
  the mirror fallback and any in-flight mirror refresh (sessions, API
  keys, collab); deleted owners' kept member rows are scrubbed.
- Admin deletion: the live admin role is required at scheduling and
  re-checked before execution; the point of no return is tied to the
  Stripe customer the preflight saw.
- Stripe webhook: billing upserts are guarded against tombstones; a
  blocked event deletes its customer, an unknown user is retried, never
  cleaned up without evidence.
- Invite-by-email no longer falls back to the mirror outside local dev;
  Stripe customer email follows identity email changes seen by the
  standing check.
- Admin sign-in lands on its deep link; deletion-sync paging can't skip
  or stall on same-millisecond deletions; import script arg parsing.
- Cutover doc: freeze window, Stripe replay, clients disabled until
  deletions are reconciled against a final export.
Sets OIDC_CLIENT_ID to the client registered at auth.cubityfir.st
(oidc_7369d6d5736d2bea35f1ab47). The provider matches post-logout
redirect URIs byte for byte and the registration is the bare origin, so
the default no longer appends a trailing slash (verified against the live
provider: the bare origin is accepted, the slashed form is refused).

Adds scripts/oidc-check.mjs: a dev-machine end-to-end check of the
registration (real sign-in, code exchange, the worker's id_token checks,
claims printed; secret read from the environment, never printed).
…mirror write

Each sign-in now gets its own handoff cookie (annex_handoff_<attempt>),
named by a non-secret attempt id the completion page passes back, so two
sign-ins finishing at once in one browser each redeem their own session.

refreshMirror reads the previous email in the same batch and updates the
linked Stripe customer when it changes, so whichever path writes a new
address first (sign-in, standing check, invite lookup, admin) keeps
receipts in step.
…fter the identity import

The login-state cookie is now annex_oidc_<state>, so sign-ins started in
two tabs before either callback don't overwrite or clear each other's
state.

The cutover runbook now reconciles additions as well as deletions:
accounts registered on the old Annex after the identity service's import
must be added there with their original ids before the clients are
enabled, or their Annex data is stranded under an id nobody can sign in as.
…y module

workerd loads every named export of the main module as an entrypoint, so
exporting the cron string from src/index.ts stopped annex-api from
starting. Moved it to lib/identityDeletions.ts, with a test that the
entry module exports only handlers and classes.
POST /api/dev/quick-login on the admin worker mints an admin dev user and
an admin session, gated like the api worker's (DEV_QUICK_LOGIN=true AND a
localhost APP_ORIGIN), so the admin e2e suite runs without a local
identity service.
Every suite now signs in through e2e/signIn.ts (devSignIn); the admin
suite uses the admin worker's quick login. Drops the Turnstile mocks and
the 2FA, change-email and change-password suites, whose features moved to
auth.cubityfir.st.
@CubityFirst
CubityFirst merged commit 9b1b32f into oidc/3-admin-deletion-sync Nov 19, 2026
1 check passed
CubityFirst added a commit that referenced this pull request Nov 19, 2026
…ount deletions (#25)

* feat(admin): sign in to the admin panel through auth.cubityfir.st

The admin panel is its own first-party OIDC client (scopes openid profile
email roles; sign-in requires the admin role, re-checked live via the
identity service). It reuses the API worker's sign-in flow (now a shared
AuthFlow: login/callback/exchange/logout) with an 'admin' session kind, and
server-side OIDC requests go over the IDENTITY_OIDC service binding.

Removed what moved to auth.cubityfir.st: the docs-app handoff, the OAuth
clients tab, and account moderation (disable/suspend/re-enable, force
password change). Standing shows as read-only from the users mirror, with
a live refresh in user details and links to manage the account there.

Delayed deletion now deletes Annex data only: scheduling blocks the person
from Annex, the cron removes sites/orgs the operator confirmed, Stripe,
memberships, billing, preferences and sessions, and marks the schedule
completed. The users row and schedule stay, so they remain blocked until
the identity account is deleted on auth.cubityfir.st. All admin data now
lives in cubedocs-main; no AUTH_DB or AUTH binding.

* feat(api): sync account deletions from auth.cubityfir.st

An hourly cron polls IdentityService.listDeletedUsers from the newest
deletion already recorded in identity_deletions and removes each deleted
account's Annex data: the Stripe customer (cancelling Ink), memberships,
API keys, doc shares, favourites, avatars and the users mirror row
(cascading sessions, billing, preferences and any admin deletion).
Sites and organizations they owned are kept with their owner rows and
listed in the admin panel's Projects page for an operator to review.
Failures (e.g. Stripe) stay pending with last_error and retry hourly.

Drops cleanupDeletedAccount, which deleted owned sites and had no caller
left after DELETE /me moved to the identity service.

* chore(oidc): remove annex-auth, harden the client after review, port e2e to the new sign-in (#26)

* chore: remove packages/auth (annex-auth) now that nothing depends on it

Identity lives on auth.cubityfir.st and everything Annex-specific moved
into the api worker, so the annex-auth worker package goes: root
dev/build/deploy/typecheck/test scripts, the auth migrations step,
d1-local's "auth" database and e2e's auth-DB calls (account data is in
cubedocs-main now). The cubedocs-auth schema survives as a fixture for the
one-time import script. Admin + admin-frontend tests join the root
`pnpm test`, and `dev:stripe` forwards to the api worker.

Adds e2e/signIn.ts (dev quick-login) for porting the e2e suites, which
still drive Annex's old registration and login forms.

* docs: describe Annex as a client of auth.cubityfir.st

CLAUDE.md's auth section, schema notes, admin deletion, worker config and
local-dev notes now describe the OIDC client model: Annex sessions and the
users mirror in cubedocs-main, the IDENTITY RPC and IDENTITY_OIDC bindings
(and why same-zone fetches must use the binding), the deletion sync, and
the e2e suites that still need porting. New memories/Identity-Client.md
covers the flow, client registration and the cutover steps;
.dev.vars.example files show how to point local dev at a local identity
worker. Ink-Stripe, Api-Keys, Collab, Worktree-Dev, README and
CONTRIBUTING drop the auth worker.

* fix(oidc): harden sign-in handoff, deletion and billing paths after review

- The single-use handoff code now travels only in an HttpOnly,
  SameSite=Strict cookie (never in a URL), so a crafted /auth/complete
  link can't sign anyone in (login CSRF).
- A recorded or persisted identity deletion wins over the standing cache,
  the mirror fallback and any in-flight mirror refresh (sessions, API
  keys, collab); deleted owners' kept member rows are scrubbed.
- Admin deletion: the live admin role is required at scheduling and
  re-checked before execution; the point of no return is tied to the
  Stripe customer the preflight saw.
- Stripe webhook: billing upserts are guarded against tombstones; a
  blocked event deletes its customer, an unknown user is retried, never
  cleaned up without evidence.
- Invite-by-email no longer falls back to the mirror outside local dev;
  Stripe customer email follows identity email changes seen by the
  standing check.
- Admin sign-in lands on its deep link; deletion-sync paging can't skip
  or stall on same-millisecond deletions; import script arg parsing.
- Cutover doc: freeze window, Stripe replay, clients disabled until
  deletions are reconciled against a final export.

* fix(oidc): use the registered docs client and its exact post-logout URI

Sets OIDC_CLIENT_ID to the client registered at auth.cubityfir.st
(oidc_7369d6d5736d2bea35f1ab47). The provider matches post-logout
redirect URIs byte for byte and the registration is the bare origin, so
the default no longer appends a trailing slash (verified against the live
provider: the bare origin is accepted, the slashed form is refused).

Adds scripts/oidc-check.mjs: a dev-machine end-to-end check of the
registration (real sign-in, code exchange, the worker's id_token checks,
claims printed; secret read from the environment, never printed).

* fix(oidc): per-attempt handoff cookie and Stripe email sync on every mirror write

Each sign-in now gets its own handoff cookie (annex_handoff_<attempt>),
named by a non-secret attempt id the completion page passes back, so two
sign-ins finishing at once in one browser each redeem their own session.

refreshMirror reads the previous email in the same batch and updates the
linked Stripe customer when it changes, so whichever path writes a new
address first (sign-in, standing check, invite lookup, admin) keeps
receipts in step.

* fix(oidc): per-sign-in login-state cookie; reconcile accounts added after the identity import

The login-state cookie is now annex_oidc_<state>, so sign-ins started in
two tabs before either callback don't overwrite or clear each other's
state.

The cutover runbook now reconciles additions as well as deletions:
accounts registered on the old Annex after the identity service's import
must be added there with their original ids before the clients are
enabled, or their Annex data is stranded under an id nobody can sign in as.

* docs(oidc): freeze old Annex sign-ups before the cutover export

* fix(api): keep the deletion-sync cron constant out of the worker entry module

workerd loads every named export of the main module as an entrypoint, so
exporting the cron string from src/index.ts stopped annex-api from
starting. Moved it to lib/identityDeletions.ts, with a test that the
entry module exports only handlers and classes.

* feat(admin): localhost-only dev quick-login for the admin panel

POST /api/dev/quick-login on the admin worker mints an admin dev user and
an admin session, gated like the api worker's (DEV_QUICK_LOGIN=true AND a
localhost APP_ORIGIN), so the admin e2e suite runs without a local
identity service.

* test(e2e): sign in with the dev quick login instead of Annex's old forms

Every suite now signs in through e2e/signIn.ts (devSignIn); the admin
suite uses the admin worker's quick login. Drops the Turnstile mocks and
the 2FA, change-email and change-password suites, whose features moved to
auth.cubityfir.st.

* test(e2e): scope the admin smoke test to this run's user and audit entry

* chore(admin): use the registered auth.cubityfir.st client id for the admin panel
CubityFirst added a commit that referenced this pull request Nov 19, 2026
* feat(frontend): sign in and out through auth.cubityfir.st

/login and /register hand off to /api/auth/login (the hosted page links to
registration and returns here); /auth/complete redeems the callback's
single-use code for the session JWT, which still lives in localStorage.
Sign-out revokes the Annex session and continues to the identity
service's end-session URL. Local dev keeps the quick-login buttons.

Removed the pages and helpers that moved to auth.cubityfir.st (login,
register, check/verify email, OAuth authorize, 2FA prompts, passkeys,
pending OAuth) and the security parts of account settings (password,
email change, TOTP, passkeys, sessions, delete account); settings now
links to the identity service's account and security pages, and email
and display name are read-only. /oauth/authorize redirects to the
identity service, query string included (frontend worker and SPA).
Dropped the now-unused zxcvbn, react-qr-code, @simplewebauthn/browser and
Turnstile script.

* chore(auth): retire annex-auth's OIDC provider after the cutover

auth.cubityfir.st is now the cubityfirst-auth worker's Custom Domain.
Remove annex-auth's two auth.cubityfir.st zone routes (a deploy that kept
them would try to re-add routes on a hostname another Worker owns) and the
now-unreachable provider: /oauth/{authorize,token,userinfo,jwks},
/.well-known/openid-configuration, the /admin/oauth/clients management
handlers, OIDC_ISSUER/OIDC_AUTHORIZE_URL, RATE_LIMITER_OIDC and the
OIDC_PRIVATE_KEY secret. The scheduled sweep stays. Docs, memories and
the key/client helper scripts that described Annex as the provider are
replaced by a pointer to auth.cubityfir.st.

Touches only packages/auth, docs, memories, scripts and CLAUDE.md, so it
can be cherry-picked onto main and shipped with the next annex-auth deploy.

* feat(admin): admin panel signs in through auth.cubityfir.st; sync account deletions (#25)

* feat(admin): sign in to the admin panel through auth.cubityfir.st

The admin panel is its own first-party OIDC client (scopes openid profile
email roles; sign-in requires the admin role, re-checked live via the
identity service). It reuses the API worker's sign-in flow (now a shared
AuthFlow: login/callback/exchange/logout) with an 'admin' session kind, and
server-side OIDC requests go over the IDENTITY_OIDC service binding.

Removed what moved to auth.cubityfir.st: the docs-app handoff, the OAuth
clients tab, and account moderation (disable/suspend/re-enable, force
password change). Standing shows as read-only from the users mirror, with
a live refresh in user details and links to manage the account there.

Delayed deletion now deletes Annex data only: scheduling blocks the person
from Annex, the cron removes sites/orgs the operator confirmed, Stripe,
memberships, billing, preferences and sessions, and marks the schedule
completed. The users row and schedule stay, so they remain blocked until
the identity account is deleted on auth.cubityfir.st. All admin data now
lives in cubedocs-main; no AUTH_DB or AUTH binding.

* feat(api): sync account deletions from auth.cubityfir.st

An hourly cron polls IdentityService.listDeletedUsers from the newest
deletion already recorded in identity_deletions and removes each deleted
account's Annex data: the Stripe customer (cancelling Ink), memberships,
API keys, doc shares, favourites, avatars and the users mirror row
(cascading sessions, billing, preferences and any admin deletion).
Sites and organizations they owned are kept with their owner rows and
listed in the admin panel's Projects page for an operator to review.
Failures (e.g. Stripe) stay pending with last_error and retry hourly.

Drops cleanupDeletedAccount, which deleted owned sites and had no caller
left after DELETE /me moved to the identity service.

* chore(oidc): remove annex-auth, harden the client after review, port e2e to the new sign-in (#26)

* chore: remove packages/auth (annex-auth) now that nothing depends on it

Identity lives on auth.cubityfir.st and everything Annex-specific moved
into the api worker, so the annex-auth worker package goes: root
dev/build/deploy/typecheck/test scripts, the auth migrations step,
d1-local's "auth" database and e2e's auth-DB calls (account data is in
cubedocs-main now). The cubedocs-auth schema survives as a fixture for the
one-time import script. Admin + admin-frontend tests join the root
`pnpm test`, and `dev:stripe` forwards to the api worker.

Adds e2e/signIn.ts (dev quick-login) for porting the e2e suites, which
still drive Annex's old registration and login forms.

* docs: describe Annex as a client of auth.cubityfir.st

CLAUDE.md's auth section, schema notes, admin deletion, worker config and
local-dev notes now describe the OIDC client model: Annex sessions and the
users mirror in cubedocs-main, the IDENTITY RPC and IDENTITY_OIDC bindings
(and why same-zone fetches must use the binding), the deletion sync, and
the e2e suites that still need porting. New memories/Identity-Client.md
covers the flow, client registration and the cutover steps;
.dev.vars.example files show how to point local dev at a local identity
worker. Ink-Stripe, Api-Keys, Collab, Worktree-Dev, README and
CONTRIBUTING drop the auth worker.

* fix(oidc): harden sign-in handoff, deletion and billing paths after review

- The single-use handoff code now travels only in an HttpOnly,
  SameSite=Strict cookie (never in a URL), so a crafted /auth/complete
  link can't sign anyone in (login CSRF).
- A recorded or persisted identity deletion wins over the standing cache,
  the mirror fallback and any in-flight mirror refresh (sessions, API
  keys, collab); deleted owners' kept member rows are scrubbed.
- Admin deletion: the live admin role is required at scheduling and
  re-checked before execution; the point of no return is tied to the
  Stripe customer the preflight saw.
- Stripe webhook: billing upserts are guarded against tombstones; a
  blocked event deletes its customer, an unknown user is retried, never
  cleaned up without evidence.
- Invite-by-email no longer falls back to the mirror outside local dev;
  Stripe customer email follows identity email changes seen by the
  standing check.
- Admin sign-in lands on its deep link; deletion-sync paging can't skip
  or stall on same-millisecond deletions; import script arg parsing.
- Cutover doc: freeze window, Stripe replay, clients disabled until
  deletions are reconciled against a final export.

* fix(oidc): use the registered docs client and its exact post-logout URI

Sets OIDC_CLIENT_ID to the client registered at auth.cubityfir.st
(oidc_7369d6d5736d2bea35f1ab47). The provider matches post-logout
redirect URIs byte for byte and the registration is the bare origin, so
the default no longer appends a trailing slash (verified against the live
provider: the bare origin is accepted, the slashed form is refused).

Adds scripts/oidc-check.mjs: a dev-machine end-to-end check of the
registration (real sign-in, code exchange, the worker's id_token checks,
claims printed; secret read from the environment, never printed).

* fix(oidc): per-attempt handoff cookie and Stripe email sync on every mirror write

Each sign-in now gets its own handoff cookie (annex_handoff_<attempt>),
named by a non-secret attempt id the completion page passes back, so two
sign-ins finishing at once in one browser each redeem their own session.

refreshMirror reads the previous email in the same batch and updates the
linked Stripe customer when it changes, so whichever path writes a new
address first (sign-in, standing check, invite lookup, admin) keeps
receipts in step.

* fix(oidc): per-sign-in login-state cookie; reconcile accounts added after the identity import

The login-state cookie is now annex_oidc_<state>, so sign-ins started in
two tabs before either callback don't overwrite or clear each other's
state.

The cutover runbook now reconciles additions as well as deletions:
accounts registered on the old Annex after the identity service's import
must be added there with their original ids before the clients are
enabled, or their Annex data is stranded under an id nobody can sign in as.

* docs(oidc): freeze old Annex sign-ups before the cutover export

* fix(api): keep the deletion-sync cron constant out of the worker entry module

workerd loads every named export of the main module as an entrypoint, so
exporting the cron string from src/index.ts stopped annex-api from
starting. Moved it to lib/identityDeletions.ts, with a test that the
entry module exports only handlers and classes.

* feat(admin): localhost-only dev quick-login for the admin panel

POST /api/dev/quick-login on the admin worker mints an admin dev user and
an admin session, gated like the api worker's (DEV_QUICK_LOGIN=true AND a
localhost APP_ORIGIN), so the admin e2e suite runs without a local
identity service.

* test(e2e): sign in with the dev quick login instead of Annex's old forms

Every suite now signs in through e2e/signIn.ts (devSignIn); the admin
suite uses the admin worker's quick login. Drops the Turnstile mocks and
the 2FA, change-email and change-password suites, whose features moved to
auth.cubityfir.st.

* test(e2e): scope the admin smoke test to this run's user and audit entry

* chore(admin): use the registered auth.cubityfir.st client id for the admin panel
CubityFirst added a commit that referenced this pull request Nov 19, 2026
Annex becomes an OpenID Connect client of auth.cubityfir.st and keeps its own sessions, users mirror, billing and preferences. annex-auth and packages/auth are removed.

Squashes the stack:
- #23 api: OIDC client, users mirror, billing/webhook/me moved out of annex-auth
- #24 frontend: sign-in/out through the provider, /oauth/authorize redirect
- #25 admin: admin panel as its own client, hourly identity deletion sync
- #26 annex-auth removal, review fixes, e2e port, registered admin client id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant