@serve.zone/interfaces 32.122.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 +14 -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/corestoredata.d.ts +87 -0
- package/dist_ts/data/corestoredata.js +164 -0
- package/dist_ts/data/delegatedadmintoken.d.ts +7 -1
- package/dist_ts/data/delegatedadmintoken.js +17 -2
- 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 +4 -0
- package/dist_ts/data/index.js +5 -1
- package/dist_ts/data/palletworkspace.d.ts +59 -0
- package/dist_ts/data/palletworkspace.js +39 -0
- package/dist_ts/requests/backupmx.d.ts +209 -0
- package/dist_ts/requests/backupmx.js +2 -0
- package/dist_ts/requests/corestore.d.ts +75 -0
- package/dist_ts/requests/corestore.js +1 -1
- 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/dist_ts/requests/runtimesession.d.ts +38 -0
- package/package.json +17 -1
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/data/backupmx.ts +252 -0
- package/ts/data/corestoredata.ts +255 -0
- package/ts/data/delegatedadmintoken.ts +16 -1
- 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 +4 -0
- package/ts/data/palletworkspace.ts +90 -0
- package/ts/requests/backupmx.ts +275 -0
- package/ts/requests/corestore.ts +100 -0
- package/ts/requests/hetzner.ts +276 -0
- package/ts/requests/index.ts +4 -0
- package/ts/requests/runtimesession.ts +53 -0
|
@@ -1830,12 +1830,21 @@ const validateMail = (scopeArg: IScope, contentArg: Record<string, unknown>, dns
|
|
|
1830
1830
|
}
|
|
1831
1831
|
});
|
|
1832
1832
|
rowList(scopeArg, 'domains', contentArg.domains, bounds.domains, (rowScopeArg, rowArg) => {
|
|
1833
|
-
const
|
|
1834
|
-
|
|
1835
|
-
|
|
1833
|
+
const hasBackupMxEnabled = isPlainRecord(rowArg) && Object.hasOwn(rowArg, 'backupMxEnabled');
|
|
1834
|
+
const row = exact(
|
|
1835
|
+
rowScopeArg,
|
|
1836
|
+
rowArg,
|
|
1837
|
+
hasBackupMxEnabled
|
|
1838
|
+
? ['id', 'domain', 'linkedDomainId', 'subdomain', 'dkim', 'rateLimits', 'edgeFilter', 'backupMxEnabled']
|
|
1839
|
+
: ['id', 'domain', 'linkedDomainId', 'subdomain', 'dkim', 'rateLimits', 'edgeFilter'],
|
|
1840
|
+
null,
|
|
1841
|
+
);
|
|
1836
1842
|
if (row === null) {
|
|
1837
1843
|
return;
|
|
1838
1844
|
}
|
|
1845
|
+
if (hasBackupMxEnabled) {
|
|
1846
|
+
checkBoolean(rowScopeArg, row.backupMxEnabled, 'backupMxEnabled');
|
|
1847
|
+
}
|
|
1839
1848
|
check(rowScopeArg, isZoneName(row.domain), 'domain');
|
|
1840
1849
|
if (typeof row.linkedDomainId !== 'string') {
|
|
1841
1850
|
refuse(rowScopeArg, 'linkedDomainId', 'invalid-value');
|
|
@@ -1945,6 +1954,29 @@ const validateMail = (scopeArg: IScope, contentArg: Record<string, unknown>, dns
|
|
|
1945
1954
|
checkText(rowScopeArg, row.transferOrigin, 'transferOrigin', 2048);
|
|
1946
1955
|
checkCoreMailVerifiers(rowScopeArg, row.credentials);
|
|
1947
1956
|
});
|
|
1957
|
+
if (Object.hasOwn(contentArg, 'backupMxTargets')) {
|
|
1958
|
+
const seenBackupHostnames = new Set<string>();
|
|
1959
|
+
rowList(scopeArg, 'backupMxTargets', contentArg.backupMxTargets, 64, (rowScopeArg, rowArg) => {
|
|
1960
|
+
const row = exact(rowScopeArg, rowArg, [
|
|
1961
|
+
'id', 'hostname', 'priority', 'ipv4', 'ipv6', 'enabled',
|
|
1962
|
+
], null);
|
|
1963
|
+
if (row === null) {
|
|
1964
|
+
return;
|
|
1965
|
+
}
|
|
1966
|
+
check(rowScopeArg, isZoneName(row.hostname), 'hostname');
|
|
1967
|
+
if (typeof row.hostname === 'string' && isZoneName(row.hostname)) {
|
|
1968
|
+
if (seenBackupHostnames.has(row.hostname)) {
|
|
1969
|
+
refuse(rowScopeArg, 'hostname', 'duplicate-key');
|
|
1970
|
+
} else {
|
|
1971
|
+
seenBackupHostnames.add(row.hostname);
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
check(rowScopeArg, typeof row.priority === 'number' && Number.isSafeInteger(row.priority) && row.priority >= 21 && row.priority <= 65535, 'priority');
|
|
1975
|
+
checkNullableAddress(rowScopeArg, row.ipv4, 'ipv4', 4);
|
|
1976
|
+
checkNullableAddress(rowScopeArg, row.ipv6, 'ipv6', 6);
|
|
1977
|
+
checkBoolean(rowScopeArg, row.enabled, 'enabled');
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1948
1980
|
};
|
|
1949
1981
|
|
|
1950
1982
|
// ---------------------------------------------------------------------------------------------
|
|
@@ -2151,7 +2183,11 @@ const validateArea = (
|
|
|
2151
2183
|
refuse(scope, null, 'not-strict-json');
|
|
2152
2184
|
return;
|
|
2153
2185
|
}
|
|
2154
|
-
const
|
|
2186
|
+
const hasBackupMxTargets = areaArg === 'mail' && isPlainRecord(contentArg) && Object.hasOwn(contentArg, 'backupMxTargets');
|
|
2187
|
+
const expectedKeys = hasBackupMxTargets
|
|
2188
|
+
? [...gatewayAreaMembers.mail, 'backupMxTargets']
|
|
2189
|
+
: gatewayAreaMembers[areaArg];
|
|
2190
|
+
const content = exact(scope, contentArg, expectedKeys, null);
|
|
2155
2191
|
if (content === null) {
|
|
2156
2192
|
return;
|
|
2157
2193
|
}
|
|
@@ -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
|
@@ -12,6 +12,7 @@ export * from './controller.js';
|
|
|
12
12
|
export * from './controlledtakeover.js';
|
|
13
13
|
export * from './corestore.js';
|
|
14
14
|
export * from './corestorecontroltoken.js';
|
|
15
|
+
export * from './corestoredata.js';
|
|
15
16
|
export * from './corestorelegacyadoption.js';
|
|
16
17
|
export * from './corestorereplication.js';
|
|
17
18
|
export * from './delegatedadmintoken.js';
|
|
@@ -72,6 +73,7 @@ export { runtimeNetworkProjectionRetirementContract, snapshotRuntimeNetworkProje
|
|
|
72
73
|
export * from './networkprotection.js';
|
|
73
74
|
export * from './networksigning.js';
|
|
74
75
|
export * from './privatenetwork.js';
|
|
76
|
+
export * from './palletworkspace.js';
|
|
75
77
|
export * from './preparedimages.js';
|
|
76
78
|
export * from './registry.js';
|
|
77
79
|
export * from './releaseversion.js';
|
|
@@ -91,7 +93,9 @@ export * from './secret.js';
|
|
|
91
93
|
export * from './baremetal.js';
|
|
92
94
|
export * from './baseos.js';
|
|
93
95
|
export * from './backup.js';
|
|
96
|
+
export * from './backupmx.js';
|
|
94
97
|
export * from './backuprestorerefusal.js';
|
|
98
|
+
export * from './hetzner.js';
|
|
95
99
|
export * from './clusternode.js';
|
|
96
100
|
export * from './clusternodehostname.js';
|
|
97
101
|
export * from './settings.js';
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { IRuntimeSessionBinding } from './runtimesession.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Bounded command execution and interactive shell contracts between a Cloudly
|
|
5
|
+
* controller and an authenticated Pallet node session.
|
|
6
|
+
*/
|
|
7
|
+
export const palletWorkspaceContract = Object.freeze({
|
|
8
|
+
maxCommandArguments: 256,
|
|
9
|
+
maxCommandBytes: 65_536,
|
|
10
|
+
defaultTimeoutMs: 30_000,
|
|
11
|
+
maxTimeoutMs: 120_000,
|
|
12
|
+
maxOutputBytes: 512 * 1024,
|
|
13
|
+
maxStdinBytes: 2 * 1024 * 1024,
|
|
14
|
+
maxShellSessions: 8,
|
|
15
|
+
shellIdleTimeoutMs: 15 * 60 * 1000,
|
|
16
|
+
maxTerminalDimension: 65_535,
|
|
17
|
+
} as const);
|
|
18
|
+
|
|
19
|
+
export interface IRunRuntimeAssignmentExecRequest {
|
|
20
|
+
session: IRuntimeSessionBinding;
|
|
21
|
+
assignmentId: string;
|
|
22
|
+
command: string[];
|
|
23
|
+
stdinBase64?: string;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface IRunRuntimeAssignmentExecResponse {
|
|
28
|
+
stdoutBase64: string;
|
|
29
|
+
stderrBase64: string;
|
|
30
|
+
exitCode: number;
|
|
31
|
+
timedOut?: boolean;
|
|
32
|
+
truncated?: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IStartRuntimeAssignmentShellRequest {
|
|
36
|
+
session: IRuntimeSessionBinding;
|
|
37
|
+
assignmentId: string;
|
|
38
|
+
processId: string;
|
|
39
|
+
command: string[];
|
|
40
|
+
columns?: number;
|
|
41
|
+
rows?: number;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface IStartRuntimeAssignmentShellResponse {
|
|
45
|
+
processId: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface IWriteRuntimeAssignmentShellRequest {
|
|
49
|
+
session: IRuntimeSessionBinding;
|
|
50
|
+
processId: string;
|
|
51
|
+
inputBase64: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface IKillRuntimeAssignmentShellRequest {
|
|
55
|
+
session: IRuntimeSessionBinding;
|
|
56
|
+
processId: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface IPushRuntimeAssignmentShellOutputRequest {
|
|
60
|
+
session: IRuntimeSessionBinding;
|
|
61
|
+
processId: string;
|
|
62
|
+
output?: string;
|
|
63
|
+
error?: string;
|
|
64
|
+
done: boolean;
|
|
65
|
+
exitCode?: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export const validatePalletWorkspaceCommand = (commandArg: unknown): string[] => {
|
|
69
|
+
if (!Array.isArray(commandArg) || commandArg.length === 0) {
|
|
70
|
+
return ['command must be a non-empty array of strings'];
|
|
71
|
+
}
|
|
72
|
+
if (commandArg.length > palletWorkspaceContract.maxCommandArguments) {
|
|
73
|
+
return [`command exceeds maximum of ${palletWorkspaceContract.maxCommandArguments} arguments`];
|
|
74
|
+
}
|
|
75
|
+
const encoder = new TextEncoder();
|
|
76
|
+
let totalBytes = 0;
|
|
77
|
+
for (const [index, part] of commandArg.entries()) {
|
|
78
|
+
if (typeof part !== 'string' || part.includes('\0')) {
|
|
79
|
+
return [`command[${index}] must be a string without null bytes`];
|
|
80
|
+
}
|
|
81
|
+
if (index === 0 && part.length === 0) {
|
|
82
|
+
return ['command[0] must be non-empty'];
|
|
83
|
+
}
|
|
84
|
+
totalBytes += encoder.encode(part).byteLength;
|
|
85
|
+
if (totalBytes > palletWorkspaceContract.maxCommandBytes) {
|
|
86
|
+
return [`command exceeds maximum byte length of ${palletWorkspaceContract.maxCommandBytes}`];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return [];
|
|
90
|
+
};
|