@ebowwa/hetzner 0.2.2 → 0.3.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.
Files changed (61) hide show
  1. package/dist/bootstrap/index.js +1126 -0
  2. package/dist/bootstrap/index.js.map +15 -0
  3. package/dist/index.js +3540 -0
  4. package/dist/index.js.map +31 -0
  5. package/dist/onboarding/index.js +460 -0
  6. package/dist/onboarding/index.js.map +14 -0
  7. package/package.json +53 -16
  8. package/actions.js +0 -1084
  9. package/actions.ts +0 -1053
  10. package/auth.js +0 -39
  11. package/auth.ts +0 -37
  12. package/bootstrap/FIREWALL.md +0 -326
  13. package/bootstrap/KERNEL-HARDENING.md +0 -258
  14. package/bootstrap/SECURITY-INTEGRATION.md +0 -281
  15. package/bootstrap/TESTING.md +0 -301
  16. package/bootstrap/cloud-init.js +0 -323
  17. package/bootstrap/cloud-init.ts +0 -394
  18. package/bootstrap/firewall.js +0 -292
  19. package/bootstrap/firewall.ts +0 -342
  20. package/bootstrap/genesis.js +0 -424
  21. package/bootstrap/genesis.ts +0 -518
  22. package/bootstrap/index.js +0 -59
  23. package/bootstrap/index.ts +0 -71
  24. package/bootstrap/kernel-hardening.js +0 -270
  25. package/bootstrap/kernel-hardening.test.js +0 -182
  26. package/bootstrap/kernel-hardening.test.ts +0 -230
  27. package/bootstrap/kernel-hardening.ts +0 -272
  28. package/bootstrap/security-audit.js +0 -122
  29. package/bootstrap/security-audit.ts +0 -124
  30. package/bootstrap/ssh-hardening.js +0 -186
  31. package/bootstrap/ssh-hardening.ts +0 -192
  32. package/client.js +0 -234
  33. package/client.ts +0 -177
  34. package/config.js +0 -7
  35. package/config.ts +0 -5
  36. package/errors.js +0 -345
  37. package/errors.ts +0 -371
  38. package/index.js +0 -73
  39. package/index.ts +0 -59
  40. package/onboarding/doppler.ts +0 -116
  41. package/onboarding/git.ts +0 -133
  42. package/onboarding/index.ts +0 -18
  43. package/onboarding/onboarding.ts +0 -193
  44. package/onboarding/tailscale.ts +0 -159
  45. package/onboarding/types.ts +0 -115
  46. package/pricing.js +0 -387
  47. package/pricing.ts +0 -422
  48. package/schemas.js +0 -667
  49. package/schemas.ts +0 -765
  50. package/server-status.js +0 -122
  51. package/server-status.ts +0 -81
  52. package/servers.js +0 -667
  53. package/servers.ts +0 -568
  54. package/ssh-keys.js +0 -180
  55. package/ssh-keys.ts +0 -122
  56. package/ssh-setup.js +0 -253
  57. package/ssh-setup.ts +0 -218
  58. package/types.js +0 -99
  59. package/types.ts +0 -389
  60. package/volumes.js +0 -295
  61. package/volumes.ts +0 -229
@@ -1,323 +0,0 @@
1
- "use strict";
2
- /**
3
- * Cloud-Init Bootstrap Generator
4
- *
5
- * Generates cloud-init YAML scripts for first-boot server provisioning.
6
- * Handles seed repository installation and initial setup.
7
- *
8
- * Security Integration:
9
- * This module integrates all security modules in the correct order:
10
- * 1. UFW Firewall (network-level defense)
11
- * 2. Kernel Hardening (system-level hardening)
12
- * 3. SSH Hardening (service-level hardening)
13
- * 4. Security Audit (verification and reporting)
14
- */
15
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
16
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
17
- if (ar || !(i in from)) {
18
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
19
- ar[i] = from[i];
20
- }
21
- }
22
- return to.concat(ar || Array.prototype.slice.call(from));
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.securityAuditRunCmd = exports.securityAuditWriteFiles = exports.securityAuditPackages = exports.kernelHardeningRunCmd = exports.kernelHardeningWriteFiles = exports.kernelHardeningPackages = exports.generateUFWFirewallForWorker = exports.generateUFWFirewallForGenesis = exports.DEFAULT_UFW_GENESIS_OPTIONS = exports.DEFAULT_UFW_WORKER_OPTIONS = exports.ufwFirewallRunCmd = exports.ufwFirewallWriteFiles = exports.ufwFirewallPackages = exports.sshdHardeningRunCmd = exports.sshdHardeningWriteFiles = exports.sshdHardeningPackages = exports.GenesisBootstrapPresets = exports.generateRemoteGenesisBootstrap = exports.generateGenesisBootstrap = exports.BootstrapPresets = void 0;
26
- exports.generateSeedBootstrap = generateSeedBootstrap;
27
- exports.generateRemoteBootstrap = generateRemoteBootstrap;
28
- var ssh_hardening_1 = require("./ssh-hardening");
29
- var firewall_1 = require("./firewall");
30
- var kernel_hardening_1 = require("./kernel-hardening");
31
- var security_audit_1 = require("./security-audit");
32
- /**
33
- * Generate a cloud-init YAML script for seed installation
34
- *
35
- * @param options - Bootstrap configuration options
36
- * @returns Cloud-init YAML string
37
- */
38
- function generateSeedBootstrap(options) {
39
- if (options === void 0) { options = {}; }
40
- var _a = options.seedRepo, seedRepo = _a === void 0 ? "https://github.com/ebowwa/seed" : _a, _b = options.seedBranch, seedBranch = _b === void 0 ? "dev" : _b, _c = options.seedPath, seedPath = _c === void 0 ? "/root/seed" : _c, _d = options.runSetup, runSetup = _d === void 0 ? true : _d, _e = options.setupEnv, setupEnv = _e === void 0 ? {} : _e, _f = options.packages, packages = _f === void 0 ? [] : _f, _g = options.additionalCommands, additionalCommands = _g === void 0 ? [] : _g, _h = options.enableSecurity, enableSecurity = _h === void 0 ? true : _h;
41
- var lines = [];
42
- // Cloud-config header
43
- lines.push("#cloud-config");
44
- lines.push("");
45
- // System updates
46
- lines.push("# Update system packages");
47
- lines.push("package_update: true");
48
- lines.push("package_upgrade: true");
49
- lines.push("");
50
- // Required packages
51
- lines.push("# Install required packages");
52
- lines.push("packages:");
53
- lines.push(" - git");
54
- lines.push(" - curl");
55
- lines.push(" - jq");
56
- lines.push(" - unzip");
57
- lines.push(" - tmux");
58
- // Security Module 1: UFW Firewall packages
59
- if (enableSecurity) {
60
- lines.push(" # Security: UFW Firewall");
61
- lines.push.apply(lines, (0, firewall_1.ufwFirewallPackages)());
62
- }
63
- // Security Module 2: Kernel hardening packages
64
- if (enableSecurity) {
65
- lines.push(" # Security: Kernel hardening");
66
- lines.push.apply(lines, (0, kernel_hardening_1.kernelHardeningPackages)());
67
- }
68
- // Security Module 3: SSH hardening packages (fail2ban)
69
- if (enableSecurity) {
70
- lines.push(" # Security: SSH hardening");
71
- lines.push.apply(lines, (0, ssh_hardening_1.sshdHardeningPackages)());
72
- }
73
- // Security Module 4: Security audit packages (lynis)
74
- if (enableSecurity) {
75
- lines.push(" # Security: Security audit");
76
- lines.push.apply(lines, (0, security_audit_1.securityAuditPackages)());
77
- }
78
- // Add additional packages
79
- for (var _i = 0, packages_1 = packages; _i < packages_1.length; _i++) {
80
- var pkg = packages_1[_i];
81
- lines.push(" - ".concat(pkg));
82
- }
83
- lines.push("");
84
- // Status tracking file
85
- lines.push("# Write bootstrap status file");
86
- lines.push("write_files:");
87
- lines.push(" - path: /root/.bootstrap-status");
88
- lines.push(" owner: root:root");
89
- lines.push(" permissions: '0644'");
90
- lines.push(" content: |");
91
- lines.push(" status=started");
92
- lines.push(" started_at=$(date -Iseconds)");
93
- lines.push(" source=cloud-init");
94
- if (enableSecurity) {
95
- lines.push(" security=enabled");
96
- }
97
- lines.push("");
98
- // Add bun to system-wide PATH via /etc/environment
99
- // NOTE: /etc/environment uses simple KEY="value" format (no variables, no comments)
100
- // We need to replace PATH rather than append, and include all standard paths
101
- lines.push(" # Add bun to /etc/environment for all users/shells");
102
- lines.push(" # Format: Simple KEY=\"value\" pairs, no variable expansion");
103
- lines.push(" - path: /etc/environment");
104
- lines.push(" owner: root:root");
105
- lines.push(" permissions: '0644'");
106
- lines.push(" content: |");
107
- lines.push(" PATH=\"/root/.bun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin\"");
108
- lines.push("");
109
- // Security Module 1: UFW Firewall configuration files
110
- if (enableSecurity) {
111
- lines.push(" # Security Module 1: UFW Firewall configuration");
112
- lines.push.apply(lines, (0, firewall_1.ufwFirewallWriteFiles)(firewall_1.DEFAULT_UFW_WORKER_OPTIONS));
113
- }
114
- // Security Module 2: Kernel hardening configuration files
115
- if (enableSecurity) {
116
- lines.push(" # Security Module 2: Kernel hardening");
117
- lines.push.apply(lines, (0, kernel_hardening_1.kernelHardeningWriteFiles)());
118
- }
119
- // Security Module 3: SSH hardening configuration files
120
- if (enableSecurity) {
121
- lines.push(" # Security Module 3: SSH hardening");
122
- lines.push.apply(lines, (0, ssh_hardening_1.sshdHardeningWriteFiles)());
123
- }
124
- // Security Module 4: Security audit script
125
- if (enableSecurity) {
126
- lines.push(" # Security Module 4: Security audit");
127
- lines.push.apply(lines, (0, security_audit_1.securityAuditWriteFiles)());
128
- }
129
- // Node-agent systemd service
130
- lines.push(" # Node-agent systemd service for Ralph Loop orchestration");
131
- lines.push(" - path: /etc/systemd/system/node-agent.service");
132
- lines.push(" owner: root:root");
133
- lines.push(" permissions: '0644'");
134
- lines.push(" content: |");
135
- lines.push(" [Unit]");
136
- lines.push(" Description=Node Agent for Ralph Loop Orchestration");
137
- lines.push(" Documentation=https://github.com/ebowwa/seed");
138
- lines.push(" After=network-online.target");
139
- lines.push(" Wants=network-online.target");
140
- lines.push("");
141
- lines.push(" [Service]");
142
- lines.push(" Type=simple");
143
- lines.push(" User=root");
144
- lines.push(" WorkingDirectory=".concat(seedPath, "/node-agent"));
145
- lines.push(" ExecStart=/root/.bun/bin/bun run src/index.ts");
146
- lines.push(" EnvironmentFile=-".concat(seedPath, "/node-agent/.env"));
147
- lines.push(" Environment=PORT=8911");
148
- lines.push(" Restart=always");
149
- lines.push(" RestartSec=10");
150
- lines.push(" StandardOutput=journal");
151
- lines.push(" StandardError=journal");
152
- lines.push(" SyslogIdentifier=node-agent");
153
- lines.push("");
154
- // Security hardening for node-agent service
155
- if (enableSecurity) {
156
- lines.push(" # Security hardening");
157
- lines.push(" NoNewPrivileges=true");
158
- lines.push(" PrivateTmp=true");
159
- lines.push(" ProtectSystem=strict");
160
- lines.push(" ProtectHome=true");
161
- lines.push(" ReadOnlyPaths=/");
162
- lines.push(" ReadWritePaths=/var/log " + seedPath + "/node-agent");
163
- }
164
- lines.push("");
165
- lines.push(" [Install]");
166
- lines.push(" WantedBy=multi-user.target");
167
- lines.push("");
168
- // Run commands
169
- lines.push("# Bootstrap commands");
170
- lines.push("runcmd:");
171
- // Install Bun and create node symlink
172
- lines.push(" # Install Bun");
173
- lines.push(" - curl -fsSL https://bun.sh/install | bash");
174
- lines.push(" - ln -sf /root/.bun/bin/bun /root/.bun/bin/node # Create 'node' symlink to bun");
175
- lines.push("");
176
- // Clone seed repository
177
- lines.push(" # Clone seed repository");
178
- lines.push(" - git clone --depth 1 --branch ".concat(seedBranch, " ").concat(seedRepo, " ").concat(seedPath));
179
- lines.push("");
180
- if (runSetup) {
181
- // Build environment variables
182
- var envVars = __spreadArray(["NONINTERACTIVE=1"], Object.entries(setupEnv).map(function (_a) {
183
- var k = _a[0], v = _a[1];
184
- return "".concat(k, "=").concat(v);
185
- }), true);
186
- var envString = envVars.join(" ");
187
- lines.push(" # Run seed setup non-interactively");
188
- lines.push(" - cd ".concat(seedPath, " && ").concat(envString, " bash ./setup.sh 2>&1 | tee /var/log/seed-setup.log"));
189
- lines.push("");
190
- // Create completion marker
191
- lines.push(" # Mark setup complete");
192
- lines.push(" - touch ".concat(seedPath, "/.seed-setup-complete"));
193
- lines.push("");
194
- }
195
- // Additional commands
196
- if (additionalCommands.length > 0) {
197
- lines.push(" # Additional custom commands");
198
- for (var _j = 0, additionalCommands_1 = additionalCommands; _j < additionalCommands_1.length; _j++) {
199
- var cmd = additionalCommands_1[_j];
200
- lines.push(" - ".concat(cmd));
201
- }
202
- lines.push("");
203
- }
204
- // Security Module 1: UFW Firewall activation (runs first)
205
- if (enableSecurity) {
206
- lines.push(" # Security Module 1: Activate UFW Firewall");
207
- lines.push.apply(lines, (0, firewall_1.ufwFirewallRunCmd)(firewall_1.DEFAULT_UFW_WORKER_OPTIONS));
208
- }
209
- // Security Module 2: Kernel hardening activation
210
- if (enableSecurity) {
211
- lines.push(" # Security Module 2: Apply kernel hardening");
212
- lines.push.apply(lines, (0, kernel_hardening_1.kernelHardeningRunCmd)());
213
- }
214
- // Security Module 3: SSH hardening activation
215
- if (enableSecurity) {
216
- lines.push(" # Security Module 3: Activate SSH hardening");
217
- lines.push.apply(lines, (0, ssh_hardening_1.sshdHardeningRunCmd)());
218
- }
219
- // Security Module 4: Security audit (runs last)
220
- if (enableSecurity) {
221
- lines.push(" # Security Module 4: Run security audit");
222
- lines.push.apply(lines, (0, security_audit_1.securityAuditRunCmd)());
223
- }
224
- // Mark bootstrap complete
225
- lines.push(" # Mark bootstrap complete");
226
- lines.push(" - echo \"status=complete\" >> /root/.bootstrap-status");
227
- lines.push(" - echo \"completed_at=$(date -Iseconds)\" >> /root/.bootstrap-status");
228
- if (enableSecurity) {
229
- lines.push(" - echo \"security_hardening=applied\" >> /root/.bootstrap-status");
230
- }
231
- lines.push("");
232
- lines.push(" # Start node-agent service");
233
- lines.push(" - systemctl daemon-reload");
234
- lines.push(" - systemctl enable node-agent");
235
- lines.push(" - systemctl start node-agent");
236
- return lines.join("\n");
237
- }
238
- /**
239
- * Generate a minimal cloud-init script that uses #include to fetch from a URL
240
- *
241
- * This is useful for larger bootstrap scripts or when you want to update
242
- * the bootstrap without code changes.
243
- *
244
- * @param url - URL to fetch the cloud-init config from
245
- * @returns Cloud-init YAML string with #include directive
246
- */
247
- function generateRemoteBootstrap(url) {
248
- return "#include\n".concat(url);
249
- }
250
- /**
251
- * Bootstrap configuration presets for common scenarios
252
- */
253
- exports.BootstrapPresets = {
254
- /**
255
- * Default seed installation with setup.sh and full security hardening
256
- */
257
- default: function () { return generateSeedBootstrap(); },
258
- /**
259
- * Seed installation with full security hardening and verbose logging
260
- */
261
- secure: function () {
262
- return generateSeedBootstrap({
263
- setupEnv: {
264
- DEBUG: "1",
265
- VERBOSE: "1",
266
- },
267
- });
268
- },
269
- /**
270
- * Seed installation without running setup.sh (useful for debugging)
271
- */
272
- cloneOnly: function () { return generateSeedBootstrap({ runSetup: false }); },
273
- /**
274
- * Development bootstrap without security hardening (for testing)
275
- */
276
- development: function () {
277
- return generateSeedBootstrap({
278
- enableSecurity: false,
279
- packages: ["htop", "vim", "strace"],
280
- });
281
- },
282
- /**
283
- * Verbose bootstrap with logging enabled
284
- */
285
- verbose: function () {
286
- return generateSeedBootstrap({
287
- setupEnv: {
288
- DEBUG: "1",
289
- VERBOSE: "1",
290
- },
291
- });
292
- },
293
- };
294
- // Re-export Genesis bootstrap functions
295
- var genesis_1 = require("./genesis");
296
- Object.defineProperty(exports, "generateGenesisBootstrap", { enumerable: true, get: function () { return genesis_1.generateGenesisBootstrap; } });
297
- Object.defineProperty(exports, "generateRemoteGenesisBootstrap", { enumerable: true, get: function () { return genesis_1.generateRemoteGenesisBootstrap; } });
298
- Object.defineProperty(exports, "GenesisBootstrapPresets", { enumerable: true, get: function () { return genesis_1.GenesisBootstrapPresets; } });
299
- // Re-export SSH hardening components so callers can compose custom
300
- // cloud-init scripts with hardening baked in (e.g. for non-standard node types)
301
- var ssh_hardening_2 = require("./ssh-hardening");
302
- Object.defineProperty(exports, "sshdHardeningPackages", { enumerable: true, get: function () { return ssh_hardening_2.sshdHardeningPackages; } });
303
- Object.defineProperty(exports, "sshdHardeningWriteFiles", { enumerable: true, get: function () { return ssh_hardening_2.sshdHardeningWriteFiles; } });
304
- Object.defineProperty(exports, "sshdHardeningRunCmd", { enumerable: true, get: function () { return ssh_hardening_2.sshdHardeningRunCmd; } });
305
- // Re-export UFW firewall components
306
- var firewall_2 = require("./firewall");
307
- Object.defineProperty(exports, "ufwFirewallPackages", { enumerable: true, get: function () { return firewall_2.ufwFirewallPackages; } });
308
- Object.defineProperty(exports, "ufwFirewallWriteFiles", { enumerable: true, get: function () { return firewall_2.ufwFirewallWriteFiles; } });
309
- Object.defineProperty(exports, "ufwFirewallRunCmd", { enumerable: true, get: function () { return firewall_2.ufwFirewallRunCmd; } });
310
- Object.defineProperty(exports, "DEFAULT_UFW_WORKER_OPTIONS", { enumerable: true, get: function () { return firewall_2.DEFAULT_UFW_WORKER_OPTIONS; } });
311
- Object.defineProperty(exports, "DEFAULT_UFW_GENESIS_OPTIONS", { enumerable: true, get: function () { return firewall_2.DEFAULT_UFW_GENESIS_OPTIONS; } });
312
- Object.defineProperty(exports, "generateUFWFirewallForGenesis", { enumerable: true, get: function () { return firewall_2.generateUFWFirewallForGenesis; } });
313
- Object.defineProperty(exports, "generateUFWFirewallForWorker", { enumerable: true, get: function () { return firewall_2.generateUFWFirewallForWorker; } });
314
- // Re-export kernel hardening components
315
- var kernel_hardening_2 = require("./kernel-hardening");
316
- Object.defineProperty(exports, "kernelHardeningPackages", { enumerable: true, get: function () { return kernel_hardening_2.kernelHardeningPackages; } });
317
- Object.defineProperty(exports, "kernelHardeningWriteFiles", { enumerable: true, get: function () { return kernel_hardening_2.kernelHardeningWriteFiles; } });
318
- Object.defineProperty(exports, "kernelHardeningRunCmd", { enumerable: true, get: function () { return kernel_hardening_2.kernelHardeningRunCmd; } });
319
- // Re-export security audit components
320
- var security_audit_2 = require("./security-audit");
321
- Object.defineProperty(exports, "securityAuditPackages", { enumerable: true, get: function () { return security_audit_2.securityAuditPackages; } });
322
- Object.defineProperty(exports, "securityAuditWriteFiles", { enumerable: true, get: function () { return security_audit_2.securityAuditWriteFiles; } });
323
- Object.defineProperty(exports, "securityAuditRunCmd", { enumerable: true, get: function () { return security_audit_2.securityAuditRunCmd; } });