@serve.zone/interfaces 32.41.0 → 32.42.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 +50 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/corestorecontroltoken.d.ts +90 -0
- package/dist_ts/data/corestorecontroltoken.js +106 -0
- package/dist_ts/data/index.d.ts +2 -0
- package/dist_ts/data/index.js +3 -1
- package/dist_ts/data/networkaddressplan.js +3 -12
- package/dist_ts/data/networkauthority.d.ts +16 -0
- package/dist_ts/data/networkauthority.js +45 -1
- package/dist_ts/data/networkcredential.d.ts +12 -8
- package/dist_ts/data/networkcredential.js +18 -13
- package/dist_ts/data/networkegressretirement.d.ts +105 -0
- package/dist_ts/data/networkegressretirement.js +113 -0
- package/dist_ts/data/noderetirement.d.ts +24 -4
- package/dist_ts/data/noderetirement.js +20 -3
- package/dist_ts/private/networkcontract.d.ts +2 -0
- package/dist_ts/private/networkcontract.js +10 -1
- package/dist_ts/requests/corestorecontrol.d.ts +33 -0
- package/dist_ts/requests/corestorecontrol.js +2 -0
- package/dist_ts/requests/index.d.ts +2 -1
- package/dist_ts/requests/index.js +3 -2
- package/dist_ts/requests/node.d.ts +9 -1
- package/package.json +3 -3
- package/readme.md +143 -20
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/corestorecontroltoken.ts +195 -0
- package/ts/data/index.ts +2 -0
- package/ts/data/networkaddressplan.ts +3 -13
- package/ts/data/networkauthority.ts +46 -0
- package/ts/data/networkcredential.ts +17 -12
- package/ts/data/networkegressretirement.ts +195 -0
- package/ts/data/noderetirement.ts +41 -5
- package/ts/private/networkcontract.ts +9 -0
- package/ts/requests/corestorecontrol.ts +43 -0
- package/ts/requests/index.ts +2 -0
- package/ts/requests/node.ts +9 -1
|
@@ -249,6 +249,52 @@ export const computeRuntimeNetworkProtectedAuthorityDigest = (value: IRuntimeNet
|
|
|
249
249
|
export const computeRuntimeNetworkHandoffLeaseDigest = (value: IRuntimeNetworkHandoffLease): Promise<TSha256Digest> =>
|
|
250
250
|
computeDigest(runtimeNetworkAuthorityContract.handoffDigestDomain, snapshotRuntimeNetworkHandoffLease(value));
|
|
251
251
|
|
|
252
|
+
/** Every address of `prefix` lies in one of `cover`, which must not overlap itself. */
|
|
253
|
+
const covered = (prefix: string, cover: string[]): boolean => {
|
|
254
|
+
const [first, last] = bounds(prefix);
|
|
255
|
+
let held = 0;
|
|
256
|
+
for (const range of cover) {
|
|
257
|
+
const [low, high] = bounds(range);
|
|
258
|
+
if (low <= last && first <= high) held += Math.min(last, high) - Math.max(first, low) + 1;
|
|
259
|
+
}
|
|
260
|
+
return held === last - first + 1;
|
|
261
|
+
};
|
|
262
|
+
/** Every entry of `previous` is in `next` with exactly the same content, matched by `key`. */
|
|
263
|
+
const retains = <T>(previous: T[], next: T[], key: (value: T) => string): boolean =>
|
|
264
|
+
previous.every(entry => next.some(candidate => key(candidate) === key(entry) && equals(candidate, entry)));
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Whether `next` continues the protection `previous` states without taking anything from it:
|
|
268
|
+
* `next` is `previous` itself, or exactly the next step of its chain (the same `id` and controller,
|
|
269
|
+
* `next.previous` naming `previous`) that only adds. Every egress authority, pool, resolver and
|
|
270
|
+
* platform endpoint of `previous` is in `next` with exactly the same content, and the prefixes of
|
|
271
|
+
* `next` still cover every address `previous` protected, however split.
|
|
272
|
+
*
|
|
273
|
+
* Such a step is a cluster topology change: a node joins the egress, or a cluster's hub joins the
|
|
274
|
+
* platform endpoints. It changes no address, endpoint or pool anything already allocated or selected
|
|
275
|
+
* under `previous` relies on. It does not waive the step's barrier: every egress authority still
|
|
276
|
+
* acknowledges `next` with its own protection receipt before an allocation is bound to it
|
|
277
|
+
* (`bindRuntimeNetworkAllocationProtection`). Any removal or change, a later step than the next one,
|
|
278
|
+
* or another chain answers `false`. It validates both authorities, including their digests, and
|
|
279
|
+
* rejects either that does not validate.
|
|
280
|
+
*/
|
|
281
|
+
export const continuesRuntimeNetworkProtection = async (previousValue: unknown, nextValue: unknown): Promise<boolean> => {
|
|
282
|
+
const previous = snapshotRuntimeNetworkProtectedAuthority(previousValue);
|
|
283
|
+
const next = snapshotRuntimeNetworkProtectedAuthority(nextValue);
|
|
284
|
+
requireValue(previous.digest === await computeRuntimeNetworkProtectedAuthorityDigest(previous)
|
|
285
|
+
&& next.digest === await computeRuntimeNetworkProtectedAuthorityDigest(next));
|
|
286
|
+
if (equals(previous, next)) return true;
|
|
287
|
+
const ownerKey = (value: IRuntimeNetworkProtectedAuthority['egressAuthorities'][number]) =>
|
|
288
|
+
canonical([value.nodeId, value.runtimeNamespace]);
|
|
289
|
+
return next.id === previous.id && equals(next.controller, previous.controller)
|
|
290
|
+
&& equals(next.previous, { id: previous.id, generation: previous.generation, digest: previous.digest })
|
|
291
|
+
&& retains(previous.egressAuthorities, next.egressAuthorities, ownerKey)
|
|
292
|
+
&& retains(previous.pools, next.pools, value => value.id)
|
|
293
|
+
&& retains(previous.resolvers, next.resolvers, value => value.id)
|
|
294
|
+
&& retains(previous.platformEndpoints, next.platformEndpoints, value => value.id)
|
|
295
|
+
&& previous.prefixes.every(prefix => covered(prefix, next.prefixes));
|
|
296
|
+
};
|
|
297
|
+
|
|
252
298
|
/** Detached, digest-verified allocation binding. Does not establish pool activation or live link identity. */
|
|
253
299
|
export const bindRuntimeNetworkHandoffLease = async (leaseValue: unknown, authorityValue: unknown): Promise<{
|
|
254
300
|
lease: IRuntimeNetworkHandoffLease; authority: IRuntimeNetworkProtectedAuthority;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { IRuntimeAuthorityReference } from './runtimeassignment.js';
|
|
2
2
|
import { runtimeNetworkAddressPlanContract, type TRuntimeNetworkVpnTransport } from './networkaddressplan.js';
|
|
3
3
|
import { snapshotRuntimeSessionBinding, type IRuntimeSessionBinding } from './runtimesession.js';
|
|
4
|
+
import { continuesRuntimeNetworkProtection } from './networkauthority.js';
|
|
4
5
|
import { snapshotRuntimeNetworkProjection, validateRuntimeNetworkProjection,
|
|
5
6
|
type IRuntimeNetworkProjection } from './networkprojection.js';
|
|
6
7
|
import { snapshotRuntimeNetworkDnsLeaseRenewal, validateRuntimeNetworkDnsLeaseRenewal,
|
|
@@ -84,11 +85,11 @@ export const bindGetRuntimeManagedVpnCredentialRequest = async (value: unknown,
|
|
|
84
85
|
* A valid projection's handoff lease names the projection's own node scope, so one handoff
|
|
85
86
|
* reference is one node scope and the scope needs no comparison of its own.
|
|
86
87
|
*/
|
|
87
|
-
const continuesMembership = (previous: IRuntimeNetworkProjection, next: IRuntimeNetworkProjection): boolean =>
|
|
88
|
+
const continuesMembership = async (previous: IRuntimeNetworkProjection, next: IRuntimeNetworkProjection): Promise<boolean> =>
|
|
88
89
|
previous.handoff !== null && next.handoff !== null && previous.id === next.id
|
|
89
|
-
&& networkEqual(networkReferenceOf(previous.protectedAuthority), networkReferenceOf(next.protectedAuthority))
|
|
90
90
|
&& networkEqual(networkReferenceOf(previous.handoff), networkReferenceOf(next.handoff))
|
|
91
|
-
&& (next.generation > previous.generation || networkEqual(networkReferenceOf(previous), networkReferenceOf(next)))
|
|
91
|
+
&& (next.generation > previous.generation || networkEqual(networkReferenceOf(previous), networkReferenceOf(next)))
|
|
92
|
+
&& await continuesRuntimeNetworkProtection(previous.protectedAuthority, next.protectedAuthority);
|
|
92
93
|
|
|
93
94
|
/** What a membership's credential keeps across its projections: everything but the projection and the expiry. */
|
|
94
95
|
const credentialIdentity = (value: IGetRuntimeManagedVpnCredentialResponse) => ({
|
|
@@ -98,17 +99,21 @@ const credentialIdentity = (value: IGetRuntimeManagedVpnCredentialResponse) => (
|
|
|
98
99
|
|
|
99
100
|
/**
|
|
100
101
|
* Whether `next` continues the managed VPN membership `previous` belongs to: the same projection
|
|
101
|
-
* lineage (`id`),
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
*
|
|
102
|
+
* lineage (`id`), a protected authority that continues the previous one
|
|
103
|
+
* (`continuesRuntimeNetworkProtection`: the same authority, or its next step that only adds), and
|
|
104
|
+
* the same handoff lease, which names the node scope and carries the node's router incarnation.
|
|
105
|
+
* Both must hold a handoff, because a node without one is no member. `next` is `previous` itself
|
|
106
|
+
* or a later generation; an earlier one, or another projection under the same generation,
|
|
107
|
+
* continues nothing.
|
|
105
108
|
*
|
|
106
109
|
* Everything else a projection states may move under one membership: its workload endpoints, their
|
|
107
110
|
* readiness, observations and egress, its private networks, its router selection and its DNS window.
|
|
108
|
-
* Those are what the member's network carries, never who the member is.
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* (
|
|
111
|
+
* Those are what the member's network carries, never who the member is. So does a cluster topology
|
|
112
|
+
* change: a node joining the egress or a cluster hub joining the platform endpoints is an additive
|
|
113
|
+
* protection step, and every member keeps its key pair across it. A protection step that removes or
|
|
114
|
+
* changes anything, or skips a step, a fresh handoff (router reincarnation) or a new controller
|
|
115
|
+
* epoch ends the membership. Whether the hub a credential names is still selected is the
|
|
116
|
+
* credential's question (`bindGetRuntimeManagedVpnCredentialSuccessor`), not the membership's.
|
|
112
117
|
*
|
|
113
118
|
* Validates both complete projections and rejects either that does not validate; a valid pair that
|
|
114
119
|
* is not one membership answers `false`. It samples no clock and fences no session.
|
|
@@ -190,7 +195,7 @@ export const bindGetRuntimeManagedVpnCredentialSuccessor = async (value: unknown
|
|
|
190
195
|
const previousProjection = await validateRuntimeNetworkProjection(previousInput);
|
|
191
196
|
const projection = await validateRuntimeNetworkProjection(projectionInput);
|
|
192
197
|
const renewal = renewalInput === null ? null : await validateRuntimeNetworkDnsLeaseRenewal(renewalInput);
|
|
193
|
-
requireNetwork(continuesMembership(previousProjection, projection));
|
|
198
|
+
requireNetwork(await continuesMembership(previousProjection, projection));
|
|
194
199
|
requireNetwork(networkEqual(previous.session, trusted)
|
|
195
200
|
&& networkEqual(previous.projection, networkReferenceOf(previousProjection)));
|
|
196
201
|
requireNetwork(networkEqual(credentialIdentity(previous), credentialIdentity(response)));
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import type { TSha256Digest } from './immutableimage.js';
|
|
2
|
+
import type { IRuntimeAuthorityReference } from './runtimeassignment.js';
|
|
3
|
+
import type { IRuntimeNetworkNodeScope } from './networkprojection.js';
|
|
4
|
+
import type { IRuntimeNetworkProtectedAuthority } from './networkauthority.js';
|
|
5
|
+
import { computeRuntimeNetworkProtectedAuthorityDigest, runtimeNetworkAuthorityContract,
|
|
6
|
+
snapshotRuntimeNetworkProtectedAuthority } from './networkauthority.js';
|
|
7
|
+
import { nodeRuntimeRetirementDispositions, type TNodeRuntimeRetirementDisposition } from './noderetirement.js';
|
|
8
|
+
import { readDataElements } from '../private/dataproperties.js';
|
|
9
|
+
import { isOneOf } from '../private/producercontract.js';
|
|
10
|
+
import { captureNetwork, failNetwork, networkCanonical, networkCounter, networkCoveredBy, networkDigest, networkEqual,
|
|
11
|
+
networkHash, networkId, networkList, networkNodeId, networkRecord, networkReference, networkReferenceOf, networkSafe,
|
|
12
|
+
networkScope, networkSorted, requireNetwork } from '../private/networkcontract.js';
|
|
13
|
+
|
|
14
|
+
/** One egress owner of a protected authority, as `IRuntimeNetworkProtectedAuthority.egressAuthorities` names it. */
|
|
15
|
+
export interface IRuntimeNetworkEgressOwner {
|
|
16
|
+
nodeId: string;
|
|
17
|
+
runtimeNamespace: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** A remaining owner's acknowledged projection head, which carries no endpoint of the retired owner. */
|
|
21
|
+
export interface IRuntimeNetworkEgressRetirementClearance extends IRuntimeNetworkEgressOwner {
|
|
22
|
+
projection: IRuntimeAuthorityReference;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The independent fence that lets one egress owner leave a protected authority.
|
|
27
|
+
*
|
|
28
|
+
* A protected authority's egress owners only grow by default: an owner that is offline, revoked or
|
|
29
|
+
* gone can never acknowledge a successor, and omitting it is not a revocation. This record is the
|
|
30
|
+
* controller's statement that the owner holds no packet authority any more, recorded against the
|
|
31
|
+
* exact authority it is about to leave. Every member is evidence the controller read from its own
|
|
32
|
+
* durable state when it recorded the fence:
|
|
33
|
+
*
|
|
34
|
+
* 1. the node carries an `INodeRuntimeRetirement` row (`disposition` copies it);
|
|
35
|
+
* 2. both node credentials are revoked (`revokedCredentials`, committed at `revokedAt`), so the node
|
|
36
|
+
* can no longer register, renew a DNS lease or fetch a managed VPN credential;
|
|
37
|
+
* 3. every DNS and managed VPN window the node was ever issued has ended (`packetWindowExpiresAt`),
|
|
38
|
+
* so no hub relays for it even if it was never told to stop;
|
|
39
|
+
* 4. every handoff and workload lease the node was granted is quarantined (`quarantinedHandoffs`,
|
|
40
|
+
* `quarantinedWorkloads`) and is never handed out again;
|
|
41
|
+
* 5. every remaining owner of `protectedAuthority` acknowledged a projection head that carries no
|
|
42
|
+
* endpoint of the node (`clearedProjections`).
|
|
43
|
+
*
|
|
44
|
+
* `lastReceipt` is the node's last accepted protection receipt. A `withdrawn` node took part in its
|
|
45
|
+
* retirement, so it always has one — its null withdrawal; a `lost` node may never have reported.
|
|
46
|
+
*
|
|
47
|
+
* A structural snapshot and digest do not authenticate any of it: the controller must fence the
|
|
48
|
+
* rows it read together with the authority it stages.
|
|
49
|
+
*/
|
|
50
|
+
export interface IRuntimeNetworkEgressRetirement extends IRuntimeNetworkNodeScope {
|
|
51
|
+
/** The exact protected authority the owner leaves: the predecessor of the step that drops it. */
|
|
52
|
+
protectedAuthority: IRuntimeAuthorityReference;
|
|
53
|
+
disposition: TNodeRuntimeRetirementDisposition;
|
|
54
|
+
lastReceipt: IRuntimeAuthorityReference | null;
|
|
55
|
+
/** The generation each node credential was revoked at. */
|
|
56
|
+
revokedCredentials: { spark: number; pallet: number };
|
|
57
|
+
/** Unix milliseconds on the controller's clock when the later of the two revocations committed. */
|
|
58
|
+
revokedAt: number;
|
|
59
|
+
/**
|
|
60
|
+
* Unix milliseconds: the latest end of any DNS or managed VPN window the node was ever issued, or
|
|
61
|
+
* `revokedAt` when it was issued none.
|
|
62
|
+
*/
|
|
63
|
+
packetWindowExpiresAt: number;
|
|
64
|
+
/** Unix milliseconds when the fence was recorded: never before `revokedAt` or `packetWindowExpiresAt`. */
|
|
65
|
+
fencedAt: number;
|
|
66
|
+
/** Every handoff lease the node was granted, each quarantined, in canonical order. */
|
|
67
|
+
quarantinedHandoffs: IRuntimeAuthorityReference[];
|
|
68
|
+
/** Every workload lease the node was granted, each quarantined, in canonical order. */
|
|
69
|
+
quarantinedWorkloads: IRuntimeAuthorityReference[];
|
|
70
|
+
/** One entry per remaining owner of `protectedAuthority`, in canonical owner order. */
|
|
71
|
+
clearedProjections: IRuntimeNetworkEgressRetirementClearance[];
|
|
72
|
+
digest: TSha256Digest;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const runtimeNetworkEgressRetirementContract = Object.freeze({
|
|
76
|
+
digestDomain: 'serve.zone/runtime-network-egress-retirement',
|
|
77
|
+
maximumQuarantinedHandoffs: runtimeNetworkAuthorityContract.maximumRetainedHandoffLeases,
|
|
78
|
+
maximumQuarantinedWorkloads: 512,
|
|
79
|
+
maximumClearedProjections: runtimeNetworkAuthorityContract.maximumEgressAuthorities - 1,
|
|
80
|
+
/** Fences one step may consume. Each is read on its own, so one step stays bounded. */
|
|
81
|
+
maximumFencesPerStep: 16,
|
|
82
|
+
/** Owners every earlier step fenced, over the lifetime of one protected authority. */
|
|
83
|
+
maximumRetiredOwners: 4096,
|
|
84
|
+
removal: 'absent-owner-requires-fence-bound-to-exact-previous-authority',
|
|
85
|
+
reentry: 'a-fenced-owner-never-returns',
|
|
86
|
+
} as const);
|
|
87
|
+
|
|
88
|
+
const ownerKey = (value: IRuntimeNetworkEgressOwner): string => networkCanonical([value.nodeId, value.runtimeNamespace]);
|
|
89
|
+
const referenceKey = (value: IRuntimeAuthorityReference): string => networkCanonical(value);
|
|
90
|
+
|
|
91
|
+
const readOwner = (value: unknown): IRuntimeNetworkEgressOwner => {
|
|
92
|
+
const item = networkRecord(value, ['nodeId', 'runtimeNamespace']);
|
|
93
|
+
return { nodeId: networkNodeId(item.nodeId), runtimeNamespace: networkId(item.runtimeNamespace) };
|
|
94
|
+
};
|
|
95
|
+
const readReferences = (value: unknown, maximum: number): IRuntimeAuthorityReference[] =>
|
|
96
|
+
networkSorted(networkList(value, maximum, networkReference), referenceKey);
|
|
97
|
+
const readClearance = (value: unknown): IRuntimeNetworkEgressRetirementClearance => {
|
|
98
|
+
const item = networkRecord(value, ['nodeId', 'runtimeNamespace', 'projection']);
|
|
99
|
+
return { ...readOwner({ nodeId: item.nodeId, runtimeNamespace: item.runtimeNamespace }),
|
|
100
|
+
projection: networkReference(item.projection) };
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
/** Exact-key structural snapshot, detached from its input. It verifies no digest and fences nothing. */
|
|
104
|
+
export const snapshotRuntimeNetworkEgressRetirement = (value: unknown): IRuntimeNetworkEgressRetirement => networkSafe(() => {
|
|
105
|
+
const item = networkRecord(captureNetwork(value), ['controller', 'nodeId', 'runtimeNamespace', 'protectedAuthority',
|
|
106
|
+
'disposition', 'lastReceipt', 'revokedCredentials', 'revokedAt', 'packetWindowExpiresAt', 'fencedAt',
|
|
107
|
+
'quarantinedHandoffs', 'quarantinedWorkloads', 'clearedProjections', 'digest']);
|
|
108
|
+
const scope = networkScope(item);
|
|
109
|
+
const disposition = item.disposition;
|
|
110
|
+
requireNetwork(isOneOf(nodeRuntimeRetirementDispositions, disposition));
|
|
111
|
+
const lastReceipt = item.lastReceipt === null ? null : networkReference(item.lastReceipt);
|
|
112
|
+
requireNetwork(disposition === 'lost' || lastReceipt !== null);
|
|
113
|
+
const credentials = networkRecord(item.revokedCredentials, ['spark', 'pallet']);
|
|
114
|
+
const revokedAt = networkCounter(item.revokedAt), packetWindowExpiresAt = networkCounter(item.packetWindowExpiresAt);
|
|
115
|
+
const fencedAt = networkCounter(item.fencedAt);
|
|
116
|
+
requireNetwork(fencedAt >= revokedAt && fencedAt >= packetWindowExpiresAt);
|
|
117
|
+
const contract = runtimeNetworkEgressRetirementContract;
|
|
118
|
+
const clearedProjections = networkSorted(networkList(item.clearedProjections, contract.maximumClearedProjections,
|
|
119
|
+
readClearance), ownerKey);
|
|
120
|
+
requireNetwork(clearedProjections.every(owner => ownerKey(owner) !== ownerKey(scope)));
|
|
121
|
+
return { ...scope, protectedAuthority: networkReference(item.protectedAuthority), disposition, lastReceipt,
|
|
122
|
+
revokedCredentials: { spark: networkCounter(credentials.spark), pallet: networkCounter(credentials.pallet) },
|
|
123
|
+
revokedAt, packetWindowExpiresAt, fencedAt,
|
|
124
|
+
quarantinedHandoffs: readReferences(item.quarantinedHandoffs, contract.maximumQuarantinedHandoffs),
|
|
125
|
+
quarantinedWorkloads: readReferences(item.quarantinedWorkloads, contract.maximumQuarantinedWorkloads),
|
|
126
|
+
clearedProjections, digest: networkDigest(item.digest) };
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
export const computeRuntimeNetworkEgressRetirementDigest = (value: IRuntimeNetworkEgressRetirement): Promise<TSha256Digest> =>
|
|
130
|
+
networkHash(runtimeNetworkEgressRetirementContract.digestDomain, snapshotRuntimeNetworkEgressRetirement(value));
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Whether `next` may succeed `previous`, judged on its egress owners and the address space it keeps.
|
|
134
|
+
*
|
|
135
|
+
* Pure and fail-closed. `fences` are the egress retirements this step consumes; `retiredOwners` is
|
|
136
|
+
* the complete list of owners every earlier step fenced, which the caller's durable history must
|
|
137
|
+
* supply in canonical owner order. The step is accepted only when:
|
|
138
|
+
*
|
|
139
|
+
* - `next` is the exact successor of `previous` under the same controller, and both digests verify;
|
|
140
|
+
* - an owner of `previous` is absent from `next` only when exactly one fence, recorded against the
|
|
141
|
+
* exact `previous` reference and verified by its digest, names it — a fence for an owner `next`
|
|
142
|
+
* still names, or for an owner `previous` does not name, refuses the step;
|
|
143
|
+
* - every fence's `clearedProjections` names exactly the owners of `previous` this step keeps;
|
|
144
|
+
* - no owner in `retiredOwners` is named by `previous` or `next`, so a fenced owner never returns;
|
|
145
|
+
* - every pool of `previous` is kept unchanged and the prefixes of `next` cover those of `previous`;
|
|
146
|
+
* a step that removes an owner also keeps every resolver of `previous` unchanged.
|
|
147
|
+
*
|
|
148
|
+
* Owners that join in the same step are admitted. With no fence this is the additive owner rule:
|
|
149
|
+
* nobody leaves. It verifies no fence evidence against live state and fences no record.
|
|
150
|
+
*/
|
|
151
|
+
export const bindRuntimeNetworkProtectedAuthorityRetirement = async (
|
|
152
|
+
previousValue: unknown, nextValue: unknown, fencesValue: unknown, retiredOwnersValue: unknown,
|
|
153
|
+
): Promise<{
|
|
154
|
+
previous: IRuntimeNetworkProtectedAuthority;
|
|
155
|
+
next: IRuntimeNetworkProtectedAuthority;
|
|
156
|
+
fences: IRuntimeNetworkEgressRetirement[];
|
|
157
|
+
}> => {
|
|
158
|
+
try {
|
|
159
|
+
const contract = runtimeNetworkEgressRetirementContract;
|
|
160
|
+
const previous = snapshotRuntimeNetworkProtectedAuthority(captureNetwork(previousValue));
|
|
161
|
+
const next = snapshotRuntimeNetworkProtectedAuthority(captureNetwork(nextValue));
|
|
162
|
+
const elements = readDataElements(fencesValue, contract.maximumFencesPerStep);
|
|
163
|
+
requireNetwork(elements);
|
|
164
|
+
const fences = networkSorted(elements.map(snapshotRuntimeNetworkEgressRetirement), ownerKey);
|
|
165
|
+
const retiredOwners = networkSorted(networkList(captureNetwork(retiredOwnersValue), contract.maximumRetiredOwners,
|
|
166
|
+
readOwner), ownerKey);
|
|
167
|
+
requireNetwork(previous.digest === await computeRuntimeNetworkProtectedAuthorityDigest(previous)
|
|
168
|
+
&& next.digest === await computeRuntimeNetworkProtectedAuthorityDigest(next));
|
|
169
|
+
const reference = networkReferenceOf(previous);
|
|
170
|
+
requireNetwork(networkEqual(next.controller, previous.controller) && next.id === previous.id
|
|
171
|
+
&& next.generation === previous.generation + 1 && networkEqual(next.previous, reference));
|
|
172
|
+
|
|
173
|
+
const previousOwners = new Set(previous.egressAuthorities.map(ownerKey));
|
|
174
|
+
const nextOwners = new Set(next.egressAuthorities.map(ownerKey));
|
|
175
|
+
const fenced = new Set(fences.map(ownerKey));
|
|
176
|
+
for (const fence of fences) {
|
|
177
|
+
requireNetwork(fence.digest === await computeRuntimeNetworkEgressRetirementDigest(fence)
|
|
178
|
+
&& networkEqual(fence.controller, previous.controller) && networkEqual(fence.protectedAuthority, reference)
|
|
179
|
+
&& previousOwners.has(ownerKey(fence)) && !nextOwners.has(ownerKey(fence)));
|
|
180
|
+
}
|
|
181
|
+
requireNetwork([...previousOwners].every(owner => nextOwners.has(owner) || fenced.has(owner)));
|
|
182
|
+
const kept = previous.egressAuthorities.filter(owner => !fenced.has(ownerKey(owner))).map(ownerKey);
|
|
183
|
+
for (const fence of fences) {
|
|
184
|
+
requireNetwork(networkEqual(fence.clearedProjections.map(ownerKey), kept));
|
|
185
|
+
}
|
|
186
|
+
requireNetwork(retiredOwners.every(owner => !previousOwners.has(ownerKey(owner)) && !nextOwners.has(ownerKey(owner))));
|
|
187
|
+
|
|
188
|
+
requireNetwork(previous.pools.every(pool => next.pools.some(candidate => networkEqual(candidate, pool)))
|
|
189
|
+
&& previous.prefixes.every(prefix => networkCoveredBy(next.prefixes, prefix)));
|
|
190
|
+
if (fences.length > 0) {
|
|
191
|
+
requireNetwork(previous.resolvers.every(resolver => next.resolvers.some(candidate => networkEqual(candidate, resolver))));
|
|
192
|
+
}
|
|
193
|
+
return { previous, next, fences };
|
|
194
|
+
} catch { return failNetwork(); }
|
|
195
|
+
};
|
|
@@ -5,11 +5,29 @@ const nodeRuntimeRetirementStates = ['retiring', 'retired'] as const;
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* How far a node's retirement has come: `retiring` while the producer still stops and removes the
|
|
8
|
-
* node's slots, the compiler quarantines its handoff and both node credentials are revoked
|
|
9
|
-
*
|
|
8
|
+
* node's slots, the compiler quarantines its handoff and leases, both node credentials are revoked
|
|
9
|
+
* and the node's egress fence (`IRuntimeNetworkEgressRetirement`) is not yet recorded; `retired`
|
|
10
|
+
* once the protected authority no longer names the node and nothing but the node document is left
|
|
11
|
+
* to delete.
|
|
10
12
|
*/
|
|
11
13
|
export type TNodeRuntimeRetirementState = typeof nodeRuntimeRetirementStates[number];
|
|
12
14
|
|
|
15
|
+
/** Every way a node can leave its runtime, in the order an escalation moves through them. */
|
|
16
|
+
export const nodeRuntimeRetirementDispositions = Object.freeze(['withdrawn', 'lost'] as const);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* How the node leaves.
|
|
20
|
+
*
|
|
21
|
+
* `withdrawn`: the node still runs and takes part. Its slots are removed against its own removal
|
|
22
|
+
* receipts, and its Pallet withdraws its protection receipt before its credentials are revoked.
|
|
23
|
+
*
|
|
24
|
+
* `lost`: an administrator states that the node will never report again — its host is gone, wiped
|
|
25
|
+
* or unreachable for good. Its slots are abandoned without removal receipts, which is the one thing
|
|
26
|
+
* this statement authorizes. It authorizes nothing about packets: a lost node leaves the protected
|
|
27
|
+
* authority behind exactly the same controller-owned fence as a withdrawn one.
|
|
28
|
+
*/
|
|
29
|
+
export type TNodeRuntimeRetirementDisposition = typeof nodeRuntimeRetirementDispositions[number];
|
|
30
|
+
|
|
13
31
|
/**
|
|
14
32
|
* That one node leaves its cluster's runtime, stored beside the node document rather than inside
|
|
15
33
|
* it, because a node update merges caller data and no caller may retire a node with it.
|
|
@@ -24,7 +42,9 @@ export interface INodeRuntimeRetirement {
|
|
|
24
42
|
/** The cluster the node is retiring from, copied by Cloudly; never caller-chosen. */
|
|
25
43
|
clusterId: string;
|
|
26
44
|
state: TNodeRuntimeRetirementState;
|
|
27
|
-
/**
|
|
45
|
+
/** How the node leaves; a `withdrawn` retirement still `retiring` may be escalated to `lost`. */
|
|
46
|
+
disposition: TNodeRuntimeRetirementDisposition;
|
|
47
|
+
/** The administrator who asked for the retirement, or for its escalation. */
|
|
28
48
|
actorId: string;
|
|
29
49
|
/** Unix milliseconds on Cloudly's clock, when the row entered its current state. */
|
|
30
50
|
since: number;
|
|
@@ -42,22 +62,38 @@ export const nodeRuntimeRetirementRefusals = Object.freeze([
|
|
|
42
62
|
* `pallet`. Which of the two it is, `getClusterRuntime` says.
|
|
43
63
|
*/
|
|
44
64
|
'cluster-runtime-not-pallet',
|
|
45
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* The node already carries a retirement row that this request cannot move: anything but a
|
|
67
|
+
* `withdrawn` row still `retiring`, asked again as `lost`.
|
|
68
|
+
*/
|
|
46
69
|
'node-already-retired',
|
|
47
70
|
/** `expectedGeneration` is not the cluster runtime's current generation, so a cutover moved underneath the caller. */
|
|
48
71
|
'conflict',
|
|
72
|
+
/**
|
|
73
|
+
* A `lost` retirement of a node whose last accepted report is younger than
|
|
74
|
+
* `clusterNodeObservationFreshnessMs`: a node that still reports is not lost, and it leaves as
|
|
75
|
+
* `withdrawn`.
|
|
76
|
+
*/
|
|
77
|
+
'node-still-reporting',
|
|
49
78
|
] as const);
|
|
50
79
|
|
|
51
80
|
/** One of the reasons Cloudly answers instead of a retirement row. */
|
|
52
81
|
export type TNodeRuntimeRetirementRefusal = typeof nodeRuntimeRetirementRefusals[number];
|
|
53
82
|
|
|
83
|
+
/** One disposition, exactly as `nodeRuntimeRetirementDispositions` spells it. */
|
|
84
|
+
export const snapshotNodeRuntimeRetirementDisposition = (value: unknown): TNodeRuntimeRetirementDisposition => producerSafe(() => {
|
|
85
|
+
requireNetwork(isOneOf(nodeRuntimeRetirementDispositions, value));
|
|
86
|
+
return value;
|
|
87
|
+
});
|
|
88
|
+
|
|
54
89
|
/**
|
|
55
90
|
* Structural snapshot for exact persistence; whether the node exists and whether its cluster admits
|
|
56
91
|
* the retirement is Cloudly's.
|
|
57
92
|
*/
|
|
58
93
|
export const snapshotNodeRuntimeRetirement = (value: unknown): INodeRuntimeRetirement => producerSafe(() => {
|
|
59
|
-
const item = networkRecord(captureNetwork(value), ['id', 'clusterId', 'state', 'actorId', 'since']);
|
|
94
|
+
const item = networkRecord(captureNetwork(value), ['id', 'clusterId', 'state', 'disposition', 'actorId', 'since']);
|
|
60
95
|
requireNetwork(isOneOf(nodeRuntimeRetirementStates, item.state));
|
|
61
96
|
return { id: networkNodeId(item.id), clusterId: networkId(item.clusterId), state: item.state,
|
|
97
|
+
disposition: snapshotNodeRuntimeRetirementDisposition(item.disposition),
|
|
62
98
|
actorId: networkId(item.actorId), since: networkCounter(item.since) };
|
|
63
99
|
});
|
|
@@ -244,3 +244,12 @@ export const networkContains = (outer: string, inner: string): boolean => {
|
|
|
244
244
|
export const networkOverlaps = (left: string, right: string): boolean => {
|
|
245
245
|
const [a, b] = networkPrefixBounds(left), [c, d] = networkPrefixBounds(right); return a <= d && c <= b;
|
|
246
246
|
};
|
|
247
|
+
/** Whether the union of `prefixes`, which never overlap one another, covers every address of `prefix`. */
|
|
248
|
+
export const networkCoveredBy = (prefixes: string[], prefix: string): boolean => {
|
|
249
|
+
const [first, last] = networkPrefixBounds(prefix);
|
|
250
|
+
const covered = prefixes.reduce((sum, candidate) => {
|
|
251
|
+
const [low, high] = networkPrefixBounds(candidate);
|
|
252
|
+
return sum + Math.max(0, Math.min(last, high) - Math.max(first, low) + 1);
|
|
253
|
+
}, 0);
|
|
254
|
+
return covered === last - first + 1;
|
|
255
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as plugins from '../plugins.js';
|
|
2
|
+
import type * as userInterfaces from '../data/user.js';
|
|
3
|
+
import type * as controlTokenInterfaces from '../data/corestorecontroltoken.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Stores the Corestore control token for every cluster relay to read sealed, so an administrator
|
|
7
|
+
* sets it without an exec into Cloudly's process.
|
|
8
|
+
*
|
|
9
|
+
* One token for both Corestore provider configs, stored in one transaction: either both hold the
|
|
10
|
+
* new token or neither does. `expected` is the state `getCorestoreControlTokenState` answered, and
|
|
11
|
+
* Cloudly stores only while the token is still exactly there; a set that committed in between is
|
|
12
|
+
* refused, never overwritten. Only the verified credential of a freshly authenticated
|
|
13
|
+
* administrator is read, and Cloudly writes the `receipt` in the transaction that stores the token.
|
|
14
|
+
* The token is in this request and nowhere else: never in the answer, a log, a hook or a receipt.
|
|
15
|
+
* Cloudly refuses with one of `data.corestoreControlTokenSetRefusals`.
|
|
16
|
+
*/
|
|
17
|
+
export interface IReq_Admin_Cloudly_SetCorestoreControlToken
|
|
18
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
19
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
20
|
+
IReq_Admin_Cloudly_SetCorestoreControlToken
|
|
21
|
+
> {
|
|
22
|
+
method: 'setCorestoreControlToken';
|
|
23
|
+
request: controlTokenInterfaces.ICorestoreControlTokenSetRequest & {
|
|
24
|
+
identity: userInterfaces.IIdentityCredential;
|
|
25
|
+
};
|
|
26
|
+
response: controlTokenInterfaces.ICorestoreControlTokenSetResult;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Whether Cloudly holds the Corestore control token, at which revision, and every receipt of a set,
|
|
31
|
+
* oldest first. Value-free: no token, no hash. Requires an administrator.
|
|
32
|
+
*/
|
|
33
|
+
export interface IReq_Admin_Cloudly_GetCorestoreControlTokenState
|
|
34
|
+
extends plugins.typedrequestInterfaces.implementsTR<
|
|
35
|
+
plugins.typedrequestInterfaces.ITypedRequest,
|
|
36
|
+
IReq_Admin_Cloudly_GetCorestoreControlTokenState
|
|
37
|
+
> {
|
|
38
|
+
method: 'getCorestoreControlTokenState';
|
|
39
|
+
request: {
|
|
40
|
+
identity: userInterfaces.IIdentityCredential;
|
|
41
|
+
};
|
|
42
|
+
response: controlTokenInterfaces.ICorestoreControlTokenStateRead;
|
|
43
|
+
}
|
package/ts/requests/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import * as configRequests from './config.js';
|
|
|
12
12
|
import * as coreMailRequests from './coremail.js';
|
|
13
13
|
import * as coreMailAdminRequests from './coremail.admin.js';
|
|
14
14
|
import * as corestoreRequests from './corestore.js';
|
|
15
|
+
import * as corestoreControlRequests from './corestorecontrol.js';
|
|
15
16
|
import * as deploymentRequests from './deployment.js';
|
|
16
17
|
import * as dnsRequests from './dns.js';
|
|
17
18
|
import * as domainRequests from './domain.js';
|
|
@@ -52,6 +53,7 @@ export {
|
|
|
52
53
|
coreMailRequests as coremail,
|
|
53
54
|
coreMailAdminRequests as coremailAdmin,
|
|
54
55
|
corestoreRequests as corestore,
|
|
56
|
+
corestoreControlRequests as corestorecontrol,
|
|
55
57
|
deploymentRequests as deployment,
|
|
56
58
|
dnsRequests as dns,
|
|
57
59
|
domainRequests as domain,
|
package/ts/requests/node.ts
CHANGED
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
INodeCredentialMutationResult,
|
|
13
13
|
TNodeCredentialPurpose,
|
|
14
14
|
} from '../data/nodecredential.js';
|
|
15
|
-
import type { INodeRuntimeRetirement } from '../data/noderetirement.js';
|
|
15
|
+
import type { INodeRuntimeRetirement, TNodeRuntimeRetirementDisposition } from '../data/noderetirement.js';
|
|
16
16
|
import type { INodeRuntimeBindingRead, INodeRuntimeBindingRequest } from '../data/noderuntimebinding.js';
|
|
17
17
|
import type {
|
|
18
18
|
INodeEnrollmentRequest,
|
|
@@ -232,6 +232,13 @@ export interface IReq_Any_Cloudly_DeleteNodeById extends plugins.typedrequestInt
|
|
|
232
232
|
* `expectedGeneration` is the cluster runtime generation the caller read with `getClusterRuntime`:
|
|
233
233
|
* retirement is a statement about a node of a Pallet cluster, so a cutover that moved the phase
|
|
234
234
|
* meanwhile refuses the write instead of retiring a node out of a runtime it no longer runs in.
|
|
235
|
+
*
|
|
236
|
+
* `disposition` states how the node leaves (`data.TNodeRuntimeRetirementDisposition`). A request
|
|
237
|
+
* that states none asks for `withdrawn`, the retirement this request always described: the node
|
|
238
|
+
* takes part, and nothing is abandoned. `lost` is taken only when stated, is refused as
|
|
239
|
+
* `node-still-reporting` for a node that still reports, and escalates a `withdrawn` retirement that
|
|
240
|
+
* is still `retiring`. Neither disposition shortens the egress fence: the node leaves the protected
|
|
241
|
+
* authority only behind its `data.IRuntimeNetworkEgressRetirement`.
|
|
235
242
|
* Every refusal is one of `data.nodeRuntimeRetirementRefusals` and takes nothing away.
|
|
236
243
|
*/
|
|
237
244
|
export interface IReq_Any_Cloudly_RetireClusterNode extends plugins.typedrequestInterfaces.implementsTR<
|
|
@@ -243,6 +250,7 @@ export interface IReq_Any_Cloudly_RetireClusterNode extends plugins.typedrequest
|
|
|
243
250
|
identity: IIdentity;
|
|
244
251
|
nodeId: string;
|
|
245
252
|
expectedGeneration: number;
|
|
253
|
+
disposition?: TNodeRuntimeRetirementDisposition;
|
|
246
254
|
};
|
|
247
255
|
response: {
|
|
248
256
|
retirement: INodeRuntimeRetirement;
|