@serve.zone/interfaces 32.123.0 → 32.124.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 +8 -0
- package/dist_ts/00_commitinfo_data.js +1 -1
- package/dist_ts/data/backupmx.d.ts +135 -0
- package/dist_ts/data/backupmx.js +128 -0
- package/dist_ts/data/gateway.d.ts +5 -0
- package/dist_ts/data/gateway.js +1 -1
- package/dist_ts/data/gatewayarearows.d.ts +2 -1
- package/dist_ts/data/gatewayarearows.js +1 -1
- package/dist_ts/data/gatewayareas.d.ts +19 -0
- package/dist_ts/data/gatewayareas.js +1 -1
- package/dist_ts/data/gatewayareas.validation.js +37 -5
- package/dist_ts/data/hetzner.d.ts +177 -0
- package/dist_ts/data/hetzner.js +253 -0
- package/dist_ts/data/index.d.ts +2 -0
- package/dist_ts/data/index.js +3 -1
- package/dist_ts/requests/backupmx.d.ts +209 -0
- package/dist_ts/requests/backupmx.js +2 -0
- package/dist_ts/requests/hetzner.d.ts +216 -0
- package/dist_ts/requests/hetzner.js +2 -0
- package/dist_ts/requests/index.d.ts +3 -1
- package/dist_ts/requests/index.js +4 -2
- package/package.json +23 -8
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/backupmx.ts +252 -0
- package/ts/data/gateway.ts +5 -0
- package/ts/data/gatewayarearows.ts +2 -0
- package/ts/data/gatewayareas.ts +20 -0
- package/ts/data/gatewayareas.validation.ts +40 -4
- package/ts/data/hetzner.ts +419 -0
- package/ts/data/index.ts +2 -0
- package/ts/requests/backupmx.ts +275 -0
- package/ts/requests/hetzner.ts +276 -0
- package/ts/requests/index.ts +4 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
import { parseCanonicalIpAddress } from '../private/ipaddress.js';
|
|
2
|
+
|
|
3
|
+
export const managedHetznerHostRoles = Object.freeze([
|
|
4
|
+
'remoteingress',
|
|
5
|
+
'backupmx',
|
|
6
|
+
'witness',
|
|
7
|
+
'cluster-node',
|
|
8
|
+
] as const);
|
|
9
|
+
|
|
10
|
+
export type TManagedHetznerHostRole = typeof managedHetznerHostRoles[number];
|
|
11
|
+
|
|
12
|
+
export const managedHetznerHostLifecycles = Object.freeze([
|
|
13
|
+
'planned',
|
|
14
|
+
'allocating-ip',
|
|
15
|
+
'provisioning',
|
|
16
|
+
'enrolling',
|
|
17
|
+
'active',
|
|
18
|
+
'draining',
|
|
19
|
+
'replacing',
|
|
20
|
+
'decommissioning',
|
|
21
|
+
'error',
|
|
22
|
+
] as const);
|
|
23
|
+
|
|
24
|
+
export type TManagedHetznerHostLifecycle = typeof managedHetznerHostLifecycles[number];
|
|
25
|
+
|
|
26
|
+
export const hetznerRefusals = Object.freeze([
|
|
27
|
+
'request-invalid',
|
|
28
|
+
'project-not-found',
|
|
29
|
+
'project-has-hosts',
|
|
30
|
+
'host-not-found',
|
|
31
|
+
'host-protected',
|
|
32
|
+
'host-queue-not-empty',
|
|
33
|
+
'token-invalid',
|
|
34
|
+
'enrollment-unknown',
|
|
35
|
+
'enrollment-expired',
|
|
36
|
+
'enrollment-used',
|
|
37
|
+
'enrollment-ip-mismatch',
|
|
38
|
+
'provider-unavailable',
|
|
39
|
+
'fresh-sign-in-required',
|
|
40
|
+
] as const);
|
|
41
|
+
|
|
42
|
+
export type THetznerRefusalCode = typeof hetznerRefusals[number];
|
|
43
|
+
|
|
44
|
+
export const hetznerContract = Object.freeze({
|
|
45
|
+
labelKeys: Object.freeze({
|
|
46
|
+
managed: 'servezone.managed',
|
|
47
|
+
controller: 'servezone.controller',
|
|
48
|
+
project: 'servezone.project',
|
|
49
|
+
role: 'servezone.role',
|
|
50
|
+
host: 'servezone.host',
|
|
51
|
+
ruleHash: 'servezone.rulehash',
|
|
52
|
+
} as const),
|
|
53
|
+
defaultImage: 'ubuntu-24.04',
|
|
54
|
+
defaultServerType: 'cx22',
|
|
55
|
+
enrollmentTtlMs: 15 * 60_000,
|
|
56
|
+
enrollmentTokenRandomBytes: 32,
|
|
57
|
+
maximumProjectNameLength: 120,
|
|
58
|
+
maximumHostNameLength: 63,
|
|
59
|
+
maximumAllowedLocations: 16,
|
|
60
|
+
maximumSshKeyIds: 32,
|
|
61
|
+
maximumHostsPerProject: 256,
|
|
62
|
+
} as const);
|
|
63
|
+
|
|
64
|
+
export interface IManagedHetznerProjectDefaults {
|
|
65
|
+
image: string;
|
|
66
|
+
sshKeyIds: number[];
|
|
67
|
+
remoteIngressServerType: string;
|
|
68
|
+
backupMxServerType: string;
|
|
69
|
+
witnessServerType: string;
|
|
70
|
+
clusterNodeServerType: string;
|
|
71
|
+
allowedLocations: string[];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface IManagedHetznerProjectPolicy {
|
|
75
|
+
allowAutoProvision: boolean;
|
|
76
|
+
allowAutoFirewallReconcile: boolean;
|
|
77
|
+
allowAutoDnsPtr: boolean;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export interface IManagedHetznerProjectTokenMetadata {
|
|
81
|
+
configured: boolean;
|
|
82
|
+
updatedAt: number | null;
|
|
83
|
+
/** Short SHA-256 prefix fingerprint (never the token itself). */
|
|
84
|
+
fingerprint: string | null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface IManagedHetznerUnmanagedResource {
|
|
88
|
+
kind: 'server' | 'primary_ip' | 'firewall';
|
|
89
|
+
providerId: number;
|
|
90
|
+
name: string;
|
|
91
|
+
location?: string | null;
|
|
92
|
+
ipv4?: string | null;
|
|
93
|
+
labels: Record<string, string>;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export interface IManagedHetznerProjectSyncStatus {
|
|
97
|
+
checkedAt: number;
|
|
98
|
+
status: 'ok' | 'degraded' | 'error';
|
|
99
|
+
managedServerCount: number;
|
|
100
|
+
unmanagedResources: IManagedHetznerUnmanagedResource[];
|
|
101
|
+
driftCount: number;
|
|
102
|
+
error?: string;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export interface IManagedHetznerProject {
|
|
106
|
+
id: string;
|
|
107
|
+
name: string;
|
|
108
|
+
controllerId: string;
|
|
109
|
+
ownershipMode: 'dedicated';
|
|
110
|
+
defaults: IManagedHetznerProjectDefaults;
|
|
111
|
+
policy: IManagedHetznerProjectPolicy;
|
|
112
|
+
token: IManagedHetznerProjectTokenMetadata;
|
|
113
|
+
syncStatus: IManagedHetznerProjectSyncStatus | null;
|
|
114
|
+
createdAt: number;
|
|
115
|
+
updatedAt: number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface IManagedHetznerRemoteIngressRoleConfig {
|
|
119
|
+
role: 'remoteingress';
|
|
120
|
+
gatewayId: string;
|
|
121
|
+
edgeId: string;
|
|
122
|
+
mailEnabled: boolean;
|
|
123
|
+
mailHostname: string | null;
|
|
124
|
+
tags: string[];
|
|
125
|
+
autoDerivePorts: boolean;
|
|
126
|
+
manualTcpPorts: number[];
|
|
127
|
+
manualUdpPorts: number[];
|
|
128
|
+
hubAllowedCidrs: string[];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface IManagedHetznerBackupMxRoleConfig {
|
|
132
|
+
role: 'backupmx';
|
|
133
|
+
backupMxId: string;
|
|
134
|
+
mailHostname: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface IManagedHetznerWitnessRoleConfig {
|
|
138
|
+
role: 'witness';
|
|
139
|
+
witnessOrigin: string;
|
|
140
|
+
controllerSiteCidrs: string[];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface IManagedHetznerClusterNodeRoleConfig {
|
|
144
|
+
role: 'cluster-node';
|
|
145
|
+
clusterId: string;
|
|
146
|
+
locationId: string | null;
|
|
147
|
+
baremetalId: string | null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export type TManagedHetznerRoleConfig =
|
|
151
|
+
| IManagedHetznerRemoteIngressRoleConfig
|
|
152
|
+
| IManagedHetznerBackupMxRoleConfig
|
|
153
|
+
| IManagedHetznerWitnessRoleConfig
|
|
154
|
+
| IManagedHetznerClusterNodeRoleConfig;
|
|
155
|
+
|
|
156
|
+
export interface IManagedHetznerHostDesired {
|
|
157
|
+
name: string;
|
|
158
|
+
location: string;
|
|
159
|
+
datacenter: string | null;
|
|
160
|
+
serverType: string;
|
|
161
|
+
image: string;
|
|
162
|
+
hostname: string;
|
|
163
|
+
deleteProtected: boolean;
|
|
164
|
+
enableIpv6: boolean;
|
|
165
|
+
roleConfig: TManagedHetznerRoleConfig;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface IManagedHetznerHostObserved {
|
|
169
|
+
hetznerServerId: number | null;
|
|
170
|
+
serverStatus: string | null;
|
|
171
|
+
ipv4: string | null;
|
|
172
|
+
ipv6: string | null;
|
|
173
|
+
primaryIp4Id: number | null;
|
|
174
|
+
primaryIp6Id: number | null;
|
|
175
|
+
ptrIpv4: string | null;
|
|
176
|
+
ptrIpv6: string | null;
|
|
177
|
+
firewallId: number | null;
|
|
178
|
+
firewallRuleHash: string | null;
|
|
179
|
+
deleteProtected: boolean | null;
|
|
180
|
+
installedVersion: string | null;
|
|
181
|
+
enrolledAt: number | null;
|
|
182
|
+
lastReconciledAt: number | null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export interface IManagedHetznerHost {
|
|
186
|
+
id: string;
|
|
187
|
+
projectId: string;
|
|
188
|
+
role: TManagedHetznerHostRole;
|
|
189
|
+
desired: IManagedHetznerHostDesired;
|
|
190
|
+
observed: IManagedHetznerHostObserved;
|
|
191
|
+
lifecycle: TManagedHetznerHostLifecycle;
|
|
192
|
+
adopted: boolean;
|
|
193
|
+
drift: string[];
|
|
194
|
+
lastError: string | null;
|
|
195
|
+
createdAt: number;
|
|
196
|
+
updatedAt: number;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export interface IManagedHetznerFirewallRuleSpec {
|
|
200
|
+
description: string;
|
|
201
|
+
direction: 'in' | 'out';
|
|
202
|
+
protocol: 'tcp' | 'udp' | 'icmp';
|
|
203
|
+
port?: string;
|
|
204
|
+
sourceIps?: string[];
|
|
205
|
+
destinationIps?: string[];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export function isManagedHetznerHostRole(valueArg: unknown): valueArg is TManagedHetznerHostRole {
|
|
209
|
+
return typeof valueArg === 'string' && (managedHetznerHostRoles as readonly string[]).includes(valueArg);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Deterministic Hetzner Cloud labels applied to every server, primary IP, and firewall
|
|
214
|
+
* owned by Cloudly. Values are sanitized to valid Hetzner label syntax (`[A-Za-z0-9_.-]`).
|
|
215
|
+
*/
|
|
216
|
+
export function buildManagedHetznerLabels(inputArg: {
|
|
217
|
+
controllerId: string;
|
|
218
|
+
projectId: string;
|
|
219
|
+
role: TManagedHetznerHostRole;
|
|
220
|
+
hostId: string;
|
|
221
|
+
ruleHash?: string;
|
|
222
|
+
}): Record<string, string> {
|
|
223
|
+
const sanitize = (raw: string): string =>
|
|
224
|
+
raw.replace(/[^A-Za-z0-9_.-]/g, '-').slice(0, 63).replace(/^[^A-Za-z0-9]+|[^A-Za-z0-9]+$/g, '') || 'x';
|
|
225
|
+
return {
|
|
226
|
+
[hetznerContract.labelKeys.managed]: 'true',
|
|
227
|
+
[hetznerContract.labelKeys.controller]: sanitize(inputArg.controllerId),
|
|
228
|
+
[hetznerContract.labelKeys.project]: sanitize(inputArg.projectId),
|
|
229
|
+
[hetznerContract.labelKeys.role]: inputArg.role,
|
|
230
|
+
[hetznerContract.labelKeys.host]: sanitize(inputArg.hostId),
|
|
231
|
+
...(inputArg.ruleHash ? { [hetznerContract.labelKeys.ruleHash]: sanitize(inputArg.ruleHash) } : {}),
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Pure firewall rule planner per host role.
|
|
237
|
+
* - `backupmx` exposes ONLY public TCP 25 + ICMP (control plane is outbound TypedSocket).
|
|
238
|
+
* - `witness` exposes ONLY TCP 443 to configured controller site CIDRs.
|
|
239
|
+
* - `remoteingress` exposes public HTTP/S (unless mail-only), mail ports when mailEnabled,
|
|
240
|
+
* assigned TCP/UDP ports, and hub access CIDRs.
|
|
241
|
+
*/
|
|
242
|
+
export function planManagedHetznerFirewallRules(
|
|
243
|
+
roleConfigArg: TManagedHetznerRoleConfig,
|
|
244
|
+
optionsArg?: { dynamicTcpPorts?: number[]; dynamicUdpPorts?: number[] },
|
|
245
|
+
): IManagedHetznerFirewallRuleSpec[] {
|
|
246
|
+
switch (roleConfigArg.role) {
|
|
247
|
+
case 'backupmx':
|
|
248
|
+
return [
|
|
249
|
+
{
|
|
250
|
+
description: 'Public SMTP inbound',
|
|
251
|
+
direction: 'in',
|
|
252
|
+
protocol: 'tcp',
|
|
253
|
+
port: '25',
|
|
254
|
+
sourceIps: ['0.0.0.0/0', '::/0'],
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
description: 'Public ICMP',
|
|
258
|
+
direction: 'in',
|
|
259
|
+
protocol: 'icmp',
|
|
260
|
+
sourceIps: ['0.0.0.0/0', '::/0'],
|
|
261
|
+
},
|
|
262
|
+
];
|
|
263
|
+
case 'witness': {
|
|
264
|
+
const cidrs = [...new Set(roleConfigArg.controllerSiteCidrs)].sort();
|
|
265
|
+
return cidrs.length > 0
|
|
266
|
+
? [
|
|
267
|
+
{
|
|
268
|
+
description: 'Witness HTTPS from controller sites',
|
|
269
|
+
direction: 'in',
|
|
270
|
+
protocol: 'tcp',
|
|
271
|
+
port: '443',
|
|
272
|
+
sourceIps: cidrs,
|
|
273
|
+
},
|
|
274
|
+
]
|
|
275
|
+
: [];
|
|
276
|
+
}
|
|
277
|
+
case 'remoteingress': {
|
|
278
|
+
const rules: IManagedHetznerFirewallRuleSpec[] = [];
|
|
279
|
+
const tcpPorts = new Set<number>([
|
|
280
|
+
...roleConfigArg.manualTcpPorts,
|
|
281
|
+
...(optionsArg?.dynamicTcpPorts ?? []),
|
|
282
|
+
]);
|
|
283
|
+
const udpPorts = new Set<number>([
|
|
284
|
+
...roleConfigArg.manualUdpPorts,
|
|
285
|
+
...(optionsArg?.dynamicUdpPorts ?? []),
|
|
286
|
+
]);
|
|
287
|
+
if (roleConfigArg.mailEnabled) {
|
|
288
|
+
tcpPorts.add(25);
|
|
289
|
+
tcpPorts.add(465);
|
|
290
|
+
tcpPorts.add(587);
|
|
291
|
+
}
|
|
292
|
+
if (roleConfigArg.autoDerivePorts) {
|
|
293
|
+
tcpPorts.add(80);
|
|
294
|
+
tcpPorts.add(443);
|
|
295
|
+
udpPorts.add(443);
|
|
296
|
+
}
|
|
297
|
+
for (const port of [...tcpPorts].sort((a, b) => a - b)) {
|
|
298
|
+
rules.push({
|
|
299
|
+
description: `RemoteIngress TCP ${port}`,
|
|
300
|
+
direction: 'in',
|
|
301
|
+
protocol: 'tcp',
|
|
302
|
+
port: String(port),
|
|
303
|
+
sourceIps: ['0.0.0.0/0', '::/0'],
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
for (const port of [...udpPorts].sort((a, b) => a - b)) {
|
|
307
|
+
rules.push({
|
|
308
|
+
description: `RemoteIngress UDP ${port}`,
|
|
309
|
+
direction: 'in',
|
|
310
|
+
protocol: 'udp',
|
|
311
|
+
port: String(port),
|
|
312
|
+
sourceIps: ['0.0.0.0/0', '::/0'],
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
const hubCidrs = [...new Set(roleConfigArg.hubAllowedCidrs)].sort();
|
|
316
|
+
if (hubCidrs.length > 0) {
|
|
317
|
+
rules.push({
|
|
318
|
+
description: 'DcRouter hub access',
|
|
319
|
+
direction: 'in',
|
|
320
|
+
protocol: 'tcp',
|
|
321
|
+
port: '1-65535',
|
|
322
|
+
sourceIps: hubCidrs,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
return rules;
|
|
326
|
+
}
|
|
327
|
+
case 'cluster-node':
|
|
328
|
+
return [
|
|
329
|
+
{
|
|
330
|
+
description: 'Cluster node ICMP',
|
|
331
|
+
direction: 'in',
|
|
332
|
+
protocol: 'icmp',
|
|
333
|
+
sourceIps: ['0.0.0.0/0', '::/0'],
|
|
334
|
+
},
|
|
335
|
+
];
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function validateCidrText(valueArg: string): boolean {
|
|
340
|
+
const slash = valueArg.indexOf('/');
|
|
341
|
+
if (slash <= 0) return false;
|
|
342
|
+
const ip = valueArg.slice(0, slash);
|
|
343
|
+
const prefixText = valueArg.slice(slash + 1);
|
|
344
|
+
if (!/^\d{1,3}$/.test(prefixText)) return false;
|
|
345
|
+
const prefix = Number(prefixText);
|
|
346
|
+
const parsed = parseCanonicalIpAddress(ip);
|
|
347
|
+
if (!parsed) return false;
|
|
348
|
+
return parsed.family === 4 ? prefix >= 0 && prefix <= 32 : prefix >= 0 && prefix <= 128;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export function validateManagedHetznerHostName(valueArg: string): boolean {
|
|
352
|
+
return (
|
|
353
|
+
typeof valueArg === 'string'
|
|
354
|
+
&& valueArg.length >= 1
|
|
355
|
+
&& valueArg.length <= hetznerContract.maximumHostNameLength
|
|
356
|
+
&& /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(valueArg)
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export function validateManagedHetznerFqdn(valueArg: string): boolean {
|
|
361
|
+
if (typeof valueArg !== 'string' || valueArg.length < 3 || valueArg.length > 253) return false;
|
|
362
|
+
if (valueArg !== valueArg.toLowerCase() || valueArg.endsWith('.')) return false;
|
|
363
|
+
const labels = valueArg.split('.');
|
|
364
|
+
if (labels.length < 2) return false;
|
|
365
|
+
return labels.every((label) => /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?$/.test(label));
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export function validateManagedHetznerHostDesired(desiredArg: IManagedHetznerHostDesired): string[] {
|
|
369
|
+
const errors: string[] = [];
|
|
370
|
+
if (!validateManagedHetznerHostName(desiredArg.name)) {
|
|
371
|
+
errors.push('desired.name must be a lowercase DNS label (1-63 chars)');
|
|
372
|
+
}
|
|
373
|
+
if (!validateManagedHetznerFqdn(desiredArg.hostname)) {
|
|
374
|
+
errors.push('desired.hostname must be a lowercase FQDN');
|
|
375
|
+
}
|
|
376
|
+
if (!desiredArg.location || !/^[a-z0-9-]+$/.test(desiredArg.location)) {
|
|
377
|
+
errors.push('desired.location must be a non-empty Hetzner location name');
|
|
378
|
+
}
|
|
379
|
+
if (!desiredArg.serverType || !/^[a-z0-9-]+$/.test(desiredArg.serverType)) {
|
|
380
|
+
errors.push('desired.serverType must be a non-empty Hetzner server type');
|
|
381
|
+
}
|
|
382
|
+
if (!desiredArg.image || desiredArg.image.trim().length === 0) {
|
|
383
|
+
errors.push('desired.image must be non-empty');
|
|
384
|
+
}
|
|
385
|
+
if (desiredArg.roleConfig.role === 'witness') {
|
|
386
|
+
if (!desiredArg.deleteProtected) {
|
|
387
|
+
errors.push('witness hosts must have deleteProtected enabled');
|
|
388
|
+
}
|
|
389
|
+
if (!desiredArg.roleConfig.witnessOrigin.startsWith('https://')) {
|
|
390
|
+
errors.push('witnessOrigin must be an https origin');
|
|
391
|
+
}
|
|
392
|
+
for (const cidr of desiredArg.roleConfig.controllerSiteCidrs) {
|
|
393
|
+
if (!validateCidrText(cidr)) {
|
|
394
|
+
errors.push(`invalid controllerSiteCidr: ${cidr}`);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
if (desiredArg.roleConfig.role === 'backupmx') {
|
|
399
|
+
if (!desiredArg.deleteProtected) {
|
|
400
|
+
errors.push('backupmx hosts must have deleteProtected enabled');
|
|
401
|
+
}
|
|
402
|
+
if (!validateManagedHetznerFqdn(desiredArg.roleConfig.mailHostname)) {
|
|
403
|
+
errors.push('backupmx mailHostname must be a lowercase FQDN');
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (desiredArg.roleConfig.role === 'remoteingress') {
|
|
407
|
+
if (desiredArg.roleConfig.mailEnabled && desiredArg.roleConfig.mailHostname !== null) {
|
|
408
|
+
if (!validateManagedHetznerFqdn(desiredArg.roleConfig.mailHostname)) {
|
|
409
|
+
errors.push('remoteingress mailHostname must be a lowercase FQDN');
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
for (const cidr of desiredArg.roleConfig.hubAllowedCidrs) {
|
|
413
|
+
if (!validateCidrText(cidr)) {
|
|
414
|
+
errors.push(`invalid hubAllowedCidr: ${cidr}`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return errors;
|
|
419
|
+
}
|
package/ts/data/index.ts
CHANGED
|
@@ -93,7 +93,9 @@ export * from './secret.js';
|
|
|
93
93
|
export * from './baremetal.js';
|
|
94
94
|
export * from './baseos.js';
|
|
95
95
|
export * from './backup.js';
|
|
96
|
+
export * from './backupmx.js';
|
|
96
97
|
export * from './backuprestorerefusal.js';
|
|
98
|
+
export * from './hetzner.js';
|
|
97
99
|
export * from './clusternode.js';
|
|
98
100
|
export * from './clusternodehostname.js';
|
|
99
101
|
export * from './settings.js';
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import type { ITypedRequest, implementsTR } from '@api.global/typedrequest-interfaces';
|
|
2
|
+
import type {
|
|
3
|
+
IBackupMxDesiredState,
|
|
4
|
+
IBackupMxInstance,
|
|
5
|
+
IBackupMxQueueItemSummary,
|
|
6
|
+
IBackupMxStatus,
|
|
7
|
+
TBackupMxRefusalCode,
|
|
8
|
+
} from '../data/backupmx.js';
|
|
9
|
+
import type { IControllerPeerSet } from '../data/controller.js';
|
|
10
|
+
import type { IIdentityCredential } from '../data/user.js';
|
|
11
|
+
|
|
12
|
+
// ---------------------------------------------------------------------------------------------
|
|
13
|
+
// TypedSocket session protocol (Backup MX daemon <-> Cloudly)
|
|
14
|
+
// ---------------------------------------------------------------------------------------------
|
|
15
|
+
|
|
16
|
+
/** Sent by `@serve.zone/backupmx` immediately after opening its outbound TypedSocket to Cloudly. */
|
|
17
|
+
export interface IReq_BackupMx_Cloudly_Authenticate extends implementsTR<
|
|
18
|
+
ITypedRequest,
|
|
19
|
+
IReq_BackupMx_Cloudly_Authenticate
|
|
20
|
+
> {
|
|
21
|
+
method: 'backupMxAuthenticate';
|
|
22
|
+
request: {
|
|
23
|
+
instanceId: string;
|
|
24
|
+
credentialSecret: string;
|
|
25
|
+
version: string;
|
|
26
|
+
appliedConfigEpoch: number;
|
|
27
|
+
};
|
|
28
|
+
response: {
|
|
29
|
+
ok: true;
|
|
30
|
+
controllerPeerSet: IControllerPeerSet;
|
|
31
|
+
desiredConfigEpoch: number;
|
|
32
|
+
} | {
|
|
33
|
+
ok: false;
|
|
34
|
+
code: TBackupMxRefusalCode;
|
|
35
|
+
message: string;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Periodic or event-driven status & queue counter report from Backup MX daemon to Cloudly. */
|
|
40
|
+
export interface IReq_BackupMx_Cloudly_ReportStatus extends implementsTR<
|
|
41
|
+
ITypedRequest,
|
|
42
|
+
IReq_BackupMx_Cloudly_ReportStatus
|
|
43
|
+
> {
|
|
44
|
+
method: 'backupMxReportStatus';
|
|
45
|
+
request: {
|
|
46
|
+
status: IBackupMxStatus;
|
|
47
|
+
};
|
|
48
|
+
response: {
|
|
49
|
+
acknowledged: true;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Pushed by Cloudly to a connected Backup MX daemon over the live TypedSocket session. */
|
|
54
|
+
export interface IReq_Cloudly_BackupMx_ApplyDesiredState extends implementsTR<
|
|
55
|
+
ITypedRequest,
|
|
56
|
+
IReq_Cloudly_BackupMx_ApplyDesiredState
|
|
57
|
+
> {
|
|
58
|
+
method: 'applyBackupMxDesiredState';
|
|
59
|
+
request: {
|
|
60
|
+
controllerPeerSet: IControllerPeerSet;
|
|
61
|
+
desiredState: IBackupMxDesiredState;
|
|
62
|
+
};
|
|
63
|
+
response: {
|
|
64
|
+
ok: true;
|
|
65
|
+
appliedConfigEpoch: number;
|
|
66
|
+
status: IBackupMxStatus;
|
|
67
|
+
} | {
|
|
68
|
+
ok: false;
|
|
69
|
+
code: TBackupMxRefusalCode;
|
|
70
|
+
message: string;
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Called by Cloudly over the live TypedSocket session to inspect pending or dead queue metadata. */
|
|
75
|
+
export interface IReq_Cloudly_BackupMx_ListQueueItems extends implementsTR<
|
|
76
|
+
ITypedRequest,
|
|
77
|
+
IReq_Cloudly_BackupMx_ListQueueItems
|
|
78
|
+
> {
|
|
79
|
+
method: 'listBackupMxQueueItems';
|
|
80
|
+
request: {
|
|
81
|
+
queue: 'pending' | 'dead';
|
|
82
|
+
domain?: string;
|
|
83
|
+
limit?: number;
|
|
84
|
+
};
|
|
85
|
+
response: {
|
|
86
|
+
items: IBackupMxQueueItemSummary[];
|
|
87
|
+
total: number;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Re-queues one dead-letter message back into `pending` for immediate retry. */
|
|
92
|
+
export interface IReq_Cloudly_BackupMx_RetryDeadItem extends implementsTR<
|
|
93
|
+
ITypedRequest,
|
|
94
|
+
IReq_Cloudly_BackupMx_RetryDeadItem
|
|
95
|
+
> {
|
|
96
|
+
method: 'retryBackupMxDeadItem';
|
|
97
|
+
request: {
|
|
98
|
+
queueId: string;
|
|
99
|
+
};
|
|
100
|
+
response: {
|
|
101
|
+
ok: true;
|
|
102
|
+
} | {
|
|
103
|
+
ok: false;
|
|
104
|
+
code: TBackupMxRefusalCode;
|
|
105
|
+
message: string;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Permanently deletes one dead-letter message from disk. */
|
|
110
|
+
export interface IReq_Cloudly_BackupMx_PurgeDeadItem extends implementsTR<
|
|
111
|
+
ITypedRequest,
|
|
112
|
+
IReq_Cloudly_BackupMx_PurgeDeadItem
|
|
113
|
+
> {
|
|
114
|
+
method: 'purgeBackupMxDeadItem';
|
|
115
|
+
request: {
|
|
116
|
+
queueId: string;
|
|
117
|
+
};
|
|
118
|
+
response: {
|
|
119
|
+
ok: true;
|
|
120
|
+
} | {
|
|
121
|
+
ok: false;
|
|
122
|
+
code: TBackupMxRefusalCode;
|
|
123
|
+
message: string;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ---------------------------------------------------------------------------------------------
|
|
128
|
+
// Cloudly Administrator API
|
|
129
|
+
// ---------------------------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
export interface IReq_Admin_Cloudly_CreateBackupMxInstance extends implementsTR<
|
|
132
|
+
ITypedRequest,
|
|
133
|
+
IReq_Admin_Cloudly_CreateBackupMxInstance
|
|
134
|
+
> {
|
|
135
|
+
method: 'createBackupMxInstance';
|
|
136
|
+
request: {
|
|
137
|
+
identity: IIdentityCredential;
|
|
138
|
+
name: string;
|
|
139
|
+
hostname: string;
|
|
140
|
+
mxPriority?: number;
|
|
141
|
+
ipv4?: string | null;
|
|
142
|
+
ipv6?: string | null;
|
|
143
|
+
hetznerHostId?: string | null;
|
|
144
|
+
enabled?: boolean;
|
|
145
|
+
};
|
|
146
|
+
response: {
|
|
147
|
+
ok: true;
|
|
148
|
+
instance: IBackupMxInstance;
|
|
149
|
+
/** Returned once on creation for manual hosts; Hetzner hosts receive it via claimManagedHostEnrollment. */
|
|
150
|
+
enrollmentSecret?: string;
|
|
151
|
+
} | {
|
|
152
|
+
ok: false;
|
|
153
|
+
code: TBackupMxRefusalCode;
|
|
154
|
+
message: string;
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface IReq_Admin_Cloudly_UpdateBackupMxInstance extends implementsTR<
|
|
159
|
+
ITypedRequest,
|
|
160
|
+
IReq_Admin_Cloudly_UpdateBackupMxInstance
|
|
161
|
+
> {
|
|
162
|
+
method: 'updateBackupMxInstance';
|
|
163
|
+
request: {
|
|
164
|
+
identity: IIdentityCredential;
|
|
165
|
+
instanceId: string;
|
|
166
|
+
name?: string;
|
|
167
|
+
hostname?: string;
|
|
168
|
+
mxPriority?: number;
|
|
169
|
+
ipv4?: string | null;
|
|
170
|
+
ipv6?: string | null;
|
|
171
|
+
enabled?: boolean;
|
|
172
|
+
};
|
|
173
|
+
response: {
|
|
174
|
+
ok: true;
|
|
175
|
+
instance: IBackupMxInstance;
|
|
176
|
+
} | {
|
|
177
|
+
ok: false;
|
|
178
|
+
code: TBackupMxRefusalCode;
|
|
179
|
+
message: string;
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface IReq_Admin_Cloudly_DeleteBackupMxInstance extends implementsTR<
|
|
184
|
+
ITypedRequest,
|
|
185
|
+
IReq_Admin_Cloudly_DeleteBackupMxInstance
|
|
186
|
+
> {
|
|
187
|
+
method: 'deleteBackupMxInstance';
|
|
188
|
+
request: {
|
|
189
|
+
identity: IIdentityCredential;
|
|
190
|
+
instanceId: string;
|
|
191
|
+
forceNonEmptyQueue?: boolean;
|
|
192
|
+
};
|
|
193
|
+
response: {
|
|
194
|
+
ok: true;
|
|
195
|
+
deleted: true;
|
|
196
|
+
} | {
|
|
197
|
+
ok: false;
|
|
198
|
+
code: TBackupMxRefusalCode;
|
|
199
|
+
message: string;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export interface IReq_Admin_Cloudly_ListBackupMxInstances extends implementsTR<
|
|
204
|
+
ITypedRequest,
|
|
205
|
+
IReq_Admin_Cloudly_ListBackupMxInstances
|
|
206
|
+
> {
|
|
207
|
+
method: 'listBackupMxInstances';
|
|
208
|
+
request: {
|
|
209
|
+
identity: IIdentityCredential;
|
|
210
|
+
};
|
|
211
|
+
response: {
|
|
212
|
+
instances: IBackupMxInstance[];
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface IReq_Admin_Cloudly_ListBackupMxInstanceQueue extends implementsTR<
|
|
217
|
+
ITypedRequest,
|
|
218
|
+
IReq_Admin_Cloudly_ListBackupMxInstanceQueue
|
|
219
|
+
> {
|
|
220
|
+
method: 'listBackupMxInstanceQueue';
|
|
221
|
+
request: {
|
|
222
|
+
identity: IIdentityCredential;
|
|
223
|
+
instanceId: string;
|
|
224
|
+
queue: 'pending' | 'dead';
|
|
225
|
+
domain?: string;
|
|
226
|
+
limit?: number;
|
|
227
|
+
};
|
|
228
|
+
response: {
|
|
229
|
+
ok: true;
|
|
230
|
+
items: IBackupMxQueueItemSummary[];
|
|
231
|
+
total: number;
|
|
232
|
+
} | {
|
|
233
|
+
ok: false;
|
|
234
|
+
code: TBackupMxRefusalCode;
|
|
235
|
+
message: string;
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
export interface IReq_Admin_Cloudly_RetryBackupMxInstanceDeadItem extends implementsTR<
|
|
240
|
+
ITypedRequest,
|
|
241
|
+
IReq_Admin_Cloudly_RetryBackupMxInstanceDeadItem
|
|
242
|
+
> {
|
|
243
|
+
method: 'retryBackupMxInstanceDeadItem';
|
|
244
|
+
request: {
|
|
245
|
+
identity: IIdentityCredential;
|
|
246
|
+
instanceId: string;
|
|
247
|
+
queueId: string;
|
|
248
|
+
};
|
|
249
|
+
response: {
|
|
250
|
+
ok: true;
|
|
251
|
+
} | {
|
|
252
|
+
ok: false;
|
|
253
|
+
code: TBackupMxRefusalCode;
|
|
254
|
+
message: string;
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export interface IReq_Admin_Cloudly_PurgeBackupMxInstanceDeadItem extends implementsTR<
|
|
259
|
+
ITypedRequest,
|
|
260
|
+
IReq_Admin_Cloudly_PurgeBackupMxInstanceDeadItem
|
|
261
|
+
> {
|
|
262
|
+
method: 'purgeBackupMxInstanceDeadItem';
|
|
263
|
+
request: {
|
|
264
|
+
identity: IIdentityCredential;
|
|
265
|
+
instanceId: string;
|
|
266
|
+
queueId: string;
|
|
267
|
+
};
|
|
268
|
+
response: {
|
|
269
|
+
ok: true;
|
|
270
|
+
} | {
|
|
271
|
+
ok: false;
|
|
272
|
+
code: TBackupMxRefusalCode;
|
|
273
|
+
message: string;
|
|
274
|
+
};
|
|
275
|
+
}
|