@serve.zone/interfaces 32.113.0 → 32.115.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 +22 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/backup/index.d.ts +2 -0
- package/dist_ts/data/backup/index.js +3 -0
- package/dist_ts/data/coremail/index.d.ts +2 -0
- package/dist_ts/data/coremail/index.js +3 -0
- package/dist_ts/data/corestorereplication.d.ts +90 -0
- package/dist_ts/data/corestorereplication.js +129 -0
- package/dist_ts/data/dcstorage.d.ts +206 -0
- package/dist_ts/data/dcstorage.js +322 -0
- package/dist_ts/data/delegatedadmintoken.d.ts +4 -2
- package/dist_ts/data/delegatedadmintoken.js +9 -3
- package/dist_ts/data/gateway.d.ts +15 -0
- package/dist_ts/data/gateway.js +6 -2
- package/dist_ts/data/gatewayarearows.d.ts +17 -11
- package/dist_ts/data/gatewayarearows.js +27 -11
- package/dist_ts/data/gatewayareas.d.ts +12 -2
- package/dist_ts/data/gatewayareas.js +5 -2
- package/dist_ts/data/gatewayareas.validation.js +11 -5
- package/dist_ts/data/index.d.ts +3 -0
- package/dist_ts/data/index.js +4 -1
- package/dist_ts/data/preparedimages.d.ts +80 -0
- package/dist_ts/data/preparedimages.js +154 -0
- package/dist_ts/index.d.ts +8 -2
- package/dist_ts/index.js +9 -3
- package/dist_ts/requests/backup.d.ts +1 -1
- package/dist_ts/requests/backup.js +2 -2
- package/dist_ts/requests/corestore.d.ts +1 -1
- package/dist_ts/requests/corestore.js +1 -2
- package/dist_ts/requests/corestorereplication.d.ts +108 -0
- package/dist_ts/requests/corestorereplication.js +2 -0
- package/dist_ts/requests/dcstorage.d.ts +204 -0
- package/dist_ts/requests/dcstorage.js +2 -0
- package/dist_ts/requests/gateway.d.ts +1 -1
- package/dist_ts/requests/gateway.js +2 -2
- package/dist_ts/requests/gatewaycertificatestore.d.ts +208 -0
- package/dist_ts/requests/gatewaycertificatestore.js +240 -0
- package/dist_ts/requests/gatewayconnector.d.ts +1 -1
- package/dist_ts/requests/gatewayconnector.js +2 -2
- package/dist_ts/requests/gatewayhealth.d.ts +65 -0
- package/dist_ts/requests/gatewayhealth.js +72 -0
- package/dist_ts/requests/gatewayremoteingress.d.ts +10 -2
- package/dist_ts/requests/gatewayremoteingress.js +7 -2
- package/dist_ts/requests/index.d.ts +5 -0
- package/dist_ts/requests/index.js +6 -1
- package/dist_ts/requests/mail.d.ts +1 -1
- package/dist_ts/requests/mail.js +2 -2
- package/dist_ts/requests/preparedimages.d.ts +24 -0
- package/dist_ts/requests/preparedimages.js +2 -0
- package/package.json +105 -1
- package/readme.md +96 -9
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/backup/index.ts +2 -0
- package/ts/data/coremail/index.ts +2 -0
- package/ts/data/corestorereplication.ts +223 -0
- package/ts/data/dcstorage.ts +505 -0
- package/ts/data/delegatedadmintoken.ts +9 -3
- package/ts/data/gateway.ts +20 -1
- package/ts/data/gatewayarearows.ts +32 -13
- package/ts/data/gatewayareas.ts +15 -3
- package/ts/data/gatewayareas.validation.ts +10 -4
- package/ts/data/index.ts +3 -0
- package/ts/data/preparedimages.ts +231 -0
- package/ts/index.ts +9 -2
- package/ts/requests/backup.ts +1 -1
- package/ts/requests/corestore.ts +1 -1
- package/ts/requests/corestorereplication.ts +123 -0
- package/ts/requests/dcstorage.ts +208 -0
- package/ts/requests/gateway.ts +1 -1
- package/ts/requests/gatewaycertificatestore.ts +411 -0
- package/ts/requests/gatewayconnector.ts +1 -1
- package/ts/requests/gatewayhealth.ts +135 -0
- package/ts/requests/gatewayremoteingress.ts +15 -3
- package/ts/requests/index.ts +5 -0
- package/ts/requests/mail.ts +1 -1
- package/ts/requests/preparedimages.ts +39 -0
|
@@ -152,11 +152,15 @@ export interface IGatewayCoreMailPeerRowWrite extends Omit<IGatewayCoreMailPeerR
|
|
|
152
152
|
credentials: TGatewayVerifierWrite<IGatewayCoreMailCredentialVerifier[]>;
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
/** `IGatewayEdgeRow` with its tunnel
|
|
156
|
-
export interface IGatewayEdgeRowWrite extends Omit<IGatewayEdgeRow, 'secret'> {
|
|
155
|
+
/** `IGatewayEdgeRow` with its tunnel secrets as keep-or-set choices. */
|
|
156
|
+
export interface IGatewayEdgeRowWrite extends Omit<IGatewayEdgeRow, 'secret' | 'stagedSecret'> {
|
|
157
157
|
secret: TGatewaySealedValueWrite;
|
|
158
|
+
stagedSecret: TGatewaySealedValueWrite | null;
|
|
158
159
|
}
|
|
159
160
|
|
|
161
|
+
/** The row write form for an edge that still uses the pre-rotation table shape. */
|
|
162
|
+
export type TGatewayLegacyEdgeRowWrite = Omit<IGatewayEdgeRowWrite, 'stagedSecret'> & { stagedSecret?: never };
|
|
163
|
+
|
|
160
164
|
/**
|
|
161
165
|
* The write form of one row of every member, by area and member: a list member's row, or a
|
|
162
166
|
* singleton's value. A member without secrets writes its table type unchanged.
|
|
@@ -196,7 +200,7 @@ export interface IGatewayAreaRowWrites {
|
|
|
196
200
|
};
|
|
197
201
|
edges: {
|
|
198
202
|
hub: IGatewayEdgeHubSettings;
|
|
199
|
-
edges: IGatewayEdgeRowWrite;
|
|
203
|
+
edges: IGatewayEdgeRowWrite | TGatewayLegacyEdgeRowWrite;
|
|
200
204
|
};
|
|
201
205
|
}
|
|
202
206
|
|
|
@@ -304,6 +308,10 @@ const parentOf = (rowArg: unknown, keysArg: readonly string[]): { parent: Record
|
|
|
304
308
|
return isPlainRecord(current) && Object.hasOwn(current, key) ? { parent: current, key } : null;
|
|
305
309
|
};
|
|
306
310
|
|
|
311
|
+
/** The one secret path that may be absent, in a pre-rotation edges row. */
|
|
312
|
+
const allowsLegacySecretOmission = (areaArg: TGatewayConfigArea, memberArg: string, pathArg: string): boolean =>
|
|
313
|
+
areaArg === 'edges' && memberArg === 'edges' && pathArg === 'stagedSecret';
|
|
314
|
+
|
|
307
315
|
const failRowDigest = (reasonArg: string): never => {
|
|
308
316
|
throw new Error(`Gateway area row digest input rejected: ${reasonArg}.`);
|
|
309
317
|
};
|
|
@@ -316,8 +324,8 @@ const failRowDigest = (reasonArg: string): never => {
|
|
|
316
324
|
* moves with every change of the row, a secret's included, while a reader who holds every other
|
|
317
325
|
* input (the read answers the row and the versions) cannot test a guess at a sealed value against
|
|
318
326
|
* it. Throws, naming no value, for an unknown area or member, an `id` that is not `null` exactly
|
|
319
|
-
* for a singleton, and a row that is not strict JSON or lacks a sealed member or its version
|
|
320
|
-
*
|
|
327
|
+
* for a singleton, and a row that is not strict JSON or lacks a required sealed member or its version.
|
|
328
|
+
* Legacy edges rows have no `stagedSecret` member and retain their original digest input.
|
|
321
329
|
*/
|
|
322
330
|
export const createGatewayAreaRowDigestInput = (inputArg: {
|
|
323
331
|
area: TGatewayConfigArea;
|
|
@@ -331,7 +339,11 @@ export const createGatewayAreaRowDigestInput = (inputArg: {
|
|
|
331
339
|
const row = (copyStrictJson(inputArg.row) ?? failRowDigest(`the ${area} ${member} row is not strict JSON`)).value;
|
|
332
340
|
for (const secret of secretPathsOf(area, member)) {
|
|
333
341
|
if (secret.secretClass !== 'sealed') continue;
|
|
334
|
-
const place = parentOf(row, splitPath(secret.path))
|
|
342
|
+
const place = parentOf(row, splitPath(secret.path));
|
|
343
|
+
if (place === null) {
|
|
344
|
+
if (allowsLegacySecretOmission(area, member, secret.path)) continue;
|
|
345
|
+
return failRowDigest(`the ${area} ${member} row has no member ${secret.path}`);
|
|
346
|
+
}
|
|
335
347
|
const value = place.parent[place.key];
|
|
336
348
|
if (value === null) continue;
|
|
337
349
|
const version = isPlainRecord(value) ? value.version : undefined;
|
|
@@ -526,8 +538,8 @@ const rowWriteKeys = Object.freeze({
|
|
|
526
538
|
* deleted) and a row id (`isGatewayAreaRowId`) for a list member, a `sha256:` `expectedDigest`
|
|
527
539
|
* (`null` only for a put), and for a put a strict JSON row whose `id` is the address's (a list
|
|
528
540
|
* member) and whose every secret member (`gatewayAreaSecretPaths`) is `null` or one of its
|
|
529
|
-
* keep-or-set forms. A put of a `security` `apiTokens` row
|
|
530
|
-
* (`isGatewayClientBoundApiTokenPolicy`) is refused naming the row (Linus ruling 376
|
|
541
|
+
* keep-or-set forms. A legacy edges row omits `stagedSecret`. A put of a `security` `apiTokens` row
|
|
542
|
+
* whose policy binds a gateway client (`isGatewayClientBoundApiTokenPolicy`) is refused naming the row (Linus ruling 376
|
|
531
543
|
* item 6): the controller is the one author of the tables and compiles no gateway-client token, so
|
|
532
544
|
* such a write would vanish at the next compile and a gateway from dcrouter 35 refuses it. The
|
|
533
545
|
* content validator (`validateGatewayAreaContent`) keeps accepting the role, because it also judges
|
|
@@ -569,6 +581,7 @@ export const validateGatewayAreaRowWrite = (valueArg: unknown, pathArg = 'write'
|
|
|
569
581
|
}
|
|
570
582
|
for (const secret of secretPathsOf(area, member)) {
|
|
571
583
|
const place = parentOf(row, splitPath(secret.path));
|
|
584
|
+
if (place === null && allowsLegacySecretOmission(area, member, secret.path)) continue;
|
|
572
585
|
if (place === null || readSecretWriteForm(place.parent[place.key], secret.secretClass) === null) {
|
|
573
586
|
problems.push(`${pathArg} row ${secret.path} must be null or a ${secret.secretClass} keep-or-set form`);
|
|
574
587
|
}
|
|
@@ -583,8 +596,8 @@ export const validateGatewayAreaRowWrite = (valueArg: unknown, pathArg = 'write'
|
|
|
583
596
|
/**
|
|
584
597
|
* A stored row (or singleton value) of a valid table in its write form, every secret as `keep`: a
|
|
585
598
|
* sealed member as its version, a verifier as `{ kind: 'keep' }`, a `null` member as `null`. Throws
|
|
586
|
-
* for a row that is not strict JSON or lacks a secret member
|
|
587
|
-
*
|
|
599
|
+
* for a row that is not strict JSON or lacks a required secret member. Legacy edges rows still
|
|
600
|
+
* omit `stagedSecret` in the projection.
|
|
588
601
|
*/
|
|
589
602
|
export const projectGatewayAreaRow = <TArea extends TGatewayConfigArea, TMember extends TGatewayAreaMember<TArea>>(
|
|
590
603
|
areaArg: TArea, memberArg: TMember, storedArg: unknown,
|
|
@@ -594,7 +607,10 @@ export const projectGatewayAreaRow = <TArea extends TGatewayConfigArea, TMember
|
|
|
594
607
|
const row = copied.value;
|
|
595
608
|
for (const secret of secretPathsOf(areaArg, memberArg)) {
|
|
596
609
|
const place = parentOf(row, splitPath(secret.path));
|
|
597
|
-
if (place === null)
|
|
610
|
+
if (place === null) {
|
|
611
|
+
if (allowsLegacySecretOmission(areaArg, memberArg, secret.path)) continue;
|
|
612
|
+
throw new Error(`The stored ${areaArg} ${memberArg} row has no member ${secret.path}.`);
|
|
613
|
+
}
|
|
598
614
|
const value = place.parent[place.key];
|
|
599
615
|
if (value === null) continue;
|
|
600
616
|
if (secret.secretClass === 'verifier') {
|
|
@@ -629,8 +645,9 @@ export type TGatewayAreaRowResolution =
|
|
|
629
645
|
* none) into its stored form: a sealed `keep` becomes the stored `{ version, value }` at that path
|
|
630
646
|
* when the stored row holds that version there, a verifier `keep` the stored verifier when the row
|
|
631
647
|
* holds one; a sealed `set` becomes `{ version: mintVersionArg(), value }`, a verifier `set` the
|
|
632
|
-
* stated verifier; `null` stays `null`.
|
|
633
|
-
*
|
|
648
|
+
* stated verifier; `null` stays `null`. A legacy write can omit `stagedSecret` only when the stored
|
|
649
|
+
* row also omits it or the write creates a row. Every other member is copied as written. The area
|
|
650
|
+
* validator judges the resolved row as part of its table. Judges the forms with the rule
|
|
634
651
|
* `validateGatewayAreaRowWrite` applies and never reads a value into a refusal. The minted
|
|
635
652
|
* versions are answered ascending by path. `mintVersionArg` is the writer's
|
|
636
653
|
* (`createGatewaySealedVersion`).
|
|
@@ -650,6 +667,8 @@ export const resolveGatewayAreaRowWrite = (inputArg: {
|
|
|
650
667
|
for (const secret of secretPathsOf(inputArg.area, inputArg.member)) {
|
|
651
668
|
const keys = splitPath(secret.path);
|
|
652
669
|
const place = parentOf(row, keys);
|
|
670
|
+
if (place === null && allowsLegacySecretOmission(inputArg.area, inputArg.member, secret.path)
|
|
671
|
+
&& parentOf(inputArg.stored, keys) === null) continue;
|
|
653
672
|
const form = place === null ? null : readSecretWriteForm(place.parent[place.key], secret.secretClass);
|
|
654
673
|
if (place === null || form === null) {
|
|
655
674
|
refusals.push({ path: secret.path, code: 'invalid-write-form' });
|
package/ts/data/gatewayareas.ts
CHANGED
|
@@ -1078,8 +1078,14 @@ export interface IGatewayEdgeEgress {
|
|
|
1078
1078
|
export interface IGatewayEdgeRow {
|
|
1079
1079
|
id: string;
|
|
1080
1080
|
name: string;
|
|
1081
|
-
/** The edge's tunnel secret. */
|
|
1081
|
+
/** The edge's active tunnel secret. */
|
|
1082
1082
|
secret: IGatewaySealedValue;
|
|
1083
|
+
/**
|
|
1084
|
+
* The staged tunnel secret, or `null` when idle. Cloudly stages, commits and aborts rotation
|
|
1085
|
+
* with one edges-table `replaceIntent` write each. Send this member only to a gateway that
|
|
1086
|
+
* advertises `remoteIngress.stagedSecretRotation: true`, even when the value is `null`.
|
|
1087
|
+
*/
|
|
1088
|
+
stagedSecret: IGatewaySealedValue | null;
|
|
1083
1089
|
/** A set of manually listed TCP ports; derived ports are computed on the gateway. */
|
|
1084
1090
|
listenPorts: number[];
|
|
1085
1091
|
/** A set of manually listed UDP ports (the gateway reads absent as empty). */
|
|
@@ -1099,6 +1105,9 @@ export interface IGatewayEdgeRow {
|
|
|
1099
1105
|
mailHostname: string | null;
|
|
1100
1106
|
}
|
|
1101
1107
|
|
|
1108
|
+
/** The exact edges row used before the gateway advertises staged secret rotation. */
|
|
1109
|
+
export type TGatewayLegacyEdgeRow = Omit<IGatewayEdgeRow, 'stagedSecret'> & { stagedSecret?: never };
|
|
1110
|
+
|
|
1102
1111
|
/** The tunnel hub singleton, without its listener port and TLS files. */
|
|
1103
1112
|
export interface IGatewayEdgeHubSettings {
|
|
1104
1113
|
enabled: boolean;
|
|
@@ -1114,7 +1123,7 @@ export interface IGatewayEdgesArea {
|
|
|
1114
1123
|
* that is off is `enabled: false`, with `hubDomain` and `performance` `null` when it has none.
|
|
1115
1124
|
*/
|
|
1116
1125
|
hub: IGatewayEdgeHubSettings;
|
|
1117
|
-
edges: IGatewayEdgeRow[];
|
|
1126
|
+
edges: (IGatewayEdgeRow | TGatewayLegacyEdgeRow)[];
|
|
1118
1127
|
}
|
|
1119
1128
|
|
|
1120
1129
|
// ---------------------------------------------------------------------------------------------
|
|
@@ -1210,7 +1219,10 @@ export const gatewayAreaSecretPaths: {
|
|
|
1210
1219
|
coreMailPeers: Object.freeze([Object.freeze({ path: 'credentials', secretClass: 'verifier' as const })]),
|
|
1211
1220
|
}),
|
|
1212
1221
|
edges: Object.freeze({
|
|
1213
|
-
edges: Object.freeze([
|
|
1222
|
+
edges: Object.freeze([
|
|
1223
|
+
Object.freeze({ path: 'secret', secretClass: 'sealed' as const }),
|
|
1224
|
+
Object.freeze({ path: 'stagedSecret', secretClass: 'sealed' as const }),
|
|
1225
|
+
]),
|
|
1214
1226
|
}),
|
|
1215
1227
|
});
|
|
1216
1228
|
|
|
@@ -2089,6 +2089,12 @@ const checkEgress = (scopeArg: IScope, valueArg: unknown): void => {
|
|
|
2089
2089
|
'maxConcurrentStreams');
|
|
2090
2090
|
};
|
|
2091
2091
|
|
|
2092
|
+
const edgeRowKeys = [
|
|
2093
|
+
'id', 'name', 'secret', 'listenPorts', 'listenPortsUdp', 'enabled', 'autoDerivePorts', 'performance', 'egress',
|
|
2094
|
+
'tags', 'publicIp', 'publicIpv6', 'mailHostname',
|
|
2095
|
+
] as const;
|
|
2096
|
+
const stagedEdgeRowKeys = [...edgeRowKeys, 'stagedSecret'] as const;
|
|
2097
|
+
|
|
2092
2098
|
const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): void => {
|
|
2093
2099
|
// The hub is always stated (ruling 125, Q-b5): a hub that is off is `enabled: false`, never `null`.
|
|
2094
2100
|
requiredSingleton(scopeArg, 'hub', contentArg.hub, (memberScopeArg, valueArg) => {
|
|
@@ -2103,15 +2109,15 @@ const validateEdges = (scopeArg: IScope, contentArg: Record<string, unknown>): v
|
|
|
2103
2109
|
}
|
|
2104
2110
|
});
|
|
2105
2111
|
rowList(scopeArg, 'edges', contentArg.edges, contract.maximumRows.edges.edges, (rowScopeArg, rowArg) => {
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
], null);
|
|
2112
|
+
// Validate both exact wire forms. The controller chooses the form using the peer's capability.
|
|
2113
|
+
const hasStagedSecret = isPlainRecord(rowArg) && Object.hasOwn(rowArg, 'stagedSecret');
|
|
2114
|
+
const row = exact(rowScopeArg, rowArg, hasStagedSecret ? stagedEdgeRowKeys : edgeRowKeys, null);
|
|
2110
2115
|
if (row === null) {
|
|
2111
2116
|
return;
|
|
2112
2117
|
}
|
|
2113
2118
|
checkText(rowScopeArg, row.name, 'name');
|
|
2114
2119
|
checkSealed(rowScopeArg, row.secret, 'secret');
|
|
2120
|
+
if (hasStagedSecret) checkNullableSealed(rowScopeArg, row.stagedSecret, 'stagedSecret');
|
|
2115
2121
|
checkPortSet(rowScopeArg, row.listenPorts, 'listenPorts');
|
|
2116
2122
|
checkPortSet(rowScopeArg, row.listenPortsUdp, 'listenPortsUdp');
|
|
2117
2123
|
checkBoolean(rowScopeArg, row.enabled, 'enabled');
|
package/ts/data/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './controller.js';
|
|
|
11
11
|
export * from './corestore.js';
|
|
12
12
|
export * from './corestorecontroltoken.js';
|
|
13
13
|
export * from './corestorelegacyadoption.js';
|
|
14
|
+
export * from './corestorereplication.js';
|
|
14
15
|
export * from './delegatedadmintoken.js';
|
|
15
16
|
export * from './coremail.js';
|
|
16
17
|
export * from './coremail.runtime.js';
|
|
@@ -68,6 +69,7 @@ export { runtimeNetworkProjectionRetirementContract, snapshotRuntimeNetworkProje
|
|
|
68
69
|
export * from './networkprotection.js';
|
|
69
70
|
export * from './networksigning.js';
|
|
70
71
|
export * from './privatenetwork.js';
|
|
72
|
+
export * from './preparedimages.js';
|
|
71
73
|
export * from './registry.js';
|
|
72
74
|
export * from './releaseversion.js';
|
|
73
75
|
export * from './runtimeassignment.js';
|
|
@@ -111,3 +113,4 @@ export * from './version.js';
|
|
|
111
113
|
export * from './webpush.js';
|
|
112
114
|
export * from './witness.js';
|
|
113
115
|
export * from './workloadreplicaidentity.js';
|
|
116
|
+
export * from './dcstorage.js';
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { readDataElements, readExactDataRecord } from '../private/dataproperties.js';
|
|
2
|
+
import { isSha256Digest } from './immutableimage.js';
|
|
3
|
+
import type { IRuntimeSessionBinding } from './runtimesession.js';
|
|
4
|
+
|
|
5
|
+
export interface IPreparedImageEntry {
|
|
6
|
+
/** The digest-pinned registry reference. Its pin may name an index, distinct from the manifest. */
|
|
7
|
+
imageReference: string;
|
|
8
|
+
/** The config digest is Pallet's pull key and the list's sort key. */
|
|
9
|
+
imageConfigDigest: string;
|
|
10
|
+
manifestDigest: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** The controller's whole desired list for one node, separate from assignment state. */
|
|
14
|
+
export interface IPreparedImageList {
|
|
15
|
+
/** Positive safe integer, kept monotone across controller takeovers. */
|
|
16
|
+
revision: number;
|
|
17
|
+
/** Canonical order is ascending by config digest, each digest appearing once. */
|
|
18
|
+
images: IPreparedImageEntry[];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const preparedImageBounds = Object.freeze({
|
|
22
|
+
maximumImages: 64,
|
|
23
|
+
maximumRepositoryBytes: 509,
|
|
24
|
+
maximumRegistryUsernameBytes: 4096,
|
|
25
|
+
maximumRegistryPasswordBytes: 8192,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export type TPreparedImageAdmission = 'accepted' | 'replay' | 'historical';
|
|
29
|
+
|
|
30
|
+
export interface ISyncPreparedImagesRequest {
|
|
31
|
+
session: IRuntimeSessionBinding;
|
|
32
|
+
list: IPreparedImageList;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ISyncPreparedImagesResponse {
|
|
36
|
+
status: TPreparedImageAdmission;
|
|
37
|
+
/** The list the node holds after admission. Admission does not establish image presence. */
|
|
38
|
+
list: IPreparedImageList;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export const preparedImageStates = ['present', 'pulling', 'failed'] as const;
|
|
42
|
+
export type TPreparedImageState = typeof preparedImageStates[number];
|
|
43
|
+
|
|
44
|
+
export interface IPreparedImageStatus {
|
|
45
|
+
imageConfigDigest: string;
|
|
46
|
+
state: TPreparedImageState;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface IPreparedImageReport {
|
|
50
|
+
/** Null denotes a node with no admitted list. Its images must then be empty. */
|
|
51
|
+
revision: number | null;
|
|
52
|
+
images: IPreparedImageStatus[];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface IReportPreparedImagesRequest {
|
|
56
|
+
session: IRuntimeSessionBinding;
|
|
57
|
+
report: IPreparedImageReport;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface IGetPreparedImagePullCredentialRequest {
|
|
61
|
+
session: IRuntimeSessionBinding;
|
|
62
|
+
revision: number;
|
|
63
|
+
image: IPreparedImageEntry;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Ephemeral, pull-only registry authorization. Exclude the envelope from logs and persistence. */
|
|
67
|
+
export interface IPreparedImagePullCredential {
|
|
68
|
+
username: string;
|
|
69
|
+
password: string;
|
|
70
|
+
/** Unix milliseconds. */
|
|
71
|
+
expiresAt: number;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface IGetPreparedImagePullCredentialResponse {
|
|
75
|
+
revision: number;
|
|
76
|
+
image: IPreparedImageEntry;
|
|
77
|
+
/** Null explicitly authorizes an anonymous attempt. A refusal is an RPC error. */
|
|
78
|
+
credential: IPreparedImagePullCredential | null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export class PreparedImageContractError extends Error {
|
|
82
|
+
constructor(public readonly code: 'invalid' | 'conflict') {
|
|
83
|
+
super(`Prepared image contract rejected: ${code}.`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const invalid = (): never => { throw new PreparedImageContractError('invalid'); };
|
|
88
|
+
|
|
89
|
+
const revisionOf = (value: unknown): number =>
|
|
90
|
+
typeof value === 'number' && Number.isSafeInteger(value) && value > 0 ? value : invalid();
|
|
91
|
+
|
|
92
|
+
const digestOf = (value: unknown): string =>
|
|
93
|
+
typeof value === 'string' && value.length === 71 && isSha256Digest(value) ? value : invalid();
|
|
94
|
+
|
|
95
|
+
const referenceOf = (value: unknown): string => {
|
|
96
|
+
if (typeof value !== 'string') return invalid();
|
|
97
|
+
const at = value.lastIndexOf('@');
|
|
98
|
+
if (at <= 0 || at > preparedImageBounds.maximumRepositoryBytes) return invalid();
|
|
99
|
+
const repository = value.slice(0, at);
|
|
100
|
+
// Pallet's native pull grammar, including the ability to pin an index.
|
|
101
|
+
if (/[^a-z0-9._/:-]/.test(repository) || !repository.includes('/')
|
|
102
|
+
|| repository.startsWith('/') || repository.endsWith('/')
|
|
103
|
+
|| repository.includes('//') || repository.includes('..')) return invalid();
|
|
104
|
+
digestOf(value.slice(at + 1));
|
|
105
|
+
return value;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
const entryOf = (value: unknown): IPreparedImageEntry => {
|
|
109
|
+
const entry = readExactDataRecord(value, ['imageReference', 'imageConfigDigest', 'manifestDigest']);
|
|
110
|
+
if (!entry) return invalid();
|
|
111
|
+
return {
|
|
112
|
+
imageReference: referenceOf(entry.imageReference),
|
|
113
|
+
imageConfigDigest: digestOf(entry.imageConfigDigest),
|
|
114
|
+
manifestDigest: digestOf(entry.manifestDigest),
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const compareDigest = (left: string, right: string): number => left < right ? -1 : left > right ? 1 : 0;
|
|
119
|
+
|
|
120
|
+
const requireCanonicalOrder = (rows: readonly { imageConfigDigest: string }[]): void => {
|
|
121
|
+
for (let index = 1; index < rows.length; index++) {
|
|
122
|
+
if (rows[index - 1]!.imageConfigDigest >= rows[index]!.imageConfigDigest) invalid();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const sameImage = (left: IPreparedImageEntry, right: IPreparedImageEntry): boolean =>
|
|
127
|
+
left.imageConfigDigest === right.imageConfigDigest && left.imageReference === right.imageReference
|
|
128
|
+
&& left.manifestDigest === right.manifestDigest;
|
|
129
|
+
|
|
130
|
+
/** Capture and canonicalize a whole node list using Pallet's admission grammar. */
|
|
131
|
+
export const capturePreparedImageList = (value: unknown): IPreparedImageList => {
|
|
132
|
+
const list = readExactDataRecord(value, ['revision', 'images']);
|
|
133
|
+
const entries = list && readDataElements(list.images, preparedImageBounds.maximumImages);
|
|
134
|
+
if (!list || !entries) return invalid();
|
|
135
|
+
const revision = revisionOf(list.revision);
|
|
136
|
+
const images = entries.map(entryOf).sort((left, right) => compareDigest(left.imageConfigDigest, right.imageConfigDigest));
|
|
137
|
+
requireCanonicalOrder(images);
|
|
138
|
+
return { revision, images };
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/** Judge revision order. The caller owns the authenticated transactional compare-and-replace. */
|
|
142
|
+
export const judgePreparedImageList = (
|
|
143
|
+
proposed: unknown, current: IPreparedImageList | null,
|
|
144
|
+
): ISyncPreparedImagesResponse => {
|
|
145
|
+
const next = capturePreparedImageList(proposed);
|
|
146
|
+
if (current === null) return { status: 'accepted', list: next };
|
|
147
|
+
const previous = capturePreparedImageList(current);
|
|
148
|
+
if (next.revision > previous.revision) return { status: 'accepted', list: next };
|
|
149
|
+
if (next.revision < previous.revision) return { status: 'historical', list: previous };
|
|
150
|
+
if (next.images.length !== previous.images.length
|
|
151
|
+
|| next.images.some((image, index) => !sameImage(image, previous.images[index]!))) {
|
|
152
|
+
throw new PreparedImageContractError('conflict');
|
|
153
|
+
}
|
|
154
|
+
return { status: 'replay', list: previous };
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const reportOf = (value: unknown, fromPallet: boolean): IPreparedImageReport => {
|
|
158
|
+
const report = readExactDataRecord(value, ['revision', 'images']);
|
|
159
|
+
const entries = report && readDataElements(report.images, preparedImageBounds.maximumImages);
|
|
160
|
+
if (!report || !entries) return invalid();
|
|
161
|
+
const revision = report.revision === null ? null : revisionOf(report.revision);
|
|
162
|
+
if (revision === null && entries.length !== 0) return invalid();
|
|
163
|
+
const images = entries.map((value): IPreparedImageStatus => {
|
|
164
|
+
const entry = readExactDataRecord(value, fromPallet
|
|
165
|
+
? ['imageConfigDigest', 'state', 'reason'] : ['imageConfigDigest', 'state']);
|
|
166
|
+
if (!entry) return invalid();
|
|
167
|
+
const state = fromPallet ? projectPalletState(entry.state)
|
|
168
|
+
: preparedImageStates.find((candidate) => candidate === entry.state);
|
|
169
|
+
if (!state) return invalid();
|
|
170
|
+
return { imageConfigDigest: digestOf(entry.imageConfigDigest), state };
|
|
171
|
+
});
|
|
172
|
+
requireCanonicalOrder(images);
|
|
173
|
+
return { revision, images };
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
const projectPalletState = (state: unknown): TPreparedImageState | undefined => {
|
|
177
|
+
switch (state) {
|
|
178
|
+
case 'present': return 'present';
|
|
179
|
+
case 'fetching': case 'queued': return 'pulling';
|
|
180
|
+
case 'refused': case 'unavailable': return 'failed';
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/** Project Pallet's local preparation-pass output, dropping its internal reason entirely. */
|
|
185
|
+
export const projectPreparedImageReport = (value: unknown): IPreparedImageReport =>
|
|
186
|
+
reportOf(value, true);
|
|
187
|
+
|
|
188
|
+
/** Read a wire observation. Reasons and any other extra fields are refused. */
|
|
189
|
+
export const snapshotPreparedImageReport = (value: unknown): IPreparedImageReport =>
|
|
190
|
+
reportOf(value, false);
|
|
191
|
+
|
|
192
|
+
/** Match the whole pull target to the node's exact current list. Authenticate its session first. */
|
|
193
|
+
export const isPreparedImagePullAuthorizedByList = (
|
|
194
|
+
request: Pick<IGetPreparedImagePullCredentialRequest, 'revision' | 'image'>,
|
|
195
|
+
current: IPreparedImageList | null,
|
|
196
|
+
): boolean => {
|
|
197
|
+
if (current === null) return false;
|
|
198
|
+
const list = capturePreparedImageList(current);
|
|
199
|
+
const image = entryOf(request.image);
|
|
200
|
+
return list.revision === revisionOf(request.revision) && list.images.some((entry) => sameImage(entry, image));
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
const encoder = new TextEncoder();
|
|
204
|
+
const credentialField = (value: unknown, minimum: number, maximum: number): string =>
|
|
205
|
+
typeof value === 'string' && value.length >= minimum && value.length <= maximum && !value.includes('\0')
|
|
206
|
+
&& encoder.encode(value).byteLength <= maximum ? value : invalid();
|
|
207
|
+
|
|
208
|
+
/** Accept only a response for this exact request and only unexpired credentials. */
|
|
209
|
+
export const bindPreparedImagePullCredentialResponse = (
|
|
210
|
+
value: unknown, request: Pick<IGetPreparedImagePullCredentialRequest, 'revision' | 'image'>, now: number,
|
|
211
|
+
): IGetPreparedImagePullCredentialResponse => {
|
|
212
|
+
const response = readExactDataRecord(value, ['revision', 'image', 'credential']);
|
|
213
|
+
if (!response) return invalid();
|
|
214
|
+
const revision = revisionOf(response.revision);
|
|
215
|
+
const image = entryOf(response.image);
|
|
216
|
+
if (revision !== revisionOf(request.revision) || !sameImage(image, entryOf(request.image))) return invalid();
|
|
217
|
+
if (response.credential === null) return { revision, image, credential: null };
|
|
218
|
+
const credential = readExactDataRecord(response.credential, ['username', 'password', 'expiresAt']);
|
|
219
|
+
if (!credential) return invalid();
|
|
220
|
+
const expiresAt = revisionOf(credential.expiresAt);
|
|
221
|
+
if (expiresAt <= revisionOf(now)) return invalid();
|
|
222
|
+
return {
|
|
223
|
+
revision,
|
|
224
|
+
image,
|
|
225
|
+
credential: {
|
|
226
|
+
username: credentialField(credential.username, 1, preparedImageBounds.maximumRegistryUsernameBytes),
|
|
227
|
+
password: credentialField(credential.password, 0, preparedImageBounds.maximumRegistryPasswordBytes),
|
|
228
|
+
expiresAt,
|
|
229
|
+
},
|
|
230
|
+
};
|
|
231
|
+
};
|
package/ts/index.ts
CHANGED
|
@@ -3,7 +3,8 @@ import * as appstore from './appstore/index.js';
|
|
|
3
3
|
import * as platform from './platform/index.js';
|
|
4
4
|
import * as platformservice from './platformservice/index.js';
|
|
5
5
|
import * as protocol from './protocol.js';
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
export * as requests from './requests/index.js';
|
|
7
8
|
|
|
8
9
|
export {
|
|
9
10
|
appstore,
|
|
@@ -11,5 +12,11 @@ export {
|
|
|
11
12
|
platform,
|
|
12
13
|
platformservice,
|
|
13
14
|
protocol,
|
|
14
|
-
requests
|
|
15
15
|
}
|
|
16
|
+
|
|
17
|
+
/** Storage-node and pool TypedRequest contracts are also available at requests.dcstorage. */
|
|
18
|
+
export { dcstorage } from './requests/index.js';
|
|
19
|
+
/** Prepared-image TypedRequest contracts are also available at requests.preparedimages. */
|
|
20
|
+
export { preparedimages } from './requests/index.js';
|
|
21
|
+
/** Corestore replication TypedRequest contracts are also available at requests.corestorereplication. */
|
|
22
|
+
export { corestorereplication } from './requests/index.js';
|
package/ts/requests/backup.ts
CHANGED
package/ts/requests/corestore.ts
CHANGED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type * as plugins from '../plugins.js';
|
|
2
|
+
import type { IIdentityCredential } from '../data/user.js';
|
|
3
|
+
import type {
|
|
4
|
+
ICorestoreReplicationBinding,
|
|
5
|
+
ICorestoreReplicationFence,
|
|
6
|
+
ICorestoreReplicationGrant,
|
|
7
|
+
ICorestoreReplicationLagReport,
|
|
8
|
+
ICorestoreReplicationPromotion,
|
|
9
|
+
ICorestoreReplicationQuiescence,
|
|
10
|
+
ICorestoreReplicationTimeline,
|
|
11
|
+
} from '../data/corestorereplication.js';
|
|
12
|
+
|
|
13
|
+
interface ICorestoreReplicationAdminCommand {
|
|
14
|
+
identity: IIdentityCredential;
|
|
15
|
+
expected: ICorestoreReplicationFence;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ICorestoreReplicationPromoted {
|
|
19
|
+
previous: ICorestoreReplicationFence;
|
|
20
|
+
timeline: ICorestoreReplicationTimeline;
|
|
21
|
+
displacedCopy: 'set-aside';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Cloudly verifies administrator authority and resolves both exact peers from trusted records.
|
|
26
|
+
* A grant installs a non-blocking stream for one workload database or bucket binding.
|
|
27
|
+
*/
|
|
28
|
+
export interface IReq_Admin_Cloudly_GrantCorestoreReplication extends plugins.typedrequestInterfaces.implementsTR<
|
|
29
|
+
plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_GrantCorestoreReplication
|
|
30
|
+
> {
|
|
31
|
+
method: 'grantCorestoreReplication';
|
|
32
|
+
request: {
|
|
33
|
+
identity: IIdentityCredential;
|
|
34
|
+
binding: ICorestoreReplicationBinding;
|
|
35
|
+
primaryNodeId: string;
|
|
36
|
+
replicaNodeId: string;
|
|
37
|
+
/** Null requires no active grant. A replacement requires the exact current fence. */
|
|
38
|
+
expected: ICorestoreReplicationFence | null;
|
|
39
|
+
};
|
|
40
|
+
response: { grant: ICorestoreReplicationGrant };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Install an authorized grant on one of its named peers over authenticated controller RPC.
|
|
45
|
+
* Verify the live controller, the local binding and the stored fence at commit. Retain a durable
|
|
46
|
+
* high-water mark after revocation. An identical replay may acknowledge the current grant.
|
|
47
|
+
*/
|
|
48
|
+
export interface IReq_Controller_Corestore_InstallCorestoreReplicationGrant
|
|
49
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
50
|
+
plugins.typedrequestInterfaces.ITypedRequest, IReq_Controller_Corestore_InstallCorestoreReplicationGrant
|
|
51
|
+
> {
|
|
52
|
+
method: 'installCorestoreReplicationGrant';
|
|
53
|
+
request: { grant: ICorestoreReplicationGrant; expected: ICorestoreReplicationFence | null };
|
|
54
|
+
response: { installed: ICorestoreReplicationFence };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Read-only inspection of the named copy, including standalone bindings. */
|
|
58
|
+
export interface IReq_Admin_Cloudly_GetCorestoreReplicationLag extends plugins.typedrequestInterfaces.implementsTR<
|
|
59
|
+
plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_GetCorestoreReplicationLag
|
|
60
|
+
> {
|
|
61
|
+
method: 'getCorestoreReplicationLag';
|
|
62
|
+
request: {
|
|
63
|
+
identity: IIdentityCredential;
|
|
64
|
+
binding: ICorestoreReplicationBinding;
|
|
65
|
+
nodeId: string;
|
|
66
|
+
};
|
|
67
|
+
response: { report: ICorestoreReplicationLagReport };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Pausing the replication stream leaves the source's workload writer authority in place. */
|
|
71
|
+
export interface IReq_Admin_Cloudly_PauseCorestoreReplication extends plugins.typedrequestInterfaces.implementsTR<
|
|
72
|
+
plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_PauseCorestoreReplication
|
|
73
|
+
> {
|
|
74
|
+
method: 'pauseCorestoreReplication';
|
|
75
|
+
request: ICorestoreReplicationAdminCommand;
|
|
76
|
+
response: { paused: ICorestoreReplicationFence };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Close source writes for a planned move and return the durable final source position. */
|
|
80
|
+
export interface IReq_Admin_Cloudly_QuiesceCorestoreReplication extends plugins.typedrequestInterfaces.implementsTR<
|
|
81
|
+
plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_QuiesceCorestoreReplication
|
|
82
|
+
> {
|
|
83
|
+
method: 'quiesceCorestoreReplication';
|
|
84
|
+
request: ICorestoreReplicationAdminCommand;
|
|
85
|
+
response: { quiescence: ICorestoreReplicationQuiescence };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Promote only with verified old-writer fencing and a replica that applied at least the stated
|
|
90
|
+
* sequence on the expected timeline. The new writer commits a fresh timeline.
|
|
91
|
+
*/
|
|
92
|
+
export interface IReq_Admin_Cloudly_PromoteCorestoreReplication extends plugins.typedrequestInterfaces.implementsTR<
|
|
93
|
+
plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_PromoteCorestoreReplication
|
|
94
|
+
> {
|
|
95
|
+
method: 'promoteCorestoreReplication';
|
|
96
|
+
request: ICorestoreReplicationPromotion & { identity: IIdentityCredential };
|
|
97
|
+
response: ICorestoreReplicationPromoted;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Planned promotion after the service stops and the replica applies the source's actual final
|
|
102
|
+
* sequence. Resolve the source quiescence receipt and require its exact fence and final sequence.
|
|
103
|
+
*/
|
|
104
|
+
export interface IReq_Admin_Cloudly_SwitchoverCorestoreReplication
|
|
105
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
106
|
+
plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_SwitchoverCorestoreReplication
|
|
107
|
+
> {
|
|
108
|
+
method: 'switchoverCorestoreReplication';
|
|
109
|
+
request: ICorestoreReplicationPromotion & { identity: IIdentityCredential };
|
|
110
|
+
response: ICorestoreReplicationPromoted;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Revoke the link and durably raise its binding generation. Revocation leaves provider content
|
|
115
|
+
* intact. A displaced NoSQLDB copy stays closed to clients until an authorized role read or copy.
|
|
116
|
+
*/
|
|
117
|
+
export interface IReq_Admin_Cloudly_RevokeCorestoreReplication extends plugins.typedrequestInterfaces.implementsTR<
|
|
118
|
+
plugins.typedrequestInterfaces.ITypedRequest, IReq_Admin_Cloudly_RevokeCorestoreReplication
|
|
119
|
+
> {
|
|
120
|
+
method: 'revokeCorestoreReplication';
|
|
121
|
+
request: ICorestoreReplicationAdminCommand;
|
|
122
|
+
response: { revoked: ICorestoreReplicationFence; generation: number };
|
|
123
|
+
}
|