Repository navigation
fix(account): keep out the devices a client removed on a PC it brings into the account - #2947
Conversation
…tself A client that links a PC with no account yet now hands it, over a session signed in with the account key, first the removes it signed and then the adds it signed for devices it approved itself, with their role. It never takes a key from another PC's device list. Each record's outcome is read, and the ones the PC did not answer are sent again on the next connection. /api/account/status lists the account's removals, so a key another member removed leaves the client's approved list too. Fixes #2855
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 8 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
…, finish only what was sent Review round: an approval and a removal at once could leave neither; a removal signed while an enrollment ran was dropped; a removal of a device another member approved was never tombstoned on the new PC; a re-signed removal took the current time and could undo a later pairing there. /api/account/status now says when each removal was applied.
A PC this client enrolled before it heard another member removed a device kept that device. The remove it signs on learning of the removal now goes to every PC of the account through the mailbox, kept and sent again like an add.
Lead decision after the re-review: the client no longer signs removals from a PC's unsigned status, so a PC never gains authority over the account. The status field and the PC side of it are dropped. A new PC gets this client's own adds and removes verbatim. Approvals and their queue, and the end of an enrollment with its final check, are each one store transaction; a later signed record of a device is never overwritten by an older one. The PC is listed in the directory before it is enrolled, so a later removal reaches it by mailbox.
…s its key A device another member removed could come back on the new PC: this client still held its own older add, and the other member's remove never reaches a PC that was not in the account yet. An add now goes only while a PC of the account this client is linked on lists that key as a member; the PC can only hold an add back.
|
Review notes (Codex Terra xhigh at
The account's signed removals reaching a new PC is follow-up #2956. Since |
Lead decision after the guard's re-review: an add this client signed may be for a device another member removed since, and no check against a PC's list is fresh enough. A PC new to the account now gets only this client's signed removes, which can only take devices away; adds wait for the account's signed removals to be relayed too (#2956). The PC-list guard is gone, so no add is held and no plan stays open.
|
Review at
No follow-up issue was filed: the only reproduced item needs one device key in two accounts, and it leaves things as on main. |
|
Local merge gate (owner-approved): |
…ings into the account (#3007) Part of #2956 ## What A PC that a client links into the account for the first time now also tombstones devices that **another member** removed, when the client has seen that removal on another PC. The client never signs anything for these removals: it passes them on verbatim. - **PC keeps the signed record with its tombstone.** `removeAccountKey` stores each verified `remove` with the tombstone in `account-tombstones.json`, as received. It keeps one per signer, at most 8, so a PC where only a later signer is a member can still apply one. A Revoke on the PC stores none. When two state dirs share a device list, their tombstones merge with every signer's record. - **`GET /api/account/status` lists them** as `removals`, parsed again on read. A damaged record is dropped. - **The client keeps only removals it can check.** On each connection to a PC of its account, `keepRemovals` keeps, verbatim, each listed removal that verifies, is for its account, and is signed by its own key or by a device it approved itself (an `add` it signed). At most 256 are kept. A tampered PC cannot make it keep a removal signed by a key the PC made up, and it never signs one. - **`enrollPc` relays them.** It sends the client's own removes plus the kept ones through `/api/account/records` and reads every outcome, as before. - **A relayed removal can wait for its signer.** When the signer is not yet a member of the new PC (`signer_not_member`), the PC puts the removal in its existing `account-pending.json` queue, which retries it on every mailbox pull. Only an account member's session can do this. Once the signer joins, for example by a remote approval, the key is tombstoned. A pairing made on that PC after the removal was signed is left alone (existing `issued_at` rule). ## What this does not do: adds stay disabled This PR does not do the issue's "then enroll the client's own adds" step, so it says "Part of", not "Fixes". A Codex (Terra, xhigh) design review found that no read of the PCs a client can reach proves it holds every removal of the account. A removal can wait in the unread mailbox of a PC that is off, or exist only on PCs the client has no pairing with. An add the client signed earlier could then let a removed device into the new PC. I reproduced this. Turning adds on in `enrollPc` makes the existing test "does not let back on the new PC a device another member removed" fail: Y admits the removed Mac. A known gap in device admission is not acceptable, so the new PC keeps admitting the account's devices by approval. Each device asks once and compares digits. `docs/account.md` explains why. ## Tests (real servers) - `server/account/account.contract.test.ts` - A removal's signed record stays with its tombstone and is listed in the status, verbatim, after a restart too. A second signer's record is kept beside it, and a damaged one is dropped. - Merging two state dirs keeps both signers' records. - `src/lib/account/join.test.ts` - Another member's removal is relayed to the new PC as signed. It waits there for its signer, then tombstones the key, and Y lists the very record (same signature and `issued_at`). - A pairing made on the new PC after that removal was signed is left as it is. - No removal the client cannot check is kept or relayed: unsigned, forged, another account's, or signed by a key it never approved. - The existing #2947 tests still pass, including "does not let back on the new PC a device another member removed". Failing-first: each new test fails with its part of the change reverted. Without the PC-side wait, the relay test fails at `isTombstoned`. Without the signer check, the "cannot check" test fails. With `server/devices.ts` from main, the status test fails because `removals` is `undefined`. ## Validation - `bun test server/account src/lib/account server/device-access.contract.test.ts`: 152 pass, 0 fail (head a99de96) - `bun run check fast` (old-desktop heavy runner, head a99de96): pass (workflow syntax, generated types/themes, typecheck, build, unit tests) - Review round (omo + Codex Terra xhigh) and how each finding was resolved: see the PR comment.
…movals are in (#3087) Part of #2956 (the add half) ## What A PC that a client brings into the account now gets the account's devices in one go, instead of every device asking that PC again. This is the "approve a new PC once" half of linking by account; the screens come in a follow-up PR. **Server (PC)** - **Enrollment barrier.** The link that gives a PC its first member writes `account-enrolling.json` first. Until that member's `POST /api/account/enroll` succeeds, no account `add` applies there, from `/api/account/records` or the mailbox (`refused`, `enrolling`; mailbox adds wait in `account-pending.json` and are tried again after the enrollment). A refused link leaves the barrier; the first link that succeeds keeps it. No timeout: a client that never enrolls leaves the adds held. - **Ordered enrollment.** `/api/account/enroll` now takes removes and adds (at most 512) plus `held` keys (at most 4096). The PC keeps `held` on disk (`account-held.json`), applies every remove first in signing order, then the adds in rounds (an add whose signer another add lets in applies in the next round), retrying waiting removes after each round, then lifts the barrier. - **Add gates on every path.** An add is refused `removal_pending` while a waiting remove names its key (whatever its signer), an enrollment held it, or the waiting queue is full or cannot be read. Past 1000 waiting records adds are dropped first; if a remove has to go, every add is refused from then on. An unreadable `account-pending.json` is no longer an empty queue. - **Status.** `GET /api/account/status` adds `adds` (the signed add behind each row, kept as received, including the approver's own add for a row its remote approval made), `blocked` (every tombstone key, signed or not, every key a waiting remove names, every held key) and `enrolling`. `?fresh=1` pulls the mailbox first (a pull that starts after the request; requests that come while one runs share the next). - **Introductions** persist in `account-introductions.json` for 30 days and merge by PC. **Client** - `enrollPc` first reads every other PC of the account it is linked on (`?fresh=1`, 8 s each). It then sends one enrollment: its own and kept removes, its own adds and the adds those PCs list, minus every key a PC keeps out or a verified removal names (any signer: fail closed), and those keys as `held`. It signs nothing for collected records. If no other PC answers, it sends nothing and tries on the next connection. - Each PC that answered then introduces the new PC to the devices let in, so they sign in there; an introduction a PC could not take stays in the plan and is sent again on the next connection. Design and two rounds of Codex (Terra, xhigh) adversarial design review are summarised in the first PR comment. Known, documented limit: a removal held only by PCs the client cannot reach, and hidden by the account service, is missed; the device then comes back on the new PC, announced. ## Tests `server/account/account.contract.test.ts` (real servers): - the first link holds every account add (direct and mailbox) until the member enrolls, across a restart, then lets the waiting ones in; - an enrollment applies removes before adds whatever the order sent, and adds in rounds; - a remove waiting for its signer keeps that key's adds out on every path, and once an enrollment lets the signer in the key is removed; - held keys stay out of every later path, while a device already there keeps its row; - the status lists signed adds (incl. an approver's own) and every blocked key; - an unreadable pending file, or removes pushed out of a full queue, hold every add back; - introductions merge by PC, outlast a restart and expire. `src/lib/account/join.test.ts`: - the #2947 Mac repro, "does not let back on the new PC a device another member removed": with adds enabled and no other PC read, it fails (Y admits the Mac); with the client reading X first it passes, and a copy of the Mac's add arriving later is refused `removal_pending`; - devices another PC lists come into the new PC and are introduced to it there, and sign in; - with no other PC answering nothing is sent and the PC stays in its barrier. Failing-first: each new server test fails with its part reverted (the `held` gate, the barrier start on link, the remove-first ordering, keeping the approver's add, the overflow latch). Review fixes already in (Codex Terra xhigh on the branch before opening): a remove waiting on its signer is kept before the next record of its batch; only the linking member ends the barrier, with the last part of its enrollment and every remove decided; `?fresh=1` reports `fresh` only after a whole, error-free mailbox read and the client counts only such PCs; `held_full` latches every add off; the overflow latch is written before any waiting remove is dropped; a full queue of waiting adds no longer holds every add back; the approver hands its add to the PC that let the device in. ## Validation - `bun test server/account src/lib/account src/lib/relay server/state-merge server/relay/pair-sas.contract.test.ts`: 399 pass, 0 fail (head 0c6807d, main merged) - `bun run check fast` at 0c6807d: pass (workflow syntax, generated types and themes, typecheck, build, unit tests) - Not run: `bun run check full`, browser regressions (no UI in this PR; the stacked UI PR #3088 ran the relay shell browser QA)
Fixes #2855 (the add half continues in #2956)
What
When a client links a PC that has no account yet, it now sends that PC the
removes it signed itself, verbatim, so the devices it removed from the account stay out there.devicesin theovis-accountstore): theaddfor a device it approved, or theremovefor one it removed. An older record never overwrites a later one, and a removal wins a tie. Recording an approval and queueing its mailbox delivery happen in one store transaction.enrollPcposts the client's own removes to/api/account/records. It reads each record's outcome. A record with no answer, or withaccount_unavailable, is sent again on the next connection, and so is any removal signed while the enrollment ran (checked in the transaction that ends the plan).GET /api/devices(rule 6), and nothing from a PC's status.addis enrolled yet. An add the client signed may be for a device another member has removed since, and that member'sremovedoes not reach a PC new to the account. Review reproduced this, and no check against a PC's device list was fresh enough to stop it. Adds come together with relaying the account's signed removals in Account: relay the account's signed removals to a PC a client enrolls #2956.Tests (real servers,
src/lib/account/join.test.ts)account_unavailableoutcome, is retried until every outcome is known.Validation
bun test src/lib/account server/account: 106 pass, 0 fail.bun run check fast(old-desktop heavy runner): pass (typecheck, build, unit tests ok).