Repository navigation
feat: join-code onboarding with one-command installers, dashboard login, and signed proof of origin - #10
Conversation
…he kits A hospital on another laptop can now join with a one-time join code instead of a kit made and emailed by the organiser: - directory: POST /enroll checks the code (single use, expiring, stored as its SHA-256, revoked after 5 wrong proofs), issues a CA-signed certificate for the node's own TLS key (from a CSR), a node id and a per-hospital observer token; /admin/join-codes creates, lists and revokes codes with the hub's admin token. Every attempt and code change is audited (directory store + Postgres audit_logs). An enrolled hospital may only register with the keys it enrolled with. - node/enroll.py: makes the keys locally (private keys never leave), proves the code with an HMAC keyed by its hash, verifies the hub's HMAC'd answer, nonce and TLS pin, and writes a kit laid out like provision.py's (secret in pki/network/shared_secret via SHARED_SECRET_FILE, never printed). - observer: accepts a hospital's own token, which only writes as that hospital, checked against hospital_keys (written only by the directory, never /ingest). - provision.py: the hub kit carries the CA key; kits and make up are unchanged. - image v1.1.0 default (ships deploy/node.yml for the enrolled kit).
…enrolled hospitals - The directory generates an enrolled hospital's node id as a slug of its display name plus random hex (st-marys-leeds-3f9a); identity (TLS pins, signatures, chain placement) stays keyed on the id and keys. - Display names are unique, compared case/space-insensitively, against enrolled hospitals and every hospital in the directory's documents; a clash is a 409 and the code stays valid. An enrolled hospital always appears under the name it enrolled with, whatever its node's config says. - Dashboard audit log shows display names (id in the tooltip); node start-up log names the hospital. hospital-a..e are unchanged for make up and kits.
… a Nodes page - node/proof.py: every 10 s each node with a signing key POSTs the observer a message signed with its update-signing Ed25519 key (context "proof"): host name, OS and version, uptime, Tailscale device (from the install script via MEDCHAIN_HOST_*; else the container's own, labelled), live RTT to each chain neighbour over the pinned TLS client, data row count, boot id + sequence. - observer POST /proof: verifies against hospital_keys (the directory's record), refuses unknown keys, bad signatures, replays and >10 min skew, and audits each refusal (proof_rejected); stores the latest in node_proofs (not via /ingest). - dashboard: snapshot.proofs (verified / rejected / stale / none) and a Nodes page with a Signature verified badge, key fingerprint and the facts. Start/Pause unchanged. - node.enroll takes --host-name/--host-os/--host-booted-at/--tailscale-device.
…oin-codes page - One admin account, created on first run (from MEDCHAIN_ADMIN_PASSWORD, or by the first visitor's setup screen while none exists; the table holds at most one), password stored as a bcrypt hash (cost 12). - Sessions: random 32-byte token in an httpOnly SameSite=Strict cookie, only its SHA-256 in Postgres, 12 h, logout deletes it; 5 failed logins lock an address out for 5 minutes; cross-site Origin refused on state-changing requests. - Every /api route (snapshot, Start/Pause, assess relay, admin) and the /ws snapshot stream need the session; the UI shows the login screen first. The existing pages are unchanged; a Log out button and a Join codes page are added. - Join codes page relays to the directory's admin API with the hub admin token (shared hub-secrets volume): create (validity, data slice), shown once; list; revoke; and the hospitals that enrolled. - Integration tests and CI log in (MEDCHAIN_ADMIN_PASSWORD).
…ly the foreign item Found on the live two-node stack: an enrolled hospital's batches carry audit rows for the updates it received (node_id = itself, sender = its neighbour), so the batch-wide check on node_id/sender refused every such batch with 403 and the node's writer retried forever: its metrics never reached the dashboard. - The identity field is per kind (update_sent: sender; everything else: node_id), and only an item written as another hospital is refused, like an unknown kind; the rest of the batch is applied. A batch claiming another hospital is still 403. - node/proof.py: a host boot time that cannot be one reports no uptime. - The first proof-of-origin message waits one interval, after registration.
…acOS/Linux shell) deploy/install/install.ps1 and install.sh, versioned (1.1.0, image v1.1.0) and fetched from the release tag. Assuming Docker and Tailscale are installed and the laptop is on the organiser's tailnet, they: - check Docker engine running, Tailscale logged in, the hub reachable over the tailnet and >= 5 GB free, each failure with a plain-English fix (never a trace; the PowerShell one never closes the window, it returns); - ask for the hospital's name and the join code (hidden), or take them from MEDCHAIN_DISPLAY_NAME / MEDCHAIN_JOIN_CODE; re-ask on a taken name (exit 3); - read this laptop's Tailscale IP/MagicDNS name and host facts (hostname, OS, boot time) for the proof of origin; - pull the published image and run python -m node.enroll inside it (free text passed via env, the code never on a command line), then docker compose up -d. Re-running keeps the enrollment and keys, refreshes the address and host facts, and restarts the node; an image already present is used if the pull fails. No secret is printed or embedded. Also: the Join codes page shows both install commands with the hub address (HUB_ADDRESS, written to hub.env by provision.py); Log out sits in the nav; docs.
Windows end-to-end test of PR #10 (
|
Blocking: - hub.yml passes INSTALLER_VERSION to the dashboard (default v1.1.0), so the Join codes page can point at a test tag before the release. - The organiser can take a hospital out on its behalf: POST /admin/members/<id>/remove (directory, admin token) does what /leave does, and forgets an enrolled hospital (its credential and observer token stop working, its name is free). Remove button on the Nodes page (which now lists every chain member, proof or not), Forget on the Join codes page. - A run is flagged incomplete in the control strip when a chain member that was registered before it started never took part (snapshot run.missing). Should fix: - Forget frees the name of an abandoned install (enrolled record deleted). - Installers: a re-run with MEDCHAIN_PORT moves NODE_PORT/ADVERTISE_ADDR (no new code); the port-conflict advice says so; an empty folder a failed run made is removed again. - install.ps1 unattended (MEDCHAIN_DISPLAY_NAME set) stops on a taken name like install.sh; no input at all (null Read-Host) stops with a plain reason. - Proof freshness by arrival (boot id + seq), not the sender's clock; the skew is shown on the Nodes page; proof_rejected audit rows rate-limited per hospital and reason (5 min); certificates back-dated a day. - /register re-syncs an enrolled hospital's observer token hash to Postgres. - A changed DASHBOARD_ADMIN_PASSWORD (or user) replaces the account and ends all sessions; an unchanged one is left alone. - A hub kit made before join codes: the 503 says how to upgrade it; documented. Nits: .gitattributes (*.sh eol=lf); hub Postgres port is POSTGRES_PORT (default 5432).
…orget, defer missing
…-of-run incomplete flag
|
Thanks for testing this on a real Windows 11 laptop. Below is what changed for each point, as of Blocks the "one command" promise1. Nothing at
2. A dead member splits the chain, and the run still reports "completed". Fixed.
Should fix3. A failed or abandoned install burns the name. Fixed.
4.
5.
6. Clock skew could mark a genuine node "Rejected". Fixed.
7. The observer token reached Postgres only once. Fixed.
8. Changing
9. Hubs made before this PR can't take join codes. Fixed.
Nits
How this was checked
|
Re-test of
|
| # | Claim | Live result on Windows |
|---|---|---|
| 1 | INSTALLER_VERSION reaches the Join codes page |
✅ Set to a test value in hub.env. Both install commands on the page used it. v1.1.0 is still unpublished: the URL 404s, the image gives manifest unknown, and the only tag is v1.0.0. Expected, and it's on you after merge. |
| 2 | Remove and the incomplete-run flag | ✅ See "Item 2 in detail" below the table. |
| 2 | Two-hospital removal leaves the survivor alone | ✅ With one hospital left, Start → 409 hospital-a is alone in the chain: a run needs another hospital to join. |
| 3 | Forget frees the name | ✅ See "Item 3 in detail" below the table. |
| 4 | MEDCHAIN_PORT on re-run |
✅ Riverside moved 18004 → 18024 with the same signing key. .env got the new NODE_PORT and ADVERTISE_ADDR. hospital-a then dialled :18024 (epoch 6) and a 3-hospital run completed. A later re-run without MEDCHAIN_PORT kept 18024. |
| 5 | Unattended taken name stops | ✅ PS 5.1, valid code: [!] That name is taken. Set $env:MEDCHAIN_DISPLAY_NAME…, and the code was not spent. The case that enrolled ABCD-EFGH-… last time (junk lines on stdin) now stops the same way. |
| 5 | No input: "No hospital name given" | ✅ Clean message, no null-reference error. |
| 5 | No input: "No join code given" | ❌ Hangs forever on PS 5.1. See "Still open" 1. |
| 6 | Clock skew | ✅ From inside a real node container, I sent correctly signed proofs with the clock shifted -3600 s. All accepted (200 verified). The snapshot had message.clock_skew_s = 3600, which the Nodes page shows as "clock behind by 1 h". A replay of the same message got 403 replayed message (sequence 3, already had 3). Only 1 proof_rejected audit row was written, and the status went back to verified on the next genuine proof. New certificates start now - 1 day. |
| 7 | Token re-sync on /register |
✅ I deleted the hospital's hospital_keys row in Postgres and restarted the node. The row came back with its token hash and enrolled=t, and /proof and /ingest returned 200 straight away. |
| 8 | Admin password change | ✅ A restart without a change kept the session (200). After a change: old session 401, old password 401, new password 200. |
| 9 | Old hub 503 + upgrade path | ✅ See "Item 9 in detail" below the table. |
| nit | .gitattributes |
✅ On a Windows checkout with core.autocrlf=true, install.sh is now w/lf. |
| nit | POSTGRES_PORT |
✅ The hub came up on 127.0.0.1:55433 next to a local PostgreSQL on 5432, with no override file. |
| nit | Empty folder after a failure | ✅ Wrong code, taken name and no name all left no folder behind. |
Item 2 in detail
- Setup: I stopped the middle hospital of a 3-chain without
/leave, then started a run. - Run result:
forwarded: unreachable, and the run endedmissing: [Riverside Clinic, St Mary's Leeds]. That's correct: Riverside was cut off too. - Incomplete text: on the dashboard (Chrome) the strip reads "… / completed - incomplete: St Mary's Leeds never took part".
- Remove: Remove, through the API and through the Nodes page button, bridged the survivors (epoch 4 and epoch 7). The next run trained everyone with
missing: []. - Audit and errors: Remove is written to the audit log as
member_removed, and an unknown id gets404 … neither in the chain nor an enrolled hospital. - No false alarms: a run with everyone alive had
missing: [].
Item 3 in detail
- Same name back: after a hospital was removed, a fresh install with a new code under the same name "St Mary's Leeds" enrolled (
st-mary-s-leeds-43af) and joined the chain. - Never-started enrollment: enrolled through
node.enroll, never started, then Forget (API and the Join codes page button). The name was free immediately (ghost clinicre-enrolled). - Removed node is locked out: when its laptop came back,
/registerreturned403 … is not a hospital this directory knowsand/ingestreturned 401.
Item 9 in detail
- The 503: I ran the new image on a hub kit made with
mainthat morning (noca.key, noenrollment:)./enrollreturns 503 with the upgrade instructions. - The documented upgrade on a copy:
--hospital directory --force --pki <same>. CA unchanged,ca.keyand theenrollment:block added, and an oldhospital-bcertificate still verifies against the CA.
Also verified:
- Login gates: without a session, snapshot, round start, join codes and remove are all 401. Cross-site remove → 403.
- Spent codes: a spent code is refused.
- No secrets in
.env: noSHARED_SECRETline, and the secret is inpki/network/shared_secret. - Nodes page (Chrome): shows SIGNATURE VERIFIED, key, computer, OS, uptime, Tailscale device, live round-trip times and data rows for each hospital.
- Log out: returns to the login screen, and the API then answers 401.
- Tests: 157/157 Python unit tests (the whole
tests/unit) and 18/18 dashboard server tests pass, run inside the built images.
Still open
1. install.ps1: name given, no join code, nothing to type → hangs forever on Windows PowerShell 5.1 (not fixed, despite the reply)
- Repro: set
MEDCHAIN_DISPLAY_NAMEwithoutMEDCHAIN_JOIN_CODE, with no console input. It stops atRead-Host … -AsSecureStringand was still waiting after 60 s. The folder it made is left behind. - Cause: on 5.1,
-AsSecureStringreads the console directly and never returns$null, so the new$null -eq $secureguard can't fire. - Fix: check before prompting.
if ($unattended -and -not $joinCode) { Problem "No join code given." "Set$env:MEDCHAIN_JOIN_CODE …"; return }`. - Severity: low, since only scripted runs hit it. But the reply says this path is handled.
2. A removed hospital that re-runs the installer is told "Done" while the hub refuses it
- Repro: the organiser removes or forgets a hospital, and later the friend pastes the same command again (the docs say to do this after every reboot).
- What the friend sees:
[ok] This laptop is already enrolled (st-mary-s-leeds-ca3a); keeping its keys→Done. This laptop is running hospital …. - What the node actually gets:
register … 403 … is not a hospital this directory knowsandobserver … 401on every retry, forever. - Why it matters: the friend believes they're in, and the organiser doesn't see them.
- Fix: after
up -d, have the installer wait about 20 s for the node to register (or call the directory once). On a 403, say "The organiser removed this laptop from the network: delete$HOME\MedChain, ask for a new join code, and run the command again."
3. A run with a dead neighbour crawls for about 20 minutes and can't be stopped
- Repro: a 2-chain with the second hospital down, then Start training round from the dashboard (default 400 rounds).
- What happens: hospital-a trains alone and never converges. After round ~300 each round waits out the timeout, about 15 s each. At round 323 it would have needed roughly 20 more minutes.
- Why it matters: the dashboard only offers Pause, and the incomplete flag appears only after the run ends, so the organiser is stuck. I had to restart the node.
- Fix: end a run early when every neighbour has been unreachable for N rounds (it's already known as
missing). Or add a Stop next to Pause.
4. Same display name shown twice after a Remove + re-enroll (cosmetic)
- The topology lists "St Mary's Leeds (head): alive" and "St Mary's Leeds: left the chain".
- The Nodes page also keeps the removed
st-mary-s-leeds-ca3arow ("not in the chain") next to the new one. - Fix: show the node id with left or removed entries, or drop forgotten hospitals from those lists.
Not covered here
- The interactive join-code prompt: typing it into a real window couldn't be automated from my session (no visible desktop window). A person needs to paste the Join codes command into a PowerShell window once and type a taken name, then the code, then a free name.
- Two physical machines: everything ran on one Windows laptop's Tailscale IP. The Mac ↔ Windows path was already proven with v1.0.0 earlier today.
Verdict: items 1 (code), 2, 3, 4, 6, 7, 8 and 9 and the nits are fixed and verified on Windows. Item 5 is fixed except for the missing-code hang (Still open 1). Before the friend session:
- Must do: publish v1.1.0 (tag, image, public package).
- Should fix: Still open 2 and 3. They're what a friend or the organiser would actually hit on the day.
- Stop: POST /round/stop floods like Pause and cancels the run on every hospital it reaches (both run loops end a cancelled run as "stopped"); a Stop button next to Pause while a run is going; the dashboard relays it; a stopped run is also checked for hospitals that never took part. The way out of a run a dead neighbour keeps from finishing. - A removed hospital is told so: the node reports its directory registration in /status (registered / retrying / refused on 401/403), python -m node.registered reads it, and both installers wait up to a minute after starting the node. On refused they stop the node and say the organiser removed the laptop and a new join code is needed, instead of "Done". - install.ps1 unattended with no join code stops before prompting (on Windows PowerShell 5.1 Read-Host -AsSecureString never returns null, so it hung). - After a remove + re-enroll under the same name, the topology names the departed entry by its node id, and the Nodes page lists a hospital outside the chain only while its proofs still verify.
…its hub registration
…board's Stop relay
|
Thanks for the second Windows pass. This reply covers the four "Still open" items, as of 1. A run with a dead neighbour crawls and can't be stopped: fixed, with StopWhat changed:
Not done: I did not add "end the run automatically after N rounds without a neighbour". That would mean changing the training round loop in 2. A removed hospital that re-runs the installer is told "Done": fixedWhat changed:
How it was checked:
3.
|
Intent
The captain is preparing to onboard friends onto a two-machine (and eventually multi-machine) test of this project's distributed hospital-chain training system over Tailscale. A friend already joined once as hospital-b by hand-unzipping a kit file and running two docker commands; that worked, but the setup required manually generating and emailing a kit containing a shared secret, used hardcoded hospital-a/hospital-b names, and had no way to prove on screen that a friend's machine was really the one connected, other than clicking a Start/Pause button that looks unconvincing to an audience. For an upcoming session with friends on Windows laptops (Docker Desktop and Tailscale already installed), the captain wants: each friend to set up their hospital node in close to one command instead of cloning the repo or hand-editing files; each friend to type their own hospital's name instead of using the hardcoded hospital-a/hospital-b identifiers; a basic login screen in front of the dashboard's monitoring pages, since right now anyone can open it and press Start/Pause with no accountability; and real, verifiable proof visible on the dashboard that the numbers and connections are actually coming from each friend's own physical machine, not just a button that nobody watching would believe. The captain explicitly said this phase is about making the communication/network and onboarding work properly, not about changing the training model or how hospitals' data is processed - that is explicitly out of scope for now. The captain also flagged that the single shared secret used to start a training round had been exposed in plaintext in a chat/terminal session and should no longer be something that needs to be shared and typed by hand at all. The captain's plan is to have a friend test this change for real on a Windows laptop before it is merged.
What Changed
deploy/install/install.ps1(Windows) ordeploy/install/install.sh(macOS/Linux), types its own display name, and enrolls with/enroll. Its keys are generated locally and its private keys never leave it. The hub signs a TLS certificate for it, assigns a stable node id (a slug of the name plus random hex), and issues a per-hospital observer token. Display names are free text and must be unique. Removing a hospital frees its name for reuse. Every enrollment attempt is written to the audit log.MEDCHAIN_ADMIN_PASSWORD). The dashboard server relays Start, Pause and Resume to the first live hospital that answers. Stop is sent to every live hospital with one shared op id, so a hospital beyond a dead neighbour still stops. Nobody has to type the shared secret any more: the hub's dashboard sends it from its own environment.docs/MULTI_LAPTOP.md, the deploy compose and env files, and the CI workflow, and adds unit tests for enrollment, the installer, the observer, auth and the relay.Risk Assessment
✅ Low: This round's fix commit is small and well bounded. Stop now goes to every alive chain member that has a recent heartbeat, with one shared op_id per press. The nodes already ignore an op_id they have seen, and they never forward to the sender (named 'dashboard'), so the copies are harmless. Start, pause and resume behave exactly as before, now through a pure function that is unit-tested. The installer reports the refusal whatever 'docker compose down' returns, and the extended test covers that. I found no new reachable defects.
Testing
I brought the round-1 hub back up on this Mac over Tailscale, with two kit hospitals running. Then I ran deploy/install/install.sh from this commit as a friend would, three times: a fresh join-code enrollment, a re-run while still enrolled, and a re-run after the organiser clicked Remove while the node was running. All three gave the expected result. The last one is the case that wrongly said "Done" in round 1; it now reports the refusal and exits 1. The 5 install.sh unit tests also pass. The install.ps1 half of the fix could not be run on a real Windows machine here. All test containers were torn down afterwards and the worktree is clean.
Evidence: Fresh install.sh enrollment (container created, no recreate)
Evidence: Re-run while still enrolled: container recreated (new ID), Done, exit 0
Evidence: Remove while running, then re-run: recreated, refused with 403 reason, exit 1, container gone
Evidence: install.sh unit tests
5 passed in 35.39sPipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
dashboard/server/index.js:202- Stop is sent the same way as Pause:relay()posts it to the first alive chain member and returns after that node answers, and the node then passes it only to its directrunner().neighbours(node/main.py:296). Stop exists for exactly the case where a neighbour is dead, and there the message can't get past the dead node. Concrete path: chain A–B–C, B's laptop dies mid-run, the organiser presses Stop. The dashboard relays to A (first by node_id), A stops and tries B, which is unreachable. C keeps running.runStateputs 'running' ahead of 'stopped', so the control strip still shows the run as going, and pressing Stop again only reaches A again. The docs do say 'on every hospital it reaches', but the button can't do the job it was added for once there are more than two machines. Fix: forstop(and arguably pause/resume), have the dashboard post to every alive chain member in the relay query instead of returning after the first OK. Each node's op_id dedup already makes repeated delivery harmless if the same op_id is reused.deploy/install/install.sh:177-[ $code -eq 3 ] && docker compose ... down >/dev/null 2>&1 && problem ...only reports the refusal ifdocker compose downsucceeds. If down fails (a Docker hiccup), the loop goes on as if nothing happened and the installer ends with 'Done. This computer is running hospital …' for a hospital the hub refuses. install.ps1 calls Problem no matter how down ends. Fix:[ $code -eq 3 ] && { docker compose ... down >/dev/null 2>&1; problem ...; }.🔧 Fix applied.
✅ Re-checked - no issues remain.
🔧 **Test** - 1 issue found → auto-fixed ✅
deploy/install/install.sh:175- This gap existed before this commit. The node checks its registration only at startup (node/main.py register_with_directory), so the new refusal branch only fires after the node restarts. Live repro: the organiser removes riverside-clinic-05bd while its container is running, and the friend re-runs install.sh.node.registeredstill returns 0 ('registered'), and the installer prints 'Done. This computer is running hospital …' and exits 0, even though the observer is already answering the node's writes with 401. Afterdocker restart, the same re-run correctly reports the refusal. Possible fix: have install.sh/install.ps1 restart an already-enrolled node before pollingnode.registered, or have the node re-register on a heartbeat. Needs a decision on whether this is in scope.docker build -t medchain-node:nm3 -f node/Dockerfile .anddocker build -t medchain-dashboard:nm3 -f dashboard/Dockerfile .from the worktreescripts/provision.py --peers hospital-a=100.89.221.7:18001,hospital-b=…:18002,hospital-c=…:18003 --directory 100.89.221.7:18100then the hub (deploy/hub.yml, project nm3-hub, dashboard on :18080) and three node kits (deploy/node.yml)curl the dashboard API without a session, with a wrong password and with the right one (login gate)Start a 300-round run,docker kill nm3-hospital-b-node-1, then POST /api/round/stop; check each node's run_state in the snapshotSame again with the middle hospital dead, pressing the dashboard's Stop button in headless Chrome (chrome-devtools-axi) and accepting the confirm dialogPause, Resume and Stop across four alive hospitals (single-node relay plus flood; shared op_id dedup shows as 'seen')Create a join code via /api/admin/join-codes, thenMEDCHAIN_DISPLAY_NAME='Riverside Clinic' MEDCHAIN_JOIN_CODE=… bash deploy/install/install.sh </dev/null(unattended)Nodes page screenshot and snapshot proofs: friend's signature verifiedPOST /api/admin/members/riverside-clinic-05bd/remove, then re-run install.sh (node still running), then restart the node container and re-run install.sh (refusal path)Unauthenticated and wrong-token POST /proof to the observer naming hospital-anode --test dashboard/server/relay.test.jspytest -q tests/unit/test_install_sh.py🔧 Fix applied.
✅ Re-checked - no issues remain.
Brought the hub back up (docker compose -p medchain-nm3hub ... -f deploy/hub.yml up -d --wait, nm3 images, Tailscale IP 100.89.221.7) and started the hospital-a and hospital-b kit nodesLogged in throughPOST /api/auth/loginand created a join code throughPOST /api/admin/join-codesFresh unattended enrollment:MEDCHAIN_DISPLAY_NAME='Harbour View Hospital' MEDCHAIN_JOIN_CODE=... bash deploy/install/install.sh </dev/nullRe-ranbash deploy/install/install.shwhile still enrolled, recording the container ID and start time before and afterClicked Remove through the dashboard API (POST /api/admin/members/harbour-view-hospita-a74d/remove) while the node was running, then re-ranbash deploy/install/install.shpytest -q tests/unit/test_install_sh.py(5 passed)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.