@serve.zone/interfaces 32.91.0 → 32.93.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 +14 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/gatewayarearows.d.ts +379 -0
- package/dist_ts/data/gatewayarearows.js +347 -0
- package/dist_ts/data/gatewayareas.d.ts +24 -0
- package/dist_ts/data/gatewayareas.js +41 -1
- package/dist_ts/data/gatewayareas.validation.d.ts +11 -3
- package/dist_ts/data/gatewayareas.validation.js +41 -58
- package/dist_ts/data/gatewayconnector.d.ts +7 -1
- package/dist_ts/data/gatewayconnector.js +1 -1
- package/dist_ts/data/gatewayintent.d.ts +71 -12
- package/dist_ts/data/gatewayintent.js +35 -12
- package/dist_ts/data/index.d.ts +1 -0
- package/dist_ts/data/index.js +2 -1
- package/dist_ts/requests/gatewayconnector.d.ts +125 -1
- package/package.json +1 -1
- package/readme.md +82 -6
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/gatewayarearows.ts +688 -0
- package/ts/data/gatewayareas.ts +55 -0
- package/ts/data/gatewayareas.validation.ts +43 -59
- package/ts/data/gatewayconnector.ts +7 -1
- package/ts/data/gatewayintent.ts +95 -15
- package/ts/data/index.ts +1 -0
- package/ts/requests/gatewayconnector.ts +151 -1
package/ts/data/gatewayareas.ts
CHANGED
|
@@ -1131,6 +1131,61 @@ export const gatewayAreaMembers = Object.freeze({
|
|
|
1131
1131
|
edges: Object.freeze(['hub', 'edges'] as const),
|
|
1132
1132
|
} as const);
|
|
1133
1133
|
|
|
1134
|
+
/** The secret classes of the area contents: a sealed value (`IGatewaySealedValue`) or a verifier. */
|
|
1135
|
+
export type TGatewayAreaSecretClass = 'sealed' | 'verifier';
|
|
1136
|
+
|
|
1137
|
+
/** Where one secret-class member of a member's rows (or of a singleton) is, and its class. */
|
|
1138
|
+
export interface IGatewayAreaSecretPath {
|
|
1139
|
+
/** The dotted key path inside the row or singleton. */
|
|
1140
|
+
path: string;
|
|
1141
|
+
secretClass: TGatewayAreaSecretClass;
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
/**
|
|
1145
|
+
* Every secret-class member of the area contents, by area and member, each member's paths in the
|
|
1146
|
+
* order `listGatewayAreaSecrets` lists them (Linus ruling 171 section 4): the one list of where a
|
|
1147
|
+
* table holds a secret. `listGatewayAreaSecrets` is computed from it, and the operator row read and
|
|
1148
|
+
* write walk it (`projectGatewayAreaRow`, `resolveGatewayAreaRowWrite`,
|
|
1149
|
+
* `computeGatewayAreaRowDigest`, `validateGatewayAreaRowWrite`), so the secrets a controller seals,
|
|
1150
|
+
* the ones a row read hides and the ones a row token takes by version only are the same. A member not
|
|
1151
|
+
* named holds no secret. A sealed member holds no secret when it is `null`, a verifier when it is
|
|
1152
|
+
* `null` or an empty list (a CoreMail peer without credentials). A secret member added to an area
|
|
1153
|
+
* type goes in here and into its row write type (`IGatewayAreaRowWrites`).
|
|
1154
|
+
*/
|
|
1155
|
+
export const gatewayAreaSecretPaths: {
|
|
1156
|
+
readonly [TArea in TGatewayConfigArea]: {
|
|
1157
|
+
readonly [TMember in keyof IGatewayAreaContents[TArea]]?: readonly IGatewayAreaSecretPath[];
|
|
1158
|
+
};
|
|
1159
|
+
} = Object.freeze({
|
|
1160
|
+
security: Object.freeze({
|
|
1161
|
+
apiTokens: Object.freeze([Object.freeze({ path: 'credential', secretClass: 'verifier' as const })]),
|
|
1162
|
+
}),
|
|
1163
|
+
dns: Object.freeze({
|
|
1164
|
+
providers: Object.freeze([Object.freeze({ path: 'credentials.apiToken', secretClass: 'sealed' as const })]),
|
|
1165
|
+
}),
|
|
1166
|
+
routes: Object.freeze({
|
|
1167
|
+
routes: Object.freeze([
|
|
1168
|
+
Object.freeze({ path: 'secrets.tlsKey', secretClass: 'sealed' as const }),
|
|
1169
|
+
Object.freeze({ path: 'secrets.basicAuthUsers', secretClass: 'sealed' as const }),
|
|
1170
|
+
Object.freeze({ path: 'secrets.jwtSecret', secretClass: 'sealed' as const }),
|
|
1171
|
+
Object.freeze({ path: 'secrets.requestHeaders', secretClass: 'sealed' as const }),
|
|
1172
|
+
]),
|
|
1173
|
+
sourceProfiles: Object.freeze([
|
|
1174
|
+
Object.freeze({ path: 'secrets.basicAuthUsers', secretClass: 'sealed' as const }),
|
|
1175
|
+
Object.freeze({ path: 'secrets.jwtSecret', secretClass: 'sealed' as const }),
|
|
1176
|
+
]),
|
|
1177
|
+
}),
|
|
1178
|
+
mail: Object.freeze({
|
|
1179
|
+
server: Object.freeze([Object.freeze({ path: 'tlsKey', secretClass: 'sealed' as const })]),
|
|
1180
|
+
smtpAccounts: Object.freeze([Object.freeze({ path: 'credential', secretClass: 'verifier' as const })]),
|
|
1181
|
+
identities: Object.freeze([Object.freeze({ path: 'credential', secretClass: 'verifier' as const })]),
|
|
1182
|
+
coreMailPeers: Object.freeze([Object.freeze({ path: 'credentials', secretClass: 'verifier' as const })]),
|
|
1183
|
+
}),
|
|
1184
|
+
edges: Object.freeze({
|
|
1185
|
+
edges: Object.freeze([Object.freeze({ path: 'secret', secretClass: 'sealed' as const })]),
|
|
1186
|
+
}),
|
|
1187
|
+
});
|
|
1188
|
+
|
|
1134
1189
|
/**
|
|
1135
1190
|
* The closed key vocabulary refused inside every engine configuration (a route's `route`, a source
|
|
1136
1191
|
* profile's `security`, the mail server's `emailConfig`, the proxy policy, and every policy override
|
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
gatewayAreaContentContract,
|
|
34
34
|
gatewayAreaMembers,
|
|
35
35
|
gatewayAreaRefusedEngineKeys,
|
|
36
|
+
gatewayAreaSecretPaths,
|
|
36
37
|
gatewayBlockRuleTypes,
|
|
37
38
|
gatewayDnsRecordTypes,
|
|
38
39
|
gatewayDnsStaticRecordTypes,
|
|
@@ -40,9 +41,12 @@ import {
|
|
|
40
41
|
gatewayMailIdentityScramIterations,
|
|
41
42
|
gatewayRoutePathClasses,
|
|
42
43
|
isGatewayApiTokenScope,
|
|
44
|
+
type IGatewayAreaSecretPath,
|
|
43
45
|
type IGatewayDnsStaticRecordRow,
|
|
44
46
|
type IGatewayScramVerifier,
|
|
47
|
+
type IGatewaySealedValue,
|
|
45
48
|
type TGatewayAreaContent,
|
|
49
|
+
type TGatewayAreaSecretClass,
|
|
46
50
|
type TGatewayRoutePortEntry,
|
|
47
51
|
type TGatewayRoutePortsInput,
|
|
48
52
|
} from './gatewayareas.js';
|
|
@@ -318,7 +322,12 @@ const zoneLabel = /^[a-z0-9_](?:[a-z0-9_-]{0,61}[a-z0-9])?$/;
|
|
|
318
322
|
const portKey = /^[1-9][0-9]{0,4}$/;
|
|
319
323
|
const clientTypes = ['onebox', 'cloudly', 'custom'] as const;
|
|
320
324
|
|
|
321
|
-
|
|
325
|
+
/**
|
|
326
|
+
* Whether a value is a row id of the area contents: a text of 1 to
|
|
327
|
+
* `gatewayAreaContentContract.maximumRowIdLength` UTF-16 code units without a control character. A
|
|
328
|
+
* member may narrow its own ids further (`invalid-row-id`); this is the rule every row id meets.
|
|
329
|
+
*/
|
|
330
|
+
export const isGatewayAreaRowId = (valueArg: unknown): valueArg is string => (
|
|
322
331
|
typeof valueArg === 'string' && valueArg.length > 0 && valueArg.length <= contract.maximumRowIdLength
|
|
323
332
|
&& !controlCharacter.test(valueArg)
|
|
324
333
|
);
|
|
@@ -752,10 +761,10 @@ const rowList = (
|
|
|
752
761
|
let previous: string | null = null;
|
|
753
762
|
rows.forEach((rowArg, indexArg) => {
|
|
754
763
|
const id = readDataProperty(rowArg, 'id')?.value;
|
|
755
|
-
const rowScope: IScope =
|
|
764
|
+
const rowScope: IScope = isGatewayAreaRowId(id)
|
|
756
765
|
? { ...memberScope, rowId: id }
|
|
757
766
|
: { ...memberScope, prefix: `[${indexArg}].` };
|
|
758
|
-
if (!
|
|
767
|
+
if (!isGatewayAreaRowId(id)) {
|
|
759
768
|
refuse(rowScope, 'id', 'invalid-row-id');
|
|
760
769
|
} else {
|
|
761
770
|
if (previous !== null && compareWireTokens(previous, id) >= 0) {
|
|
@@ -824,7 +833,7 @@ const checkUniqueKey = (scopeArg: IScope, memberArg: string, rowsArg: unknown, k
|
|
|
824
833
|
}
|
|
825
834
|
if (seen.has(key)) {
|
|
826
835
|
const id = readDataProperty(rowArg, 'id')?.value;
|
|
827
|
-
refuse({ ...scopeArg, member: memberArg, rowId:
|
|
836
|
+
refuse({ ...scopeArg, member: memberArg, rowId: isGatewayAreaRowId(id) ? id : null, prefix: '' }, pathArg, 'duplicate-key');
|
|
828
837
|
}
|
|
829
838
|
seen.add(key);
|
|
830
839
|
});
|
|
@@ -1568,7 +1577,7 @@ const validateRoutes = (scopeArg: IScope, contentArg: Record<string, unknown>):
|
|
|
1568
1577
|
}), 'targets', 'set-not-ascending');
|
|
1569
1578
|
}
|
|
1570
1579
|
}
|
|
1571
|
-
checkTextSet(rowScopeArg, row.routeRefs, 'routeRefs', (entryArg) =>
|
|
1580
|
+
checkTextSet(rowScopeArg, row.routeRefs, 'routeRefs', (entryArg) => isGatewayAreaRowId(entryArg));
|
|
1572
1581
|
checkBoolean(rowScopeArg, row.allowRoutesByClientSourceIp, 'allowRoutesByClientSourceIp');
|
|
1573
1582
|
});
|
|
1574
1583
|
checkUniqueKey(scopeArg, 'targetProfiles', contentArg.targetProfiles, (rowArg) => field(rowArg, 'name'), 'name');
|
|
@@ -2212,73 +2221,48 @@ export interface IGatewayAreaSecretReference {
|
|
|
2212
2221
|
rowId: string | null;
|
|
2213
2222
|
/** The key path inside the row or singleton. */
|
|
2214
2223
|
path: string;
|
|
2215
|
-
secretClass:
|
|
2224
|
+
secretClass: TGatewayAreaSecretClass;
|
|
2216
2225
|
/** The sealed version; `null` for a verifier. */
|
|
2217
2226
|
version: string | null;
|
|
2218
2227
|
}
|
|
2219
2228
|
|
|
2229
|
+
/** The value at a dotted key path inside a row or singleton of a valid content; `null` where none is. */
|
|
2230
|
+
const readSecretAt = (rowArg: unknown, pathArg: string): unknown => {
|
|
2231
|
+
let current: unknown = rowArg;
|
|
2232
|
+
for (const key of pathArg.split('.')) {
|
|
2233
|
+
if (!isPlainRecord(current)) return null;
|
|
2234
|
+
current = current[key] ?? null;
|
|
2235
|
+
}
|
|
2236
|
+
return current;
|
|
2237
|
+
};
|
|
2238
|
+
|
|
2220
2239
|
/**
|
|
2221
2240
|
* Every secret-class value of a valid area content: what a controller seals, and what its
|
|
2222
|
-
* revisions and diffs name by version instead of by value.
|
|
2241
|
+
* revisions and diffs name by version instead of by value. Computed from `gatewayAreaSecretPaths`:
|
|
2242
|
+
* member by member in its order, row by row in table order, path by path in its order; a sealed
|
|
2243
|
+
* member stated `null` and a verifier stated `null` or as an empty list hold no secret.
|
|
2223
2244
|
*/
|
|
2224
2245
|
export const listGatewayAreaSecrets = <TArea extends TGatewayConfigArea>(
|
|
2225
2246
|
areaArg: TArea,
|
|
2226
2247
|
contentArg: TGatewayAreaContent<TArea>,
|
|
2227
2248
|
): IGatewayAreaSecretReference[] => {
|
|
2228
2249
|
const references: IGatewayAreaSecretReference[] = [];
|
|
2229
|
-
const
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
break;
|
|
2245
|
-
}
|
|
2246
|
-
case 'dns': {
|
|
2247
|
-
const content = contentArg as TGatewayAreaContent<'dns'>;
|
|
2248
|
-
content.providers.forEach((rowArg) => sealed('providers', rowArg.id, 'credentials.apiToken',
|
|
2249
|
-
rowArg.credentials.apiToken));
|
|
2250
|
-
break;
|
|
2251
|
-
}
|
|
2252
|
-
case 'routes': {
|
|
2253
|
-
const content = contentArg as TGatewayAreaContent<'routes'>;
|
|
2254
|
-
for (const row of content.routes) {
|
|
2255
|
-
for (const key of ['tlsKey', 'basicAuthUsers', 'jwtSecret', 'requestHeaders'] as const) {
|
|
2256
|
-
sealed('routes', row.id, `secrets.${key}`, row.secrets[key]);
|
|
2257
|
-
}
|
|
2250
|
+
const content = contentArg as unknown as Record<string, unknown>;
|
|
2251
|
+
const members = Object.entries(gatewayAreaSecretPaths[areaArg]) as [string, readonly IGatewayAreaSecretPath[]][];
|
|
2252
|
+
for (const [member, paths] of members) {
|
|
2253
|
+
const value = content[member];
|
|
2254
|
+
const rows = Array.isArray(value)
|
|
2255
|
+
? value.map((rowArg: { id: string }) => ({ rowId: rowArg.id as string | null, row: rowArg as unknown }))
|
|
2256
|
+
: [{ rowId: null, row: value }];
|
|
2257
|
+
for (const { rowId, row } of rows) {
|
|
2258
|
+
for (const { path, secretClass } of paths) {
|
|
2259
|
+
const held = readSecretAt(row, path);
|
|
2260
|
+
if (held === null || (Array.isArray(held) && held.length === 0)) continue;
|
|
2261
|
+
references.push({
|
|
2262
|
+
area: areaArg, member, rowId, path, secretClass,
|
|
2263
|
+
version: secretClass === 'sealed' ? (held as IGatewaySealedValue).version : null,
|
|
2264
|
+
});
|
|
2258
2265
|
}
|
|
2259
|
-
for (const row of content.sourceProfiles) {
|
|
2260
|
-
for (const key of ['basicAuthUsers', 'jwtSecret'] as const) {
|
|
2261
|
-
sealed('sourceProfiles', row.id, `secrets.${key}`, row.secrets[key]);
|
|
2262
|
-
}
|
|
2263
|
-
}
|
|
2264
|
-
break;
|
|
2265
|
-
}
|
|
2266
|
-
case 'mail': {
|
|
2267
|
-
const content = contentArg as TGatewayAreaContent<'mail'>;
|
|
2268
|
-
sealed('server', null, 'tlsKey', content.server.tlsKey);
|
|
2269
|
-
content.smtpAccounts.forEach((rowArg) => verifier('smtpAccounts', rowArg.id, 'credential'));
|
|
2270
|
-
content.identities.forEach((rowArg) => verifier('identities', rowArg.id, 'credential'));
|
|
2271
|
-
content.coreMailPeers.forEach((rowArg) => {
|
|
2272
|
-
if (rowArg.credentials.length > 0) {
|
|
2273
|
-
verifier('coreMailPeers', rowArg.id, 'credentials');
|
|
2274
|
-
}
|
|
2275
|
-
});
|
|
2276
|
-
break;
|
|
2277
|
-
}
|
|
2278
|
-
case 'edges': {
|
|
2279
|
-
const content = contentArg as TGatewayAreaContent<'edges'>;
|
|
2280
|
-
content.edges.forEach((rowArg) => sealed('edges', rowArg.id, 'secret', rowArg.secret));
|
|
2281
|
-
break;
|
|
2282
2266
|
}
|
|
2283
2267
|
}
|
|
2284
2268
|
return references;
|
|
@@ -228,11 +228,17 @@ export interface IGatewayAreaTable {
|
|
|
228
228
|
}
|
|
229
229
|
|
|
230
230
|
/**
|
|
231
|
-
* The whole desired state a controller pushes to one gateway (`applyDesiredState`)
|
|
231
|
+
* The whole desired state a controller pushes to one gateway (`applyDesiredState`), also exported to
|
|
232
|
+
* an administrator (`exportGatewayDesiredState`) and applied from a file through a gateway's host
|
|
233
|
+
* control socket.
|
|
232
234
|
*
|
|
233
235
|
* Documents are ordered by `(epoch, revision)` (`data.compareControllerRevisionOrder`): a newer one
|
|
234
236
|
* is applied, an equal one is an idempotent replay answered with the stored report, and an older
|
|
235
237
|
* one is refused `desired-state-stale` (`gatewayConnectorRefusals`).
|
|
238
|
+
*
|
|
239
|
+
* The area tables carry their values, secrets included, in plain text: keep a document out of every
|
|
240
|
+
* log, ticket and transcript, store it only in an owner-only file, and name it by its tuple
|
|
241
|
+
* (gateway, controller, epoch, revision, per-area digests).
|
|
236
242
|
*/
|
|
237
243
|
export interface IGatewayDesiredState {
|
|
238
244
|
gatewayId: string;
|
package/ts/data/gatewayintent.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* What a controller answers about the gateway intent it holds: the per-gateway, per-area tables it
|
|
3
|
-
* authored once it took a gateway over (`gatewayareas.ts`). These are the
|
|
4
|
-
*
|
|
5
|
-
* takeover
|
|
6
|
-
*
|
|
3
|
+
* authored once it took a gateway over (`gatewayareas.ts`). These are the shapes an administrator's
|
|
4
|
+
* tools and the dashboard see: a gateway's takeover state, the dry run of its takeover, and the
|
|
5
|
+
* takeover itself (the export digests its request names, what it imported, its refusals). The
|
|
6
|
+
* tables themselves, their revisions and how a controller compiles them are the controller's own;
|
|
7
|
+
* nothing here carries a table value, a password or a verifier.
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import type { IControllerRevision } from './controller.js';
|
|
@@ -14,14 +15,18 @@ import type { TSha256Digest } from './immutableimage.js';
|
|
|
14
15
|
* Every reason the gateway intent refuses an operation: the controller's one vocabulary, which it
|
|
15
16
|
* imports from here and keeps no copy of.
|
|
16
17
|
*
|
|
17
|
-
* The
|
|
18
|
-
* `code` name `gateway-not-found`, `area-contract-missing`, `export-missing`,
|
|
19
|
-
* `controller-origin-unserved`, `lifeline-unjudged` and
|
|
20
|
-
*
|
|
21
|
-
*
|
|
18
|
+
* The requests this package declares cover the list between them: a dry run's `refusals` and the
|
|
19
|
+
* report's `code` name `gateway-not-found`, `area-contract-missing`, `export-missing`,
|
|
20
|
+
* `area-table-invalid`, `controller-origin-unserved`, `lifeline-unjudged` and
|
|
21
|
+
* `compiled-table-invalid`; a takeover's report (`TGatewayTakeoverReport`) names those and
|
|
22
|
+
* `gateway-not-adopted`, `gateway-areas-not-offered`, `gateway-taken-over`, `takeover-not-pure` and
|
|
23
|
+
* `takeover-exports-moved`; an operator's row read and write (`gatewayarearows.ts`) name
|
|
24
|
+
* `gateway-not-found`, `gateway-not-taken-over`, `row-compile-owned`, `intent-row-stale`,
|
|
25
|
+
* `kept-secret-unknown`, `area-table-invalid`, `controller-origin-unserved`, `lifeline-unjudged`,
|
|
26
|
+
* `gateway-vocabulary-newer` and `intent-revision-stale`.
|
|
22
27
|
*
|
|
23
|
-
* A reader of these
|
|
24
|
-
* it:
|
|
28
|
+
* A reader of these answers shows a name it does not know as text and never refuses the answer for
|
|
29
|
+
* it: they have no validator, and a controller built after the reader may name a newer reason.
|
|
25
30
|
*/
|
|
26
31
|
export const gatewayIntentRefusals = Object.freeze([
|
|
27
32
|
/** The registry records no such gateway. */
|
|
@@ -42,12 +47,30 @@ export const gatewayIntentRefusals = Object.freeze([
|
|
|
42
47
|
'area-table-invalid',
|
|
43
48
|
/** The compiled document differs from the exported tables, so the takeover would change the data plane. */
|
|
44
49
|
'takeover-not-pure',
|
|
50
|
+
/**
|
|
51
|
+
* The gateway exports another table now than the dry run the administrator read named
|
|
52
|
+
* (`exportDigests` of the takeover request): the takeover imports nothing nobody saw. Read the
|
|
53
|
+
* dry run again.
|
|
54
|
+
*/
|
|
55
|
+
'takeover-exports-moved',
|
|
45
56
|
/** The revision leaves the controller's public origin unserved on a gateway that served it. */
|
|
46
57
|
'controller-origin-unserved',
|
|
47
58
|
/** The routes table changes and no routes contract can judge the lifeline. */
|
|
48
59
|
'lifeline-unjudged',
|
|
49
60
|
/** The table moved past the revision the write was based on. */
|
|
50
61
|
'intent-revision-stale',
|
|
62
|
+
/**
|
|
63
|
+
* The row is not the one an operator's row write was based on (its `expectedDigest`): another write
|
|
64
|
+
* changed, added or removed it. Read the row again (`gatewayarearows.ts`).
|
|
65
|
+
*/
|
|
66
|
+
'intent-row-stale',
|
|
67
|
+
/**
|
|
68
|
+
* An operator's row write keeps a secret the row does not hold at that path under that version
|
|
69
|
+
* (a new row, a member stored `null`, another row's version). A row that moved since the read
|
|
70
|
+
* answers `intent-row-stale` first, so this names the written row, not a stale read: fix the
|
|
71
|
+
* written row rather than reading again (`gatewayarearows.ts`).
|
|
72
|
+
*/
|
|
73
|
+
'kept-secret-unknown',
|
|
51
74
|
/**
|
|
52
75
|
* A compile from the controller's records cannot build a record's rows (the operation that wrote
|
|
53
76
|
* that record fails, the rest compile), or builds a table it cannot place: one its area contract
|
|
@@ -177,6 +200,15 @@ export interface IGatewayIntentDryRun {
|
|
|
177
200
|
/** Five, in `gatewayConfigAreaApplyOrder`. */
|
|
178
201
|
areas: IGatewayAreaDryRun[];
|
|
179
202
|
lifeline: TGatewayLifeline;
|
|
203
|
+
/**
|
|
204
|
+
* Whether the routes table the gateway exports now serves the controller's public origin, judged by
|
|
205
|
+
* the controller's own routes predicate on the exported content whatever the digests say (Linus
|
|
206
|
+
* ruling 166 point 3): `true`, `false`, or `null` when no routes predicate can judge or the gateway
|
|
207
|
+
* exported no single routes table. `lifeline` answers `unchanged` for equal tables without asking
|
|
208
|
+
* the predicate, so it cannot tell a guarded origin from an unguarded one; this member can. A
|
|
209
|
+
* report, not a refusal: no refusal and no pass criterion of the dry run reads it.
|
|
210
|
+
*/
|
|
211
|
+
exportedRoutesServeControllerOrigin: boolean | null;
|
|
180
212
|
/** Empty when the dry run passes. */
|
|
181
213
|
refusals: TGatewayIntentRefusal[];
|
|
182
214
|
/**
|
|
@@ -229,11 +261,59 @@ export type TGatewayDryRunRefusal = TGatewayIntentRefusal | 'controller-gateway-
|
|
|
229
261
|
/**
|
|
230
262
|
* A gateway's dry run: per area whether the exported and compiled tables validate, their digests and
|
|
231
263
|
* the row ids that differ, the rows of the controller's client that no record claims and the records
|
|
232
|
-
* the compile holds, the lifeline, the
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
264
|
+
* the compile holds, the lifeline, whether the exported routes serve the controller origin, the
|
|
265
|
+
* refusals by name, the password state of every mail identity the compile claims, and whether it
|
|
266
|
+
* passes (every area validates, every compiled table is the exported one, nothing is refused; the
|
|
267
|
+
* origin member and the mail identity report are not read); or the refusal that left no dry run. No
|
|
268
|
+
* table value, password or verifier.
|
|
236
269
|
*/
|
|
237
270
|
export type TGatewayDryRunReport =
|
|
238
271
|
| { ok: true; passes: boolean; dryRun: IGatewayIntentDryRun }
|
|
239
272
|
| { ok: false; code: TGatewayDryRunRefusal };
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* The digest of one area's table as the dry run the administrator read exported it
|
|
276
|
+
* (`IGatewayAreaDryRun.exportDigest`): what a takeover request names, so the takeover imports
|
|
277
|
+
* exactly the tables that dry run saw. The controller matches the entries to the exports by `area`;
|
|
278
|
+
* their order means nothing.
|
|
279
|
+
*/
|
|
280
|
+
export interface IGatewayTakeoverExportDigest {
|
|
281
|
+
area: TGatewayConfigArea;
|
|
282
|
+
digest: TSha256Digest;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** One area a takeover imported: the table's digest, its rows and how many of them the controller's records claim. */
|
|
286
|
+
export interface IGatewayTakeoverArea {
|
|
287
|
+
area: TGatewayConfigArea;
|
|
288
|
+
/** The digest of the imported table, which is the exported one: a takeover changes no table. */
|
|
289
|
+
digest: TSha256Digest;
|
|
290
|
+
rows: number;
|
|
291
|
+
/** Rows the controller's records compile; every other row is an operator row. */
|
|
292
|
+
claimedRows: number;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** What a takeover imported. */
|
|
296
|
+
export interface IGatewayTakeover {
|
|
297
|
+
gatewayId: string;
|
|
298
|
+
/**
|
|
299
|
+
* The `import` revision the takeover appended, naming who took the gateway over; the takeover
|
|
300
|
+
* state (`IGatewayTakeoverState.imported`) answers it with its actor and time.
|
|
301
|
+
*/
|
|
302
|
+
revision: number;
|
|
303
|
+
/** Five, in `gatewayConfigAreaApplyOrder`. */
|
|
304
|
+
areas: IGatewayTakeoverArea[];
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Why the running controller did not take the gateway over: a refusal of the gateway intent (among
|
|
309
|
+
* them `gateway-taken-over`, which a request repeated after a lost answer meets, and
|
|
310
|
+
* `takeover-exports-moved`), no socket carries the gateway now, or the gateway kept answering an
|
|
311
|
+
* export with a momentary refusal (ask again later).
|
|
312
|
+
*/
|
|
313
|
+
export type TGatewayTakeoverRefusal = TGatewayIntentRefusal | 'controller-gateway-disconnected'
|
|
314
|
+
| TGatewayConnectorMomentaryRefusal;
|
|
315
|
+
|
|
316
|
+
/** A takeover's answer: what it imported, or the refusal that left the gateway as it was. No table value. */
|
|
317
|
+
export type TGatewayTakeoverReport =
|
|
318
|
+
| { ok: true; takeover: IGatewayTakeover }
|
|
319
|
+
| { ok: false; code: TGatewayTakeoverRefusal };
|
package/ts/data/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ export * from './fleetcutover.js';
|
|
|
31
31
|
export * from './gateway.js';
|
|
32
32
|
export * from './gatewayareas.js';
|
|
33
33
|
export * from './gatewayareas.validation.js';
|
|
34
|
+
export * from './gatewayarearows.js';
|
|
34
35
|
export * from './gatewayconnector.js';
|
|
35
36
|
export * from './gatewayintent.js';
|
|
36
37
|
export * from './hostedapp.js';
|
|
@@ -11,7 +11,18 @@ import type {
|
|
|
11
11
|
IRegisterGatewaySessionRequest,
|
|
12
12
|
TGatewayConfigArea,
|
|
13
13
|
} from '../data/gatewayconnector.js';
|
|
14
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
IGatewayTakeoverExportDigest,
|
|
16
|
+
IGatewayTakeoverState,
|
|
17
|
+
TGatewayDryRunReport,
|
|
18
|
+
TGatewayTakeoverReport,
|
|
19
|
+
} from '../data/gatewayintent.js';
|
|
20
|
+
import type {
|
|
21
|
+
TGatewayAreaMember,
|
|
22
|
+
TGatewayAreaRowsReport,
|
|
23
|
+
TGatewayAreaRowWrite,
|
|
24
|
+
TGatewayAreaRowWriteReport,
|
|
25
|
+
} from '../data/gatewayarearows.js';
|
|
15
26
|
import type { IGatewayRouteDnsResult } from '../data/gateway.js';
|
|
16
27
|
import type { ILocationScope } from '../data/location.js';
|
|
17
28
|
import type { IIdentityCredential } from '../data/user.js';
|
|
@@ -257,3 +268,142 @@ export interface IReq_Admin_Cloudly_GetGatewayDryRun extends plugins.typedreques
|
|
|
257
268
|
report: TGatewayDryRunReport;
|
|
258
269
|
};
|
|
259
270
|
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* An administrator takes a gateway over (Linus rulings 30, 117 §1 and §4, 121 §6 item 7, 166 point
|
|
274
|
+
* 1): the running controller reads the five tables the gateway's socket exports now, refuses unless
|
|
275
|
+
* they are exactly the tables of the dry run the administrator read (`exportDigests`: every area's
|
|
276
|
+
* `exportDigest`) and unless that dry run of them passes, then imports them byte for byte as its
|
|
277
|
+
* intent in one transaction that appends one `import` revision naming the administrator, and pushes
|
|
278
|
+
* them. The takeover changes no table the gateway serves, only their owner. A gateway is taken over
|
|
279
|
+
* once: a repeated request, after a lost answer too, is answered
|
|
280
|
+
* `{ ok: false, code: 'gateway-taken-over' }` and writes nothing; the takeover state answers who
|
|
281
|
+
* took it over and when. Which administrators may call it is the controller's decision.
|
|
282
|
+
*
|
|
283
|
+
* `exportDigests` answers, by what it holds:
|
|
284
|
+
* - not a list, or an entry that is not exactly `{ area, digest }` with a configuration area and a
|
|
285
|
+
* `sha256:` digest: the connector refusal `request-invalid`, thrown, never a report;
|
|
286
|
+
* - well-formed entries but not exactly one per configuration area (one missing, one twice), or one
|
|
287
|
+
* whose digest is not the table the gateway exports now:
|
|
288
|
+
* `{ ok: false, code: 'takeover-exports-moved' }`;
|
|
289
|
+
* - one entry per area, in any order: matched by `area`; the order is never a refusal.
|
|
290
|
+
*/
|
|
291
|
+
export interface IReq_Admin_Cloudly_TakeOverGateway extends plugins.typedrequestInterfaces.implementsTR<
|
|
292
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
293
|
+
IReq_Admin_Cloudly_TakeOverGateway
|
|
294
|
+
> {
|
|
295
|
+
method: 'takeOverGateway';
|
|
296
|
+
request: {
|
|
297
|
+
identity: IIdentityCredential;
|
|
298
|
+
gatewayId: string;
|
|
299
|
+
/** One per configuration area, matched by `area` (the order is free); five in all. */
|
|
300
|
+
exportDigests: IGatewayTakeoverExportDigest[];
|
|
301
|
+
};
|
|
302
|
+
response: {
|
|
303
|
+
report: TGatewayTakeoverReport;
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* An administrator exports the document the running controller pushes a gateway now (Linus ruling
|
|
309
|
+
* 162 point 6), so the operator can carry it to the gateway's host control socket
|
|
310
|
+
* (`dcrouter apply-desired-state --file`) when no session carries it: the controller's document as
|
|
311
|
+
* its push builds it, judged by `data.validateGatewayDesiredState` (a gateway that was not taken
|
|
312
|
+
* over is pushed no area). It reads only: no revision, table or claim is written, nothing is pushed
|
|
313
|
+
* and the gateway is not called, so it answers while the gateway is unreachable. A gateway the
|
|
314
|
+
* controller does not record is refused `gateway-not-found` (a connector refusal).
|
|
315
|
+
*
|
|
316
|
+
* Exclude bodies from logs: the document carries the tables' values, secrets included, in plain
|
|
317
|
+
* text. The caller writes it to an owner-only file and states only its tuple (gateway, controller,
|
|
318
|
+
* epoch, revision and per-area digests), which the gateway's apply line states too.
|
|
319
|
+
*/
|
|
320
|
+
export interface IReq_Admin_Cloudly_ExportGatewayDesiredState extends plugins.typedrequestInterfaces.implementsTR<
|
|
321
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
322
|
+
IReq_Admin_Cloudly_ExportGatewayDesiredState
|
|
323
|
+
> {
|
|
324
|
+
method: 'exportGatewayDesiredState';
|
|
325
|
+
request: {
|
|
326
|
+
identity: IIdentityCredential;
|
|
327
|
+
gatewayId: string;
|
|
328
|
+
};
|
|
329
|
+
response: {
|
|
330
|
+
desired: IGatewayDesiredState;
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* An administrator reads one area table of a taken-over gateway (Linus rulings 121 §6 item 7, 166
|
|
336
|
+
* point 4 and 171), all members or the one named: the table's revision and digest and, per row, its
|
|
337
|
+
* address, its compare token (`digest`, `data.computeGatewayAreaRowDigest`), whether the controller's
|
|
338
|
+
* records compile it (`owner`) and its write form with every secret as `keep` (a sealed member's
|
|
339
|
+
* version, never its value). It reads only and calls no gateway. The answer is
|
|
340
|
+
* `data.TGatewayAreaRowsReport`: the table, or `{ ok: false, code }` with `gateway-not-found` or
|
|
341
|
+
* `gateway-not-taken-over` (`data.gatewayAreaRowsRefusals`).
|
|
342
|
+
*
|
|
343
|
+
* Caller (Linus ruling 171 D6, the write's rule): a human administrator who signed in within the
|
|
344
|
+
* last five minutes, with neither a delegated admin temp token nor a machine identity. The
|
|
345
|
+
* controller judges it before it reads anything and refuses anyone else with a `TypedResponseError`
|
|
346
|
+
* naming the requirement, never a report. An area that is no configuration area, or a `member` the
|
|
347
|
+
* area does not have, is refused `request-invalid` (a connector refusal, thrown).
|
|
348
|
+
*/
|
|
349
|
+
export interface IReq_Admin_Cloudly_GetGatewayAreaRows extends plugins.typedrequestInterfaces.implementsTR<
|
|
350
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
351
|
+
IReq_Admin_Cloudly_GetGatewayAreaRows
|
|
352
|
+
> {
|
|
353
|
+
method: 'getGatewayAreaRows';
|
|
354
|
+
request: {
|
|
355
|
+
identity: IIdentityCredential;
|
|
356
|
+
gatewayId: string;
|
|
357
|
+
area: TGatewayConfigArea;
|
|
358
|
+
/** One member of the area; `null` for every member. */
|
|
359
|
+
member: TGatewayAreaMember | null;
|
|
360
|
+
};
|
|
361
|
+
response: {
|
|
362
|
+
report: TGatewayAreaRowsReport;
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* An administrator writes one row of a taken-over gateway's table with compare-and-swap (Linus
|
|
368
|
+
* rulings 121 §6 item 7, 166 point 4 and 171): put one row (or one singleton's value) or delete one
|
|
369
|
+
* list row, based on the row's `digest` as the administrator read it (`expectedDigest`; `null` for a
|
|
370
|
+
* list row that must be absent). The controller resolves the write form's secrets
|
|
371
|
+
* (`data.resolveGatewayAreaRowWrite`: a `keep` to the stored value, a `set` to a value under a
|
|
372
|
+
* version it mints), judges the resulting table with its area contract and the whole document, the
|
|
373
|
+
* lifeline of a routes change and the rows its own records compile, appends one `change` revision
|
|
374
|
+
* naming the administrator, and pushes the gateway, or leaves the revision to the gateway's next
|
|
375
|
+
* session. It never waits for the gateway and never depends on its session, so it answers while the
|
|
376
|
+
* gateway is away; the gateway list (`getGateways`) tells when it applied the revision. Nothing
|
|
377
|
+
* table-wide: a write never changes another row.
|
|
378
|
+
*
|
|
379
|
+
* Caller (Linus ruling 166 point 2): a human administrator who signed in within the last five
|
|
380
|
+
* minutes, with neither a delegated admin temp token nor a machine identity, judged again inside the
|
|
381
|
+
* write's transaction, so an authority that lapsed or changed meanwhile writes nothing. Anyone else
|
|
382
|
+
* is refused with a `TypedResponseError` naming the requirement before anything is read; a write
|
|
383
|
+
* `data.validateGatewayAreaRowWrite` refuses is the connector refusal `request-invalid`, thrown.
|
|
384
|
+
*
|
|
385
|
+
* The answer is `data.TGatewayAreaRowWriteReport`: what it changed (the revision, the row's and the
|
|
386
|
+
* table's digest, the versions it minted), or `{ ok: false, code, problems }` with one of
|
|
387
|
+
* `data.gatewayAreaRowWriteRefusals`, in the order its doc states, and the validator lines naming
|
|
388
|
+
* why. A put whose row equals the stored one, or a delete of an absent row, writes nothing and
|
|
389
|
+
* answers `revision: null` (judged after the gateway and `row-compile-owned`, before
|
|
390
|
+
* `expectedDigest`), so a repeat after a lost answer is safe; a put that sets a secret mints a new
|
|
391
|
+
* version each time, so its repeat is refused `intent-row-stale` (read the row: its versions tell
|
|
392
|
+
* whether the first one landed).
|
|
393
|
+
*
|
|
394
|
+
* Exclude bodies from logs: a `set` carries a secret value in plain text.
|
|
395
|
+
*/
|
|
396
|
+
export interface IReq_Admin_Cloudly_WriteGatewayAreaRow extends plugins.typedrequestInterfaces.implementsTR<
|
|
397
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
398
|
+
IReq_Admin_Cloudly_WriteGatewayAreaRow
|
|
399
|
+
> {
|
|
400
|
+
method: 'writeGatewayAreaRow';
|
|
401
|
+
request: {
|
|
402
|
+
identity: IIdentityCredential;
|
|
403
|
+
gatewayId: string;
|
|
404
|
+
write: TGatewayAreaRowWrite;
|
|
405
|
+
};
|
|
406
|
+
response: {
|
|
407
|
+
report: TGatewayAreaRowWriteReport;
|
|
408
|
+
};
|
|
409
|
+
}
|