@serve.zone/interfaces 32.75.0 → 32.76.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 +15 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/controller.d.ts +70 -0
- package/dist_ts/data/controller.js +44 -0
- package/dist_ts/data/gatewayconnector.d.ts +278 -0
- package/dist_ts/data/gatewayconnector.js +418 -0
- package/dist_ts/data/index.d.ts +2 -0
- package/dist_ts/data/index.js +3 -1
- package/dist_ts/data/location.d.ts +3 -1
- package/dist_ts/data/location.js +7 -5
- package/dist_ts/private/controllercontract.d.ts +8 -0
- package/dist_ts/private/controllercontract.js +50 -0
- package/dist_ts/requests/baremetal.d.ts +2 -1
- package/dist_ts/requests/cluster.d.ts +5 -3
- package/dist_ts/requests/gatewayconnector.d.ts +133 -0
- package/dist_ts/requests/gatewayconnector.js +2 -0
- package/dist_ts/requests/index.d.ts +2 -1
- package/dist_ts/requests/index.js +3 -2
- package/dist_ts/requests/node.d.ts +4 -1
- package/dist_ts/runtime.corestore.database.d.ts +23 -0
- package/dist_ts/runtime.corestore.database.js +41 -0
- package/dist_ts/runtime.d.ts +1 -0
- package/dist_ts/runtime.js +2 -1
- package/package.json +2 -2
- package/readme.md +98 -5
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/controller.ts +106 -0
- package/ts/data/gatewayconnector.ts +714 -0
- package/ts/data/index.ts +2 -0
- package/ts/data/location.ts +6 -4
- package/ts/private/controllercontract.ts +59 -0
- package/ts/requests/baremetal.ts +2 -1
- package/ts/requests/cluster.ts +5 -3
- package/ts/requests/gatewayconnector.ts +168 -0
- package/ts/requests/index.ts +2 -0
- package/ts/requests/node.ts +4 -1
- package/ts/runtime.corestore.database.ts +64 -0
- package/ts/runtime.ts +1 -0
package/readme.md
CHANGED
|
@@ -3805,7 +3805,8 @@ create that names no location for a cluster without nodes, and `getLocations` ma
|
|
|
3805
3805
|
- The member kinds are the stored kinds `data.locationMemberKinds` (`edge`, `gateway`, `node`,
|
|
3806
3806
|
`oneboxHost`); `getLocations` answers which of them the Cloudly records
|
|
3807
3807
|
(`recordedMemberKinds`). A cluster is no member and no part of the digest: `getClusters` with a
|
|
3808
|
-
`locationScope` lists the clusters standing in a location.
|
|
3808
|
+
`locationScope` lists the clusters standing in a location. A cluster whose nodes span locations
|
|
3809
|
+
is in no scoped answer.
|
|
3809
3810
|
- `data.initialLocationId` (`location-initial`) is fixed; Cloudly generates every other location id
|
|
3810
3811
|
with a generator that can never produce it.
|
|
3811
3812
|
|
|
@@ -3820,15 +3821,19 @@ canonical JSON of the sorted `[kind, id]` pairs and the recorded kinds
|
|
|
3820
3821
|
The requests (`requests.location`) are administrator-only, admitted by no delegated-admin scope:
|
|
3821
3822
|
`createLocation`, `renameLocation`, `getLocations`, `setClusterLocation` (answers
|
|
3822
3823
|
`data.setClusterLocationOutcomes`: `moved`, `unchanged`, or `cluster-empty` for a cluster without
|
|
3823
|
-
nodes) and `confirmLocationMembership`. Every refusal is one of `data.locationRefusals
|
|
3824
|
+
nodes) and `confirmLocationMembership`. Every refusal is one of `data.locationRefusals` and
|
|
3825
|
+
travels by name as a `TypedResponseError`, except at a jump-code claim or node enrollment: there
|
|
3826
|
+
Cloudly logs the refusal by name and the claimant receives that path's single refusal sentence.
|
|
3824
3827
|
`createCluster` and `createNodeJumpCommand` take an optional `locationId`; for a cluster with nodes
|
|
3825
3828
|
a named location must be the cluster's (`location-mismatch`). A `createCluster` that names a
|
|
3826
|
-
location but creates no node (
|
|
3829
|
+
location but creates no node (a setup mode that provisions no node: today every mode but
|
|
3830
|
+
`hetzner`) is refused `location-needs-node`,
|
|
3827
3831
|
checked before `location-not-found`: name the location on `createNodeJumpCommand` instead.
|
|
3828
3832
|
`getClusters`, `getNodes` and `getBaremetalServers` take an optional `locationScope` and echo it as `appliedLocationScope`: a
|
|
3829
|
-
response without the echo comes from a Cloudly that ignored the scope and is not scoped.
|
|
3833
|
+
response without the echo comes from a Cloudly that ignored the scope and is not scoped. Each is
|
|
3834
|
+
refused `location-not-found` when no location has that id.
|
|
3830
3835
|
|
|
3831
|
-
Cloudly's
|
|
3836
|
+
Cloudly's `initial-location` data step writes one transaction per cluster (the cluster document and
|
|
3832
3837
|
all its node documents, setting `locationId` only where it is missing, so a rerun is safe) and one
|
|
3833
3838
|
transaction per node whose `clusterId` names no existing cluster. It never calls
|
|
3834
3839
|
`data.getClusterLocationId`, which throws for node copies that disagree.
|
|
@@ -4327,6 +4332,73 @@ const request: requests.gateway.IReq_SyncGatewayClientDnsRecord['request'] = {
|
|
|
4327
4332
|
};
|
|
4328
4333
|
```
|
|
4329
4334
|
|
|
4335
|
+
### Gateway Connector
|
|
4336
|
+
|
|
4337
|
+
A gateway (dcrouter) dials its controller (Cloudly) on the controller's typedsocket server and is
|
|
4338
|
+
never dialled once adopted. It authenticates with `registerCloudlyClientSession` as the machine
|
|
4339
|
+
identity it received at adoption, then says hello with `registerGatewaySession`; the gateway is the
|
|
4340
|
+
one that identity names and is never a request field. The controller records its gateways as
|
|
4341
|
+
`data.IGateway`: every gateway stands in a location, and its `connection` is either `legacy` (the
|
|
4342
|
+
dcrouter the controller still dials at a URL as a gateway client) or `adopted` (machine user and
|
|
4343
|
+
credential generation, no URL).
|
|
4344
|
+
|
|
4345
|
+
- Adoption: an administrator makes a one-time code (`createGatewayAdoptionCode`, for a new gateway
|
|
4346
|
+
in an existing location or for an existing gateway record) and runs the answered `command` on
|
|
4347
|
+
the gateway's host. The gateway redeems it with `adoptGateway` and its `data.IGatewayAdoptionFacts`;
|
|
4348
|
+
the controller answers the gateway id, its `data.IControllerPeerSet` and the credential, once.
|
|
4349
|
+
Adopting again raises the credential generation. Keep both bodies out of logs.
|
|
4350
|
+
- Peers: a gateway stores the peer set (`controllerId`, `epoch`, `activeOrigin`, `shadowOrigins`) and
|
|
4351
|
+
refuses any other controller and any older epoch. A takeover and a database restore raise the
|
|
4352
|
+
epoch. Later controller contracts extend `data.IControllerPeerSet` and never define a second one.
|
|
4353
|
+
- Desired state: the controller pushes the whole `data.IGatewayDesiredState` (`applyDesiredState`):
|
|
4354
|
+
`{ gatewayId, controllerId, epoch, revision, areas }`, one whole table per controller-owned area.
|
|
4355
|
+
Documents order by `(epoch, revision)` (`data.compareControllerRevisionOrder`): newer applies,
|
|
4356
|
+
equal replays the stored report, older is refused `stale`. A gateway validates every table first,
|
|
4357
|
+
skips an area whose digest it already serves, applies the rest in
|
|
4358
|
+
`data.gatewayConfigAreaApplyOrder` (`security`, `dns`, `routes`, `mail`, `edges`) and stops at the
|
|
4359
|
+
first failure; `data.IGatewayApplyReport.appliedRevision` advances only when the whole document
|
|
4360
|
+
applied. Refusals are `data.gatewayApplyRefusals`.
|
|
4361
|
+
- Area content is untyped here (`content: unknown`); each area's content type and validator ship in
|
|
4362
|
+
the release that moves that area. Its digest is `data.computeGatewayAreaTableDigest(area, content)`,
|
|
4363
|
+
`sha256:<hex>` of the strict canonical JSON of the domain `serve.zone/gateway-area-table`, the area
|
|
4364
|
+
and the content, which both sides compute.
|
|
4365
|
+
- Takeover: an area has one owner per gateway, `gateway` or `controller`, and moves to the controller
|
|
4366
|
+
once. The controller reads the local table (`exportGatewayArea`), writes an import revision and
|
|
4367
|
+
pushes the table with `takeover.localDigest`; a gateway whose local table changed since refuses
|
|
4368
|
+
`local-changed-since-export`.
|
|
4369
|
+
- Status: a gateway pushes its `data.IGatewayStatusDocument` (`pushGatewayStatus`) after its hello,
|
|
4370
|
+
after every apply and on change, at most once per
|
|
4371
|
+
`data.gatewayConnectorContract.minimumStatusPushIntervalMs` (5 s). `getGateways` lists the gateways
|
|
4372
|
+
with their connection state and last status, and takes the optional `locationScope`.
|
|
4373
|
+
`listeningPorts` (`data.IGatewayListeningPorts`) reports every public socket the gateway has open,
|
|
4374
|
+
not only its SmartProxy routes, as `{ tcp, udp }`: two lists of ranges the way routes state them
|
|
4375
|
+
(`data.IGatewayPortRange`, `{ from, to }`, inclusive), so a route on 10000–20000 is one entry. A
|
|
4376
|
+
route's `match.transport` `udp` counts under udp, `all` under both, `tcp` or none under tcp; QUIC
|
|
4377
|
+
and HTTP/3 count under udp. A gateway merges each transport's ports on its own into ranges sorted by
|
|
4378
|
+
`from` that neither overlap nor touch, at most
|
|
4379
|
+
`data.gatewayConnectorContract.maximumListeningPortRanges` (1024) per transport; one port may
|
|
4380
|
+
appear in both lists. A gateway lowercases its zone names before reporting them in `dnsZones`.
|
|
4381
|
+
- Validators name every refusal and never run an accessor: `data.validateControllerPeerSet`,
|
|
4382
|
+
`data.validateGatewayAdoptionFacts`, `data.validateRegisterGatewaySessionRequest`,
|
|
4383
|
+
`data.validateGatewayDesiredState` (envelope only), `data.validateGatewayApplyReport`,
|
|
4384
|
+
`data.validateGatewayStatusDocument` and `data.validateGatewayAreaExport`.
|
|
4385
|
+
|
|
4386
|
+
```typescript
|
|
4387
|
+
import { data, requests } from '@serve.zone/interfaces';
|
|
4388
|
+
|
|
4389
|
+
const content = { routes: [] };
|
|
4390
|
+
const desired: requests.gatewayconnector.IReq_Cloudly_Gateway_ApplyDesiredState['request'] = {
|
|
4391
|
+
desired: {
|
|
4392
|
+
gatewayId: 'gateway-fra-1',
|
|
4393
|
+
controllerId: 'controller-fra',
|
|
4394
|
+
epoch: 7,
|
|
4395
|
+
revision: 42,
|
|
4396
|
+
areas: [{ area: 'routes', digest: await data.computeGatewayAreaTableDigest('routes', content), content, takeover: null }],
|
|
4397
|
+
},
|
|
4398
|
+
};
|
|
4399
|
+
data.validateGatewayDesiredState(desired.desired); // []
|
|
4400
|
+
```
|
|
4401
|
+
|
|
4330
4402
|
### CoreMail contracts
|
|
4331
4403
|
|
|
4332
4404
|
`requests.coremail` is the shared contract boundary for authenticated workload
|
|
@@ -4735,6 +4807,27 @@ bytes and digests exactly.
|
|
|
4735
4807
|
payload, one-byte-larger framed snapshot-original, 128 MiB verified closure
|
|
4736
4808
|
plaintext, and 256 MiB closure boundaries used by Corestore.
|
|
4737
4809
|
|
|
4810
|
+
### Corestore Database Helpers
|
|
4811
|
+
|
|
4812
|
+
The Corestore database helpers its readers share live in the Node-only `/runtime` export, so a
|
|
4813
|
+
reader such as Onebox needs no `@serve.zone/corestore` dependency:
|
|
4814
|
+
|
|
4815
|
+
- `ICorestoreDatabaseAllocationReference`, read with `normalizeCorestoreDatabaseAllocationReference()`
|
|
4816
|
+
(see Corestore Runtime Credentials), and `corestoreDatabaseAllocationReferencesEqual(left, right)`,
|
|
4817
|
+
true when every member of two normalized references is equal.
|
|
4818
|
+
- `getCorestoreDatabaseIdentity(serviceId, serviceName?)` answers the `ICorestoreDatabaseIdentity`
|
|
4819
|
+
(`databaseName`, `username`) Corestore derives for a service: `sz_<base>_<hash>` and
|
|
4820
|
+
`u_<base>_<hash>`, with `<hash>` the first 12 hex digits of the SHA-1 of the service id and
|
|
4821
|
+
`<base>` the sanitized service name (the id when the name is absent or empty), at most 36
|
|
4822
|
+
characters. Every created database carries these names, so the derivation never changes.
|
|
4823
|
+
|
|
4824
|
+
```typescript
|
|
4825
|
+
import * as runtime from '@serve.zone/interfaces/runtime';
|
|
4826
|
+
|
|
4827
|
+
runtime.getCorestoreDatabaseIdentity('onebox-service-1');
|
|
4828
|
+
// { databaseName: 'sz_onebox_service_1_aa2bf033ccdf', username: 'u_onebox_service_1_aa2bf033ccdf' }
|
|
4829
|
+
```
|
|
4830
|
+
|
|
4738
4831
|
### Corestore Control Token Administration
|
|
4739
4832
|
|
|
4740
4833
|
The elected relay of every cluster calls its nodes' Corestore control API with one control token
|
package/ts/00_commitinfo_data.ts
CHANGED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateControllerCounter,
|
|
3
|
+
validateControllerIdentifier,
|
|
4
|
+
validateControllerOrigin,
|
|
5
|
+
} from '../private/controllercontract.js';
|
|
6
|
+
import { readDataElements, readExactDataRecord } from '../private/dataproperties.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The controller as the components that dial it know it: which controller they belong to, which
|
|
10
|
+
* epoch it is in and where to reach it.
|
|
11
|
+
*
|
|
12
|
+
* A dialling component (a gateway today) stores this when it is adopted and replaces it with every
|
|
13
|
+
* answer the controller gives it. It refuses any other `controllerId` and any older `epoch`: a
|
|
14
|
+
* takeover and a database restore both raise the epoch, so the controller that answers with the
|
|
15
|
+
* highest one is the one whose revisions count. Later controller contracts extend this shape and
|
|
16
|
+
* never define a second one.
|
|
17
|
+
*/
|
|
18
|
+
export interface IControllerPeerSet {
|
|
19
|
+
/** Fixed for the controller's life; stored at adoption. */
|
|
20
|
+
controllerId: string;
|
|
21
|
+
/** A positive safe integer; never lowered while the controller lives. */
|
|
22
|
+
epoch: number;
|
|
23
|
+
/** The canonical `https` origin of the active controller, dialled first. */
|
|
24
|
+
activeOrigin: string;
|
|
25
|
+
/** The canonical `https` origins of the shadow controllers, dialled in this order after the active one. */
|
|
26
|
+
shadowOrigins: string[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const controllerPeerSetContract = Object.freeze({
|
|
30
|
+
maximumOriginLength: 2048,
|
|
31
|
+
maximumShadowOrigins: 16,
|
|
32
|
+
} as const);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Negative, zero or positive as the left controller position is older than, the same as or newer
|
|
36
|
+
* than the right one: the epoch decides first and the revision only within one epoch, so a higher
|
|
37
|
+
* epoch with a lower revision (after a takeover or a restore) is still newer.
|
|
38
|
+
*/
|
|
39
|
+
export const compareControllerRevisionOrder = (
|
|
40
|
+
leftArg: Readonly<{ epoch: number; revision: number }>,
|
|
41
|
+
rightArg: Readonly<{ epoch: number; revision: number }>,
|
|
42
|
+
): number => Math.sign(leftArg.epoch - rightArg.epoch) || Math.sign(leftArg.revision - rightArg.revision);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* One record of the controller-wide revision sequence, written in the same transaction as the
|
|
46
|
+
* change it records. A secret appears in `changes` by its ids and versions only, never by value.
|
|
47
|
+
*/
|
|
48
|
+
export interface IControllerRevision {
|
|
49
|
+
/** A positive safe integer from the one controller-wide sequence. */
|
|
50
|
+
revision: number;
|
|
51
|
+
/** The controller epoch the revision was written in. */
|
|
52
|
+
epoch: number;
|
|
53
|
+
/** Unix milliseconds on the controller's clock. */
|
|
54
|
+
at: number;
|
|
55
|
+
actor: {
|
|
56
|
+
kind: 'person' | 'machine' | 'system';
|
|
57
|
+
/** The acting identity's subject; `null` for the controller itself (`system`). */
|
|
58
|
+
sub: string | null;
|
|
59
|
+
displayName: string;
|
|
60
|
+
};
|
|
61
|
+
kind: 'change' | 'adoption' | 'import' | 'revert';
|
|
62
|
+
changes: {
|
|
63
|
+
objectKind: string;
|
|
64
|
+
objectId: string;
|
|
65
|
+
/** The object before the change; `null` when the change created it. */
|
|
66
|
+
before: unknown;
|
|
67
|
+
/** The object after the change; `null` when the change deleted it. */
|
|
68
|
+
after: unknown;
|
|
69
|
+
}[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Validates one controller peer set and names every reason it is refused.
|
|
74
|
+
*
|
|
75
|
+
* Shape only: whether the controller id is the one a gateway stored, and whether the epoch is not
|
|
76
|
+
* older than its stored one, is the dialling component's decision against its own state.
|
|
77
|
+
*/
|
|
78
|
+
export const validateControllerPeerSet = (
|
|
79
|
+
valueArg: unknown,
|
|
80
|
+
pathArg = 'controller peer set',
|
|
81
|
+
): string[] => {
|
|
82
|
+
const record = readExactDataRecord(valueArg, ['controllerId', 'epoch', 'activeOrigin', 'shadowOrigins']);
|
|
83
|
+
if (record === null) {
|
|
84
|
+
return [`${pathArg} must use its exact schema`];
|
|
85
|
+
}
|
|
86
|
+
const { maximumOriginLength, maximumShadowOrigins } = controllerPeerSetContract;
|
|
87
|
+
const errors = [
|
|
88
|
+
...validateControllerIdentifier(record.controllerId, `${pathArg} controllerId`),
|
|
89
|
+
...validateControllerCounter(record.epoch, `${pathArg} epoch`),
|
|
90
|
+
...validateControllerOrigin(record.activeOrigin, `${pathArg} activeOrigin`, maximumOriginLength),
|
|
91
|
+
];
|
|
92
|
+
const shadowOrigins = readDataElements(record.shadowOrigins, maximumShadowOrigins);
|
|
93
|
+
if (shadowOrigins === null) {
|
|
94
|
+
errors.push(`${pathArg} shadowOrigins must be a dense list of at most ${maximumShadowOrigins} origins`);
|
|
95
|
+
return errors;
|
|
96
|
+
}
|
|
97
|
+
shadowOrigins.forEach((originArg, indexArg) => {
|
|
98
|
+
errors.push(...validateControllerOrigin(originArg, `${pathArg} shadowOrigins[${indexArg}]`,
|
|
99
|
+
maximumOriginLength));
|
|
100
|
+
});
|
|
101
|
+
const origins = [record.activeOrigin, ...shadowOrigins];
|
|
102
|
+
if (new Set(origins).size !== origins.length) {
|
|
103
|
+
errors.push(`${pathArg} must name each origin once`);
|
|
104
|
+
}
|
|
105
|
+
return errors;
|
|
106
|
+
};
|