@serve.zone/interfaces 32.16.0 → 32.17.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.
@@ -0,0 +1,352 @@
1
+ import type { IFleetCutoverAcceptedEvidenceReference } from './fleetcutover.js';
2
+ import type { TSha256Digest } from './immutableimage.js';
3
+ import { isReleaseVersion } from '../private/releaseversion.js';
4
+ import {
5
+ captureNetwork,
6
+ networkCounter,
7
+ networkDigest,
8
+ networkEqual,
9
+ networkHash,
10
+ networkId,
11
+ networkNodeId,
12
+ networkRecord,
13
+ networkReference,
14
+ networkRevision,
15
+ requireNetwork,
16
+ } from '../private/networkcontract.js';
17
+
18
+ /** The two runtimes a released Spark could be put into by its `mode` configuration key. */
19
+ export const sparkLegacyRuntimeModes = ['cloudly', 'coreflow-node'] as const;
20
+
21
+ export type TSparkLegacyRuntimeMode = typeof sparkLegacyRuntimeModes[number];
22
+
23
+ /**
24
+ * Which Docker services a released mode owns, sorted, so a refusal names a mode instead of
25
+ * restating a set. A record over the mode union: a mode cannot be added without naming its
26
+ * services, and a reader can never meet a mode whose services it does not know.
27
+ */
28
+ export const sparkLegacyRuntimeModeServices = Object.freeze({
29
+ 'cloudly': Object.freeze(['cloudly']),
30
+ 'coreflow-node': Object.freeze(['coreflow', 'corestore', 'coretraffic']),
31
+ } satisfies Record<TSparkLegacyRuntimeMode, readonly string[]>);
32
+
33
+ /**
34
+ * Which verified Spark code is installed on one host and which systemd unit will boot it.
35
+ *
36
+ * Every member is read back from the installed tree and the installed unit file, never from the
37
+ * running process's own build constants: a build can state its own version, it cannot state that
38
+ * the host will start that same code again.
39
+ */
40
+ export interface ISparkNodeBundleIdentity {
41
+ /** The installed bundle's release, exactly as its verified manifest names it. */
42
+ version: string;
43
+ /** The commit that manifest was built from, in the 40-hex form the manifest carries. */
44
+ sourceCommit: string;
45
+ /** The manifest digest the installed tree was verified against, in its bare 64-hex form. */
46
+ manifestSha256: string;
47
+ /** The systemd unit that starts this bundle at boot. */
48
+ unitName: string;
49
+ /** SHA-256 of the exact installed unit-file bytes. */
50
+ unitDigest: TSha256Digest;
51
+ }
52
+
53
+ /**
54
+ * The released key-value configuration source, by digest and disposition only.
55
+ *
56
+ * Never its bytes and never a decoded member: that file carries this node's released bearer and
57
+ * its jump code. `sourceSha256` covers the whole file, whose smallest unguessable part is a
58
+ * 256-bit token, so it identifies the file without stating anything that is in it.
59
+ */
60
+ export interface ISparkLegacyConfigurationState {
61
+ /** The node's own monotonic counter; one accepted local disposition change advances it by one. */
62
+ ownerGeneration: number;
63
+ /** SHA-256 of the exact source bytes this node imported, once, under its fenced read. */
64
+ sourceSha256: string;
65
+ /** On disk and read by nothing, or unlinked. Erasure is not a cutover requirement. */
66
+ disposition: 'retained-inert' | 'removed';
67
+ }
68
+
69
+ /**
70
+ * What one node states about the released Spark runtime it is replacing, on one observation.
71
+ *
72
+ * Observed values and one statement the owner makes about its own behaviour. It names no node:
73
+ * Cloudly binds it to the reporter it already authenticated, so there is nothing to disagree
74
+ * with. It carries no digest of its own either, because the whole observation is digested by
75
+ * `computeSparkSwarmObservationDigest`.
76
+ */
77
+ export interface ISparkLegacyRuntimeRetirement {
78
+ /** The released mode this process is configured in and no longer serves. */
79
+ refusedMode: TSparkLegacyRuntimeMode;
80
+ bundle: ISparkNodeBundleIdentity;
81
+ configuration: ISparkLegacyConfigurationState;
82
+ }
83
+
84
+ interface ISparkLegacyRetirementReceiptBase {
85
+ id: string;
86
+ generation: number;
87
+ previous: IFleetCutoverAcceptedEvidenceReference | null;
88
+ clusterId: string;
89
+ nodeId: string;
90
+ /** The accepted observation this was derived from; Cloudly read it, the node never named it. */
91
+ observation: IFleetCutoverAcceptedEvidenceReference;
92
+ reporterSessionId: string;
93
+ observationSequence: number;
94
+ acceptedAt: number;
95
+ digest: TSha256Digest;
96
+ }
97
+
98
+ /**
99
+ * Cloudly's accepted record that one node refuses its released owning mode.
100
+ *
101
+ * It is revisioned rather than written once: a node restates the refusal on every observation,
102
+ * and a bundle upgrade changes what the boot path is, which is a new fact about the same node.
103
+ */
104
+ export interface ISparkLegacyModeRefusal extends ISparkLegacyRetirementReceiptBase {
105
+ refusedMode: TSparkLegacyRuntimeMode;
106
+ bundle: ISparkNodeBundleIdentity;
107
+ }
108
+
109
+ /**
110
+ * Cloudly's accepted record of one node's released configuration source at an exact generation.
111
+ *
112
+ * Two counters, deliberately: `generation` is contiguous because it is this record's own
113
+ * revision, while `configuration.ownerGeneration` is the node's and may skip — an observation
114
+ * that never arrived must not look like a skipped revision here.
115
+ */
116
+ export interface ISparkLegacyConfigurationRetirement extends ISparkLegacyRetirementReceiptBase {
117
+ configuration: ISparkLegacyConfigurationState;
118
+ }
119
+
120
+ export const sparkLegacyRetirementContract = Object.freeze({
121
+ modeRefusalDigestDomain: 'serve.zone/spark-legacy-mode-refusal',
122
+ configurationRetirementDigestDomain: 'serve.zone/spark-legacy-configuration-retirement',
123
+ } as const);
124
+
125
+ /** Every reason Cloudly answers instead of advancing a node's legacy retirement state. */
126
+ export const sparkLegacyRetirementRefusals = Object.freeze([
127
+ /** The observed owner generation is below the accepted one. */
128
+ 'legacy-retirement-generation-stale',
129
+ /** The observed owner generation equals the accepted one and states something else. */
130
+ 'legacy-retirement-generation-conflict',
131
+ /** A node imported one source once; another source digest describes another host. */
132
+ 'legacy-retirement-source-changed',
133
+ /** A removed source cannot become a retained one. */
134
+ 'legacy-retirement-disposition-reversed',
135
+ /** The stated bundle is below the release whose refusal this server accepts as real. */
136
+ 'legacy-retirement-bundle-below-minimum',
137
+ ] as const);
138
+
139
+ export type TSparkLegacyRetirementRefusal = typeof sparkLegacyRetirementRefusals[number];
140
+
141
+ const fail = (): never => { throw new Error('Spark legacy retirement contract rejected.'); };
142
+ const safe = <T>(operationArg: () => T): T => {
143
+ try { return operationArg(); } catch { return fail(); }
144
+ };
145
+
146
+ const sha256Hex = (valueArg: unknown): string => {
147
+ requireNetwork(typeof valueArg === 'string' && /^[a-f0-9]{64}$/.test(valueArg));
148
+ return valueArg;
149
+ };
150
+
151
+ const sourceCommit = (valueArg: unknown): string => {
152
+ requireNetwork(typeof valueArg === 'string' && /^[a-f0-9]{40}$/.test(valueArg));
153
+ return valueArg;
154
+ };
155
+
156
+ const releaseVersion = (valueArg: unknown): string => {
157
+ requireNetwork(isReleaseVersion(valueArg));
158
+ return valueArg;
159
+ };
160
+
161
+ const legacyRuntimeMode = (valueArg: unknown): TSparkLegacyRuntimeMode => {
162
+ requireNetwork(sparkLegacyRuntimeModes.includes(valueArg as TSparkLegacyRuntimeMode));
163
+ return valueArg as TSparkLegacyRuntimeMode;
164
+ };
165
+
166
+ const configurationDisposition = (
167
+ valueArg: unknown,
168
+ ): ISparkLegacyConfigurationState['disposition'] => {
169
+ requireNetwork(valueArg === 'retained-inert' || valueArg === 'removed');
170
+ return valueArg;
171
+ };
172
+
173
+ /** Structural copy only; whether the tree it describes is installed is the node's to observe. */
174
+ export const snapshotSparkNodeBundleIdentity = (
175
+ valueArg: unknown,
176
+ ): ISparkNodeBundleIdentity => safe(() => {
177
+ const value = networkRecord(captureNetwork(valueArg), [
178
+ 'version', 'sourceCommit', 'manifestSha256', 'unitName', 'unitDigest',
179
+ ]);
180
+ return {
181
+ version: releaseVersion(value.version),
182
+ sourceCommit: sourceCommit(value.sourceCommit),
183
+ manifestSha256: sha256Hex(value.manifestSha256),
184
+ unitName: networkId(value.unitName),
185
+ unitDigest: networkDigest(value.unitDigest),
186
+ };
187
+ });
188
+
189
+ export const snapshotSparkLegacyConfigurationState = (
190
+ valueArg: unknown,
191
+ ): ISparkLegacyConfigurationState => safe(() => {
192
+ const value = networkRecord(captureNetwork(valueArg), [
193
+ 'ownerGeneration', 'sourceSha256', 'disposition',
194
+ ]);
195
+ return {
196
+ ownerGeneration: networkCounter(value.ownerGeneration),
197
+ sourceSha256: sha256Hex(value.sourceSha256),
198
+ disposition: configurationDisposition(value.disposition),
199
+ };
200
+ });
201
+
202
+ export const snapshotSparkLegacyRuntimeRetirement = (
203
+ valueArg: unknown,
204
+ ): ISparkLegacyRuntimeRetirement => safe(() => {
205
+ const value = networkRecord(captureNetwork(valueArg), [
206
+ 'refusedMode', 'bundle', 'configuration',
207
+ ]);
208
+ return {
209
+ refusedMode: legacyRuntimeMode(value.refusedMode),
210
+ bundle: snapshotSparkNodeBundleIdentity(value.bundle),
211
+ configuration: snapshotSparkLegacyConfigurationState(value.configuration),
212
+ };
213
+ });
214
+
215
+ /**
216
+ * Synchronous because the member carries no digest: the observation that transports it is
217
+ * digested as a whole, so a second domain here would only be a second thing to keep in step.
218
+ */
219
+ export const validateSparkLegacyRuntimeRetirement = (valueArg: unknown): string[] => {
220
+ try {
221
+ snapshotSparkLegacyRuntimeRetirement(valueArg);
222
+ return [];
223
+ } catch { return ['Spark legacy runtime retirement must use its exact canonical schema']; }
224
+ };
225
+
226
+ /** The revision rule every accepted receipt of this contract obeys, read once for both of them. */
227
+ const retirementReceiptBase = (
228
+ valueArg: unknown,
229
+ ownKeysArg: string[],
230
+ ): { base: ISparkLegacyRetirementReceiptBase; record: Record<string, unknown> } => {
231
+ const value = networkRecord(captureNetwork(valueArg), [
232
+ 'id', 'generation', 'previous', 'clusterId', 'nodeId', 'observation', 'reporterSessionId',
233
+ 'observationSequence', 'acceptedAt', 'digest',
234
+ ...ownKeysArg,
235
+ ]);
236
+ const { id, generation, previous } = networkRevision(value);
237
+ return {
238
+ base: {
239
+ id,
240
+ generation,
241
+ previous,
242
+ clusterId: networkId(value.clusterId),
243
+ nodeId: networkNodeId(value.nodeId),
244
+ observation: networkReference(value.observation),
245
+ reporterSessionId: networkId(value.reporterSessionId),
246
+ observationSequence: networkCounter(value.observationSequence),
247
+ acceptedAt: networkCounter(value.acceptedAt),
248
+ digest: networkDigest(value.digest),
249
+ },
250
+ record: value,
251
+ };
252
+ };
253
+
254
+ export const snapshotSparkLegacyModeRefusal = (
255
+ valueArg: unknown,
256
+ ): ISparkLegacyModeRefusal => safe(() => {
257
+ const { base, record } = retirementReceiptBase(valueArg, ['refusedMode', 'bundle']);
258
+ return {
259
+ ...base,
260
+ refusedMode: legacyRuntimeMode(record.refusedMode),
261
+ bundle: snapshotSparkNodeBundleIdentity(record.bundle),
262
+ };
263
+ });
264
+
265
+ export const computeSparkLegacyModeRefusalDigest = async (
266
+ valueArg: unknown,
267
+ ): Promise<TSha256Digest> => networkHash(
268
+ sparkLegacyRetirementContract.modeRefusalDigestDomain,
269
+ snapshotSparkLegacyModeRefusal(valueArg),
270
+ );
271
+
272
+ export const validateSparkLegacyModeRefusal = async (valueArg: unknown): Promise<string[]> => {
273
+ try {
274
+ const value = snapshotSparkLegacyModeRefusal(valueArg);
275
+ return value.digest === await computeSparkLegacyModeRefusalDigest(value)
276
+ ? [] : ['Spark legacy mode refusal digest does not match'];
277
+ } catch { return ['Spark legacy mode refusal must use its exact canonical schema']; }
278
+ };
279
+
280
+ export const snapshotSparkLegacyConfigurationRetirement = (
281
+ valueArg: unknown,
282
+ ): ISparkLegacyConfigurationRetirement => safe(() => {
283
+ const { base, record } = retirementReceiptBase(valueArg, ['configuration']);
284
+ return { ...base, configuration: snapshotSparkLegacyConfigurationState(record.configuration) };
285
+ });
286
+
287
+ export const computeSparkLegacyConfigurationRetirementDigest = async (
288
+ valueArg: unknown,
289
+ ): Promise<TSha256Digest> => networkHash(
290
+ sparkLegacyRetirementContract.configurationRetirementDigestDomain,
291
+ snapshotSparkLegacyConfigurationRetirement(valueArg),
292
+ );
293
+
294
+ export const validateSparkLegacyConfigurationRetirement = async (
295
+ valueArg: unknown,
296
+ ): Promise<string[]> => {
297
+ try {
298
+ const value = snapshotSparkLegacyConfigurationRetirement(valueArg);
299
+ return value.digest === await computeSparkLegacyConfigurationRetirementDigest(value)
300
+ ? [] : ['Spark legacy configuration retirement digest does not match'];
301
+ } catch {
302
+ return ['Spark legacy configuration retirement must use its exact canonical schema'];
303
+ }
304
+ };
305
+
306
+ /**
307
+ * Whether one observed configuration state is a legal successor of the accepted one.
308
+ *
309
+ * `null` is a node's first accepted state. A replay states the accepted generation again and is
310
+ * therefore not an advance: it renews nothing, which is what keeps `acceptedAt` and the named
311
+ * observation from aging forward on a node that has stopped changing.
312
+ */
313
+ export const advancesSparkLegacyConfigurationState = (
314
+ currentArg: ISparkLegacyConfigurationState | null,
315
+ nextArg: ISparkLegacyConfigurationState,
316
+ ): boolean => {
317
+ const next = snapshotSparkLegacyConfigurationState(nextArg);
318
+ if (currentArg === null) return true;
319
+ if (next.sourceSha256 !== currentArg.sourceSha256) return false;
320
+ if (next.ownerGeneration <= currentArg.ownerGeneration) return false;
321
+ return !(currentArg.disposition === 'removed' && next.disposition !== 'removed');
322
+ };
323
+
324
+ /**
325
+ * Joins the two accepted receipts a Coreflow retirement cites to the one observation they were
326
+ * derived from.
327
+ *
328
+ * Content join only. Whether each receipt is its node's current revision, and whether the
329
+ * observation it names is still fresh, remain Cloudly's to decide against its own records.
330
+ */
331
+ export const bindSparkLegacyRetirement = async (
332
+ modeRefusalArg: unknown,
333
+ configurationRetirementArg: unknown,
334
+ ): Promise<{
335
+ modeRefusal: ISparkLegacyModeRefusal;
336
+ configurationRetirement: ISparkLegacyConfigurationRetirement;
337
+ }> => {
338
+ try {
339
+ const modeRefusal = snapshotSparkLegacyModeRefusal(modeRefusalArg);
340
+ const configurationRetirement = snapshotSparkLegacyConfigurationRetirement(
341
+ configurationRetirementArg,
342
+ );
343
+ if ((await validateSparkLegacyModeRefusal(modeRefusal)).length
344
+ || (await validateSparkLegacyConfigurationRetirement(configurationRetirement)).length) fail();
345
+ requireNetwork(modeRefusal.clusterId === configurationRetirement.clusterId
346
+ && modeRefusal.nodeId === configurationRetirement.nodeId
347
+ && modeRefusal.reporterSessionId === configurationRetirement.reporterSessionId
348
+ && modeRefusal.observationSequence === configurationRetirement.observationSequence
349
+ && networkEqual(modeRefusal.observation, configurationRetirement.observation));
350
+ return { modeRefusal, configurationRetirement };
351
+ } catch { return fail(); }
352
+ };
@@ -1,5 +1,6 @@
1
1
  import * as userInterfaces from '../data/user.js';
2
2
  import * as clusterInterfaces from '../data/cluster.js';
3
+ import type * as relayCredentialInterfaces from '../data/clusterrelaycredential.js';
3
4
  import type * as clusterVpnInterfaces from '../data/clustervpn.js';
4
5
  import type { IClusterRuntime, TClusterRuntimeBlocker } from '../data/clusterruntime.js';
5
6
  import type { IServiceRuntimeAssignmentView } from '../data/serviceruntime.js';
@@ -150,6 +151,74 @@ export interface IReq_Relay_Cloudly_RegisterClusterRelay extends plugins.typedre
150
151
  response: clusterInterfaces.IRegisterClusterRelayResponse;
151
152
  }
152
153
 
154
+ /**
155
+ * Mints a cluster's relay credential, or rotates it at its exact current generation.
156
+ *
157
+ * Only the verified credential is read from the caller: a credential mutation trusts no identity
158
+ * member a caller states about itself. The bearer is never in the answer; it is delivered as the
159
+ * encrypted secret version `credential.delivery` names. The first mint also records the shared
160
+ * authority the cluster still carries, so a replacement never exists without a named predecessor.
161
+ * Cloudly refuses with one of `data.clusterRelayCredentialRefusals`.
162
+ */
163
+ export interface IReq_Admin_Cloudly_MutateClusterRelayCredential
164
+ extends plugins.typedrequestInterfaces.implementsTR<
165
+ plugins.typedrequestInterfaces.ITypedRequest,
166
+ IReq_Admin_Cloudly_MutateClusterRelayCredential
167
+ > {
168
+ method: 'mutateClusterRelayCredential';
169
+ request: {
170
+ identity: userInterfaces.IIdentityCredential;
171
+ mutation: relayCredentialInterfaces.TClusterRelayCredentialMutation;
172
+ };
173
+ response: relayCredentialInterfaces.IClusterRelayCredentialMutationResult;
174
+ }
175
+
176
+ /**
177
+ * One cluster's relay authority chain as Cloudly records it: the relay credential, the shared
178
+ * authority it replaces and the current accepted registration, each `null` while no record exists.
179
+ *
180
+ * Liveness is not here. It is a fact of a socket, which `getClusterRelayRegistrations` answers and
181
+ * which Cloudly checks for itself before it accepts a retirement.
182
+ */
183
+ export interface IReq_Any_Cloudly_GetClusterRelayCredential
184
+ extends plugins.typedrequestInterfaces.implementsTR<
185
+ plugins.typedrequestInterfaces.ITypedRequest,
186
+ IReq_Any_Cloudly_GetClusterRelayCredential
187
+ > {
188
+ method: 'getClusterRelayCredential';
189
+ request: {
190
+ identity: userInterfaces.IIdentityCredential;
191
+ clusterId: string;
192
+ };
193
+ response: {
194
+ credential: relayCredentialInterfaces.IClusterRelayCredential | null;
195
+ legacy: relayCredentialInterfaces.IClusterLegacyRelayCredential | null;
196
+ registration: clusterInterfaces.IClusterRelayAcceptedRegistration | null;
197
+ };
198
+ }
199
+
200
+ /**
201
+ * Revokes a cluster's shared pre-relay authority, which is the last step of replacing it.
202
+ *
203
+ * Its own request rather than a mutation of the relay credential, because it is the one step that
204
+ * removes authority: Cloudly accepts it only while the named replacement is the current relay
205
+ * credential, the named registration is current and was made under that replacement, and a
206
+ * verified socket carries that registration. Every other answer is one of
207
+ * `data.clusterRelayCredentialRefusals`.
208
+ */
209
+ export interface IReq_Admin_Cloudly_RetireLegacyClusterRelayCredential
210
+ extends plugins.typedrequestInterfaces.implementsTR<
211
+ plugins.typedrequestInterfaces.ITypedRequest,
212
+ IReq_Admin_Cloudly_RetireLegacyClusterRelayCredential
213
+ > {
214
+ method: 'retireLegacyClusterRelayCredential';
215
+ request: {
216
+ identity: userInterfaces.IIdentityCredential;
217
+ retirement: relayCredentialInterfaces.IClusterLegacyRelayCredentialRetirementRequest;
218
+ };
219
+ response: relayCredentialInterfaces.IClusterLegacyRelayCredentialRetirementResult;
220
+ }
221
+
153
222
  /**
154
223
  * Cloudly hands the cluster relay the DNS lease renewals it has signed ahead of time for one node.
155
224
  *