Skip to content

P5: a machine key speaks for one ref whatever the route (409 key-held), and one member-email grammar - #338

Merged
SSFSKIM merged 13 commits into
masterfrom
p5-hub-key-held
Oct 29, 2026
Merged

SSFSKIM merged 13 commits into
masterfrom
p5-hub-key-held

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 29, 2026

Copy link
Copy Markdown
Owner

A key speaks for one ref, whatever route it came by; one email grammar

Two hardenings of the org's records, ruled by the MAWS architect (P5's spec owner) after M4a's review. Built on P5 O8 M4a's successorProblems commits (5935f62, 5922119, 37ce207), which have not landed.

(A) 409 key-held on POST /machine/key and POST /machine/cert

Until now the hub kept any key a redeemed machine posted. A key the head already held went on to the admin's listing successor, where successorProblems (key-held-twice) refused it before signing, or a verifier refused it after. A certificate could likewise certify a key the state or an enrollment held under another ref, and nothing refused that. The hub now refuses both at their posts.

The invariant (the architect's ruling): one holder per key spans the hub's records as well as the state, so the order of posts never decides which ref holds a key.

A key is held by another holder when:

  • the head holds it as current under any other holder. That is a machine of another ref, a device's channel or step-up key, a delegation, or the recovery key. key-held-twice counts all of them. The hub reads the holders through the package's own heldKeys, now exported.
  • the head holds it retired or revoked, whatever the ref. The model never lets either be current again:
    • a retired entry stays or moves to revoked (keysAccounted);
    • a state holding a retired key is retired-key-held, and one holding a revoked key is refused revoked;
    • a retired key still speaks for its ref's history up to its notAfter (machineSigners), so as anyone's current key again, its notAfter would bound nothing.
  • another enrollment posted it, or a kept certificate certifies it, under another ref.
    • machine_keys rows are never deleted, and the real endpoint mints a fresh key at every enrollment (src/endpoint/enroll.ts), so a repeat across refs is a bug or a forgery.
    • Either way the one private key would speak for two refs, whose owners may differ (machineSigners, machineOwners).

The same ref is fine, both ways. O11 M6's rename keeps the key and the ref, and the machine then enrolls under the new name with both (relay-fences.test.ts's rename cases, which fail if this is counted). A VM's own key posted under its own ref is taken before or after its certificate. On /machine/key, ref-taken has already held the ref to the poster's name by then.

POST /machine/key (keepMachineKey) checks after its existing answers: 201 kept, 200 the same again, 409 key-posted, 409 ref-taken. It is now async, because a revoked entry is named only by key id. After that one await, it re-checks the poster's enrollment, judges and keeps the key in one synchronous step, as storeCert does.

POST /machine/cert (storeCert) checks in its synchronous commit, not in its judgment. A machine's key post moves neither the head nor the certificates, so only the commit sees one made during the certificate's awaits. Of two posts at once, one is kept and the other refused. Its existing answers come first:

  • a key retired or revoked in the state is refused by verifyMachineCert (409 expired, 409 revoked), whatever the ref;
  • another certificate for the same key stays 409 conflict.

How a refused certificate reaches its caller.

  • The route answers 409 {"error": "key-held", "message": "the certificate's key is <holder>: certify a fresh key"}.
  • mawsd's endpoint provision (src/endpoint/provision.ts, settle) throws CertRefused: "the hub refused the machine's certificate: 409 key-held". The command exits failed with that line.
  • provisioning.json is kept, so a rerun posts the same certificate and is refused again. A VM recreated with a fresh key provisions.
  • The fake machine's enrollDelegated throws "the certificate was refused: 409 {…}".
  • The real endpoint mints a fresh key at redemption, so it meets this only if its key was forged or reused.

A refused machine key reaches mawsd's endpoint enroll as "the hub refused the machine's key: 409 key-held".

Both answers are named in apps/desk-hub/src/protocol/identity.ts (MACHINE_KEY_PATH and MACHINE_CERT_PATH), and key-held is in O10's route listing (docs/doperpowers/plans/2026-10-27-p5-o10-endpoint.md). Nothing reads either route's codes by name, so no client changes. sminos never calls these routes. O11's own decision entry (line 601) is a dated record, left as written.

M4a's admin case "a machine posting a key m1 holds" posted m1's key under a twin, which the hub now refuses. That case is now a holder that another signer lists while the owner compares the posted key, which only the pre-sign check can see. Its assertion is unchanged.

(B) One email grammar

  • isMemberEmail (org-protocol, names.ts) is the app hub client's grammar, byte for byte: /^[^\s@\p{Cc}]{1,64}@[^\s@\p{Cc}]{1,253}$/u. src/main/org/hub-client.ts now uses it.
  • Strict where an email is written.
    • successorProblems names email-grammar for a member who is new, or whose email changed, in the successor. An unchanged member is never judged, so a head already holding an email outside the grammar can still be followed, and fixed.
    • deployment admin genesis, the one admin verb that writes a member (the admin, as /api/me names them), refuses an email outside the grammar before the recovery key is made. Nothing is written, signed or posted.
    • Every other admin verb's successor already goes through successorProblems in amend, and none adds a member or changes an email.
  • Tolerant where the state is read, checked and unchanged:
    • isOrgState takes any non-empty text, and verifySuccessor makes no email rule. A test pins that the successor successorProblems refuses for its email verifies once signed.
    • The hub resolves and projects members by any text, lower-cased (registry.ts resolve, org-chain.ts projectMembers and submit).
  • Strict where the app reads /api/me, for security (the architect's ruling).
    • hub-client.me() takes the email only in this grammar, as it has since O8 M1's review, so a hostile hub can't reflect the bearer token as an email.
    • With the grammar now enforced where an email is written, the strict read can refuse only legacy data. Production has none: its org state's only member's email passes (read-only, by the dispatching session).
    • A future change to the grammar must check the stored emails before it ships.
    • The read (hub-client.ts:134) and isMemberEmail carry a comment saying so, so nobody tolerates it away.

Sequencing with M4a

This branch sits on M4a's successorProblems commits. Whichever of this PR and M4a lands second switches M4a's own composer (src/main/org/edits.ts, member.add and member.email) to isMemberEmail. The same PR adds email-grammar to O8's §M list of pre-sign codes. Nothing here touches M4a's later work or the O8 plan.

Residue

  • OrgAdmin composes without successorProblems. apps/desk-hub/deploy/org-admin.ts, staging's test device, composes a throwaway org's genesis, and successors such as acceptance's member add. It signs and posts with no pre-sign check and no email grammar, so a broken successor surfaces as the hub's refusal. The architect writes the tracker row at landing.
  • No test revokes an enrollment during keepMachineKey's key-id await. The re-check there is storeCert's pattern.

Deploy

The hub change takes effect only with a production deploy of desk-hub, which is the owner's. Nothing here ran against production.

Gates

  • This PR's head, aee2381: run 40834069677, green.
    • It ran class 1a on the pool (static, unit 1–4, probes), plus hosted e2e:desk-web-hub and e2e:desk-web.
    • e2e:desk-web was added because ci-gate's import check, on the first head's run, found desk-web specs reaching identity.ts, names.ts and org-state.ts.
    • There is no flaky line, and the run printed no missing-group warning.
  • Earlier heads, both green on the same gates:
  • Locally, while iterating, all passing:
    • org-protocol's successor-problems (66) and the app's hub-client (4);
    • desk-hub's org-enrollment (26), org-delegations, relay-fences, relay, history-attestations, app-connection, deploy/admin-verbs (39), and deploy/admin with protocol (241).
    • Each new negative case was seen to fail with its check disabled.

Review

  • reviewer-medium on 37ce207..e40d88b found nothing material. Its verdict: the key check matches the model's ref-based holders, same-ref reposts and renames stay valid, and the standing check, holder lookup and insert run with no await between them. Email validation stays at the writing boundaries, and the readers are unchanged. It noted one coverage gap, no case for a delegation's key, which a650031 adds.
  • reviewer-high on 37ce207..a650031 (the dispatching session's) found nothing material.
  • e361633 and aee2381 carry out the architect's rulings after those rounds. Both certificate directions have a case that fails with its check disabled.

Commits

  • a4128de: one email grammar (isMemberEmail), strict where a member's email is written.
  • e40d88b: POST /machine/key refuses a key another holder has (409 key-held).
  • a650031: key-held's suite covers a delegation's key.
  • e361633: certificates both ways: /machine/key refuses a key a certificate holds under another ref, and /machine/cert a certificate whose key another holder has.
  • aee2381: /api/me's email stays strict, and the code says why.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…ocol

judgeEntry, entryDevice, isPairedDeviceId and isRpId move byte for byte into apps/org-protocol/src/pairing.ts, exported through index.ts; their input becomes the package-owned structural PendingEntry, which the hub's PendingDevice satisfies. admin.ts imports judgeEntry from org-protocol and re-exports the three it exported before, so its suites and the two test importers are unchanged. pairing.test.ts pins the judges directly: a good entry, a wrong MAC, a wrong class, an already-listed id, a bad id and rpId, and what no state could list.

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…overy directories

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…'s amend runs it before signing

successorProblems names, before signing, every check verifySuccessor makes on an ordinary successor but the signatures; stateProblems names the whole-state rules by code, and stateInvariants is now its reading. verifySuccessor's verdicts and their order are unchanged (the vectors replay as before). deployment admin's amend (and propose) refuse a successor with a problem, naming its codes, before anything is signed or kept pending.

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…overy directory

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…ts fails fast

verifySuccessor judges the whole state before the root signature, so the problem list stateInvariants built was open to any envelope: 120 copies of one delegation made 7,140 diagnostics. stateInvariants now stops at the first problem and builds no detail. The full diagnostics keep at most PROBLEMS_PER_CODE (8) problems per code, and build each detail as a thunk only for a problem they keep. onDetail counts what is built. Verdicts and their order are unchanged.

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…for unauthenticated input (comment only)

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
…r's email is written

isMemberEmail is the app hub client's address grammar, moved to the package byte for byte: one @, no space or control character, at most 64 characters before it and 253 after. The hub client reads /api/me through it, unchanged.

Strict where an email is written. successorProblems names `email-grammar` for a member that is new, or whose email changed, in the successor; an unchanged member is never judged, so a head that already holds an email outside the grammar can still be followed, and fixed. deployment admin's genesis, the one admin verb that writes a member (the admin, as /api/me names them), refuses an email outside it before the recovery key is made, with nothing written, signed or posted; every other verb's successor already passes successorProblems in amend.

Tolerant where one is read, as before: isOrgState takes any non-empty text and verifySuccessor makes no email rule (a test pins that the successor successorProblems refuses verifies once signed); the hub resolves and projects members by any text, lower-cased. The app hub client's /api/me read was already this grammar (O8 M1's review, so a hostile hub can't reflect the token as an email), and stays so.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
…-held)

The hub kept any key a redeemed machine posted, so a key the head already held reached the admin's listing successor, which successorProblems (key-held-twice) or a verifier then refused. One holder per key (RL5) is now refused at the post, after the existing 201 / 200 / 409 key-posted / 409 ref-taken:

- the head holding the key as current under any other holder: a machine of another ref, or a device, a delegation or the recovery key, all of which key-held-twice counts;
- the head holding it retired or revoked, whatever the ref. Retired and removed machines' keys still count as held, because the model never lets either be current again: a retired entry stays or moves to revoked (keysAccounted), a state holding a retired key is retired-key-held and one holding a revoked key is refused revoked. A retired key still speaks for its ref's history up to its notAfter (machineSigners), so as anyone's current key again its notAfter would bound nothing;
- another enrollment's posted key under another ref: machine_keys rows are never deleted, and the real endpoint mints a fresh key at every enrollment (src/endpoint/enroll.ts), so a repeat across refs is a bug or a forgery, and the two machines could never both be listed.

The machine of the posted ref is no other holder: a rename keeps the key and the ref, and the machine enrolls again under the new name with both (O11 M6; relay-fences' rename cases). ref-taken has already held the ref to the poster's name by then. A kept certificate's key is not counted: no verifier refuses a state entry that shares one, and storeCert does not refuse the converse.

keepMachineKey is async now (a revoked entry is named by key id), and judges and keeps in one synchronous step after that await, re-checking the poster's enrollment there as storeCert does. heldKeys is exported from org-protocol so the hub reads the state's holders by the package's own rule.

admin-verbs' successorProblems case posted m1's key under a twin, which the hub now refuses; it is a holder another signer lists while the owner compares instead, which only the pre-sign check can see. identity.ts and O10's route listing name the new answer.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
The review's one gap: every holder kind the refusal names now has its case, the delegation's included.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
…icates both ways

The architect's ruling on the open question of e40d88b: one holder per key spans the hub's certificates, in both directions, so posting order never decides which ref holds a key.

- POST /machine/key (keepMachineKey) refuses a key a kept certificate holds under another ref, 409 key-held, like the state's holders and other enrollments' keys.
- POST /machine/cert (storeCert) refuses a certificate whose key another holder has under another ref, 409 key-held: a machine, device or delegation of the org state, its recovery key, or another enrollment's posted key. A key retired or revoked in the state was already refused first by verifyMachineCert (409 expired, 409 revoked), whatever the ref; another certificate for the key stays 409 conflict.
- The same ref is fine both ways: a VM's own key posted under its own ref, before or after its certificate.

The certificate's check runs in storeCert's synchronous commit, not its judgment: a machine's key post moves neither the head nor the certificates, so only the commit sees one made during the certificate's awaits. keepMachineKey's sync step reads the certificates likewise, so of two posts at once one is kept and the other refused.

The refused certificate reaches its caller as 409 {error: "key-held", message} on POST /machine/cert; mawsd's endpoint provision throws CertRefused ("the hub refused the machine's certificate: 409 key-held"), exits failed, and keeps provisioning.json, whose rerun posts the same certificate and is refused again.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
The architect's ruling: the grammar keeps a hostile hub from reflecting the bearer token as an email, a security reason. With the grammar enforced where an email is written, the strict read can refuse only legacy data, and production has none. A change to the grammar checks the stored emails before it ships. The comment at the read, and isMemberEmail's own, say so, so nobody tolerates it away.

Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
Sminos-Session: p5-desk-track-owner#b4948247 (doperpowers on macbook)
@SSFSKIM
SSFSKIM merged commit 2914912 into master Oct 29, 2026
SSFSKIM added a commit that referenced this pull request Oct 29, 2026
…tes both ways), one member email grammar, O8 M4a's first two tasks; two tracker rows from its residue

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
SSFSKIM added a commit that referenced this pull request Oct 29, 2026
…dits.ts refuses bad-email through org-protocol's isMemberEmail, hub-client's EMAIL dropped; email-grammar among the pre-sign codes; the admin suite's twin case as #338 left it

Sminos-Session: GUI AI agent workspace charter#37052769 (MAWS on macbook)
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