Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #33. Builds on the hosted mode from #11 / #13.
What: in hosted mode, people sign in with their CHT username and password against one of a configured list of CHT instances, instead of creating an email + password account in the builder. The server makes the same checks cht-user-management makes, and lets in admins and users whose roles hold
can_configure(configurable).Why this was necessary: hosted sign-up was open to anyone who could reach the URL, with no email verification, no password reset and no invites.
docs/deployment-requirements.mdhad to tell whoever deploys it to put separate authentication in front. The people who should use the builder already have an identity that says whether they may configure an app: their CHT user.What it solves: access is granted and revoked in CHT, as it is for cht-user-management. Nobody manages a second set of passwords, and the builder stores no password at all.
What changed
Sign-in against CHT (
server/src/chtAuth.ts). The checks follow cht-user-management'ssrc/lib/cht-session.ts:POST <instance>/_sessionchecks the password.GET <instance>/medic/org.couchdb.user:<name>reads the user's roles. A CouchDB server admin has no user-settings doc, so their_sessionroles are used.GET <instance>/api/v1/settingsreads which roles hold which permissions. This is skipped for admins.The CHT session cookie is used only for those reads and is closed straight after (
DELETE /_session, awaited). Errors say what went wrong: wrong password is 401; a missing permission is 403 and names the permission; an unreachable instance is 502; a timeout after 15 s is 504.Instance allow-list (
server/src/config.ts).CHT_INSTANCESis a comma-separated list of base URLs, validated at boot: http(s) only, no embedded credentials, de-duplicated, trailing slash dropped. Hosted mode refuses to start without it.CHT_REQUIRED_PERMISSIONSdefaults tocan_configure.Accounts and sessions (
server/src/auth.ts).POST /api/auth/login {instance, username, password}replaces sign-up and email login.GET /api/auth/instancesis unauthenticated and feeds the form.users.jsonholds no password hashes. Bearer tokens and 30-day sessions are unchanged./api/auth/mereturns the CHT username and the instance host.Sign-in screen (
client/src/ui/SignIn.tsx). Instance picker (read-only when only one instance is configured), username and password. "Create an account" is gone. The server's message is shown as-is, e.g. Your CHT user on … is missing: can_configure.Test double (
scripts/fake-cht.mjs). Just enough of a CHT for the four endpoints above. It has a program officer who holdscan_configure, a CHW who does not, and a server admin, so no real instance is needed in CI.Docs.
README.md,docs/hosted-deploy.md,docs/deployment-requirements.md(new env vars, the deploy-checkcurl, revised security properties),docs/plans/hosted-authoring.md, theDockerfileusage comment and the CI step names.Before deploying⚠️
CHT_INSTANCESon every hosted deployment (including the Create a hostable package to test CHT UI builder #11 test hosting) before rolling this out. Without it the server will not start.DATA_ROOT/users/<old id>/but are not moved to the new (instance, username) account. Tell current test users to download anything they want to keep.DATA_ROOT/auth/sessions.jsonsigns them out immediately.Tests
server/src/chtAuth.test.ts(new, againstfake-cht.mjs): permitted user let in with roles; wrong password 401; missing permission 403 and named; server admin without a user doc let in; CHT session closed after the checks; unreachable instance 502;missingPermissionsandparseInstancesedge cases.scripts/hosted-acceptance.mjs: sign-in replaces sign-up. Adds wrong password, missing permission, an instance outsideCHT_INSTANCESrefused (no relay),/api/auth/signupgone, admin sign-in, same account on re-login in any letter case, no password in any response, and/api/auth/menaming the user and instance. The isolation checks are unchanged.client/tests/hosted-authoring.spec.ts: every journey now signs in with CHT credentials. New test: a CHW is refused and toldcan_configureis missing.playwright.hosted.config.tsstartsfake-cht.mjsalongside the server.Validation
pnpm buildpnpm typecheckpnpm --filter @cht-ui/server testnode scripts/hosted-acceptance.mjsplaywright test -c playwright.hosted.config.tspnpm lintmasteralready (164 problems, identical count on this branch); the 13 touched source files lint cleanpnpm --filter @cht-ui/shared testshared/