@serve.zone/interfaces 32.92.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.
@@ -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
- const isRowId = (valueArg: unknown): valueArg is string => (
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 = isRowId(id)
764
+ const rowScope: IScope = isGatewayAreaRowId(id)
756
765
  ? { ...memberScope, rowId: id }
757
766
  : { ...memberScope, prefix: `[${indexArg}].` };
758
- if (!isRowId(id)) {
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: isRowId(id) ? id : null, prefix: '' }, pathArg, 'duplicate-key');
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) => isRowId(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: 'sealed' | 'verifier';
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 sealed = (memberArg: string, rowIdArg: string | null, pathArg: string,
2230
- valueArg: { version: string } | null): void => {
2231
- if (valueArg !== null) {
2232
- references.push({ area: areaArg, member: memberArg, rowId: rowIdArg, path: pathArg, secretClass: 'sealed',
2233
- version: valueArg.version });
2234
- }
2235
- };
2236
- const verifier = (memberArg: string, rowIdArg: string, pathArg: string): void => {
2237
- references.push({ area: areaArg, member: memberArg, rowId: rowIdArg, path: pathArg, secretClass: 'verifier',
2238
- version: null });
2239
- };
2240
- switch (areaArg) {
2241
- case 'security': {
2242
- const content = contentArg as TGatewayAreaContent<'security'>;
2243
- content.apiTokens.forEach((rowArg) => verifier('apiTokens', rowArg.id, 'credential'));
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;
@@ -15,14 +15,15 @@ import type { TSha256Digest } from './immutableimage.js';
15
15
  * Every reason the gateway intent refuses an operation: the controller's one vocabulary, which it
16
16
  * imports from here and keeps no copy of.
17
17
  *
18
- * The requests this package declares name only some of them: a dry run's `refusals` and the
18
+ * The requests this package declares cover the list between them: a dry run's `refusals` and the
19
19
  * report's `code` name `gateway-not-found`, `area-contract-missing`, `export-missing`,
20
20
  * `area-table-invalid`, `controller-origin-unserved`, `lifeline-unjudged` and
21
21
  * `compiled-table-invalid`; a takeover's report (`TGatewayTakeoverReport`) names those and
22
22
  * `gateway-not-adopted`, `gateway-areas-not-offered`, `gateway-taken-over`, `takeover-not-pure` and
23
- * `takeover-exports-moved`. The others are answered only by operations of the controller that this
24
- * package declares no request for (an operator's write of an area table, a recompile from the
25
- * controller's records).
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`.
26
27
  *
27
28
  * A reader of these answers shows a name it does not know as text and never refuses the answer for
28
29
  * it: they have no validator, and a controller built after the reader may name a newer reason.
@@ -58,6 +59,18 @@ export const gatewayIntentRefusals = Object.freeze([
58
59
  'lifeline-unjudged',
59
60
  /** The table moved past the revision the write was based on. */
60
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',
61
74
  /**
62
75
  * A compile from the controller's records cannot build a record's rows (the operation that wrote
63
76
  * that record fails, the rest compile), or builds a table it cannot place: one its area contract
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';
@@ -17,6 +17,12 @@ import type {
17
17
  TGatewayDryRunReport,
18
18
  TGatewayTakeoverReport,
19
19
  } from '../data/gatewayintent.js';
20
+ import type {
21
+ TGatewayAreaMember,
22
+ TGatewayAreaRowsReport,
23
+ TGatewayAreaRowWrite,
24
+ TGatewayAreaRowWriteReport,
25
+ } from '../data/gatewayarearows.js';
20
26
  import type { IGatewayRouteDnsResult } from '../data/gateway.js';
21
27
  import type { ILocationScope } from '../data/location.js';
22
28
  import type { IIdentityCredential } from '../data/user.js';
@@ -324,3 +330,80 @@ export interface IReq_Admin_Cloudly_ExportGatewayDesiredState extends plugins.ty
324
330
  desired: IGatewayDesiredState;
325
331
  };
326
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
+ }