@serve.zone/interfaces 32.80.0 → 32.81.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.md +6 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/index.d.ts +1 -0
- package/dist_ts/data/index.js +2 -1
- package/dist_ts/data/witness.d.ts +217 -0
- package/dist_ts/data/witness.js +407 -0
- package/dist_ts/requests/index.d.ts +2 -1
- package/dist_ts/requests/index.js +3 -2
- package/dist_ts/requests/witness.d.ts +83 -0
- package/dist_ts/requests/witness.js +2 -0
- package/package.json +1 -1
- package/readme.md +80 -0
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/index.ts +1 -0
- package/ts/data/witness.ts +606 -0
- package/ts/requests/index.ts +2 -0
- package/ts/requests/witness.ts +121 -0
package/readme.md
CHANGED
|
@@ -4479,6 +4479,86 @@ const desired: requests.gatewayconnector.IReq_Cloudly_Gateway_ApplyDesiredState[
|
|
|
4479
4479
|
data.validateGatewayDesiredState(desired.desired); // []
|
|
4480
4480
|
```
|
|
4481
4481
|
|
|
4482
|
+
### Witness
|
|
4483
|
+
|
|
4484
|
+
The witness (AGL-1195) is a small service of its own at a third site that keeps one compare-and-set
|
|
4485
|
+
record per controller, `data.IWitnessRecord`: `controllerId`, `epoch`, `activeOrigin`,
|
|
4486
|
+
`inSyncStandbyOrigin` (or `null`), `revision` and `memberOrigins`. A site is named by its site
|
|
4487
|
+
origin, the canonical `https` origin of one controller site (the value `data.IControllerPeerSet`
|
|
4488
|
+
carries as `activeOrigin` while that site is active), never the public origin browsers use. Cloudly
|
|
4489
|
+
is the only caller and sends `requests.witness` with TypedRequest over HTTPS to
|
|
4490
|
+
`data.witnessContract.typedRequestPath` (`/typedrequest`) below the witness's origin. The witness
|
|
4491
|
+
holds no controller data and no controller credential.
|
|
4492
|
+
|
|
4493
|
+
- Bearers: a member's bearer is a fact about one site. The site creates it, the unpadded base64url
|
|
4494
|
+
of `data.witnessContract.bearerRandomBytes` (32) random bytes, 43 characters checked by an exact
|
|
4495
|
+
pattern, and keeps it in that site's own config or secret store, never in the replicated
|
|
4496
|
+
controller database. The witness learns only `bearerSha256`, the SHA-256 of the bearer's UTF-8 as
|
|
4497
|
+
64 lowercase hex characters, and no answer carries a bearer.
|
|
4498
|
+
- Pairing: the witness's operator makes a one-time code for a controller id on the witness host;
|
|
4499
|
+
the controller redeems it with `pairWitnessController` (its `epoch`, its own origin and its
|
|
4500
|
+
`bearerSha256`), and the witness creates the record (revision 1, the caller active and only
|
|
4501
|
+
member, no standby) and answers `{ record }`. A controller whose answer was lost reads the record
|
|
4502
|
+
with its own bearer (`getWitnessRecord`). The active enrolls every other member with
|
|
4503
|
+
`enrollWitnessMember`, by the `bearerSha256` that site handed it, a compare-and-set on
|
|
4504
|
+
`expectedRevision` that raises the revision and replaces an existing member's hash; it answers
|
|
4505
|
+
`{ record }`. It never enrolls the recorded in-sync standby (`transition-invalid`): the active
|
|
4506
|
+
drops that standby first. At most `data.witnessContract.maximumMemberOrigins` (17) members.
|
|
4507
|
+
- Changes: `compareAndSetWitnessRecord` stores `next` (`data.IWitnessState`) only while the stored
|
|
4508
|
+
revision is `expectedRevision`, and raises it by one, so of two changes naming one revision at most
|
|
4509
|
+
one is stored. `data.judgeWitnessChange` is the rule both sides apply: within an epoch only the
|
|
4510
|
+
active changes the record, and only its in-sync standby (dropping it before it continues without
|
|
4511
|
+
one, or recording it again once it caught up); an epoch rises by exactly one and every epoch raise
|
|
4512
|
+
records no standby; a promotion names the recorded in-sync standby as active and is stated by that
|
|
4513
|
+
site, so a stale standby is never promoted; the active raises its own epoch after a restore.
|
|
4514
|
+
`data.judgeWitnessMemberEnrollment` is the rule for enrollment. `getWitnessRecord` reads the
|
|
4515
|
+
record for any member.
|
|
4516
|
+
- Refusals: one of `data.witnessRefusals`, as a `TypedResponseError` whose `errorData` is
|
|
4517
|
+
`data.IWitnessRefusalErrorData` (`{ code, retryable }`, `data.createWitnessRefusalErrorData`). The
|
|
4518
|
+
list is a vocabulary, not a check order. The witness answers the first refusal of its gates, in
|
|
4519
|
+
this order: `request-invalid`; then the pairing code (`pairing-code-unknown`,
|
|
4520
|
+
`pairing-code-expired`, `pairing-code-used`, then `controller-mismatch` and `controller-paired`
|
|
4521
|
+
with the code unconsumed) or the authentication (`credential-invalid`, one code for an unknown
|
|
4522
|
+
controller, a non-member site and a bad bearer); then `revision-stale` (the text names the stored
|
|
4523
|
+
revision); then the judge's first refusal, in the order each judge's doc states. Only
|
|
4524
|
+
`witness-unavailable` and `outcome-unknown` (`data.witnessMomentaryRefusals`) are momentary. A
|
|
4525
|
+
change refused `outcome-unknown`, or whose answer never arrived, may have been stored: read the
|
|
4526
|
+
record before acting on it. `data.readWitnessRefusalErrorData` reads anything but exactly one
|
|
4527
|
+
refusal as no answer.
|
|
4528
|
+
- Health: the unauthenticated `getWitnessHealth` answers `{ ready, witnessVersion, interfacesVersion }`
|
|
4529
|
+
and names no controller.
|
|
4530
|
+
- Validators are exact and never carry a bearer or a pairing code in a refusal:
|
|
4531
|
+
`data.validateWitnessRecord`, `data.validateWitnessState`, `data.validateWitnessMemberCredential`,
|
|
4532
|
+
`data.validatePairWitnessControllerRequest`, `data.validateEnrollWitnessMemberRequest`,
|
|
4533
|
+
`data.validateGetWitnessRecordRequest`, `data.validateCompareAndSetWitnessRecordRequest` and
|
|
4534
|
+
`data.validateWitnessHealth`.
|
|
4535
|
+
|
|
4536
|
+
```typescript
|
|
4537
|
+
import { data, requests } from '@serve.zone/interfaces';
|
|
4538
|
+
|
|
4539
|
+
declare const activeBearer: string; // the active's own witness bearer, from its site's secret store
|
|
4540
|
+
// The record as getWitnessRecord answered it.
|
|
4541
|
+
const record: data.IWitnessRecord = {
|
|
4542
|
+
controllerId: 'controller-0123456789abcdef0123456789abcdef',
|
|
4543
|
+
epoch: 1,
|
|
4544
|
+
activeOrigin: 'https://fra.cloudly.example.com',
|
|
4545
|
+
inSyncStandbyOrigin: 'https://nbg.cloudly.example.com',
|
|
4546
|
+
revision: 4,
|
|
4547
|
+
memberOrigins: ['https://fra.cloudly.example.com', 'https://nbg.cloudly.example.com'],
|
|
4548
|
+
};
|
|
4549
|
+
// The active stops waiting for a standby that stopped answering: first the witness records none.
|
|
4550
|
+
const dropStandby: requests.witness.IReq_Cloudly_Witness_CompareAndSetWitnessRecord['request'] = {
|
|
4551
|
+
controllerId: record.controllerId,
|
|
4552
|
+
member: { origin: record.activeOrigin, bearer: activeBearer },
|
|
4553
|
+
expectedRevision: record.revision,
|
|
4554
|
+
next: { epoch: record.epoch, activeOrigin: record.activeOrigin, inSyncStandbyOrigin: null },
|
|
4555
|
+
};
|
|
4556
|
+
data.judgeWitnessChange(record, dropStandby.member.origin, dropStandby.next); // null: admissible
|
|
4557
|
+
// A promotion of the standby once the record no longer names it in sync:
|
|
4558
|
+
data.judgeWitnessChange({ ...record, inSyncStandbyOrigin: null, revision: 5 }, 'https://nbg.cloudly.example.com',
|
|
4559
|
+
{ epoch: 2, activeOrigin: 'https://nbg.cloudly.example.com', inSyncStandbyOrigin: null }); // 'standby-not-in-sync'
|
|
4560
|
+
```
|
|
4561
|
+
|
|
4482
4562
|
### CoreMail contracts
|
|
4483
4563
|
|
|
4484
4564
|
`requests.coremail` is the shared contract boundary for authenticated workload
|
package/ts/00_commitinfo_data.ts
CHANGED