@serve.zone/interfaces 32.114.0 → 32.116.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 +20 -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/controlledtakeover.d.ts +125 -0
- package/dist_ts/data/controlledtakeover.js +217 -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 +13 -0
- package/dist_ts/data/gateway.js +6 -2
- package/dist_ts/data/gatewayarearows.d.ts +30 -14
- package/dist_ts/data/gatewayarearows.js +54 -21
- 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 +4 -0
- package/dist_ts/data/index.js +5 -1
- package/dist_ts/data/preparedimages.d.ts +80 -0
- package/dist_ts/data/preparedimages.js +154 -0
- package/dist_ts/index.d.ts +10 -2
- package/dist_ts/index.js +11 -3
- package/dist_ts/requests/backup.d.ts +1 -1
- package/dist_ts/requests/backup.js +2 -2
- package/dist_ts/requests/controlledtakeover.d.ts +50 -0
- package/dist_ts/requests/controlledtakeover.js +18 -0
- 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 +10 -0
- package/dist_ts/requests/gatewaycertificatestore.js +27 -10
- 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 +113 -1
- package/readme.md +120 -10
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/backup/index.ts +2 -0
- package/ts/data/controlledtakeover.ts +338 -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 +18 -1
- package/ts/data/gatewayarearows.ts +76 -26
- package/ts/data/gatewayareas.ts +15 -3
- package/ts/data/gatewayareas.validation.ts +10 -4
- package/ts/data/index.ts +4 -0
- package/ts/data/preparedimages.ts +231 -0
- package/ts/index.ts +11 -2
- package/ts/requests/backup.ts +1 -1
- package/ts/requests/controlledtakeover.ts +108 -0
- 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 +34 -9
- 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
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import type { IProtocolOffer } from '../protocol.js';
|
|
2
|
+
import { validateProtocolOffer } from '../protocol.js';
|
|
3
|
+
import { isCanonicalBase64url32, isSha256Hex } from '../private/bearerencoding.js';
|
|
4
|
+
import { validateControllerIdentifier } from '../private/controllercontract.js';
|
|
5
|
+
import { readDataElements, readExactDataRecord } from '../private/dataproperties.js';
|
|
6
|
+
import { isClusterNodeId } from '../private/nodeidentifier.js';
|
|
7
|
+
import { outcomeUnknownCode } from './outcomeunknown.js';
|
|
8
|
+
import { isReleaseVersion } from './releaseversion.js';
|
|
9
|
+
|
|
10
|
+
export const dcStorageBounds = Object.freeze({
|
|
11
|
+
mountPathLength: 255,
|
|
12
|
+
volumesPerNode: 64,
|
|
13
|
+
membersPerPool: 16,
|
|
14
|
+
reportedMembersPerNode: 64,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const dcStorageEnrollmentStates = Object.freeze(['pending', 'enrolled', 'revoked'] as const);
|
|
18
|
+
export const dcStorageNodeHealthStates = Object.freeze(['unknown', 'healthy', 'degraded', 'offline'] as const);
|
|
19
|
+
export const dcStorageVolumeHealthStates = Object.freeze(['healthy', 'degraded', 'unavailable'] as const);
|
|
20
|
+
export const dcStoragePoolStates = Object.freeze(['writable', 'read-only', 'unavailable'] as const);
|
|
21
|
+
export const dcStoragePoolMemberStates = Object.freeze([
|
|
22
|
+
'pending', 'admitting', 'active', 'draining', 'drained', 'replacing', 'faulted', 'retired',
|
|
23
|
+
] as const);
|
|
24
|
+
export const dcStorageNativeMemberStates = Object.freeze(['stopped', 'starting', 'ready', 'faulted'] as const);
|
|
25
|
+
export const dcStorageVolumeRefusals = Object.freeze([
|
|
26
|
+
'mount-missing', 'identity-unreadable', 'mount-target-mismatch',
|
|
27
|
+
'filesystem-uuid-missing', 'filesystem-uuid-mismatch', 'marker-missing', 'marker-mismatch',
|
|
28
|
+
] as const);
|
|
29
|
+
export const dcStorageTransitionRefusals = Object.freeze([
|
|
30
|
+
'invalid-member-transition', 'volume-not-writable', 'native-operation-unsupported',
|
|
31
|
+
'quorum-unsafe', 'writer-not-fenced', 'drain-incomplete', 'replacement-not-reserved',
|
|
32
|
+
'native-membership-unconfirmed',
|
|
33
|
+
] as const);
|
|
34
|
+
export const dcStorageRefusals = Object.freeze([
|
|
35
|
+
'request-invalid', 'administrator-required', 'fresh-sign-in-required', 'enrollment-invalid',
|
|
36
|
+
'credential-invalid', 'protocol-incompatible', 'capability-unsupported', 'not-found',
|
|
37
|
+
'location-not-found', 'placement-conflict', 'stale-fence', 'volume-in-use',
|
|
38
|
+
...dcStorageVolumeRefusals, ...dcStorageTransitionRefusals, outcomeUnknownCode,
|
|
39
|
+
] as const);
|
|
40
|
+
|
|
41
|
+
export type TDcStorageVolumeRefusal = typeof dcStorageVolumeRefusals[number];
|
|
42
|
+
export type TDcStorageTransitionRefusal = typeof dcStorageTransitionRefusals[number];
|
|
43
|
+
export type TDcStorageRefusal = typeof dcStorageRefusals[number];
|
|
44
|
+
export type TDcStoragePoolMemberState = typeof dcStoragePoolMemberStates[number];
|
|
45
|
+
|
|
46
|
+
export interface IDcStorageFailureDomain {
|
|
47
|
+
/** Cloudly inventory IDs, scoped to the location. VMs on the same host share hostId. */
|
|
48
|
+
hostId: string;
|
|
49
|
+
rackId: string | null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface IDcStorageCapabilities {
|
|
53
|
+
filesystemVolumes: boolean;
|
|
54
|
+
/** The node can supervise a native member. This alone authorizes no topology changes. */
|
|
55
|
+
objectStorageMembers: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Controller-owned inventory. lastSeenAt is Cloudly's receive time, in Unix milliseconds. */
|
|
59
|
+
export interface IDcStorageNode {
|
|
60
|
+
id: string;
|
|
61
|
+
locationId: string;
|
|
62
|
+
failureDomain: IDcStorageFailureDomain;
|
|
63
|
+
enrollmentState: typeof dcStorageEnrollmentStates[number];
|
|
64
|
+
credentialGeneration: number;
|
|
65
|
+
/** CAS revision for controller-owned node intent, including assignments. */
|
|
66
|
+
revision: number;
|
|
67
|
+
softwareVersion: string | null;
|
|
68
|
+
capabilities: IDcStorageCapabilities;
|
|
69
|
+
health: typeof dcStorageNodeHealthStates[number];
|
|
70
|
+
lastSeenAt: number | null;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface IDcStorageFilesystemIdentity {
|
|
74
|
+
mountPath: string;
|
|
75
|
+
fsUuid: string;
|
|
76
|
+
markerId: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface IDcStorageVolumeAssignment {
|
|
80
|
+
volumeId: string;
|
|
81
|
+
nodeId: string;
|
|
82
|
+
/** Increases on any new assignment of this volume. Retain the high-water mark after release. */
|
|
83
|
+
generation: number;
|
|
84
|
+
expected: IDcStorageFilesystemIdentity;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type TDcStorageObservedFilesystem =
|
|
88
|
+
| { kind: 'unmounted' }
|
|
89
|
+
| { kind: 'unreadable' }
|
|
90
|
+
| { kind: 'mounted'; mountPath: string; fsUuid: string | null; markerId: string | null };
|
|
91
|
+
|
|
92
|
+
export type TDcStorageVolumeVerification = { kind: 'verified' }
|
|
93
|
+
| { kind: 'refused'; reason: TDcStorageVolumeRefusal };
|
|
94
|
+
|
|
95
|
+
export interface IDcStorageCapacity {
|
|
96
|
+
totalBytes: number;
|
|
97
|
+
usedBytes: number;
|
|
98
|
+
/** May exclude reserved blocks, so usedBytes + availableBytes may be less than totalBytes. */
|
|
99
|
+
availableBytes: number;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
interface IDcStorageVolumeObservation {
|
|
103
|
+
verification: TDcStorageVolumeVerification;
|
|
104
|
+
capacity: IDcStorageCapacity | null;
|
|
105
|
+
/** True on refusal, regardless of the kernel mount flags. */
|
|
106
|
+
readOnly: boolean;
|
|
107
|
+
health: typeof dcStorageVolumeHealthStates[number];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface IDcStorageSessionFence {
|
|
111
|
+
controllerEpoch: number;
|
|
112
|
+
credentialGeneration: number;
|
|
113
|
+
sessionEpoch: number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Private verification result. The paths and UUIDs belong in administrator inspection only. */
|
|
117
|
+
export interface IDcStorageVolumeStatus extends IDcStorageVolumeObservation {
|
|
118
|
+
assignment: IDcStorageVolumeAssignment;
|
|
119
|
+
fence: IDcStorageSessionFence;
|
|
120
|
+
observed: TDcStorageObservedFilesystem;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface IDcStoragePoolProfile {
|
|
124
|
+
dataShards: number;
|
|
125
|
+
parityShards: number;
|
|
126
|
+
/** Phase 1 places one shard per selected domain. Rack placement also requires distinct hosts. */
|
|
127
|
+
failureDomain: 'host' | 'rack';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface IDcStoragePoolMember {
|
|
131
|
+
poolId: string;
|
|
132
|
+
/** Stable logical slot, zero-based within dataShards + parityShards. */
|
|
133
|
+
slot: number;
|
|
134
|
+
nodeId: string;
|
|
135
|
+
volumeId: string;
|
|
136
|
+
volumeGeneration: number;
|
|
137
|
+
controllerEpoch: number;
|
|
138
|
+
failureDomain: IDcStorageFailureDomain;
|
|
139
|
+
/** Incarnation of the slot. A replacement raises it before the new owner begins. */
|
|
140
|
+
generation: number;
|
|
141
|
+
state: TDcStoragePoolMemberState;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface IDcStoragePool {
|
|
145
|
+
poolId: string;
|
|
146
|
+
locationId: string;
|
|
147
|
+
/** Durable CAS position for the pool intent. */
|
|
148
|
+
controllerEpoch: number;
|
|
149
|
+
revision: number;
|
|
150
|
+
profile: IDcStoragePoolProfile;
|
|
151
|
+
/** Cloudly's conservative view from native evidence. */
|
|
152
|
+
health: typeof dcStoragePoolStates[number];
|
|
153
|
+
/** Current slot records only. Cloudly retains superseded records separately. */
|
|
154
|
+
members: IDcStoragePoolMember[];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface IDcStorageRepairProgress {
|
|
158
|
+
shardsChecked: number;
|
|
159
|
+
shardsHealed: number;
|
|
160
|
+
shardsPending: number;
|
|
161
|
+
failed: number;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface IDcStorageVolumeTelemetry extends IDcStorageVolumeObservation {
|
|
165
|
+
volumeId: string;
|
|
166
|
+
generation: number;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface IDcStorageMemberTelemetry {
|
|
170
|
+
poolId: string;
|
|
171
|
+
slot: number;
|
|
172
|
+
generation: number;
|
|
173
|
+
state: typeof dcStorageNativeMemberStates[number];
|
|
174
|
+
quorumHealthy: boolean | null;
|
|
175
|
+
majorityHealthy: boolean | null;
|
|
176
|
+
/** Aggregate counters from the native engine. Null when absent. */
|
|
177
|
+
repair: IDcStorageRepairProgress | null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Observations only. No paths, filesystem identifiers, keys, endpoints or error messages. */
|
|
181
|
+
export interface IDcStorageNodeTelemetryReport {
|
|
182
|
+
nodeId: string;
|
|
183
|
+
fence: IDcStorageSessionFence;
|
|
184
|
+
/** Starts at 0 and advances within one authenticated session. */
|
|
185
|
+
sequence: number;
|
|
186
|
+
health: 'healthy' | 'degraded';
|
|
187
|
+
volumes: IDcStorageVolumeTelemetry[];
|
|
188
|
+
members: IDcStorageMemberTelemetry[];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** Secret-bearing bootstrap request. The bearer itself is generated and retained by the node. */
|
|
192
|
+
export interface IEnrollDcStorageNodeRequest {
|
|
193
|
+
pairingCode: string;
|
|
194
|
+
bearerSha256: string;
|
|
195
|
+
protocol: IProtocolOffer;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/** Secret-bearing session registration, bound to the transport that authenticates it. */
|
|
199
|
+
export interface IRegisterDcStorageNodeSessionRequest {
|
|
200
|
+
nodeId: string;
|
|
201
|
+
credentialGeneration: number;
|
|
202
|
+
bearer: string;
|
|
203
|
+
protocol: IProtocolOffer;
|
|
204
|
+
softwareVersion: string;
|
|
205
|
+
capabilities: IDcStorageCapabilities;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const hasValue = <T extends string>(values: readonly T[], value: unknown): value is T =>
|
|
209
|
+
values.some((candidate) => candidate === value);
|
|
210
|
+
const isId = (value: unknown): value is string => validateControllerIdentifier(value, 'id').length === 0;
|
|
211
|
+
const isCount = (value: unknown): value is number =>
|
|
212
|
+
typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
|
213
|
+
const isGeneration = (value: unknown): value is number => isCount(value) && value > 0;
|
|
214
|
+
const isSlot = (value: unknown): value is number => isCount(value) && value < dcStorageBounds.membersPerPool;
|
|
215
|
+
const isUuid = (value: unknown): value is string => typeof value === 'string' && value.length === 36
|
|
216
|
+
&& value !== '00000000-0000-0000-0000-000000000000'
|
|
217
|
+
&& /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/.test(value);
|
|
218
|
+
const isMountPath = (value: unknown): value is string => typeof value === 'string'
|
|
219
|
+
&& value.length <= dcStorageBounds.mountPathLength && !/[^A-Za-z0-9._/-]/.test(value)
|
|
220
|
+
&& value.startsWith('/') && value.slice(1).split('/').every((part) => part && part !== '.' && part !== '..');
|
|
221
|
+
|
|
222
|
+
export const isDcStorageRefusal = (value: unknown): value is TDcStorageRefusal => hasValue(dcStorageRefusals, value);
|
|
223
|
+
|
|
224
|
+
/** The typed error exposes a closed code with no values from the refused body. */
|
|
225
|
+
export const readDcStorageRefusalErrorData = (value: unknown): { code: TDcStorageRefusal; retryable: false } | null => {
|
|
226
|
+
const row = readExactDataRecord(value, ['code', 'retryable']);
|
|
227
|
+
return row && isDcStorageRefusal(row.code) && row.retryable === false ? { code: row.code, retryable: false } : null;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const isFailureDomain = (value: unknown): value is IDcStorageFailureDomain => {
|
|
231
|
+
const row = readExactDataRecord(value, ['hostId', 'rackId']);
|
|
232
|
+
return !!row && isId(row.hostId) && (row.rackId === null || isId(row.rackId));
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
const isCapabilities = (value: unknown): value is IDcStorageCapabilities => {
|
|
236
|
+
const row = readExactDataRecord(value, ['filesystemVolumes', 'objectStorageMembers']);
|
|
237
|
+
return !!row && typeof row.filesystemVolumes === 'boolean' && typeof row.objectStorageMembers === 'boolean'
|
|
238
|
+
&& (!row.objectStorageMembers || row.filesystemVolumes);
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
export const isDcStorageNode = (value: unknown): value is IDcStorageNode => {
|
|
242
|
+
const row = readExactDataRecord(value, [
|
|
243
|
+
'id', 'locationId', 'failureDomain', 'enrollmentState', 'credentialGeneration', 'revision',
|
|
244
|
+
'softwareVersion', 'capabilities', 'health', 'lastSeenAt',
|
|
245
|
+
]);
|
|
246
|
+
if (!row || !isClusterNodeId(row.id) || !isId(row.locationId) || !isFailureDomain(row.failureDomain)
|
|
247
|
+
|| !hasValue(dcStorageEnrollmentStates, row.enrollmentState) || !isGeneration(row.credentialGeneration)
|
|
248
|
+
|| !isGeneration(row.revision) || !isCapabilities(row.capabilities) || !hasValue(dcStorageNodeHealthStates, row.health)) {
|
|
249
|
+
return false;
|
|
250
|
+
}
|
|
251
|
+
if (row.lastSeenAt === null) {
|
|
252
|
+
return row.softwareVersion === null && !row.capabilities.filesystemVolumes && row.health === 'unknown';
|
|
253
|
+
}
|
|
254
|
+
return row.enrollmentState !== 'pending' && isCount(row.lastSeenAt) && isReleaseVersion(row.softwareVersion)
|
|
255
|
+
&& row.health !== 'unknown' && (row.enrollmentState !== 'revoked' || row.health === 'offline');
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
export const isDcStorageFilesystemIdentity = (value: unknown): value is IDcStorageFilesystemIdentity => {
|
|
259
|
+
const row = readExactDataRecord(value, ['mountPath', 'fsUuid', 'markerId']);
|
|
260
|
+
return !!row && isMountPath(row.mountPath) && isUuid(row.fsUuid) && isUuid(row.markerId);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
export const isDcStorageVolumeAssignment = (value: unknown): value is IDcStorageVolumeAssignment => {
|
|
264
|
+
const row = readExactDataRecord(value, ['volumeId', 'nodeId', 'generation', 'expected']);
|
|
265
|
+
return !!row && isId(row.volumeId) && isClusterNodeId(row.nodeId) && isGeneration(row.generation)
|
|
266
|
+
&& isDcStorageFilesystemIdentity(row.expected);
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
const isObservedFilesystem = (value: unknown): value is TDcStorageObservedFilesystem => {
|
|
270
|
+
const absent = readExactDataRecord(value, ['kind']);
|
|
271
|
+
if (absent) return absent.kind === 'unmounted' || absent.kind === 'unreadable';
|
|
272
|
+
const mounted = readExactDataRecord(value, ['kind', 'mountPath', 'fsUuid', 'markerId']);
|
|
273
|
+
return !!mounted && mounted.kind === 'mounted' && isMountPath(mounted.mountPath)
|
|
274
|
+
&& (mounted.fsUuid === null || isUuid(mounted.fsUuid)) && (mounted.markerId === null || isUuid(mounted.markerId));
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/** Call with validated identities. Authentication and safe mount probing belong to the consumer. */
|
|
278
|
+
export const judgeDcStorageVolumeIdentity = (
|
|
279
|
+
expected: Readonly<IDcStorageFilesystemIdentity>, observed: Readonly<TDcStorageObservedFilesystem>,
|
|
280
|
+
): TDcStorageVolumeRefusal | null => {
|
|
281
|
+
if (observed.kind === 'unmounted') return 'mount-missing';
|
|
282
|
+
if (observed.kind === 'unreadable') return 'identity-unreadable';
|
|
283
|
+
if (observed.mountPath !== expected.mountPath) return 'mount-target-mismatch';
|
|
284
|
+
if (observed.fsUuid === null) return 'filesystem-uuid-missing';
|
|
285
|
+
if (observed.fsUuid !== expected.fsUuid) return 'filesystem-uuid-mismatch';
|
|
286
|
+
if (observed.markerId === null) return 'marker-missing';
|
|
287
|
+
if (observed.markerId !== expected.markerId) return 'marker-mismatch';
|
|
288
|
+
return null;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
export const isDcStorageSessionFence = (value: unknown): value is IDcStorageSessionFence => {
|
|
292
|
+
const row = readExactDataRecord(value, ['controllerEpoch', 'credentialGeneration', 'sessionEpoch']);
|
|
293
|
+
return !!row && isGeneration(row.controllerEpoch) && isGeneration(row.credentialGeneration)
|
|
294
|
+
&& isGeneration(row.sessionEpoch);
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const isCapacity = (value: unknown): value is IDcStorageCapacity => {
|
|
298
|
+
const row = readExactDataRecord(value, ['totalBytes', 'usedBytes', 'availableBytes']);
|
|
299
|
+
return !!row && isGeneration(row.totalBytes) && isCount(row.usedBytes) && isCount(row.availableBytes)
|
|
300
|
+
&& row.usedBytes <= row.totalBytes && row.availableBytes <= row.totalBytes - row.usedBytes;
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
const readVerification = (value: unknown): TDcStorageVolumeVerification | null => {
|
|
304
|
+
const verified = readExactDataRecord(value, ['kind']);
|
|
305
|
+
if (verified?.kind === 'verified') return { kind: 'verified' };
|
|
306
|
+
const refused = readExactDataRecord(value, ['kind', 'reason']);
|
|
307
|
+
return refused?.kind === 'refused' && hasValue(dcStorageVolumeRefusals, refused.reason)
|
|
308
|
+
? { kind: 'refused', reason: refused.reason } : null;
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
const readVolumeObservation = (row: Record<string, unknown>): IDcStorageVolumeObservation | null => {
|
|
312
|
+
const verification = readVerification(row.verification);
|
|
313
|
+
if (!verification) return null;
|
|
314
|
+
if (verification.kind === 'refused') {
|
|
315
|
+
return row.readOnly === true && row.health === 'unavailable' && row.capacity === null
|
|
316
|
+
? { verification, readOnly: true, health: 'unavailable', capacity: null } : null;
|
|
317
|
+
}
|
|
318
|
+
if (typeof row.readOnly !== 'boolean' || (row.health !== 'healthy' && row.health !== 'degraded')
|
|
319
|
+
|| !isCapacity(row.capacity)) return null;
|
|
320
|
+
return { verification, readOnly: row.readOnly, health: row.health, capacity: { ...row.capacity } };
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export const isDcStorageVolumeStatus = (value: unknown): value is IDcStorageVolumeStatus => {
|
|
324
|
+
const row = readExactDataRecord(value, [
|
|
325
|
+
'assignment', 'fence', 'observed', 'verification', 'capacity', 'readOnly', 'health',
|
|
326
|
+
]);
|
|
327
|
+
if (!row || !isDcStorageVolumeAssignment(row.assignment) || !isDcStorageSessionFence(row.fence)
|
|
328
|
+
|| !isObservedFilesystem(row.observed)) return false;
|
|
329
|
+
const observation = readVolumeObservation(row);
|
|
330
|
+
if (!observation) return false;
|
|
331
|
+
const refusal = judgeDcStorageVolumeIdentity(row.assignment.expected, row.observed);
|
|
332
|
+
return observation.verification.kind === 'verified' ? refusal === null : refusal === observation.verification.reason;
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
export const isDcStoragePoolProfile = (value: unknown): value is IDcStoragePoolProfile => {
|
|
336
|
+
const row = readExactDataRecord(value, ['dataShards', 'parityShards', 'failureDomain']);
|
|
337
|
+
return !!row && isGeneration(row.dataShards) && isGeneration(row.parityShards)
|
|
338
|
+
&& row.dataShards + row.parityShards <= dcStorageBounds.membersPerPool
|
|
339
|
+
&& (row.failureDomain === 'host' || row.failureDomain === 'rack');
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
export const isDcStoragePoolMember = (value: unknown): value is IDcStoragePoolMember => {
|
|
343
|
+
const row = readExactDataRecord(value, [
|
|
344
|
+
'poolId', 'slot', 'nodeId', 'volumeId', 'volumeGeneration', 'controllerEpoch', 'failureDomain', 'generation', 'state',
|
|
345
|
+
]);
|
|
346
|
+
return !!row && isId(row.poolId) && isSlot(row.slot) && isClusterNodeId(row.nodeId) && isId(row.volumeId)
|
|
347
|
+
&& isGeneration(row.volumeGeneration) && isGeneration(row.controllerEpoch) && isFailureDomain(row.failureDomain)
|
|
348
|
+
&& isGeneration(row.generation) && hasValue(dcStoragePoolMemberStates, row.state);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
export const isDcStoragePool = (value: unknown): value is IDcStoragePool => {
|
|
352
|
+
const row = readExactDataRecord(value, ['poolId', 'locationId', 'controllerEpoch', 'revision', 'profile', 'health', 'members']);
|
|
353
|
+
if (!row || !isId(row.poolId) || !isId(row.locationId) || !isGeneration(row.controllerEpoch)
|
|
354
|
+
|| !isGeneration(row.revision) || !isDcStoragePoolProfile(row.profile)
|
|
355
|
+
|| !hasValue(dcStoragePoolStates, row.health)) return false;
|
|
356
|
+
const slots = row.profile.dataShards + row.profile.parityShards;
|
|
357
|
+
const members = readDataElements(row.members, slots);
|
|
358
|
+
if (!members) return false;
|
|
359
|
+
const seen = new Set<string>();
|
|
360
|
+
let serving = 0;
|
|
361
|
+
let acceptingWrites = 0;
|
|
362
|
+
for (const member of members) {
|
|
363
|
+
if (!isDcStoragePoolMember(member) || member.poolId !== row.poolId
|
|
364
|
+
|| member.controllerEpoch !== row.controllerEpoch || member.slot >= slots) return false;
|
|
365
|
+
if (member.state === 'active' || member.state === 'draining') serving++;
|
|
366
|
+
if (member.state === 'active') acceptingWrites++;
|
|
367
|
+
const keys = [`slot:${member.slot}`];
|
|
368
|
+
if (member.state !== 'retired') {
|
|
369
|
+
keys.push(`host:${member.failureDomain.hostId}`, `volume:${member.volumeId}`, `node:${member.nodeId}`);
|
|
370
|
+
if (row.profile.failureDomain === 'rack') {
|
|
371
|
+
if (member.failureDomain.rackId === null) return false;
|
|
372
|
+
keys.push(`rack:${member.failureDomain.rackId}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
for (const key of keys) {
|
|
376
|
+
if (seen.has(key)) return false;
|
|
377
|
+
seen.add(key);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
// These counts only rule out impossible health claims. Native evidence decides actual health.
|
|
381
|
+
if (row.health === 'read-only') return serving >= row.profile.dataShards;
|
|
382
|
+
if (row.health === 'writable') return acceptingWrites >= Math.max(row.profile.dataShards + 1, Math.floor(slots / 2) + 1);
|
|
383
|
+
return true;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
/** Internal Cloudly evidence, derived under the operation fence. Never accept it from a caller. */
|
|
387
|
+
export interface IDcStoragePoolMemberTransitionEvidence {
|
|
388
|
+
volumeVerifiedWritable: boolean;
|
|
389
|
+
nativeOperationSupported: boolean;
|
|
390
|
+
quorumSafe: boolean;
|
|
391
|
+
writerFenced: boolean;
|
|
392
|
+
drainComplete: boolean;
|
|
393
|
+
replacementReserved: boolean;
|
|
394
|
+
nativeMembershipConfirmed: boolean;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const transitions: Record<TDcStoragePoolMemberState, readonly TDcStoragePoolMemberState[]> = {
|
|
398
|
+
pending: ['admitting'],
|
|
399
|
+
admitting: ['active', 'faulted'],
|
|
400
|
+
active: ['draining', 'faulted'],
|
|
401
|
+
draining: ['drained', 'faulted'],
|
|
402
|
+
drained: ['replacing', 'retired'],
|
|
403
|
+
replacing: ['retired', 'faulted'],
|
|
404
|
+
faulted: ['replacing'],
|
|
405
|
+
retired: [],
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
/** Check a new edge under CAS. An idempotent replay is recovered from the operation receipt. */
|
|
409
|
+
export const judgeDcStoragePoolMemberTransition = (
|
|
410
|
+
current: TDcStoragePoolMemberState, next: TDcStoragePoolMemberState,
|
|
411
|
+
evidence: Readonly<IDcStoragePoolMemberTransitionEvidence>,
|
|
412
|
+
): TDcStorageTransitionRefusal | null => {
|
|
413
|
+
if (!transitions[current].includes(next)) return 'invalid-member-transition';
|
|
414
|
+
if (next === 'faulted') return null;
|
|
415
|
+
if (!evidence.nativeOperationSupported) return 'native-operation-unsupported';
|
|
416
|
+
if ((next === 'admitting' || next === 'active' || next === 'replacing') && !evidence.volumeVerifiedWritable) {
|
|
417
|
+
return 'volume-not-writable';
|
|
418
|
+
}
|
|
419
|
+
if (!evidence.quorumSafe) return 'quorum-unsafe';
|
|
420
|
+
if ((next === 'drained' || next === 'replacing' || next === 'retired') && !evidence.writerFenced) {
|
|
421
|
+
return 'writer-not-fenced';
|
|
422
|
+
}
|
|
423
|
+
if (next === 'drained' && !evidence.drainComplete) return 'drain-incomplete';
|
|
424
|
+
if (next === 'replacing' && !evidence.replacementReserved) return 'replacement-not-reserved';
|
|
425
|
+
if ((next === 'active' || next === 'retired') && !evidence.nativeMembershipConfirmed) {
|
|
426
|
+
return 'native-membership-unconfirmed';
|
|
427
|
+
}
|
|
428
|
+
return null;
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
const readVolumeTelemetry = (value: unknown): IDcStorageVolumeTelemetry | null => {
|
|
432
|
+
const row = readExactDataRecord(value, ['volumeId', 'generation', 'verification', 'capacity', 'readOnly', 'health']);
|
|
433
|
+
if (!row || !isId(row.volumeId) || !isGeneration(row.generation)) return null;
|
|
434
|
+
const observation = readVolumeObservation(row);
|
|
435
|
+
return observation ? { volumeId: row.volumeId, generation: row.generation, ...observation } : null;
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
const readRepairProgress = (value: unknown): IDcStorageRepairProgress | null => {
|
|
439
|
+
const row = readExactDataRecord(value, ['shardsChecked', 'shardsHealed', 'shardsPending', 'failed']);
|
|
440
|
+
if (!row || !isCount(row.shardsChecked) || !isCount(row.shardsHealed)
|
|
441
|
+
|| !isCount(row.shardsPending) || !isCount(row.failed)) return null;
|
|
442
|
+
return { shardsChecked: row.shardsChecked, shardsHealed: row.shardsHealed, shardsPending: row.shardsPending, failed: row.failed };
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
const readMemberTelemetry = (value: unknown): IDcStorageMemberTelemetry | null => {
|
|
446
|
+
const row = readExactDataRecord(value, [
|
|
447
|
+
'poolId', 'slot', 'generation', 'state', 'quorumHealthy', 'majorityHealthy', 'repair',
|
|
448
|
+
]);
|
|
449
|
+
if (!row || !isId(row.poolId) || !isSlot(row.slot) || !isGeneration(row.generation)
|
|
450
|
+
|| !hasValue(dcStorageNativeMemberStates, row.state)
|
|
451
|
+
|| (row.quorumHealthy !== null && typeof row.quorumHealthy !== 'boolean')
|
|
452
|
+
|| (row.majorityHealthy !== null && typeof row.majorityHealthy !== 'boolean')) return null;
|
|
453
|
+
const repair = readRepairProgress(row.repair);
|
|
454
|
+
if (row.repair !== null && !repair) return null;
|
|
455
|
+
return {
|
|
456
|
+
poolId: row.poolId, slot: row.slot, generation: row.generation, state: row.state,
|
|
457
|
+
quorumHealthy: row.quorumHealthy, majorityHealthy: row.majorityHealthy, repair,
|
|
458
|
+
};
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
const readUniqueRows = <T>(
|
|
462
|
+
value: unknown, maximum: number, read: (row: unknown) => T | null, keyOf: (row: T) => string,
|
|
463
|
+
): T[] | null => {
|
|
464
|
+
const rows = readDataElements(value, maximum);
|
|
465
|
+
if (!rows) return null;
|
|
466
|
+
const result: T[] = [];
|
|
467
|
+
const keys = new Set<string>();
|
|
468
|
+
for (const raw of rows) {
|
|
469
|
+
const row = read(raw);
|
|
470
|
+
if (!row) return null;
|
|
471
|
+
const key = keyOf(row);
|
|
472
|
+
if (keys.has(key)) return null;
|
|
473
|
+
keys.add(key);
|
|
474
|
+
result.push(row);
|
|
475
|
+
}
|
|
476
|
+
return result;
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
/** Defensively rebuild the exact wire record for serialization or persistence. */
|
|
480
|
+
export const snapshotDcStorageNodeTelemetryReport = (value: unknown): IDcStorageNodeTelemetryReport | null => {
|
|
481
|
+
const row = readExactDataRecord(value, ['nodeId', 'fence', 'sequence', 'health', 'volumes', 'members']);
|
|
482
|
+
if (!row || !isClusterNodeId(row.nodeId) || !isDcStorageSessionFence(row.fence) || !isCount(row.sequence)
|
|
483
|
+
|| (row.health !== 'healthy' && row.health !== 'degraded')) return null;
|
|
484
|
+
const volumes = readUniqueRows(row.volumes, dcStorageBounds.volumesPerNode, readVolumeTelemetry, (entry) => entry.volumeId);
|
|
485
|
+
const members = readUniqueRows(row.members, dcStorageBounds.reportedMembersPerNode, readMemberTelemetry,
|
|
486
|
+
(entry) => `${entry.poolId}:${entry.slot}`);
|
|
487
|
+
return volumes && members
|
|
488
|
+
? { nodeId: row.nodeId, fence: { ...row.fence }, sequence: row.sequence, health: row.health, volumes, members } : null;
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
export const isDcStorageNodeTelemetryReport = (value: unknown): value is IDcStorageNodeTelemetryReport =>
|
|
492
|
+
snapshotDcStorageNodeTelemetryReport(value) !== null;
|
|
493
|
+
|
|
494
|
+
export const isEnrollDcStorageNodeRequest = (value: unknown): value is IEnrollDcStorageNodeRequest => {
|
|
495
|
+
const row = readExactDataRecord(value, ['pairingCode', 'bearerSha256', 'protocol']);
|
|
496
|
+
return !!row && isCanonicalBase64url32(row.pairingCode) && isSha256Hex(row.bearerSha256)
|
|
497
|
+
&& validateProtocolOffer(row.protocol).length === 0;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
export const isRegisterDcStorageNodeSessionRequest = (value: unknown): value is IRegisterDcStorageNodeSessionRequest => {
|
|
501
|
+
const row = readExactDataRecord(value, ['nodeId', 'credentialGeneration', 'bearer', 'protocol', 'softwareVersion', 'capabilities']);
|
|
502
|
+
return !!row && isClusterNodeId(row.nodeId) && isGeneration(row.credentialGeneration)
|
|
503
|
+
&& isCanonicalBase64url32(row.bearer) && validateProtocolOffer(row.protocol).length === 0
|
|
504
|
+
&& isReleaseVersion(row.softwareVersion) && isCapabilities(row.capabilities);
|
|
505
|
+
};
|
|
@@ -46,8 +46,9 @@ export const delegatedAdminTokenContract = Object.freeze({
|
|
|
46
46
|
* creates, rotates, retires and revokes nothing.
|
|
47
47
|
* - `serviceCredentials`: a service's platform credential (`SERVEZONE_PLATFORM_AUTHORIZATION`):
|
|
48
48
|
* inspect, ensure, rotate and revoke it.
|
|
49
|
+
* - `monitor`: read clusters, nodes, services, deployments, runtime log attempts and assignment logs.
|
|
49
50
|
*/
|
|
50
|
-
export const delegatedAdminTokenScopes = ['secrets', 'serviceCredentials'] as const;
|
|
51
|
+
export const delegatedAdminTokenScopes = ['secrets', 'serviceCredentials', 'monitor'] as const;
|
|
51
52
|
|
|
52
53
|
export type TDelegatedAdminTokenScope = typeof delegatedAdminTokenScopes[number];
|
|
53
54
|
|
|
@@ -58,6 +59,10 @@ export const delegatedAdminTokenScopeRequests = Object.freeze({
|
|
|
58
59
|
'changeSecretLifecycle',
|
|
59
60
|
] as const),
|
|
60
61
|
serviceCredentials: Object.freeze(['getServiceMachineCredential', 'mutateServiceMachineCredential'] as const),
|
|
62
|
+
monitor: Object.freeze([
|
|
63
|
+
'getClusters', 'getNodes', 'getServices', 'getDeployments', 'getServiceRuntimeLogAttempts',
|
|
64
|
+
'getRuntimeAssignmentLogs',
|
|
65
|
+
] as const),
|
|
61
66
|
}) satisfies Readonly<Record<TDelegatedAdminTokenScope, readonly string[]>>;
|
|
62
67
|
|
|
63
68
|
/** A request one scope admits, by its wire method name. */
|
|
@@ -110,7 +115,7 @@ export interface IDelegatedAdminTokenMint {
|
|
|
110
115
|
* `isDelegatableSecretKeyPrefix`, distinct, at most `maximumSecretKeyPrefixes`; only with the
|
|
111
116
|
* `secrets` scope. Prefixes must be application-specific (`GITSYNC_`): a prefix that overlaps a
|
|
112
117
|
* reserved name is refused. Absent or empty: the token creates, rotates, retires and revokes
|
|
113
|
-
* nothing.
|
|
118
|
+
* nothing. A mint with `monitor` and without `secrets` must omit this member.
|
|
114
119
|
*/
|
|
115
120
|
secretKeyPrefixes?: string[];
|
|
116
121
|
}
|
|
@@ -242,7 +247,8 @@ export const snapshotDelegatedAdminTokenMint = (value: unknown): IDelegatedAdmin
|
|
|
242
247
|
}
|
|
243
248
|
if (namesPrefixes) {
|
|
244
249
|
const prefixes = secretKeyPrefixes(mint.secretKeyPrefixes, false);
|
|
245
|
-
|
|
250
|
+
// Preserve the empty-list input accepted by existing serviceCredentials-only mints.
|
|
251
|
+
requireValue(copy.scopes.includes('secrets') || (prefixes.length === 0 && !copy.scopes.includes('monitor')));
|
|
246
252
|
copy.secretKeyPrefixes = prefixes;
|
|
247
253
|
}
|
|
248
254
|
return copy;
|
package/ts/data/gateway.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TDnsRecordType } from './dns.js';
|
|
2
|
-
import { hasExactKeys, isPlainRecord, readDataElements, readDataProperties } from '../private/dataproperties.js';
|
|
2
|
+
import { hasExactKeys, isPlainRecord, readDataElements, readDataProperties, readDataProperty } from '../private/dataproperties.js';
|
|
3
3
|
import { isPlausibleUnicastIpv4 } from '../private/ipv4.js';
|
|
4
4
|
import type { TCompleteKeyList } from '../private/keylist.js';
|
|
5
5
|
import {
|
|
@@ -285,6 +285,8 @@ export interface IGatewayCapabilities {
|
|
|
285
285
|
vpn?: { peerManagement: boolean };
|
|
286
286
|
networkOverview?: true;
|
|
287
287
|
configEvents?: true;
|
|
288
|
+
/** The adopted controller session serves `readGatewayServiceHealth`. */
|
|
289
|
+
serviceHealth?: true;
|
|
288
290
|
routes: {
|
|
289
291
|
read: boolean;
|
|
290
292
|
write: boolean;
|
|
@@ -319,6 +321,8 @@ export interface IGatewayCapabilities {
|
|
|
319
321
|
exactIssuance?: boolean;
|
|
320
322
|
/** Legacy ACME/Proxy store metadata, import, private export and delete on the adopted session. */
|
|
321
323
|
storeManagement?: true;
|
|
324
|
+
/** Related wildcard import against an observed legacy backing on the adopted session. */
|
|
325
|
+
storeRelatedImport?: true;
|
|
322
326
|
};
|
|
323
327
|
email: {
|
|
324
328
|
domains: boolean;
|
|
@@ -338,6 +342,11 @@ export interface IGatewayCapabilities {
|
|
|
338
342
|
tunnelStatus?: true;
|
|
339
343
|
/** The adopted connector can copy one configured edge's applied connection token. */
|
|
340
344
|
connectionToken?: true;
|
|
345
|
+
/**
|
|
346
|
+
* The edges area accepts `stagedSecret`. Cloudly may send that member only when the gateway
|
|
347
|
+
* advertises this flag. Older gateways reject the whole table even if the member is `null`.
|
|
348
|
+
*/
|
|
349
|
+
stagedSecretRotation?: true;
|
|
341
350
|
};
|
|
342
351
|
dns: {
|
|
343
352
|
authoritative: boolean;
|
|
@@ -364,6 +373,14 @@ export interface IGatewayCapabilities {
|
|
|
364
373
|
};
|
|
365
374
|
}
|
|
366
375
|
|
|
376
|
+
/** The health read is available only when the gateway advertises the literal capability. */
|
|
377
|
+
export const supportsGatewayServiceHealth = (capabilitiesArg: unknown): boolean =>
|
|
378
|
+
readDataProperty(capabilitiesArg, 'serviceHealth')?.value === true;
|
|
379
|
+
|
|
380
|
+
/** Whether the gateway advertises support for edges rows carrying `stagedSecret`. */
|
|
381
|
+
export const supportsGatewayRemoteIngressStagedSecretRotation = (capabilitiesArg: unknown): boolean =>
|
|
382
|
+
readDataProperty(readDataProperty(capabilitiesArg, 'remoteIngress')?.value, 'stagedSecretRotation')?.value === true;
|
|
383
|
+
|
|
367
384
|
/**
|
|
368
385
|
* Capability flags granted to a gateway client token.
|
|
369
386
|
*/
|