@serve.zone/interfaces 32.92.0 → 32.94.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 +12 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/gatewayarearows.d.ts +369 -0
- package/dist_ts/data/gatewayarearows.js +335 -0
- package/dist_ts/data/gatewayareas.d.ts +41 -0
- package/dist_ts/data/gatewayareas.js +61 -1
- package/dist_ts/data/gatewayareas.validation.d.ts +5 -3
- package/dist_ts/data/gatewayareas.validation.js +35 -59
- package/dist_ts/data/gatewayconnector.d.ts +62 -4
- package/dist_ts/data/gatewayconnector.js +75 -4
- package/dist_ts/data/gatewayintent.d.ts +6 -5
- package/dist_ts/data/gatewayintent.js +18 -5
- package/dist_ts/data/index.d.ts +1 -0
- package/dist_ts/data/index.js +2 -1
- package/dist_ts/requests/gatewayconnector.d.ts +70 -0
- package/package.json +1 -1
- package/readme.md +62 -4
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/gatewayarearows.ts +680 -0
- package/ts/data/gatewayareas.ts +80 -0
- package/ts/data/gatewayareas.validation.ts +38 -63
- package/ts/data/gatewayconnector.ts +146 -4
- package/ts/data/gatewayintent.ts +17 -4
- package/ts/data/index.ts +1 -0
- package/ts/requests/gatewayconnector.ts +83 -0
package/ts/data/gatewayareas.ts
CHANGED
|
@@ -141,6 +141,19 @@ export const gatewayAreaContentContract = Object.freeze({
|
|
|
141
141
|
}),
|
|
142
142
|
} as const);
|
|
143
143
|
|
|
144
|
+
const rowIdControlCharacter = /[\u0000-\u001f\u007f]/;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Whether a value is a row id of the area contents: a text of 1 to
|
|
148
|
+
* `gatewayAreaContentContract.maximumRowIdLength` UTF-16 code units without a control character. A
|
|
149
|
+
* member may narrow its own ids further (`invalid-row-id`); this is the rule every row id meets.
|
|
150
|
+
*/
|
|
151
|
+
export const isGatewayAreaRowId = (valueArg: unknown): valueArg is string => (
|
|
152
|
+
typeof valueArg === 'string' && valueArg.length > 0
|
|
153
|
+
&& valueArg.length <= gatewayAreaContentContract.maximumRowIdLength
|
|
154
|
+
&& !rowIdControlCharacter.test(valueArg)
|
|
155
|
+
);
|
|
156
|
+
|
|
144
157
|
/**
|
|
145
158
|
* The API token scopes a gateway (dcrouter) knows, in its own order: the vocabulary a controller
|
|
146
159
|
* mints from. A table carries any scope of the scope syntax (`isGatewayApiTokenScope`), and a scope
|
|
@@ -1131,6 +1144,73 @@ export const gatewayAreaMembers = Object.freeze({
|
|
|
1131
1144
|
edges: Object.freeze(['hub', 'edges'] as const),
|
|
1132
1145
|
} as const);
|
|
1133
1146
|
|
|
1147
|
+
/**
|
|
1148
|
+
* The members of each area that hold one value rather than rows (an object or `null`, never a list),
|
|
1149
|
+
* addressed with `id: null`: the singletons of `gatewayAreaMembers`.
|
|
1150
|
+
*/
|
|
1151
|
+
export const gatewayAreaSingletonMembers = Object.freeze({
|
|
1152
|
+
security: Object.freeze(['proxyPolicy'] as const),
|
|
1153
|
+
dns: Object.freeze(['server', 'acme'] as const),
|
|
1154
|
+
routes: Object.freeze(['http3'] as const),
|
|
1155
|
+
mail: Object.freeze(['server'] as const),
|
|
1156
|
+
edges: Object.freeze(['hub'] as const),
|
|
1157
|
+
} as const);
|
|
1158
|
+
|
|
1159
|
+
/** The secret classes of the area contents: a sealed value (`IGatewaySealedValue`) or a verifier. */
|
|
1160
|
+
export type TGatewayAreaSecretClass = 'sealed' | 'verifier';
|
|
1161
|
+
|
|
1162
|
+
/** Where one secret-class member of a member's rows (or of a singleton) is, and its class. */
|
|
1163
|
+
export interface IGatewayAreaSecretPath {
|
|
1164
|
+
/** The dotted key path inside the row or singleton. */
|
|
1165
|
+
path: string;
|
|
1166
|
+
secretClass: TGatewayAreaSecretClass;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
/**
|
|
1170
|
+
* Every secret-class member of the area contents, by area and member, each member's paths in the
|
|
1171
|
+
* order `listGatewayAreaSecrets` lists them (Linus ruling 171 section 4): the one list of where a
|
|
1172
|
+
* table holds a secret. `listGatewayAreaSecrets` is computed from it, and the operator row read and
|
|
1173
|
+
* write walk it (`projectGatewayAreaRow`, `resolveGatewayAreaRowWrite`,
|
|
1174
|
+
* `computeGatewayAreaRowDigest`, `validateGatewayAreaRowWrite`), so the secrets a controller seals,
|
|
1175
|
+
* the ones a row read hides and the ones a row token takes by version only are the same. A member not
|
|
1176
|
+
* named holds no secret. A sealed member holds no secret when it is `null`, a verifier when it is
|
|
1177
|
+
* `null` or an empty list (a CoreMail peer without credentials). A secret member added to an area
|
|
1178
|
+
* type goes in here and into its row write type (`IGatewayAreaRowWrites`).
|
|
1179
|
+
*/
|
|
1180
|
+
export const gatewayAreaSecretPaths: {
|
|
1181
|
+
readonly [TArea in TGatewayConfigArea]: {
|
|
1182
|
+
readonly [TMember in keyof IGatewayAreaContents[TArea]]?: readonly IGatewayAreaSecretPath[];
|
|
1183
|
+
};
|
|
1184
|
+
} = Object.freeze({
|
|
1185
|
+
security: Object.freeze({
|
|
1186
|
+
apiTokens: Object.freeze([Object.freeze({ path: 'credential', secretClass: 'verifier' as const })]),
|
|
1187
|
+
}),
|
|
1188
|
+
dns: Object.freeze({
|
|
1189
|
+
providers: Object.freeze([Object.freeze({ path: 'credentials.apiToken', secretClass: 'sealed' as const })]),
|
|
1190
|
+
}),
|
|
1191
|
+
routes: Object.freeze({
|
|
1192
|
+
routes: Object.freeze([
|
|
1193
|
+
Object.freeze({ path: 'secrets.tlsKey', secretClass: 'sealed' as const }),
|
|
1194
|
+
Object.freeze({ path: 'secrets.basicAuthUsers', secretClass: 'sealed' as const }),
|
|
1195
|
+
Object.freeze({ path: 'secrets.jwtSecret', secretClass: 'sealed' as const }),
|
|
1196
|
+
Object.freeze({ path: 'secrets.requestHeaders', secretClass: 'sealed' as const }),
|
|
1197
|
+
]),
|
|
1198
|
+
sourceProfiles: Object.freeze([
|
|
1199
|
+
Object.freeze({ path: 'secrets.basicAuthUsers', secretClass: 'sealed' as const }),
|
|
1200
|
+
Object.freeze({ path: 'secrets.jwtSecret', secretClass: 'sealed' as const }),
|
|
1201
|
+
]),
|
|
1202
|
+
}),
|
|
1203
|
+
mail: Object.freeze({
|
|
1204
|
+
server: Object.freeze([Object.freeze({ path: 'tlsKey', secretClass: 'sealed' as const })]),
|
|
1205
|
+
smtpAccounts: Object.freeze([Object.freeze({ path: 'credential', secretClass: 'verifier' as const })]),
|
|
1206
|
+
identities: Object.freeze([Object.freeze({ path: 'credential', secretClass: 'verifier' as const })]),
|
|
1207
|
+
coreMailPeers: Object.freeze([Object.freeze({ path: 'credentials', secretClass: 'verifier' as const })]),
|
|
1208
|
+
}),
|
|
1209
|
+
edges: Object.freeze({
|
|
1210
|
+
edges: Object.freeze([Object.freeze({ path: 'secret', secretClass: 'sealed' as const })]),
|
|
1211
|
+
}),
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1134
1214
|
/**
|
|
1135
1215
|
* The closed key vocabulary refused inside every engine configuration (a route's `route`, a source
|
|
1136
1216
|
* 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,13 @@ import {
|
|
|
40
41
|
gatewayMailIdentityScramIterations,
|
|
41
42
|
gatewayRoutePathClasses,
|
|
42
43
|
isGatewayApiTokenScope,
|
|
44
|
+
isGatewayAreaRowId,
|
|
45
|
+
type IGatewayAreaSecretPath,
|
|
43
46
|
type IGatewayDnsStaticRecordRow,
|
|
44
47
|
type IGatewayScramVerifier,
|
|
48
|
+
type IGatewaySealedValue,
|
|
45
49
|
type TGatewayAreaContent,
|
|
50
|
+
type TGatewayAreaSecretClass,
|
|
46
51
|
type TGatewayRoutePortEntry,
|
|
47
52
|
type TGatewayRoutePortsInput,
|
|
48
53
|
} from './gatewayareas.js';
|
|
@@ -318,11 +323,6 @@ const zoneLabel = /^[a-z0-9_](?:[a-z0-9_-]{0,61}[a-z0-9])?$/;
|
|
|
318
323
|
const portKey = /^[1-9][0-9]{0,4}$/;
|
|
319
324
|
const clientTypes = ['onebox', 'cloudly', 'custom'] as const;
|
|
320
325
|
|
|
321
|
-
const isRowId = (valueArg: unknown): valueArg is string => (
|
|
322
|
-
typeof valueArg === 'string' && valueArg.length > 0 && valueArg.length <= contract.maximumRowIdLength
|
|
323
|
-
&& !controlCharacter.test(valueArg)
|
|
324
|
-
);
|
|
325
|
-
|
|
326
326
|
const isZoneName = (valueArg: unknown): valueArg is string => (
|
|
327
327
|
typeof valueArg === 'string' && valueArg.length > 0 && valueArg.length <= 253
|
|
328
328
|
&& valueArg.split('.').every((labelArg) => zoneLabel.test(labelArg))
|
|
@@ -752,10 +752,10 @@ const rowList = (
|
|
|
752
752
|
let previous: string | null = null;
|
|
753
753
|
rows.forEach((rowArg, indexArg) => {
|
|
754
754
|
const id = readDataProperty(rowArg, 'id')?.value;
|
|
755
|
-
const rowScope: IScope =
|
|
755
|
+
const rowScope: IScope = isGatewayAreaRowId(id)
|
|
756
756
|
? { ...memberScope, rowId: id }
|
|
757
757
|
: { ...memberScope, prefix: `[${indexArg}].` };
|
|
758
|
-
if (!
|
|
758
|
+
if (!isGatewayAreaRowId(id)) {
|
|
759
759
|
refuse(rowScope, 'id', 'invalid-row-id');
|
|
760
760
|
} else {
|
|
761
761
|
if (previous !== null && compareWireTokens(previous, id) >= 0) {
|
|
@@ -824,7 +824,7 @@ const checkUniqueKey = (scopeArg: IScope, memberArg: string, rowsArg: unknown, k
|
|
|
824
824
|
}
|
|
825
825
|
if (seen.has(key)) {
|
|
826
826
|
const id = readDataProperty(rowArg, 'id')?.value;
|
|
827
|
-
refuse({ ...scopeArg, member: memberArg, rowId:
|
|
827
|
+
refuse({ ...scopeArg, member: memberArg, rowId: isGatewayAreaRowId(id) ? id : null, prefix: '' }, pathArg, 'duplicate-key');
|
|
828
828
|
}
|
|
829
829
|
seen.add(key);
|
|
830
830
|
});
|
|
@@ -1568,7 +1568,7 @@ const validateRoutes = (scopeArg: IScope, contentArg: Record<string, unknown>):
|
|
|
1568
1568
|
}), 'targets', 'set-not-ascending');
|
|
1569
1569
|
}
|
|
1570
1570
|
}
|
|
1571
|
-
checkTextSet(rowScopeArg, row.routeRefs, 'routeRefs', (entryArg) =>
|
|
1571
|
+
checkTextSet(rowScopeArg, row.routeRefs, 'routeRefs', (entryArg) => isGatewayAreaRowId(entryArg));
|
|
1572
1572
|
checkBoolean(rowScopeArg, row.allowRoutesByClientSourceIp, 'allowRoutesByClientSourceIp');
|
|
1573
1573
|
});
|
|
1574
1574
|
checkUniqueKey(scopeArg, 'targetProfiles', contentArg.targetProfiles, (rowArg) => field(rowArg, 'name'), 'name');
|
|
@@ -2212,73 +2212,48 @@ export interface IGatewayAreaSecretReference {
|
|
|
2212
2212
|
rowId: string | null;
|
|
2213
2213
|
/** The key path inside the row or singleton. */
|
|
2214
2214
|
path: string;
|
|
2215
|
-
secretClass:
|
|
2215
|
+
secretClass: TGatewayAreaSecretClass;
|
|
2216
2216
|
/** The sealed version; `null` for a verifier. */
|
|
2217
2217
|
version: string | null;
|
|
2218
2218
|
}
|
|
2219
2219
|
|
|
2220
|
+
/** The value at a dotted key path inside a row or singleton of a valid content; `null` where none is. */
|
|
2221
|
+
const readSecretAt = (rowArg: unknown, pathArg: string): unknown => {
|
|
2222
|
+
let current: unknown = rowArg;
|
|
2223
|
+
for (const key of pathArg.split('.')) {
|
|
2224
|
+
if (!isPlainRecord(current)) return null;
|
|
2225
|
+
current = current[key] ?? null;
|
|
2226
|
+
}
|
|
2227
|
+
return current;
|
|
2228
|
+
};
|
|
2229
|
+
|
|
2220
2230
|
/**
|
|
2221
2231
|
* 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.
|
|
2232
|
+
* revisions and diffs name by version instead of by value. Computed from `gatewayAreaSecretPaths`:
|
|
2233
|
+
* member by member in its order, row by row in table order, path by path in its order; a sealed
|
|
2234
|
+
* member stated `null` and a verifier stated `null` or as an empty list hold no secret.
|
|
2223
2235
|
*/
|
|
2224
2236
|
export const listGatewayAreaSecrets = <TArea extends TGatewayConfigArea>(
|
|
2225
2237
|
areaArg: TArea,
|
|
2226
2238
|
contentArg: TGatewayAreaContent<TArea>,
|
|
2227
2239
|
): IGatewayAreaSecretReference[] => {
|
|
2228
2240
|
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
|
-
}
|
|
2241
|
+
const content = contentArg as unknown as Record<string, unknown>;
|
|
2242
|
+
const members = Object.entries(gatewayAreaSecretPaths[areaArg]) as [string, readonly IGatewayAreaSecretPath[]][];
|
|
2243
|
+
for (const [member, paths] of members) {
|
|
2244
|
+
const value = content[member];
|
|
2245
|
+
const rows = Array.isArray(value)
|
|
2246
|
+
? value.map((rowArg: { id: string }) => ({ rowId: rowArg.id as string | null, row: rowArg as unknown }))
|
|
2247
|
+
: [{ rowId: null, row: value }];
|
|
2248
|
+
for (const { rowId, row } of rows) {
|
|
2249
|
+
for (const { path, secretClass } of paths) {
|
|
2250
|
+
const held = readSecretAt(row, path);
|
|
2251
|
+
if (held === null || (Array.isArray(held) && held.length === 0)) continue;
|
|
2252
|
+
references.push({
|
|
2253
|
+
area: areaArg, member, rowId, path, secretClass,
|
|
2254
|
+
version: secretClass === 'sealed' ? (held as IGatewaySealedValue).version : null,
|
|
2255
|
+
});
|
|
2258
2256
|
}
|
|
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
2257
|
}
|
|
2283
2258
|
}
|
|
2284
2259
|
return references;
|
|
@@ -9,7 +9,13 @@ import {
|
|
|
9
9
|
validateControllerNonNegativeInteger,
|
|
10
10
|
validateControllerStrictJson,
|
|
11
11
|
} from '../private/controllercontract.js';
|
|
12
|
-
import {
|
|
12
|
+
import {
|
|
13
|
+
hasExactKeys,
|
|
14
|
+
readDataElements,
|
|
15
|
+
readDataProperties,
|
|
16
|
+
readDataProperty,
|
|
17
|
+
readExactDataRecord,
|
|
18
|
+
} from '../private/dataproperties.js';
|
|
13
19
|
import { ipv4PrefixOfMapped, parseCanonicalIpAddress } from '../private/ipaddress.js';
|
|
14
20
|
import type { TCompleteKeyList } from '../private/keylist.js';
|
|
15
21
|
import { networkDigest } from '../private/networkcontract.js';
|
|
@@ -18,6 +24,13 @@ import { isGatewayClientIdText } from '../private/gatewayclientid.js';
|
|
|
18
24
|
import { clusterIngressLimits, validateClusterRouteSourceAllowList } from './clusteringress.js';
|
|
19
25
|
import { validateGatewayRouteDnsResult } from './gateway.js';
|
|
20
26
|
import { type IControllerPeerSet, validateControllerPeerSet } from './controller.js';
|
|
27
|
+
import type { TGatewayAreaListMember } from './gatewayarearows.js';
|
|
28
|
+
import {
|
|
29
|
+
gatewayAreaContentContract,
|
|
30
|
+
gatewayAreaMembers,
|
|
31
|
+
gatewayAreaSingletonMembers,
|
|
32
|
+
isGatewayAreaRowId,
|
|
33
|
+
} from './gatewayareas.js';
|
|
21
34
|
import type { TSha256Digest } from './immutableimage.js';
|
|
22
35
|
import { isLocationName } from './location.js';
|
|
23
36
|
import { isReleaseVersion } from './releaseversion.js';
|
|
@@ -63,6 +76,16 @@ export const gatewayConnectorContract = Object.freeze({
|
|
|
63
76
|
maximumDnsZones: 1024,
|
|
64
77
|
maximumHostnameLength: 253,
|
|
65
78
|
maximumRefusalDetailLength: 1024,
|
|
79
|
+
/**
|
|
80
|
+
* Entries one area refusal names (`IGatewayAreaApplyRefusal.rows`). The report travels in the
|
|
81
|
+
* hello, every status push and every apply answer: at this bound, with row ids and reasons at
|
|
82
|
+
* theirs, five refusing areas add at most about 1.1 MiB, so a status document at every bound of
|
|
83
|
+
* this contract, every free-text member at its widest JSON character, stays below the 2 MiB message
|
|
84
|
+
* cap of the controller's socket server (Cloudly): 1,584,299 bytes (`test.gatewayapplyrefusalrows`).
|
|
85
|
+
*/
|
|
86
|
+
maximumRefusalRows: 256,
|
|
87
|
+
/** Characters of one refused row's reason (`IGatewayAreaApplyRefusedRow.reason`). */
|
|
88
|
+
maximumRefusalRowReasonLength: 64,
|
|
66
89
|
maximumStorageBackendLength: 64,
|
|
67
90
|
maximumStoragePathLength: 4096,
|
|
68
91
|
/** Hostnames per `getGatewayRouteDnsResults` request. */
|
|
@@ -502,6 +525,58 @@ export const isGatewayApplyRefusal = (valueArg: unknown): valueArg is TGatewayAp
|
|
|
502
525
|
(gatewayApplyRefusals as readonly unknown[]).includes(valueArg)
|
|
503
526
|
);
|
|
504
527
|
|
|
528
|
+
/**
|
|
529
|
+
* One row an area refusal names as data (`IGatewayAreaApplyRefusal.rows`, Linus ruling 212): the
|
|
530
|
+
* row's address in the refused table and why the gateway refuses it, never a value of the row.
|
|
531
|
+
*/
|
|
532
|
+
export interface IGatewayAreaApplyRefusedRow {
|
|
533
|
+
/** A list member of the refused area (`gatewayAreaMembers` without `gatewayAreaSingletonMembers`). */
|
|
534
|
+
member: TGatewayAreaListMember;
|
|
535
|
+
/** The row's `id` in that member (`isGatewayAreaRowId`), without an unpaired UTF-16 surrogate. */
|
|
536
|
+
id: string;
|
|
537
|
+
/**
|
|
538
|
+
* Why the gateway refuses the row: one or more words of lowercase ASCII letters joined by single
|
|
539
|
+
* hyphens, at most `gatewayConnectorContract.maximumRefusalRowReasonLength` characters, such as
|
|
540
|
+
* `no-managed-domain`. The words are the gateway's own; this package judges their form only, so a
|
|
541
|
+
* new word needs no release of it, and a reader shows a word it does not know as text. The form
|
|
542
|
+
* excludes digits, dots and every separator but the hyphen, so no address, count or dotted
|
|
543
|
+
* hostname fits, and a gateway never writes a hostname here.
|
|
544
|
+
*/
|
|
545
|
+
reason: string;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Why a gateway refused one area of a desired state it accepted as a whole.
|
|
550
|
+
*
|
|
551
|
+
* `rows` names the rows of the area's table the gateway refuses, as data (Linus ruling 212): 1 to
|
|
552
|
+
* `gatewayConnectorContract.maximumRefusalRows` entries, each `(member, id, reason)` once, in no
|
|
553
|
+
* particular order. A gateway names a row only when it judged that row; a gateway that could not
|
|
554
|
+
* judge names none (Linus ruling 216). When the gateway names no row the key is omitted: every
|
|
555
|
+
* refusal of a gateway built before the member, every refusal that is not about rows, and every
|
|
556
|
+
* refusal of a gateway that could not judge; `rows: undefined` and `rows: []` are refused. It adds
|
|
557
|
+
* to `detail` and replaces nothing: `reason` and `detail` keep their meaning, and the detail still
|
|
558
|
+
* states the findings as text. It is no promise that the table applies without the named rows: the
|
|
559
|
+
* detail can state further causes.
|
|
560
|
+
*
|
|
561
|
+
* Writer rule above the bound (Linus ruling 216): the bound counts entries, so a row with two
|
|
562
|
+
* reasons takes two. A gateway that refuses more entries than the bound names the first
|
|
563
|
+
* `maximumRefusalRows` in a fixed order (member order of `gatewayAreaMembers`, then row order of the
|
|
564
|
+
* pushed table, then reason), and its `detail` starts with the total count. The controller holds
|
|
565
|
+
* what is named and pushes again, so the rest arrives in the next refusal.
|
|
566
|
+
*
|
|
567
|
+
* Reader before writer: the refusal is exact-keys like the area state and the report, so a reader
|
|
568
|
+
* built before `rows` refuses the whole report that carries it (the apply answer, the hello and the
|
|
569
|
+
* status document). The gateway learns no version of its controller and cannot gate the member on
|
|
570
|
+
* it, so the controller moves to a release that reads `rows` before any gateway writes it, and
|
|
571
|
+
* neither side goes back below such a release once a report with rows is stored.
|
|
572
|
+
*/
|
|
573
|
+
export interface IGatewayAreaApplyRefusal {
|
|
574
|
+
reason: TGatewayApplyRefusal;
|
|
575
|
+
/** 1 to `gatewayConnectorContract.maximumRefusalDetailLength` characters. */
|
|
576
|
+
detail: string;
|
|
577
|
+
rows?: IGatewayAreaApplyRefusedRow[];
|
|
578
|
+
}
|
|
579
|
+
|
|
505
580
|
/** Where one area of one gateway stands after the last desired state it received. */
|
|
506
581
|
export interface IGatewayAreaApplyState {
|
|
507
582
|
area: TGatewayConfigArea;
|
|
@@ -517,7 +592,7 @@ export interface IGatewayAreaApplyState {
|
|
|
517
592
|
* owns that no document carried is `applied` with `revision: null`.
|
|
518
593
|
*/
|
|
519
594
|
state: 'applied' | 'rejected' | 'not-attempted';
|
|
520
|
-
refusal:
|
|
595
|
+
refusal: IGatewayAreaApplyRefusal | null;
|
|
521
596
|
}
|
|
522
597
|
|
|
523
598
|
/** What a gateway applied, as `applyDesiredState` answers and the status document carries it. */
|
|
@@ -670,6 +745,14 @@ const desiredStateKeys: TCompleteKeyList<IGatewayDesiredState, typeof desiredSta
|
|
|
670
745
|
const areaApplyStateKeyList = ['area', 'owner', 'digest', 'revision', 'state', 'refusal'] as const;
|
|
671
746
|
const areaApplyStateKeys: TCompleteKeyList<IGatewayAreaApplyState, typeof areaApplyStateKeyList> =
|
|
672
747
|
areaApplyStateKeyList;
|
|
748
|
+
const areaApplyRefusalKeyList = ['reason', 'detail', 'rows'] as const;
|
|
749
|
+
const areaApplyRefusalKeys: TCompleteKeyList<IGatewayAreaApplyRefusal, typeof areaApplyRefusalKeyList> =
|
|
750
|
+
areaApplyRefusalKeyList;
|
|
751
|
+
/** `rows` is optional: a refusal of a gateway built before it carries exactly these. */
|
|
752
|
+
const areaApplyRefusalRequiredKeys = ['reason', 'detail'] as const satisfies readonly (keyof IGatewayAreaApplyRefusal)[];
|
|
753
|
+
const areaApplyRefusedRowKeyList = ['member', 'id', 'reason'] as const;
|
|
754
|
+
const areaApplyRefusedRowKeys: TCompleteKeyList<IGatewayAreaApplyRefusedRow, typeof areaApplyRefusedRowKeyList> =
|
|
755
|
+
areaApplyRefusedRowKeyList;
|
|
673
756
|
const applyReportKeyList = ['epoch', 'appliedRevision', 'areas'] as const;
|
|
674
757
|
const applyReportKeys: TCompleteKeyList<IGatewayApplyReport, typeof applyReportKeyList> = applyReportKeyList;
|
|
675
758
|
const statusDocumentKeyList = [
|
|
@@ -832,6 +915,62 @@ export const validateGatewayDesiredState = (
|
|
|
832
915
|
];
|
|
833
916
|
};
|
|
834
917
|
|
|
918
|
+
const refusedRowReason = /^[a-z]+(?:-[a-z]+)*$/;
|
|
919
|
+
|
|
920
|
+
/** A member of the area's `gatewayAreaMembers` that holds rows, not one value. */
|
|
921
|
+
const isAreaListMember = (areaArg: TGatewayConfigArea, memberArg: unknown): boolean => (
|
|
922
|
+
typeof memberArg === 'string'
|
|
923
|
+
&& (gatewayAreaMembers[areaArg] as readonly string[]).includes(memberArg)
|
|
924
|
+
&& !(gatewayAreaSingletonMembers[areaArg] as readonly string[]).includes(memberArg)
|
|
925
|
+
);
|
|
926
|
+
|
|
927
|
+
/**
|
|
928
|
+
* The rows one area refusal names (`IGatewayAreaApplyRefusal.rows`): 1 to `maximumRefusalRows`
|
|
929
|
+
* entries of exactly `{ member, id, reason }`, each triple once. The member is judged against the
|
|
930
|
+
* refused area only when that area is one; an unknown area is refused by its own check.
|
|
931
|
+
*/
|
|
932
|
+
const validateRefusedRows = (valueArg: unknown, areaArg: unknown, pathArg: string): string[] => {
|
|
933
|
+
const { maximumRefusalRows, maximumRefusalRowReasonLength } = gatewayConnectorContract;
|
|
934
|
+
const rows = readDataElements(valueArg, maximumRefusalRows);
|
|
935
|
+
if (rows === null || rows.length === 0) {
|
|
936
|
+
return [`${pathArg} must be a dense list of 1 to ${maximumRefusalRows} rows`];
|
|
937
|
+
}
|
|
938
|
+
const errors: string[] = [];
|
|
939
|
+
const named = new Set<string>();
|
|
940
|
+
let repeated = false;
|
|
941
|
+
rows.forEach((rowArg, indexArg) => {
|
|
942
|
+
const path = `${pathArg}[${indexArg}]`;
|
|
943
|
+
const row = readExactDataRecord(rowArg, areaApplyRefusedRowKeys);
|
|
944
|
+
if (row === null) {
|
|
945
|
+
errors.push(`${path} must use its exact schema`);
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
if (isGatewayConfigArea(areaArg) && !isAreaListMember(areaArg, row.member)) {
|
|
949
|
+
errors.push(`${path} member must be a list member of the ${areaArg} area`);
|
|
950
|
+
}
|
|
951
|
+
// A row id of a table meets the table's strict-JSON check, which refuses an unpaired surrogate;
|
|
952
|
+
// the report does not run that check, so the id is held to it here (Linus ruling 216 point 3).
|
|
953
|
+
if (!isGatewayAreaRowId(row.id) || validateControllerStrictJson(row.id, `${path} id`).length > 0) {
|
|
954
|
+
errors.push(`${path} id must be a row id of 1 to ${gatewayAreaContentContract.maximumRowIdLength} characters `
|
|
955
|
+
+ 'without a control character or an unpaired UTF-16 surrogate');
|
|
956
|
+
}
|
|
957
|
+
if (typeof row.reason !== 'string' || row.reason.length > maximumRefusalRowReasonLength
|
|
958
|
+
|| !refusedRowReason.test(row.reason)) {
|
|
959
|
+
errors.push(`${path} reason must be lowercase letter words joined by single hyphens, at most `
|
|
960
|
+
+ `${maximumRefusalRowReasonLength} characters`);
|
|
961
|
+
}
|
|
962
|
+
if (typeof row.member === 'string' && typeof row.id === 'string' && typeof row.reason === 'string') {
|
|
963
|
+
const key = JSON.stringify([row.member, row.id, row.reason]);
|
|
964
|
+
repeated ||= named.has(key);
|
|
965
|
+
named.add(key);
|
|
966
|
+
}
|
|
967
|
+
});
|
|
968
|
+
if (repeated) {
|
|
969
|
+
errors.push(`${pathArg} must name each member, id and reason once`);
|
|
970
|
+
}
|
|
971
|
+
return errors;
|
|
972
|
+
};
|
|
973
|
+
|
|
835
974
|
const validateAreaApplyState = (valueArg: unknown, pathArg: string): string[] => {
|
|
836
975
|
const record = readExactDataRecord(valueArg, areaApplyStateKeys);
|
|
837
976
|
if (record === null) {
|
|
@@ -857,8 +996,8 @@ const validateAreaApplyState = (valueArg: unknown, pathArg: string): string[] =>
|
|
|
857
996
|
if (record.state === 'applied') {
|
|
858
997
|
errors.push(`${pathArg} refusal must be null for an applied area`);
|
|
859
998
|
}
|
|
860
|
-
const refusal =
|
|
861
|
-
if (refusal === null) {
|
|
999
|
+
const refusal = readDataProperties(record.refusal);
|
|
1000
|
+
if (refusal === null || !hasExactKeys(refusal, areaApplyRefusalRequiredKeys, areaApplyRefusalKeys)) {
|
|
862
1001
|
errors.push(`${pathArg} refusal must be null or use its exact schema`);
|
|
863
1002
|
return errors;
|
|
864
1003
|
}
|
|
@@ -867,6 +1006,9 @@ const validateAreaApplyState = (valueArg: unknown, pathArg: string): string[] =>
|
|
|
867
1006
|
}
|
|
868
1007
|
errors.push(...validateBoundedString(refusal.detail, `${pathArg} refusal detail`,
|
|
869
1008
|
gatewayConnectorContract.maximumRefusalDetailLength));
|
|
1009
|
+
if (Object.hasOwn(refusal, 'rows')) {
|
|
1010
|
+
errors.push(...validateRefusedRows(refusal.rows, record.area, `${pathArg} refusal rows`));
|
|
1011
|
+
}
|
|
870
1012
|
return errors;
|
|
871
1013
|
};
|
|
872
1014
|
|
package/ts/data/gatewayintent.ts
CHANGED
|
@@ -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
|
|
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
|
|
24
|
-
*
|
|
25
|
-
* controller
|
|
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
|
+
}
|