@highstate/common 0.9.3 → 0.9.5

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.
Files changed (48) hide show
  1. package/dist/chunk-USV6SHAU.js +530 -0
  2. package/dist/chunk-USV6SHAU.js.map +1 -0
  3. package/dist/highstate.manifest.json +9 -5
  4. package/dist/index.js +33 -7
  5. package/dist/units/dns/record-set/index.js +18 -0
  6. package/dist/units/dns/record-set/index.js.map +1 -0
  7. package/dist/units/existing-server/index.js +34 -0
  8. package/dist/units/existing-server/index.js.map +1 -0
  9. package/dist/units/network/l3-endpoint/index.js +15 -0
  10. package/dist/units/network/l3-endpoint/index.js.map +1 -0
  11. package/dist/units/network/l4-endpoint/index.js +15 -0
  12. package/dist/units/network/l4-endpoint/index.js.map +1 -0
  13. package/dist/{script → units/script}/index.js +5 -6
  14. package/dist/units/script/index.js.map +1 -0
  15. package/dist/units/server-dns/index.js +30 -0
  16. package/dist/units/server-dns/index.js.map +1 -0
  17. package/dist/units/server-patch/index.js +29 -0
  18. package/dist/units/server-patch/index.js.map +1 -0
  19. package/dist/units/ssh/key-pair/index.js +22 -0
  20. package/dist/units/ssh/key-pair/index.js.map +1 -0
  21. package/package.json +15 -10
  22. package/src/shared/command.ts +132 -0
  23. package/src/shared/dns.ts +209 -21
  24. package/src/shared/index.ts +2 -2
  25. package/src/shared/network.ts +311 -0
  26. package/src/shared/ssh.ts +111 -38
  27. package/src/units/dns/record-set/index.ts +16 -0
  28. package/src/units/existing-server/index.ts +34 -0
  29. package/src/units/network/l3-endpoint/index.ts +9 -0
  30. package/src/units/network/l4-endpoint/index.ts +9 -0
  31. package/src/{script → units/script}/index.ts +3 -5
  32. package/src/units/server-dns/index.ts +26 -0
  33. package/src/units/server-patch/index.ts +25 -0
  34. package/src/units/ssh/key-pair/index.ts +16 -0
  35. package/dist/chunk-ZA27FN5N.js +0 -214
  36. package/dist/chunk-ZA27FN5N.js.map +0 -1
  37. package/dist/dns/record/index.js +0 -1
  38. package/dist/dns/record/index.js.map +0 -1
  39. package/dist/existing-server/index.js +0 -48
  40. package/dist/existing-server/index.js.map +0 -1
  41. package/dist/script/index.js.map +0 -1
  42. package/dist/ssh/key-pair/index.js +0 -30
  43. package/dist/ssh/key-pair/index.js.map +0 -1
  44. package/src/dns/record/index.ts +0 -0
  45. package/src/existing-server/index.ts +0 -46
  46. package/src/shared/server.ts +0 -85
  47. package/src/shared/utils.ts +0 -18
  48. package/src/ssh/key-pair/index.ts +0 -24
@@ -0,0 +1,530 @@
1
+ // src/shared/network.ts
2
+ import { toPromise } from "@highstate/pulumi";
3
+ import { uniqueBy } from "remeda";
4
+ function l3EndpointToString(l3Endpoint) {
5
+ switch (l3Endpoint.type) {
6
+ case "ipv4":
7
+ return l3Endpoint.address;
8
+ case "ipv6":
9
+ return l3Endpoint.address;
10
+ case "hostname":
11
+ return l3Endpoint.hostname;
12
+ }
13
+ }
14
+ function l4EndpointToString(l4Endpoint) {
15
+ if (l4Endpoint.type === "ipv6") {
16
+ return `[${l4Endpoint.address}]:${l4Endpoint.port}`;
17
+ }
18
+ return `${l3EndpointToString(l4Endpoint)}:${l4Endpoint.port}`;
19
+ }
20
+ function l34EndpointToString(l34Endpoint) {
21
+ if (l34Endpoint.port) {
22
+ return l4EndpointToString(l34Endpoint);
23
+ }
24
+ return l3EndpointToString(l34Endpoint);
25
+ }
26
+ var L34_ENDPOINT_RE = /^(?:(?<protocol>[a-z]+):\/\/)?(?:(?:\[?(?<ipv6>[0-9A-Fa-f:]+)\]?)|(?<ipv4>(?:\d{1,3}\.){3}\d{1,3})|(?<hostname>[a-zA-Z0-9-*]+(?:\.[a-zA-Z0-9-*]+)*))(?::(?<port>\d{1,5}))?$/;
27
+ function parseL34Endpoint(l34Endpoint) {
28
+ if (typeof l34Endpoint === "object") {
29
+ return l34Endpoint;
30
+ }
31
+ const match = l34Endpoint.match(L34_ENDPOINT_RE);
32
+ if (!match) {
33
+ throw new Error(`Invalid L3/L4 endpoint: "${l34Endpoint}"`);
34
+ }
35
+ const { protocol, ipv6, ipv4, hostname, port } = match.groups;
36
+ if (protocol && protocol !== "tcp" && protocol !== "udp") {
37
+ throw new Error(`Invalid L4 endpoint protocol: "${protocol}"`);
38
+ }
39
+ let visibility = "public";
40
+ if (ipv4 && IPV4_PRIVATE_REGEX.test(ipv4)) {
41
+ visibility = "external";
42
+ } else if (ipv6 && IPV6_PRIVATE_REGEX.test(ipv6)) {
43
+ visibility = "external";
44
+ }
45
+ const fallbackProtocol = port ? "tcp" : void 0;
46
+ return {
47
+ type: ipv6 ? "ipv6" : ipv4 ? "ipv4" : "hostname",
48
+ visibility,
49
+ address: ipv6 || ipv4,
50
+ hostname,
51
+ port: port ? parseInt(port, 10) : void 0,
52
+ protocol: protocol ? protocol : fallbackProtocol
53
+ };
54
+ }
55
+ function parseL3Endpoint(l3Endpoint) {
56
+ if (typeof l3Endpoint === "object") {
57
+ return l3Endpoint;
58
+ }
59
+ const parsed = parseL34Endpoint(l3Endpoint);
60
+ if (parsed.port) {
61
+ throw new Error(`Port cannot be specified in L3 endpoint: "${l3Endpoint}"`);
62
+ }
63
+ return parsed;
64
+ }
65
+ function parseL4Endpoint(l4Endpoint) {
66
+ if (typeof l4Endpoint === "object") {
67
+ return l4Endpoint;
68
+ }
69
+ const parsed = parseL34Endpoint(l4Endpoint);
70
+ if (!parsed.port) {
71
+ throw new Error(`No port found in L4 endpoint: "${l4Endpoint}"`);
72
+ }
73
+ return parsed;
74
+ }
75
+ var IPV4_PRIVATE_REGEX = /^(?:10|127)(?:\.\d{1,3}){3}$|^(?:172\.1[6-9]|172\.2[0-9]|172\.3[0-1])(?:\.\d{1,3}){2}$|^(?:192\.168)(?:\.\d{1,3}){2}$/;
76
+ var IPV6_PRIVATE_REGEX = /^(?:fc|fd)(?:[0-9a-f]{2}){0,2}::(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}$|^::(?:ffff:(?:10|127)(?:\.\d{1,3}){3}|(?:172\.1[6-9]|172\.2[0-9]|172\.3[0-1])(?:\.\d{1,3}){2}|(?:192\.168)(?:\.\d{1,3}){2})$/;
77
+ async function requireInputL3Endpoint(rawEndpoint, inputEndpoint) {
78
+ if (rawEndpoint) {
79
+ return parseL3Endpoint(rawEndpoint);
80
+ }
81
+ if (inputEndpoint) {
82
+ return toPromise(inputEndpoint);
83
+ }
84
+ throw new Error("No endpoint provided");
85
+ }
86
+ async function requireInputL4Endpoint(rawEndpoint, inputEndpoint) {
87
+ if (rawEndpoint) {
88
+ return parseL4Endpoint(rawEndpoint);
89
+ }
90
+ if (inputEndpoint) {
91
+ return toPromise(inputEndpoint);
92
+ }
93
+ throw new Error("No endpoint provided");
94
+ }
95
+ function l3ToL4Endpoint(l3Endpoint, port, protocol = "tcp") {
96
+ return {
97
+ ...parseL3Endpoint(l3Endpoint),
98
+ port,
99
+ protocol
100
+ };
101
+ }
102
+ function filterEndpoints(endpoints, filter) {
103
+ if (filter?.length) {
104
+ return endpoints.filter((endpoint) => filter.includes(endpoint.visibility));
105
+ }
106
+ if (endpoints.some((endpoint) => endpoint.visibility === "public")) {
107
+ return endpoints.filter((endpoint) => endpoint.visibility === "public");
108
+ }
109
+ if (endpoints.some((endpoint) => endpoint.visibility === "external")) {
110
+ return endpoints.filter((endpoint) => endpoint.visibility === "external");
111
+ }
112
+ return endpoints;
113
+ }
114
+ function l3EndpointToCidr(l3Endpoint) {
115
+ switch (l3Endpoint.type) {
116
+ case "ipv4":
117
+ return `${l3Endpoint.address}/32`;
118
+ case "ipv6":
119
+ return `${l3Endpoint.address}/128`;
120
+ case "hostname":
121
+ throw new Error("Cannot convert hostname to CIDR");
122
+ }
123
+ }
124
+ async function updateEndpoints(currentEndpoints, endpoints, inputEndpoints, mode = "prepend") {
125
+ const resolvedCurrentEndpoints = await toPromise(currentEndpoints);
126
+ const resolvedInputEndpoints = await toPromise(inputEndpoints);
127
+ const newEndpoints = uniqueBy(
128
+ //
129
+ [...endpoints.map(parseL34Endpoint), ...resolvedInputEndpoints],
130
+ (endpoint) => l34EndpointToString(endpoint)
131
+ );
132
+ if (mode === "replace") {
133
+ return newEndpoints;
134
+ }
135
+ return uniqueBy(
136
+ //
137
+ [...newEndpoints, ...resolvedCurrentEndpoints],
138
+ (endpoint) => l34EndpointToString(endpoint)
139
+ );
140
+ }
141
+
142
+ // src/shared/command.ts
143
+ import { local, remote } from "@pulumi/command";
144
+ import {
145
+ ComponentResource,
146
+ interpolate,
147
+ output
148
+ } from "@highstate/pulumi";
149
+ import "@highstate/library";
150
+ function getServerConnection(ssh2) {
151
+ return output(ssh2).apply((ssh3) => ({
152
+ host: l3EndpointToString(ssh3.endpoints[0]),
153
+ port: ssh3.endpoints[0].port,
154
+ user: ssh3.user,
155
+ password: ssh3.password,
156
+ privateKey: ssh3.keyPair?.privateKey,
157
+ dialErrorLimit: 3,
158
+ hostKey: ssh3.hostKey
159
+ }));
160
+ }
161
+ var Command = class _Command extends ComponentResource {
162
+ command;
163
+ stdout;
164
+ stderr;
165
+ constructor(name, args, opts) {
166
+ super("highstate:common:Command", name, args, opts);
167
+ this.command = output(args).apply((args2) => {
168
+ if (args2.host === "local") {
169
+ return new local.Command(
170
+ name,
171
+ {
172
+ create: args2.create,
173
+ update: args2.update,
174
+ delete: args2.delete,
175
+ logging: args2.logging,
176
+ triggers: args2.triggers
177
+ },
178
+ { ...opts, parent: this }
179
+ );
180
+ }
181
+ if (!args2.host.ssh) {
182
+ throw new Error(`The host "${args2.host.hostname}" has no SSH credentials`);
183
+ }
184
+ return new remote.Command(
185
+ name,
186
+ {
187
+ connection: getServerConnection(args2.host.ssh),
188
+ create: args2.create,
189
+ update: args2.update,
190
+ delete: args2.delete,
191
+ logging: args2.logging,
192
+ triggers: args2.triggers
193
+ },
194
+ { ...opts, parent: this }
195
+ );
196
+ });
197
+ this.stdout = this.command.stdout;
198
+ this.stderr = this.command.stderr;
199
+ }
200
+ static createTextFile(name, options, opts) {
201
+ return output(options).apply((options2) => {
202
+ const escapedContent = options2.content.replace(/"/g, '\\"');
203
+ const command = new _Command(
204
+ name,
205
+ {
206
+ host: options2.host,
207
+ create: interpolate`mkdir -p $(dirname ${options2.path}) && echo "${escapedContent}" > ${options2.path}`,
208
+ delete: interpolate`rm -rf ${options2.path}`
209
+ },
210
+ opts
211
+ );
212
+ return command;
213
+ });
214
+ }
215
+ static receiveTextFile(name, options, opts) {
216
+ return output(options).apply((options2) => {
217
+ const command = new _Command(
218
+ name,
219
+ {
220
+ host: options2.host,
221
+ create: interpolate`while ! test -f ${options2.path}; do sleep 1; done; cat ${options2.path}`,
222
+ logging: "stderr"
223
+ },
224
+ opts
225
+ );
226
+ return command;
227
+ });
228
+ }
229
+ };
230
+
231
+ // src/shared/dns.ts
232
+ import {
233
+ ComponentResource as ComponentResource2,
234
+ normalize,
235
+ output as output2,
236
+ toPromise as toPromise2
237
+ } from "@highstate/pulumi";
238
+ import { capitalize, groupBy, uniqueBy as uniqueBy2 } from "remeda";
239
+ function getTypeByEndpoint(endpoint) {
240
+ switch (endpoint.type) {
241
+ case "ipv4":
242
+ return "A";
243
+ case "ipv6":
244
+ return "AAAA";
245
+ case "hostname":
246
+ return "CNAME";
247
+ }
248
+ }
249
+ var DnsRecord = class extends ComponentResource2 {
250
+ /**
251
+ * The underlying dns record resource.
252
+ */
253
+ dnsRecord;
254
+ /**
255
+ * The wait commands to be executed after the DNS record is created/updated.
256
+ *
257
+ * Use this field as a dependency for other resources.
258
+ */
259
+ waitCommands;
260
+ constructor(name, args, opts) {
261
+ super("highstate:common:DnsRecord", name, args, opts);
262
+ this.dnsRecord = output2(args).apply((args2) => {
263
+ const l3Endpoint = parseL3Endpoint(args2.value);
264
+ const type = args2.type ?? getTypeByEndpoint(l3Endpoint);
265
+ return output2(
266
+ this.create(
267
+ name,
268
+ {
269
+ ...args2,
270
+ type,
271
+ value: l3EndpointToString(l3Endpoint)
272
+ },
273
+ { ...opts, parent: this }
274
+ )
275
+ );
276
+ });
277
+ this.waitCommands = output2(args).apply((args2) => {
278
+ const waitAt = args2.waitAt ? Array.isArray(args2.waitAt) ? args2.waitAt : [args2.waitAt] : [];
279
+ return waitAt.map((host) => {
280
+ const hostname = host === "local" ? "local" : host.hostname;
281
+ return new Command(
282
+ `${name}-wait-${hostname}`,
283
+ {
284
+ host,
285
+ create: `while ! getent hosts ${args2.name} >/dev/null; do echo "Waiting for DNS record ${args2.name} to be created"; sleep 5; done`,
286
+ triggers: [args2.type, args2.ttl, args2.priority, args2.proxied]
287
+ },
288
+ { parent: this }
289
+ );
290
+ });
291
+ });
292
+ }
293
+ static create(name, args, opts) {
294
+ return output2(args).apply(async (args2) => {
295
+ const providerType = args2.provider.type;
296
+ const implName = `${capitalize(providerType)}DnsRecord`;
297
+ const implModule = await import(`@highstate/${providerType}`);
298
+ const implClass = implModule[implName];
299
+ return new implClass(name, args2, opts);
300
+ });
301
+ }
302
+ };
303
+ var DnsRecordSet = class _DnsRecordSet extends ComponentResource2 {
304
+ /**
305
+ * The underlying dns record resources.
306
+ */
307
+ dnsRecords;
308
+ /**
309
+ * The wait commands to be executed after the DNS records are created/updated.
310
+ */
311
+ waitCommands;
312
+ constructor(name, records, opts) {
313
+ super("highstate:common:DnsRecordSet", name, records, opts);
314
+ this.dnsRecords = records;
315
+ this.waitCommands = records.apply(
316
+ (records2) => records2.flatMap((record) => record.waitCommands)
317
+ );
318
+ }
319
+ static create(name, args, opts) {
320
+ const records = output2(args).apply((args2) => {
321
+ const recordName = args2.name ?? name;
322
+ const values = normalize(args2.value, args2.values);
323
+ return output2(
324
+ args2.providers.filter((provider) => recordName.endsWith(provider.domain)).flatMap((provider) => {
325
+ return values.map((value) => {
326
+ const l3Endpoint = parseL3Endpoint(value);
327
+ return DnsRecord.create(
328
+ `${provider.type}-from-${provider.name}-to-${l3EndpointToString(l3Endpoint)}`,
329
+ { name: recordName, ...args2, value: l3Endpoint, provider },
330
+ opts
331
+ );
332
+ });
333
+ })
334
+ );
335
+ });
336
+ return new _DnsRecordSet(name, records, opts);
337
+ }
338
+ };
339
+ async function updateEndpointsWithFqdn(endpoints, fqdn, fqdnEndpointFilter, patchMode, dnsProviders) {
340
+ const resolvedEndpoints = await toPromise2(endpoints);
341
+ if (!fqdn) {
342
+ return {
343
+ endpoints: resolvedEndpoints,
344
+ dnsRecordSet: void 0
345
+ };
346
+ }
347
+ const filteredEndpoints = filterEndpoints(resolvedEndpoints, fqdnEndpointFilter);
348
+ const dnsRecordSet = DnsRecordSet.create(fqdn, {
349
+ providers: dnsProviders,
350
+ values: filteredEndpoints,
351
+ waitAt: "local"
352
+ });
353
+ const portProtocolGroups = groupBy(
354
+ filteredEndpoints,
355
+ (endpoint) => endpoint.port ? `${endpoint.port}-${endpoint.protocol}` : ""
356
+ );
357
+ const newEndpoints = [];
358
+ for (const group of Object.values(portProtocolGroups)) {
359
+ newEndpoints.unshift({
360
+ type: "hostname",
361
+ hostname: fqdn,
362
+ visibility: group[0].visibility,
363
+ port: group[0].port,
364
+ protocol: group[0].protocol
365
+ });
366
+ }
367
+ await toPromise2(
368
+ dnsRecordSet.waitCommands.apply((waitCommands) => waitCommands.map((command) => command.stdout))
369
+ );
370
+ if (patchMode === "prepend") {
371
+ return {
372
+ endpoints: uniqueBy2(
373
+ //
374
+ [...newEndpoints, ...resolvedEndpoints],
375
+ (endpoint) => l34EndpointToString(endpoint)
376
+ ),
377
+ dnsRecordSet
378
+ };
379
+ }
380
+ return {
381
+ endpoints: newEndpoints,
382
+ dnsRecordSet
383
+ };
384
+ }
385
+
386
+ // src/shared/passwords.ts
387
+ import { randomBytes } from "@noble/hashes/utils";
388
+ import { secureMask } from "micro-key-producer/password.js";
389
+ function generatePassword() {
390
+ return secureMask.apply(randomBytes(32)).password;
391
+ }
392
+
393
+ // src/shared/ssh.ts
394
+ import {
395
+ getOrCreateSecret,
396
+ getUnitInstanceName,
397
+ output as output3,
398
+ secret
399
+ } from "@highstate/pulumi";
400
+ import getKeys, { PrivateExport } from "micro-key-producer/ssh.js";
401
+ import { randomBytes as randomBytes2 } from "micro-key-producer/utils.js";
402
+ import { local as local2, remote as remote2 } from "@pulumi/command";
403
+ function createSshTerminal(credentials) {
404
+ return output3(credentials).apply((credentials2) => {
405
+ if (!credentials2) {
406
+ return void 0;
407
+ }
408
+ const command = ["ssh", "-tt", "-o", "UserKnownHostsFile=/known_hosts"];
409
+ const endpoint = credentials2.endpoints[0];
410
+ command.push("-p", endpoint.port.toString());
411
+ if (credentials2.keyPair) {
412
+ command.push("-i", "/private_key");
413
+ }
414
+ command.push(`${credentials2.user}@${l3EndpointToString(endpoint)}`);
415
+ if (credentials2.password) {
416
+ command.unshift("sshpass", "-f", "/password");
417
+ }
418
+ return {
419
+ name: "ssh",
420
+ title: `SSH: ${getUnitInstanceName()}`,
421
+ description: "Connect to the server via SSH",
422
+ image: "ghcr.io/exeteres/highstate/terminal-ssh",
423
+ command,
424
+ files: {
425
+ "/password": credentials2.password,
426
+ "/private_key": {
427
+ content: credentials2.keyPair?.privateKey,
428
+ mode: 384
429
+ },
430
+ "/known_hosts": {
431
+ content: `${l4EndpointToString(endpoint)} ${credentials2.hostKey}`,
432
+ mode: 420
433
+ }
434
+ }
435
+ };
436
+ });
437
+ }
438
+ function generatePrivateKey() {
439
+ const seed = randomBytes2(32);
440
+ return getKeys(seed).privateKey;
441
+ }
442
+ function privateKeyToKeyPair(privateKeyString) {
443
+ return output3(privateKeyString).apply((privateKeyString2) => {
444
+ const privateKeyStruct = PrivateExport.decode(privateKeyString2);
445
+ const privKey = privateKeyStruct.keys[0].privKey.privKey;
446
+ const { fingerprint, publicKey, privateKey } = getKeys(privKey.slice(0, 32));
447
+ return output3({
448
+ type: "ed25519",
449
+ fingerprint,
450
+ publicKey,
451
+ privateKey: secret(privateKey)
452
+ });
453
+ });
454
+ }
455
+ function getOrCreateSshKeyPair(inputs, secrets) {
456
+ if (inputs.sshKeyPair) {
457
+ return output3(inputs.sshKeyPair);
458
+ }
459
+ const privateKey = getOrCreateSecret(secrets, "sshPrivateKey", generatePrivateKey);
460
+ return privateKey.apply(privateKeyToKeyPair);
461
+ }
462
+ function createServerEntity(fallbackHostname, endpoint, sshPort = 22, sshUser = "root", sshPassword, sshPrivateKey) {
463
+ const connection = output3({
464
+ host: l3EndpointToString(endpoint),
465
+ port: sshPort,
466
+ user: sshUser,
467
+ password: sshPassword,
468
+ privateKey: sshPrivateKey,
469
+ dialErrorLimit: 3
470
+ });
471
+ const command = new local2.Command("check-ssh", {
472
+ create: `nc -zv ${l3EndpointToString(endpoint)} ${sshPort} && echo "up" || echo "down"`
473
+ });
474
+ return command.stdout.apply((result) => {
475
+ if (result === "down") {
476
+ return output3({
477
+ hostname: fallbackHostname,
478
+ endpoints: [endpoint]
479
+ });
480
+ }
481
+ const hostnameResult = new remote2.Command("hostname", {
482
+ connection,
483
+ create: "hostname",
484
+ triggers: [Date.now()]
485
+ });
486
+ const hostKeyResult = new remote2.Command("host-key", {
487
+ connection,
488
+ create: "cat /etc/ssh/ssh_host_ed25519_key.pub",
489
+ triggers: [Date.now()]
490
+ });
491
+ return output3({
492
+ endpoints: [endpoint],
493
+ hostname: hostnameResult.stdout.apply((x) => x.trim()),
494
+ ssh: {
495
+ endpoints: [l3ToL4Endpoint(endpoint, sshPort)],
496
+ user: sshUser,
497
+ hostKey: hostKeyResult.stdout.apply((x) => x.trim()),
498
+ password: sshPassword,
499
+ keyPair: sshPrivateKey ? privateKeyToKeyPair(sshPrivateKey) : void 0
500
+ }
501
+ });
502
+ });
503
+ }
504
+
505
+ export {
506
+ l3EndpointToString,
507
+ l4EndpointToString,
508
+ l34EndpointToString,
509
+ parseL34Endpoint,
510
+ parseL3Endpoint,
511
+ parseL4Endpoint,
512
+ requireInputL3Endpoint,
513
+ requireInputL4Endpoint,
514
+ l3ToL4Endpoint,
515
+ filterEndpoints,
516
+ l3EndpointToCidr,
517
+ updateEndpoints,
518
+ getServerConnection,
519
+ Command,
520
+ DnsRecord,
521
+ DnsRecordSet,
522
+ updateEndpointsWithFqdn,
523
+ generatePassword,
524
+ createSshTerminal,
525
+ generatePrivateKey,
526
+ privateKeyToKeyPair,
527
+ getOrCreateSshKeyPair,
528
+ createServerEntity
529
+ };
530
+ //# sourceMappingURL=chunk-USV6SHAU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/shared/network.ts","../src/shared/command.ts","../src/shared/dns.ts","../src/shared/passwords.ts","../src/shared/ssh.ts"],"sourcesContent":["import type { ArrayPatchMode, network } from \"@highstate/library\"\nimport { toPromise, type Input } from \"@highstate/pulumi\"\nimport { uniqueBy } from \"remeda\"\n\n/**\n * The L3 or L4 endpoint for some service.\n *\n * The format is: `[protocol://]endpoint[:port]`\n */\nexport type InputL34Endpoint = network.L34Endpoint | string\n\n/**\n * The L3 endpoint for some service.\n */\nexport type InputL3Endpoint = network.L3Endpoint | string\n\n/**\n * The L4 endpoint for some service.\n */\nexport type InputL4Endpoint = network.L4Endpoint | string\n\n/**\n * Stringifies a L3 endpoint object into a string.\n *\n * @param l3Endpoint The L3 endpoint object to stringify.\n * @returns The string representation of the L3 endpoint.\n */\nexport function l3EndpointToString(l3Endpoint: network.L3Endpoint): string {\n switch (l3Endpoint.type) {\n case \"ipv4\":\n return l3Endpoint.address\n case \"ipv6\":\n return l3Endpoint.address\n case \"hostname\":\n return l3Endpoint.hostname\n }\n}\n\n/**\n * Stringifies a L4 endpoint object into a string.\n *\n * @param l4Endpoint The L4 endpoint object to stringify.\n *\n * @returns The string representation of the L4 endpoint.\n */\nexport function l4EndpointToString(l4Endpoint: network.L4Endpoint): string {\n if (l4Endpoint.type === \"ipv6\") {\n return `[${l4Endpoint.address}]:${l4Endpoint.port}`\n }\n\n return `${l3EndpointToString(l4Endpoint)}:${l4Endpoint.port}`\n}\n\n/**\n * Stringifies a L3 or L4 endpoint object into a string.\n *\n * @param l34Endpoint The L3 or L4 endpoint object to stringify.\n * @returns The string representation of the L3 or L4 endpoint.\n */\nexport function l34EndpointToString(l34Endpoint: network.L34Endpoint): string {\n if (l34Endpoint.port) {\n return l4EndpointToString(l34Endpoint)\n }\n\n return l3EndpointToString(l34Endpoint)\n}\n\nconst L34_ENDPOINT_RE =\n /^(?:(?<protocol>[a-z]+):\\/\\/)?(?:(?:\\[?(?<ipv6>[0-9A-Fa-f:]+)\\]?)|(?<ipv4>(?:\\d{1,3}\\.){3}\\d{1,3})|(?<hostname>[a-zA-Z0-9-*]+(?:\\.[a-zA-Z0-9-*]+)*))(?::(?<port>\\d{1,5}))?$/\n\n/**\n * Parses a L3 or L4 endpoint from a string.\n *\n * The format is `[protocol://]endpoint[:port]`.\n *\n * @param l34Endpoint The L3 or L4 endpoint string to parse.\n * @returns The parsed L3 or L4 endpoint object.\n */\nexport function parseL34Endpoint(l34Endpoint: InputL34Endpoint): network.L34Endpoint {\n if (typeof l34Endpoint === \"object\") {\n return l34Endpoint\n }\n\n const match = l34Endpoint.match(L34_ENDPOINT_RE)\n if (!match) {\n throw new Error(`Invalid L3/L4 endpoint: \"${l34Endpoint}\"`)\n }\n\n const { protocol, ipv6, ipv4, hostname, port } = match.groups!\n\n if (protocol && protocol !== \"tcp\" && protocol !== \"udp\") {\n throw new Error(`Invalid L4 endpoint protocol: \"${protocol}\"`)\n }\n\n let visibility: network.EndpointVisibility = \"public\"\n\n if (ipv4 && IPV4_PRIVATE_REGEX.test(ipv4)) {\n visibility = \"external\"\n } else if (ipv6 && IPV6_PRIVATE_REGEX.test(ipv6)) {\n visibility = \"external\"\n }\n\n const fallbackProtocol = port ? \"tcp\" : undefined\n\n return {\n type: ipv6 ? \"ipv6\" : ipv4 ? \"ipv4\" : \"hostname\",\n visibility,\n address: ipv6 || ipv4,\n hostname: hostname,\n port: port ? parseInt(port, 10) : undefined,\n protocol: protocol ? (protocol as network.L4Protocol) : fallbackProtocol,\n } as network.L34Endpoint\n}\n\n/**\n * Parses a L3 endpoint from a string.\n *\n * The same as `parseL34Endpoint`, but only for L3 endpoints and will throw an error if the endpoint contains a port.\n *\n * @param l3Endpoint The L3 endpoint string to parse.\n * @returns The parsed L3 endpoint object.\n */\nexport function parseL3Endpoint(l3Endpoint: InputL3Endpoint): network.L3Endpoint {\n if (typeof l3Endpoint === \"object\") {\n return l3Endpoint\n }\n\n const parsed = parseL34Endpoint(l3Endpoint)\n\n if (parsed.port) {\n throw new Error(`Port cannot be specified in L3 endpoint: \"${l3Endpoint}\"`)\n }\n\n return parsed\n}\n\n/**\n * Parses a L4 endpoint from a string.\n *\n * The same as `parseL34Endpoint`, but only for L4 endpoints and will throw an error if the endpoint does not contain a port.\n */\nexport function parseL4Endpoint(l4Endpoint: InputL4Endpoint): network.L4Endpoint {\n if (typeof l4Endpoint === \"object\") {\n return l4Endpoint\n }\n\n const parsed = parseL34Endpoint(l4Endpoint)\n\n if (!parsed.port) {\n throw new Error(`No port found in L4 endpoint: \"${l4Endpoint}\"`)\n }\n\n return parsed\n}\n\nconst IPV4_PRIVATE_REGEX =\n /^(?:10|127)(?:\\.\\d{1,3}){3}$|^(?:172\\.1[6-9]|172\\.2[0-9]|172\\.3[0-1])(?:\\.\\d{1,3}){2}$|^(?:192\\.168)(?:\\.\\d{1,3}){2}$/\n\nconst IPV6_PRIVATE_REGEX =\n /^(?:fc|fd)(?:[0-9a-f]{2}){0,2}::(?:[0-9a-f]{1,4}:){7}[0-9a-f]{1,4}$|^::(?:ffff:(?:10|127)(?:\\.\\d{1,3}){3}|(?:172\\.1[6-9]|172\\.2[0-9]|172\\.3[0-1])(?:\\.\\d{1,3}){2}|(?:192\\.168)(?:\\.\\d{1,3}){2})$/\n\n/**\n * Helper function to get the input L3 endpoint from the raw endpoint or input endpoint.\n *\n * If neither is provided, an error is thrown.\n *\n * @param rawEndpoint The raw endpoint string to parse.\n * @param inputEndpoint The input endpoint object to use if the raw endpoint is not provided.\n * @returns The parsed L3 endpoint object.\n */\nexport async function requireInputL3Endpoint(\n rawEndpoint: string | undefined,\n inputEndpoint: Input<network.L3Endpoint> | undefined,\n): Promise<network.L3Endpoint> {\n if (rawEndpoint) {\n return parseL3Endpoint(rawEndpoint)\n }\n\n if (inputEndpoint) {\n return toPromise(inputEndpoint)\n }\n\n throw new Error(\"No endpoint provided\")\n}\n\n/**\n * Helper function to get the input L4 endpoint from the raw endpoint or input endpoint.\n *\n * If neither is provided, an error is thrown.\n *\n * @param rawEndpoint The raw endpoint string to parse.\n * @param inputEndpoint The input endpoint object to use if the raw endpoint is not provided.\n * @returns The parsed L4 endpoint object.\n */\nexport async function requireInputL4Endpoint(\n rawEndpoint: string | undefined,\n inputEndpoint: Input<network.L4Endpoint> | undefined,\n): Promise<network.L4Endpoint> {\n if (rawEndpoint) {\n return parseL4Endpoint(rawEndpoint)\n }\n\n if (inputEndpoint) {\n return toPromise(inputEndpoint)\n }\n\n throw new Error(\"No endpoint provided\")\n}\n\n/**\n * Convers L3 endpoint to L4 endpoint by adding a port and protocol.\n *\n * @param l3Endpoint The L3 endpoint to convert.\n * @param port The port to add to the L3 endpoint.\n * @param protocol The protocol to add to the L3 endpoint. Defaults to \"tcp\".\n * @returns The L4 endpoint with the port and protocol added.\n */\nexport function l3ToL4Endpoint(\n l3Endpoint: InputL3Endpoint,\n port: number,\n protocol: network.L4Protocol = \"tcp\",\n): network.L4Endpoint {\n return {\n ...parseL3Endpoint(l3Endpoint),\n port,\n protocol,\n }\n}\n\n/**\n * Filters the endpoints based on the given filter.\n *\n * @param endpoints The list of endpoints to filter.\n * @param filter The filter to apply. If not provided, the endpoints will be filtered by the most accessible type: `public` > `external` > `internal`.\n *\n * @returns The filtered list of endpoints.\n */\nexport function filterEndpoints<TEndpoint extends network.L34Endpoint>(\n endpoints: TEndpoint[],\n filter?: network.EndpointFilter,\n): TEndpoint[] {\n if (filter?.length) {\n return endpoints.filter(endpoint => filter.includes(endpoint.visibility))\n }\n\n if (endpoints.some(endpoint => endpoint.visibility === \"public\")) {\n return endpoints.filter(endpoint => endpoint.visibility === \"public\")\n }\n\n if (endpoints.some(endpoint => endpoint.visibility === \"external\")) {\n return endpoints.filter(endpoint => endpoint.visibility === \"external\")\n }\n\n // in this case all endpoints are already internal\n return endpoints\n}\n\n/**\n * Converts a L3 endpoint to CIDR notation.\n *\n * If the endpoint is a hostname, an error is thrown.\n *\n * @param l3Endpoint The L3 endpoint to convert.\n * @returns The CIDR notation of the L3 endpoint.\n */\nexport function l3EndpointToCidr(l3Endpoint: network.L3Endpoint): string {\n switch (l3Endpoint.type) {\n case \"ipv4\":\n return `${l3Endpoint.address}/32`\n case \"ipv6\":\n return `${l3Endpoint.address}/128`\n case \"hostname\":\n throw new Error(\"Cannot convert hostname to CIDR\")\n }\n}\n\n/**\n * Updates the endpoints based on the given mode.\n *\n * @param currentEndpoints The current endpoints to update.\n * @param endpoints The new endpoints to add in string format.\n * @param inputEndpoints The input endpoints to add in object format.\n * @param mode The mode to use when updating the endpoints. Can be \"replace\" or \"prepend\". Defaults to \"prepend\".\n *\n * @returns The updated list of endpoints.\n */\nexport async function updateEndpoints<TEdnpoints extends network.L34Endpoint>(\n currentEndpoints: Input<TEdnpoints[]>,\n endpoints: string[],\n inputEndpoints: Input<TEdnpoints[]>,\n mode: ArrayPatchMode = \"prepend\",\n): Promise<TEdnpoints[]> {\n const resolvedCurrentEndpoints = await toPromise(currentEndpoints)\n const resolvedInputEndpoints = await toPromise(inputEndpoints)\n\n const newEndpoints = uniqueBy(\n //\n [...endpoints.map(parseL34Endpoint), ...resolvedInputEndpoints],\n endpoint => l34EndpointToString(endpoint),\n )\n\n if (mode === \"replace\") {\n return newEndpoints as TEdnpoints[]\n }\n\n return uniqueBy(\n //\n [...newEndpoints, ...resolvedCurrentEndpoints],\n endpoint => l34EndpointToString(endpoint),\n ) as TEdnpoints[]\n}\n","import { local, remote, type types } from \"@pulumi/command\"\nimport {\n ComponentResource,\n interpolate,\n output,\n type ComponentResourceOptions,\n type Input,\n type InputOrArray,\n type Output,\n} from \"@highstate/pulumi\"\nimport { common, ssh } from \"@highstate/library\"\nimport { l3EndpointToString } from \"./network\"\n\nexport function getServerConnection(\n ssh: Input<ssh.Credentials>,\n): Output<types.input.remote.ConnectionArgs> {\n return output(ssh).apply(ssh => ({\n host: l3EndpointToString(ssh.endpoints[0]),\n port: ssh.endpoints[0].port,\n user: ssh.user,\n password: ssh.password,\n privateKey: ssh.keyPair?.privateKey,\n dialErrorLimit: 3,\n hostKey: ssh.hostKey,\n }))\n}\n\nexport type CommandHost = \"local\" | common.Server\n\nexport type CommandArgs = {\n host: Input<CommandHost>\n create: Input<string>\n update?: Input<string>\n delete?: Input<string>\n logging?: Input<remote.Logging>\n triggers?: InputOrArray<unknown>\n}\n\nexport type TextFileArgs = {\n host: CommandHost\n path: Input<string>\n content: Input<string>\n}\n\nexport class Command extends ComponentResource {\n public readonly command: Output<local.Command | remote.Command>\n\n public readonly stdout: Output<string>\n public readonly stderr: Output<string>\n\n constructor(name: string, args: CommandArgs, opts?: ComponentResourceOptions) {\n super(\"highstate:common:Command\", name, args, opts)\n\n this.command = output(args).apply(args => {\n if (args.host === \"local\") {\n return new local.Command(\n name,\n {\n create: args.create,\n update: args.update,\n delete: args.delete,\n logging: args.logging,\n triggers: args.triggers,\n },\n { ...opts, parent: this },\n )\n }\n\n if (!args.host.ssh) {\n throw new Error(`The host \"${args.host.hostname}\" has no SSH credentials`)\n }\n\n return new remote.Command(\n name,\n {\n connection: getServerConnection(args.host.ssh),\n create: args.create,\n update: args.update,\n delete: args.delete,\n logging: args.logging,\n triggers: args.triggers,\n },\n { ...opts, parent: this },\n )\n })\n\n this.stdout = this.command.stdout\n this.stderr = this.command.stderr\n }\n\n static createTextFile(\n name: string,\n options: TextFileArgs,\n opts?: ComponentResourceOptions,\n ): Output<Command> {\n return output(options).apply(options => {\n const escapedContent = options.content.replace(/\"/g, '\\\\\"')\n\n const command = new Command(\n name,\n {\n host: options.host,\n create: interpolate`mkdir -p $(dirname ${options.path}) && echo \"${escapedContent}\" > ${options.path}`,\n delete: interpolate`rm -rf ${options.path}`,\n },\n opts,\n )\n\n return command\n })\n }\n\n static receiveTextFile(\n name: string,\n options: Omit<TextFileArgs, \"content\">,\n opts?: ComponentResourceOptions,\n ): Output<Command> {\n return output(options).apply(options => {\n const command = new Command(\n name,\n {\n host: options.host,\n create: interpolate`while ! test -f ${options.path}; do sleep 1; done; cat ${options.path}`,\n logging: \"stderr\",\n },\n opts,\n )\n\n return command\n })\n }\n}\n","import type { ArrayPatchMode, dns, network } from \"@highstate/library\"\nimport {\n ComponentResource,\n normalize,\n output,\n Output,\n Resource,\n toPromise,\n type Input,\n type InputArray,\n type InputOrArray,\n type ResourceOptions,\n type Unwrap,\n} from \"@highstate/pulumi\"\nimport { capitalize, groupBy, uniqueBy } from \"remeda\"\nimport { Command, type CommandHost } from \"./command\"\nimport {\n filterEndpoints,\n l34EndpointToString,\n l3EndpointToString,\n parseL3Endpoint,\n type InputL3Endpoint,\n} from \"./network\"\n\nexport type DnsRecordArgs = {\n /**\n * The DNS provider to use.\n */\n provider: Input<dns.Provider>\n\n /**\n * The name of the DNS record.\n * If not provided, the name of the resource will be used.\n */\n name?: Input<string>\n\n /**\n * The type of the DNS record.\n *\n * If not provided, will be automatically detected based on the value.\n */\n type?: Input<string>\n\n /**\n * The value of the DNS record.\n */\n value: Input<InputL3Endpoint>\n\n /**\n * Whether the DNS record is proxied (e.g. to provide DDoS protection).\n *\n * Available only for public IPs and some DNS providers like Cloudflare.\n * If not supported, the DNS provider will ignore this value.\n */\n proxied?: Input<boolean>\n\n /**\n * The TTL of the DNS record.\n *\n * If not provided, the DNS provider will use its default value.\n */\n ttl?: Input<number>\n\n /**\n * The priority of the DNS record.\n *\n * Only used for some DNS record types (e.g. MX).\n */\n priority?: Input<number>\n\n /**\n * Wait for the DNS record to be created/updated at the specified environment(s) before continuing.\n */\n waitAt?: InputOrArray<CommandHost>\n}\n\nexport type ResolvedDnsRecordArgs = Unwrap<Omit<DnsRecordArgs, \"value\" | \"type\">> & {\n /**\n * The value of the DNS record.\n */\n value: string\n\n /**\n * The type of the DNS record.\n */\n type: string\n}\n\nexport type DnsRecordSetArgs = Omit<DnsRecordArgs, \"provider\" | \"value\"> & {\n /**\n * The DNS providers to use to create the DNS records.\n *\n * If multiple providers matched the specified domain, multiple DNS records will be created.\n */\n providers: Input<dns.Provider[]>\n\n /**\n * The value of the DNS record.\n */\n value?: Input<InputL3Endpoint>\n\n /**\n * The values of the DNS records.\n */\n values?: InputArray<InputL3Endpoint>\n}\n\nfunction getTypeByEndpoint(endpoint: network.L3Endpoint): string {\n switch (endpoint.type) {\n case \"ipv4\":\n return \"A\"\n case \"ipv6\":\n return \"AAAA\"\n case \"hostname\":\n return \"CNAME\"\n }\n}\n\nexport abstract class DnsRecord extends ComponentResource {\n /**\n * The underlying dns record resource.\n */\n public readonly dnsRecord: Output<Resource>\n\n /**\n * The wait commands to be executed after the DNS record is created/updated.\n *\n * Use this field as a dependency for other resources.\n */\n public readonly waitCommands: Output<Command[]>\n\n protected constructor(name: string, args: DnsRecordArgs, opts?: ResourceOptions) {\n super(\"highstate:common:DnsRecord\", name, args, opts)\n\n this.dnsRecord = output(args).apply(args => {\n const l3Endpoint = parseL3Endpoint(args.value)\n const type = args.type ?? getTypeByEndpoint(l3Endpoint)\n\n return output(\n this.create(\n name,\n {\n ...args,\n type,\n value: l3EndpointToString(l3Endpoint),\n },\n { ...opts, parent: this },\n ),\n )\n })\n\n this.waitCommands = output(args).apply(args => {\n const waitAt = args.waitAt ? (Array.isArray(args.waitAt) ? args.waitAt : [args.waitAt]) : []\n\n return waitAt.map(host => {\n const hostname = host === \"local\" ? \"local\" : host.hostname\n\n return new Command(\n `${name}-wait-${hostname}`,\n {\n host,\n create: `while ! getent hosts ${args.name} >/dev/null; do echo \"Waiting for DNS record ${args.name} to be created\"; sleep 5; done`,\n triggers: [args.type, args.ttl, args.priority, args.proxied],\n },\n { parent: this },\n )\n })\n })\n }\n\n protected abstract create(\n name: string,\n args: ResolvedDnsRecordArgs,\n opts?: ResourceOptions,\n ): Input<Resource>\n\n static create(name: string, args: DnsRecordArgs, opts?: ResourceOptions): Output<DnsRecord> {\n return output(args).apply(async args => {\n const providerType = args.provider.type\n const implName = `${capitalize(providerType)}DnsRecord`\n const implModule = (await import(`@highstate/${providerType}`)) as Record<string, unknown>\n\n const implClass = implModule[implName] as new (\n name: string,\n args: Unwrap<DnsRecordArgs>,\n opts?: ResourceOptions,\n ) => DnsRecord\n\n return new implClass(name, args, opts)\n })\n }\n}\n\nexport class DnsRecordSet extends ComponentResource {\n /**\n * The underlying dns record resources.\n */\n public readonly dnsRecords: Output<DnsRecord[]>\n\n /**\n * The wait commands to be executed after the DNS records are created/updated.\n */\n public readonly waitCommands: Output<Command[]>\n\n private constructor(name: string, records: Output<DnsRecord[]>, opts?: ResourceOptions) {\n super(\"highstate:common:DnsRecordSet\", name, records, opts)\n\n this.dnsRecords = records\n\n this.waitCommands = records.apply(records =>\n records.flatMap(record => record.waitCommands),\n ) as unknown as Output<Command[]>\n }\n\n static create(name: string, args: DnsRecordSetArgs, opts?: ResourceOptions): DnsRecordSet {\n const records = output(args).apply(args => {\n const recordName = args.name ?? name\n const values = normalize(args.value, args.values)\n\n return output(\n args.providers\n .filter(provider => recordName.endsWith(provider.domain))\n .flatMap(provider => {\n return values.map(value => {\n const l3Endpoint = parseL3Endpoint(value)\n\n return DnsRecord.create(\n `${provider.type}-from-${provider.name}-to-${l3EndpointToString(l3Endpoint)}`,\n { name: recordName, ...args, value: l3Endpoint, provider },\n opts,\n )\n })\n }),\n )\n })\n\n return new DnsRecordSet(name, records, opts)\n }\n}\n\n/**\n * Registers the DNS record set for the given endpoints and prepends the corresponding hostname endpoint to the list.\n *\n * Waits for the DNS record set to be created/updated before continuing.\n *\n * Ignores the \"hostname\" endpoints in the list.\n *\n * @param endpoints The list of endpoints to register. Will be modified in place.\n * @param fqdn The FQDN to register the DNS record set for. If not provided, no DNS record set will be created and array will not be modified.\n * @param fqdnEndpointFilter The filter to apply to the endpoints before passing them to the DNS record set. Does not apply to the resulted endpoint list.\n * @param dnsProviders The DNS providers to use to create the DNS records.\n */\nexport async function updateEndpointsWithFqdn<TEndpoint extends network.L34Endpoint>(\n endpoints: Input<TEndpoint[]>,\n fqdn: string | undefined,\n fqdnEndpointFilter: network.EndpointFilter,\n patchMode: ArrayPatchMode,\n dnsProviders: Input<dns.Provider[]>,\n): Promise<{ endpoints: TEndpoint[]; dnsRecordSet: DnsRecordSet | undefined }> {\n const resolvedEndpoints = await toPromise(endpoints)\n\n if (!fqdn) {\n return {\n endpoints: resolvedEndpoints as TEndpoint[],\n dnsRecordSet: undefined,\n }\n }\n\n const filteredEndpoints = filterEndpoints(resolvedEndpoints, fqdnEndpointFilter)\n\n const dnsRecordSet = DnsRecordSet.create(fqdn, {\n providers: dnsProviders,\n values: filteredEndpoints,\n waitAt: \"local\",\n })\n\n const portProtocolGroups = groupBy(filteredEndpoints, endpoint =>\n endpoint.port ? `${endpoint.port}-${endpoint.protocol}` : \"\",\n )\n\n const newEndpoints: TEndpoint[] = []\n\n for (const group of Object.values(portProtocolGroups)) {\n newEndpoints.unshift({\n type: \"hostname\",\n hostname: fqdn,\n visibility: group[0].visibility,\n port: group[0].port,\n protocol: group[0].protocol,\n } as TEndpoint)\n }\n\n await toPromise(\n dnsRecordSet.waitCommands.apply(waitCommands => waitCommands.map(command => command.stdout)),\n )\n\n if (patchMode === \"prepend\") {\n return {\n endpoints: uniqueBy(\n //\n [...newEndpoints, ...(resolvedEndpoints as TEndpoint[])],\n endpoint => l34EndpointToString(endpoint),\n ),\n dnsRecordSet,\n }\n }\n\n return {\n endpoints: newEndpoints,\n dnsRecordSet,\n }\n}\n","import { randomBytes } from \"@noble/hashes/utils\"\nimport { secureMask } from \"micro-key-producer/password.js\"\n\nexport function generatePassword() {\n return secureMask.apply(randomBytes(32)).password\n}\n","import type { common, network, ssh } from \"@highstate/library\"\nimport {\n getOrCreateSecret,\n getUnitInstanceName,\n output,\n Output,\n secret,\n type Input,\n type InstanceTerminal,\n} from \"@highstate/pulumi\"\nimport getKeys, { PrivateExport } from \"micro-key-producer/ssh.js\"\nimport { randomBytes } from \"micro-key-producer/utils.js\"\nimport { local, remote } from \"@pulumi/command\"\nimport { l3EndpointToString, l3ToL4Endpoint, l4EndpointToString } from \"./network\"\n\nexport function createSshTerminal(\n credentials: Input<ssh.Credentials | undefined>,\n): Output<InstanceTerminal | undefined> {\n return output(credentials).apply(credentials => {\n if (!credentials) {\n return undefined\n }\n\n const command = [\"ssh\", \"-tt\", \"-o\", \"UserKnownHostsFile=/known_hosts\"]\n\n // TODO: select best endpoint based on the environment\n const endpoint = credentials.endpoints[0]\n\n command.push(\"-p\", endpoint.port.toString())\n\n if (credentials.keyPair) {\n command.push(\"-i\", \"/private_key\")\n }\n\n command.push(`${credentials.user}@${l3EndpointToString(endpoint)}`)\n\n if (credentials.password) {\n command.unshift(\"sshpass\", \"-f\", \"/password\")\n }\n\n return {\n name: \"ssh\",\n title: `SSH: ${getUnitInstanceName()}`,\n description: \"Connect to the server via SSH\",\n image: \"ghcr.io/exeteres/highstate/terminal-ssh\",\n command,\n\n files: {\n \"/password\": credentials.password,\n\n \"/private_key\": {\n content: credentials.keyPair?.privateKey,\n mode: 0o600,\n },\n\n \"/known_hosts\": {\n content: `${l4EndpointToString(endpoint)} ${credentials.hostKey}`,\n mode: 0o644,\n },\n },\n }\n })\n}\n\nexport function generatePrivateKey(): string {\n const seed = randomBytes(32)\n\n return getKeys(seed).privateKey\n}\n\nexport function privateKeyToKeyPair(privateKeyString: Input<string>): Output<ssh.KeyPair> {\n return output(privateKeyString).apply(privateKeyString => {\n const privateKeyStruct = PrivateExport.decode(privateKeyString)\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n const privKey = privateKeyStruct.keys[0].privKey.privKey as Uint8Array\n\n const { fingerprint, publicKey, privateKey } = getKeys(privKey.slice(0, 32))\n\n return output({\n type: \"ed25519\" as const,\n fingerprint,\n publicKey,\n privateKey: secret(privateKey),\n })\n })\n}\n\nexport type SshKeyPairInputs = {\n sshKeyPair?: Input<ssh.KeyPair>\n}\n\nexport type SshKeyPairSecrets = {\n sshPrivateKey?: Input<string>\n}\n\nexport function getOrCreateSshKeyPair(\n inputs: SshKeyPairInputs,\n secrets: Output<SshKeyPairSecrets>,\n): Output<ssh.KeyPair> {\n if (inputs.sshKeyPair) {\n return output(inputs.sshKeyPair)\n }\n\n const privateKey = getOrCreateSecret(secrets, \"sshPrivateKey\", generatePrivateKey)\n\n return privateKey.apply(privateKeyToKeyPair)\n}\n\nexport function createServerEntity(\n fallbackHostname: string,\n endpoint: network.L3Endpoint,\n sshPort = 22,\n sshUser = \"root\",\n sshPassword?: Input<string | undefined>,\n sshPrivateKey?: Input<string>,\n): Output<common.Server> {\n const connection = output({\n host: l3EndpointToString(endpoint),\n port: sshPort,\n user: sshUser,\n password: sshPassword,\n privateKey: sshPrivateKey,\n dialErrorLimit: 3,\n })\n\n const command = new local.Command(\"check-ssh\", {\n create: `nc -zv ${l3EndpointToString(endpoint)} ${sshPort} && echo \"up\" || echo \"down\"`,\n })\n\n return command.stdout.apply(result => {\n if (result === \"down\") {\n return output({\n hostname: fallbackHostname,\n endpoints: [endpoint],\n })\n }\n\n const hostnameResult = new remote.Command(\"hostname\", {\n connection,\n create: \"hostname\",\n triggers: [Date.now()],\n })\n\n const hostKeyResult = new remote.Command(\"host-key\", {\n connection,\n create: \"cat /etc/ssh/ssh_host_ed25519_key.pub\",\n triggers: [Date.now()],\n })\n\n return output({\n endpoints: [endpoint],\n hostname: hostnameResult.stdout.apply(x => x.trim()),\n ssh: {\n endpoints: [l3ToL4Endpoint(endpoint, sshPort)],\n user: sshUser,\n hostKey: hostKeyResult.stdout.apply(x => x.trim()),\n password: sshPassword,\n keyPair: sshPrivateKey ? privateKeyToKeyPair(sshPrivateKey) : undefined,\n },\n })\n })\n}\n"],"mappings":";AACA,SAAS,iBAA6B;AACtC,SAAS,gBAAgB;AAyBlB,SAAS,mBAAmB,YAAwC;AACzE,UAAQ,WAAW,MAAM;AAAA,IACvB,KAAK;AACH,aAAO,WAAW;AAAA,IACpB,KAAK;AACH,aAAO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,IAAI,OAAO;AAAA,EAC3D,CAAC;AAED,SAAO,QAAQ,OAAO,MAAM,YAAU;AACpC,QAAI,WAAW,QAAQ;AACrB,aAAOJ,QAAO;AAAA,QACZ,UAAU;AAAA,QACV,WAAW,CAAC,QAAQ;AAAA,MACtB,CAAC;AAAA,IACH;AAEA,UAAM,iBAAiB,IAAIK,QAAO,QAAQ,YAAY;AAAA,MACpD;AAAA,MACA,QAAQ;AAAA,MACR,UAAU,CAAC,KAAK,IAAI,CAAC;AAAA,IACvB,CAAC;AAED,UAAM,gBAAgB,IAAIA,QAAO,QAAQ,YAAY;AAAA,MACnD;AAAA,MACA,QAAQ;AAAA,MACR,UAAU,CAAC,KAAK,IAAI,CAAC;AAAA,IACvB,CAAC;AAED,WAAOL,QAAO;AAAA,MACZ,WAAW,CAAC,QAAQ;AAAA,MACpB,UAAU,eAAe,OAAO,MAAM,OAAK,EAAE,KAAK,CAAC;AAAA,MACnD,KAAK;AAAA,QACH,WAAW,CAAC,eAAe,UAAU,OAAO,CAAC;AAAA,QAC7C,MAAM;AAAA,QACN,SAAS,cAAc,OAAO,MAAM,OAAK,EAAE,KAAK,CAAC;AAAA,QACjD,UAAU;AAAA,QACV,SAAS,gBAAgB,oBAAoB,aAAa,IAAI;AAAA,MAChE;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":["ssh","args","options","ComponentResource","output","toPromise","uniqueBy","ComponentResource","output","args","records","toPromise","uniqueBy","output","randomBytes","local","remote","output","credentials","randomBytes","privateKeyString","local","remote"]}
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "sourceHashes": {
3
- "./dist/index.js": "3c4e76e0ac05b10fa2a2067695242070c6beab04f6689a5d6181c448113eac89",
4
- "./dist/dns/record/index.js": "e4f4558eaa29c589553e0c99b2f12e29e55e3db434977685b4f0e033e5666ac3",
5
- "./dist/existing-server/index.js": "ebd36ffd0f09c7ebc01a80f32e74f6b8bb2e8a2f3359b7e2f3bd5c10ebcaecf2",
6
- "./dist/ssh/key-pair/index.js": "9f3d11f005131a1e84542684bb412a72c0f4f4b21e82a4041259ec67f69a5d29",
7
- "./dist/script/index.js": "6347f09e42f10d2f1ad14361357128a538b3139a23f1348eba7d65a0e856af70"
3
+ "./dist/index.js": "72c0b335a1996396fb5cd11e2f50e32ac46112062e5d6a8d995fe1c09465c710",
4
+ "./dist/units/dns/record-set/index.js": "8875747bcfdea0f4af4bf1172938751bcc1e1e3262fd73975c16194e97c65aab",
5
+ "./dist/units/network/l3-endpoint/index.js": "5af399fbc653ab8d4fef499c04ef90ffd106156af1947dc024f649c8d36a17d2",
6
+ "./dist/units/network/l4-endpoint/index.js": "aabc2a23b8977f6aac0e3e7ce64c44ea4656e13b65d36d586f7ff8e1bfde5d4b",
7
+ "./dist/units/existing-server/index.js": "7a50a5ba150556cfa440b5dd977376ebe4d16165f92d1175e688bf1a3b52e6ab",
8
+ "./dist/units/ssh/key-pair/index.js": "f88c29988f14fd81ba88219ae445c42476e734b2784f488de5aae8f5f0c77f4a",
9
+ "./dist/units/script/index.js": "bd095cdd005451ea8efc18837e9ff95ae152acc7374e15d2f02870c2cc1a2f98",
10
+ "./dist/units/server-dns/index.js": "05248c338318a9761fe7497e113d3e2afe8d3167bbb3554d8014fc63abe3ff8b",
11
+ "./dist/units/server-patch/index.js": "50d26e714bb3156e89a70b09be79cb66a0d3bdf764443bb1a336960a603759eb"
8
12
  }
9
13
  }