@ebowwa/hetzner 0.1.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/actions.js +802 -0
- package/actions.ts +1053 -0
- package/auth.js +35 -0
- package/auth.ts +37 -0
- package/bootstrap/FIREWALL.md +326 -0
- package/bootstrap/KERNEL-HARDENING.md +258 -0
- package/bootstrap/SECURITY-INTEGRATION.md +281 -0
- package/bootstrap/TESTING.md +301 -0
- package/bootstrap/cloud-init.js +279 -0
- package/bootstrap/cloud-init.ts +394 -0
- package/bootstrap/firewall.js +279 -0
- package/bootstrap/firewall.ts +342 -0
- package/bootstrap/genesis.js +406 -0
- package/bootstrap/genesis.ts +518 -0
- package/bootstrap/index.js +35 -0
- package/bootstrap/index.ts +71 -0
- package/bootstrap/kernel-hardening.js +266 -0
- package/bootstrap/kernel-hardening.test.ts +230 -0
- package/bootstrap/kernel-hardening.ts +272 -0
- package/bootstrap/security-audit.js +118 -0
- package/bootstrap/security-audit.ts +124 -0
- package/bootstrap/ssh-hardening.js +182 -0
- package/bootstrap/ssh-hardening.ts +192 -0
- package/client.js +137 -0
- package/client.ts +177 -0
- package/config.js +5 -0
- package/config.ts +5 -0
- package/errors.js +270 -0
- package/errors.ts +371 -0
- package/index.js +28 -0
- package/index.ts +55 -0
- package/package.json +56 -0
- package/pricing.js +284 -0
- package/pricing.ts +422 -0
- package/schemas.js +660 -0
- package/schemas.ts +765 -0
- package/server-status.ts +81 -0
- package/servers.js +424 -0
- package/servers.ts +568 -0
- package/ssh-keys.js +90 -0
- package/ssh-keys.ts +122 -0
- package/ssh-setup.ts +218 -0
- package/types.js +96 -0
- package/types.ts +389 -0
- package/volumes.js +172 -0
- package/volumes.ts +229 -0
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Genesis Server Bootstrap Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates cloud-init YAML scripts for Genesis server provisioning.
|
|
5
|
+
* Genesis is a bootstrap/control plane node that runs com.hetzner.codespaces
|
|
6
|
+
* and manages Hetzner VPS worker nodes.
|
|
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
|
+
|
|
16
|
+
import {
|
|
17
|
+
sshdHardeningPackages,
|
|
18
|
+
sshdHardeningWriteFiles,
|
|
19
|
+
sshdHardeningRunCmd,
|
|
20
|
+
} from "./ssh-hardening";
|
|
21
|
+
import {
|
|
22
|
+
kernelHardeningPackages,
|
|
23
|
+
kernelHardeningWriteFiles,
|
|
24
|
+
kernelHardeningRunCmd,
|
|
25
|
+
} from "./kernel-hardening";
|
|
26
|
+
import {
|
|
27
|
+
ufwFirewallPackages,
|
|
28
|
+
ufwFirewallWriteFiles,
|
|
29
|
+
ufwFirewallRunCmd,
|
|
30
|
+
generateUFWFirewallForGenesis,
|
|
31
|
+
DEFAULT_UFW_GENESIS_OPTIONS,
|
|
32
|
+
} from "./firewall";
|
|
33
|
+
import {
|
|
34
|
+
securityAuditPackages,
|
|
35
|
+
securityAuditWriteFiles,
|
|
36
|
+
securityAuditRunCmd,
|
|
37
|
+
} from "./security-audit";
|
|
38
|
+
|
|
39
|
+
export interface GenesisBootstrapOptions {
|
|
40
|
+
/** Admin SSH public key for genesis user */
|
|
41
|
+
adminSSHKey: string;
|
|
42
|
+
|
|
43
|
+
/** Genesis repository URL (default: https://github.com/ebowwa/com.hetzner.codespaces) */
|
|
44
|
+
genesisRepo?: string;
|
|
45
|
+
|
|
46
|
+
/** Genesis repository branch or tag */
|
|
47
|
+
genesisBranch?: string;
|
|
48
|
+
|
|
49
|
+
/** Genesis server hostname (default: genesis) */
|
|
50
|
+
hostname?: string;
|
|
51
|
+
|
|
52
|
+
/** Default Hetzner server type for workers */
|
|
53
|
+
defaultServerType?: string;
|
|
54
|
+
|
|
55
|
+
/** Default Hetzner location */
|
|
56
|
+
defaultLocation?: string;
|
|
57
|
+
|
|
58
|
+
/** Maximum concurrent workers */
|
|
59
|
+
maxWorkers?: string;
|
|
60
|
+
|
|
61
|
+
/** Additional packages to install */
|
|
62
|
+
packages?: string[];
|
|
63
|
+
|
|
64
|
+
/** Additional commands to run after genesis setup */
|
|
65
|
+
additionalCommands?: string[];
|
|
66
|
+
|
|
67
|
+
/** Enable security hardening (default: true) */
|
|
68
|
+
enableSecurity?: boolean;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Generate a cloud-init YAML script for Genesis server bootstrap
|
|
73
|
+
*
|
|
74
|
+
* @param options - Genesis bootstrap configuration options
|
|
75
|
+
* @returns Cloud-init YAML string
|
|
76
|
+
*/
|
|
77
|
+
export function generateGenesisBootstrap(options: GenesisBootstrapOptions): string {
|
|
78
|
+
const {
|
|
79
|
+
adminSSHKey,
|
|
80
|
+
genesisRepo = "https://github.com/ebowwa/com.hetzner.codespaces",
|
|
81
|
+
genesisBranch = "main",
|
|
82
|
+
hostname = "genesis",
|
|
83
|
+
defaultServerType = "cpx11",
|
|
84
|
+
defaultLocation = "fsn1",
|
|
85
|
+
maxWorkers = "10",
|
|
86
|
+
packages = [],
|
|
87
|
+
additionalCommands = [],
|
|
88
|
+
enableSecurity = true,
|
|
89
|
+
} = options;
|
|
90
|
+
|
|
91
|
+
if (!adminSSHKey) {
|
|
92
|
+
throw new Error("adminSSHKey is required for Genesis bootstrap");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const lines: string[] = [];
|
|
96
|
+
|
|
97
|
+
// Cloud-config header
|
|
98
|
+
lines.push("#cloud-config");
|
|
99
|
+
lines.push("# Genesis Server Bootstrap Configuration");
|
|
100
|
+
lines.push("# Version: 1.0.0");
|
|
101
|
+
lines.push("");
|
|
102
|
+
lines.push("# This cloud-init config bootstraps a Genesis server that:");
|
|
103
|
+
lines.push("# - Runs com.hetzner.codespaces web application");
|
|
104
|
+
lines.push("# - Uses the existing Hetzner API to create any server");
|
|
105
|
+
lines.push("# - Can be ephemeral and recreated at any time");
|
|
106
|
+
lines.push("");
|
|
107
|
+
lines.push("# IMPORTANT: Never store secrets in cloud-init! Use Vault/SOPS/external sources.");
|
|
108
|
+
lines.push("");
|
|
109
|
+
|
|
110
|
+
// STAGE 1: Network & Early Setup
|
|
111
|
+
lines.push("# =====================================================");
|
|
112
|
+
lines.push("# STAGE 1: Network & Early Setup (Network stage)");
|
|
113
|
+
lines.push("# =====================================================");
|
|
114
|
+
lines.push("");
|
|
115
|
+
lines.push(`hostname: ${hostname}`);
|
|
116
|
+
lines.push("manage_etc_hosts: true");
|
|
117
|
+
lines.push("timezone: UTC");
|
|
118
|
+
lines.push("");
|
|
119
|
+
|
|
120
|
+
// STAGE 2: SSH & Security
|
|
121
|
+
lines.push("# =====================================================");
|
|
122
|
+
lines.push("# STAGE 2: SSH & Security (Network stage)");
|
|
123
|
+
lines.push("# =====================================================");
|
|
124
|
+
lines.push("");
|
|
125
|
+
lines.push("ssh_pwauth: false");
|
|
126
|
+
lines.push("");
|
|
127
|
+
lines.push("# Create genesis service user");
|
|
128
|
+
lines.push("users:");
|
|
129
|
+
lines.push(" - name: genesis");
|
|
130
|
+
lines.push(" gecos: Genesis Service Account");
|
|
131
|
+
lines.push(" primary_group: genesis");
|
|
132
|
+
lines.push(" groups: docker,wheel");
|
|
133
|
+
lines.push(" sudo: ALL=(ALL) NOPASSWD:ALL");
|
|
134
|
+
lines.push(" shell: /bin/bash");
|
|
135
|
+
lines.push(" lock_passwd: true");
|
|
136
|
+
lines.push(" ssh_authorized_keys:");
|
|
137
|
+
lines.push(` - ${adminSSHKey}`);
|
|
138
|
+
lines.push("");
|
|
139
|
+
|
|
140
|
+
// STAGE 3: Package Management
|
|
141
|
+
lines.push("# =====================================================");
|
|
142
|
+
lines.push("# STAGE 3: Package Management (Config stage)");
|
|
143
|
+
lines.push("# =====================================================");
|
|
144
|
+
lines.push("");
|
|
145
|
+
lines.push("package_update: true");
|
|
146
|
+
lines.push("package_upgrade: false");
|
|
147
|
+
lines.push("package_reboot_if_required: true");
|
|
148
|
+
lines.push("");
|
|
149
|
+
lines.push("packages:");
|
|
150
|
+
lines.push(" - curl");
|
|
151
|
+
lines.push(" - wget");
|
|
152
|
+
lines.push(" - git");
|
|
153
|
+
lines.push(" - unzip");
|
|
154
|
+
lines.push(" - jq");
|
|
155
|
+
lines.push(" - build-essential");
|
|
156
|
+
|
|
157
|
+
// Security Module 1: UFW Firewall packages
|
|
158
|
+
if (enableSecurity) {
|
|
159
|
+
lines.push(" # Security: UFW Firewall");
|
|
160
|
+
lines.push(...ufwFirewallPackages());
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Security Module 2: Kernel hardening packages
|
|
164
|
+
if (enableSecurity) {
|
|
165
|
+
lines.push(" # Security: Kernel hardening");
|
|
166
|
+
lines.push(...kernelHardeningPackages());
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Security Module 3: SSH hardening packages (fail2ban)
|
|
170
|
+
if (enableSecurity) {
|
|
171
|
+
lines.push(" # Security: SSH hardening");
|
|
172
|
+
lines.push(...sshdHardeningPackages());
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Security Module 4: Security audit packages (lynis)
|
|
176
|
+
if (enableSecurity) {
|
|
177
|
+
lines.push(" # Security: Security audit");
|
|
178
|
+
lines.push(...securityAuditPackages());
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Add additional packages
|
|
182
|
+
for (const pkg of packages) {
|
|
183
|
+
lines.push(` - ${pkg}`);
|
|
184
|
+
}
|
|
185
|
+
lines.push("");
|
|
186
|
+
|
|
187
|
+
// STAGE 4: Application Setup
|
|
188
|
+
lines.push("# =====================================================");
|
|
189
|
+
lines.push("# STAGE 4: Application Setup (Config stage)");
|
|
190
|
+
lines.push("# =====================================================");
|
|
191
|
+
lines.push("");
|
|
192
|
+
lines.push("write_files:");
|
|
193
|
+
|
|
194
|
+
// Genesis directories
|
|
195
|
+
lines.push(" # Genesis application directories");
|
|
196
|
+
lines.push(" - path: /opt/genesis");
|
|
197
|
+
lines.push(" owner: genesis:genesis");
|
|
198
|
+
lines.push(" permissions: '0755'");
|
|
199
|
+
lines.push("");
|
|
200
|
+
lines.push(" - path: /opt/genesis/data");
|
|
201
|
+
lines.push(" owner: genesis:genesis");
|
|
202
|
+
lines.push(" permissions: '0755'");
|
|
203
|
+
lines.push("");
|
|
204
|
+
lines.push(" - path: /var/log/genesis");
|
|
205
|
+
lines.push(" owner: genesis:genesis");
|
|
206
|
+
lines.push(" permissions: '0755'");
|
|
207
|
+
lines.push("");
|
|
208
|
+
|
|
209
|
+
// Environment file template
|
|
210
|
+
lines.push(" # Environment file template (do NOT include actual secrets)");
|
|
211
|
+
lines.push(" - path: /etc/default/genesis.template");
|
|
212
|
+
lines.push(" owner: genesis:genesis");
|
|
213
|
+
lines.push(" permissions: '0640'");
|
|
214
|
+
lines.push(" content: |");
|
|
215
|
+
lines.push(" # Genesis Server Environment Configuration");
|
|
216
|
+
lines.push(" # Copy this to /etc/default/genesis and fill in required values");
|
|
217
|
+
lines.push(" #");
|
|
218
|
+
lines.push(" # DO NOT commit actual secrets to version control!");
|
|
219
|
+
lines.push("");
|
|
220
|
+
lines.push(" # Application Settings");
|
|
221
|
+
lines.push(" NODE_ENV=production");
|
|
222
|
+
lines.push(` PORT=3000`);
|
|
223
|
+
lines.push(` HOST=0.0.0.0`);
|
|
224
|
+
lines.push("");
|
|
225
|
+
lines.push(" # Hetzner API (REQUIRED - use Vault or Secrets Manager in production)");
|
|
226
|
+
lines.push(" # HETZNER_API_TOKEN should be set securely after bootstrap");
|
|
227
|
+
lines.push(" HETZNER_DEFAULT_TYPE=" + defaultServerType);
|
|
228
|
+
lines.push(" HETZNER_DEFAULT_LOCATION=" + defaultLocation);
|
|
229
|
+
lines.push(" MAX_WORKER_NODES=" + maxWorkers);
|
|
230
|
+
lines.push("");
|
|
231
|
+
|
|
232
|
+
// Systemd service unit
|
|
233
|
+
lines.push(" # Genesis systemd service unit");
|
|
234
|
+
lines.push(" - path: /etc/systemd/system/genesis.service");
|
|
235
|
+
lines.push(" owner: root:root");
|
|
236
|
+
lines.push(" permissions: '0644'");
|
|
237
|
+
lines.push(" content: |");
|
|
238
|
+
lines.push(" [Unit]");
|
|
239
|
+
lines.push(" Description=Genesis Application Server (com.hetzner.codespaces)");
|
|
240
|
+
lines.push(" Documentation=https://github.com/ebowwa/com.hetzner.codespaces");
|
|
241
|
+
lines.push(" After=network-online.target");
|
|
242
|
+
lines.push(" Wants=network-online.target");
|
|
243
|
+
lines.push("");
|
|
244
|
+
lines.push(" [Service]");
|
|
245
|
+
lines.push(" Type=simple");
|
|
246
|
+
lines.push(" User=genesis");
|
|
247
|
+
lines.push(" Group=genesis");
|
|
248
|
+
lines.push(" WorkingDirectory=/opt/genesis");
|
|
249
|
+
lines.push("");
|
|
250
|
+
lines.push(" # Execution");
|
|
251
|
+
lines.push(" ExecStart=/usr/bin/bun start");
|
|
252
|
+
lines.push(" ExecReload=/bin/kill -HUP $MAINPID");
|
|
253
|
+
lines.push("");
|
|
254
|
+
lines.push(" # Restart Policy (with rate limiting)");
|
|
255
|
+
lines.push(" Restart=on-failure");
|
|
256
|
+
lines.push(" RestartSec=5s");
|
|
257
|
+
lines.push(" StartLimitIntervalSec=300");
|
|
258
|
+
lines.push(" StartLimitBurst=5");
|
|
259
|
+
lines.push("");
|
|
260
|
+
lines.push(" # Logging");
|
|
261
|
+
lines.push(" StandardOutput=journal");
|
|
262
|
+
lines.push(" StandardError=journal");
|
|
263
|
+
lines.push(" SyslogIdentifier=genesis");
|
|
264
|
+
lines.push("");
|
|
265
|
+
lines.push(" # Environment");
|
|
266
|
+
lines.push(' Environment="NODE_ENV=production"');
|
|
267
|
+
lines.push(" EnvironmentFile=/etc/default/genesis");
|
|
268
|
+
lines.push(" EnvironmentFile=-/etc/default/genesis.local");
|
|
269
|
+
lines.push("");
|
|
270
|
+
lines.push(" # Resource Limits");
|
|
271
|
+
lines.push(" LimitNOFILE=65536");
|
|
272
|
+
lines.push("");
|
|
273
|
+
|
|
274
|
+
// Security hardening for genesis service
|
|
275
|
+
if (enableSecurity) {
|
|
276
|
+
lines.push(" # Security Hardening");
|
|
277
|
+
lines.push(" NoNewPrivileges=true");
|
|
278
|
+
lines.push(" PrivateTmp=true");
|
|
279
|
+
lines.push(" ProtectSystem=strict");
|
|
280
|
+
lines.push(" ProtectHome=true");
|
|
281
|
+
lines.push(" ReadWritePaths=/opt/genesis/data /var/log/genesis");
|
|
282
|
+
} else {
|
|
283
|
+
lines.push(" # Security Hardening (minimal)");
|
|
284
|
+
lines.push(" NoNewPrivileges=false");
|
|
285
|
+
lines.push(" PrivateTmp=false");
|
|
286
|
+
}
|
|
287
|
+
lines.push("");
|
|
288
|
+
lines.push(" [Install]");
|
|
289
|
+
lines.push(" WantedBy=multi-user.target");
|
|
290
|
+
lines.push("");
|
|
291
|
+
|
|
292
|
+
// Bootstrap status tracking
|
|
293
|
+
lines.push(" # Bootstrap status tracking");
|
|
294
|
+
lines.push(" - path: /root/.genesis-bootstrap-status");
|
|
295
|
+
lines.push(" owner: root:root");
|
|
296
|
+
lines.push(" permissions: '0644'");
|
|
297
|
+
lines.push(" content: |");
|
|
298
|
+
lines.push(" status=started");
|
|
299
|
+
lines.push(" started_at=$(date -Iseconds)");
|
|
300
|
+
lines.push(" source=cloud-init");
|
|
301
|
+
lines.push(" version=1.0.0");
|
|
302
|
+
if (enableSecurity) {
|
|
303
|
+
lines.push(" security=enabled");
|
|
304
|
+
}
|
|
305
|
+
lines.push("");
|
|
306
|
+
|
|
307
|
+
// Add bun to /etc/environment
|
|
308
|
+
lines.push(" # Add bun to /etc/environment for all users/shells");
|
|
309
|
+
lines.push(" # Format: Simple KEY=\"value\" pairs, no variable expansion");
|
|
310
|
+
lines.push(" - path: /etc/environment");
|
|
311
|
+
lines.push(" owner: root:root");
|
|
312
|
+
lines.push(" permissions: '0644'");
|
|
313
|
+
lines.push(" content: |");
|
|
314
|
+
lines.push(' PATH="/root/.bun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"');
|
|
315
|
+
lines.push("");
|
|
316
|
+
|
|
317
|
+
// Security Module 1: UFW Firewall configuration files
|
|
318
|
+
if (enableSecurity) {
|
|
319
|
+
lines.push(" # Security Module 1: UFW Firewall configuration");
|
|
320
|
+
lines.push(...ufwFirewallWriteFiles(DEFAULT_UFW_GENESIS_OPTIONS));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Security Module 2: Kernel hardening configuration files
|
|
324
|
+
if (enableSecurity) {
|
|
325
|
+
lines.push(" # Security Module 2: Kernel hardening");
|
|
326
|
+
lines.push(...kernelHardeningWriteFiles());
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Security Module 3: SSH hardening configuration files
|
|
330
|
+
if (enableSecurity) {
|
|
331
|
+
lines.push(" # Security Module 3: SSH hardening");
|
|
332
|
+
lines.push(...sshdHardeningWriteFiles());
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Security Module 4: Security audit script
|
|
336
|
+
if (enableSecurity) {
|
|
337
|
+
lines.push(" # Security Module 4: Security audit");
|
|
338
|
+
lines.push(...securityAuditWriteFiles());
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// STAGE 5: Run Commands
|
|
342
|
+
lines.push("# =====================================================");
|
|
343
|
+
lines.push("# STAGE 5: Run Commands (Config stage)");
|
|
344
|
+
lines.push("# =====================================================");
|
|
345
|
+
lines.push("");
|
|
346
|
+
lines.push("runcmd:");
|
|
347
|
+
|
|
348
|
+
// Install Bun
|
|
349
|
+
lines.push(" # Install Bun runtime");
|
|
350
|
+
lines.push(" - curl -fsSL https://bun.sh/install | bash");
|
|
351
|
+
lines.push("");
|
|
352
|
+
|
|
353
|
+
// Clone genesis application
|
|
354
|
+
lines.push(" # Clone/pull genesis application");
|
|
355
|
+
const cloneCmd = genesisBranch
|
|
356
|
+
? `git clone --depth 1 --branch ${genesisBranch} ${genesisRepo} /opt/genesis`
|
|
357
|
+
: `git clone --depth 1 ${genesisRepo} /opt/genesis`;
|
|
358
|
+
|
|
359
|
+
lines.push(` - |`);
|
|
360
|
+
lines.push(` if [ ! -d /opt/genesis/.git ]; then`);
|
|
361
|
+
lines.push(` ${cloneCmd}`);
|
|
362
|
+
lines.push(` else`);
|
|
363
|
+
lines.push(` cd /opt/genesis && git pull`);
|
|
364
|
+
lines.push(` fi`);
|
|
365
|
+
lines.push("");
|
|
366
|
+
|
|
367
|
+
// Install dependencies
|
|
368
|
+
lines.push(" # Install dependencies");
|
|
369
|
+
lines.push(" - cd /opt/genesis && bun install");
|
|
370
|
+
lines.push("");
|
|
371
|
+
|
|
372
|
+
// Build application
|
|
373
|
+
lines.push(" # Build application (if needed)");
|
|
374
|
+
lines.push(" - cd /opt/genesis && bun run build");
|
|
375
|
+
lines.push("");
|
|
376
|
+
|
|
377
|
+
// Configure environment warning
|
|
378
|
+
lines.push(" # Configure environment (prompt for secrets or use external source)");
|
|
379
|
+
lines.push(" - |");
|
|
380
|
+
lines.push(` echo "WARNING: HETZNER_API_TOKEN must be configured in /etc/default/genesis"`);
|
|
381
|
+
lines.push("");
|
|
382
|
+
|
|
383
|
+
// Enable and start service
|
|
384
|
+
lines.push(" # Enable and start genesis service");
|
|
385
|
+
lines.push(" - systemctl daemon-reload");
|
|
386
|
+
lines.push(" - systemctl enable genesis.service");
|
|
387
|
+
lines.push(" - systemctl start genesis.service");
|
|
388
|
+
lines.push("");
|
|
389
|
+
|
|
390
|
+
// Security Module 1: UFW Firewall activation (runs first)
|
|
391
|
+
if (enableSecurity) {
|
|
392
|
+
lines.push(" # Security Module 1: Activate UFW Firewall");
|
|
393
|
+
lines.push(...ufwFirewallRunCmd(DEFAULT_UFW_GENESIS_OPTIONS));
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// Security Module 2: Kernel hardening activation
|
|
397
|
+
if (enableSecurity) {
|
|
398
|
+
lines.push(" # Security Module 2: Apply kernel hardening");
|
|
399
|
+
lines.push(...kernelHardeningRunCmd());
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// Security Module 3: SSH hardening activation
|
|
403
|
+
if (enableSecurity) {
|
|
404
|
+
lines.push(" # Security Module 3: Activate SSH hardening");
|
|
405
|
+
lines.push(...sshdHardeningRunCmd());
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Security Module 4: Security audit (runs last)
|
|
409
|
+
if (enableSecurity) {
|
|
410
|
+
lines.push(" # Security Module 4: Run security audit");
|
|
411
|
+
lines.push(...securityAuditRunCmd());
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// Mark bootstrap complete
|
|
415
|
+
lines.push(" # Mark bootstrap complete");
|
|
416
|
+
lines.push(' - echo "status=complete" >> /root/.genesis-bootstrap-status');
|
|
417
|
+
lines.push(' - echo "completed_at=$(date -Iseconds)" >> /root/.genesis-bootstrap-status');
|
|
418
|
+
if (enableSecurity) {
|
|
419
|
+
lines.push(' - echo "security_hardening=applied" >> /root/.genesis-bootstrap-status');
|
|
420
|
+
}
|
|
421
|
+
lines.push("");
|
|
422
|
+
|
|
423
|
+
// Additional commands
|
|
424
|
+
if (additionalCommands.length > 0) {
|
|
425
|
+
lines.push(" # Additional custom commands");
|
|
426
|
+
for (const cmd of additionalCommands) {
|
|
427
|
+
lines.push(` - ${cmd}`);
|
|
428
|
+
}
|
|
429
|
+
lines.push("");
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// STAGE 6: Final
|
|
433
|
+
lines.push("# =====================================================");
|
|
434
|
+
lines.push("# STAGE 6: Final (Final stage)");
|
|
435
|
+
lines.push("# =====================================================");
|
|
436
|
+
lines.push("");
|
|
437
|
+
lines.push('final_message: "Genesis server bootstrap completed after $UPTIME seconds"');
|
|
438
|
+
|
|
439
|
+
return lines.join("\n");
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Generate a minimal cloud-init script that uses #include to fetch from a URL
|
|
444
|
+
*
|
|
445
|
+
* This is useful for larger bootstrap scripts or when you want to update
|
|
446
|
+
* the bootstrap without code changes.
|
|
447
|
+
*
|
|
448
|
+
* @param url - URL to fetch the cloud-init config from
|
|
449
|
+
* @returns Cloud-init YAML string with #include directive
|
|
450
|
+
*/
|
|
451
|
+
export function generateRemoteGenesisBootstrap(url: string): string {
|
|
452
|
+
return `#include\n${url}`;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Genesis bootstrap configuration presets for common scenarios
|
|
457
|
+
*/
|
|
458
|
+
export const GenesisBootstrapPresets = {
|
|
459
|
+
/**
|
|
460
|
+
* Default Genesis server with standard configuration and full security
|
|
461
|
+
*/
|
|
462
|
+
default: (adminSSHKey: string) =>
|
|
463
|
+
generateGenesisBootstrap({
|
|
464
|
+
adminSSHKey,
|
|
465
|
+
}),
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Genesis server with ARM architecture (CAX series - best €/performance)
|
|
469
|
+
*/
|
|
470
|
+
arm: (adminSSHKey: string) =>
|
|
471
|
+
generateGenesisBootstrap({
|
|
472
|
+
adminSSHKey,
|
|
473
|
+
defaultServerType: "cax21",
|
|
474
|
+
}),
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Genesis server with high-performance CPU (CPX series)
|
|
478
|
+
*/
|
|
479
|
+
performance: (adminSSHKey: string) =>
|
|
480
|
+
generateGenesisBootstrap({
|
|
481
|
+
adminSSHKey,
|
|
482
|
+
defaultServerType: "cpx21",
|
|
483
|
+
}),
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Genesis server with dedicated CPU (CCX series)
|
|
487
|
+
*/
|
|
488
|
+
dedicated: (adminSSHKey: string) =>
|
|
489
|
+
generateGenesisBootstrap({
|
|
490
|
+
adminSSHKey,
|
|
491
|
+
defaultServerType: "ccx13",
|
|
492
|
+
}),
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Development Genesis server without security hardening
|
|
496
|
+
*/
|
|
497
|
+
development: (adminSSHKey: string) =>
|
|
498
|
+
generateGenesisBootstrap({
|
|
499
|
+
adminSSHKey,
|
|
500
|
+
enableSecurity: false,
|
|
501
|
+
packages: ["htop", "vim", "tmux", "strace"],
|
|
502
|
+
additionalCommands: [
|
|
503
|
+
"echo 'Genesis development server ready' | wall",
|
|
504
|
+
],
|
|
505
|
+
}),
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Secure Genesis server with full hardening and verbose logging
|
|
509
|
+
*/
|
|
510
|
+
secure: (adminSSHKey: string) =>
|
|
511
|
+
generateGenesisBootstrap({
|
|
512
|
+
adminSSHKey,
|
|
513
|
+
packages: ["lynis"],
|
|
514
|
+
additionalCommands: [
|
|
515
|
+
"echo 'Genesis secure server ready - security audit completed' | wall",
|
|
516
|
+
],
|
|
517
|
+
}),
|
|
518
|
+
} as const;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bootstrap Security Modules
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive security hardening for cloud-init server provisioning.
|
|
5
|
+
* All modules are composable and can be integrated independently.
|
|
6
|
+
*
|
|
7
|
+
* Security Module Order:
|
|
8
|
+
* 1. UFW Firewall (network-level defense)
|
|
9
|
+
* 2. Kernel Hardening (system-level hardening)
|
|
10
|
+
* 3. SSH Hardening (service-level hardening)
|
|
11
|
+
* 4. Security Audit (verification and reporting)
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { generateSeedBootstrap } from './bootstrap';
|
|
16
|
+
*
|
|
17
|
+
* const cloudInit = generateSeedBootstrap({
|
|
18
|
+
* enableSecurity: true,
|
|
19
|
+
* seedRepo: 'https://github.com/ebowwa/seed',
|
|
20
|
+
* seedBranch: 'dev',
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
// Export all bootstrap generators
|
|
25
|
+
export { generateSeedBootstrap, generateRemoteBootstrap, BootstrapPresets, } from './cloud-init';
|
|
26
|
+
export { generateGenesisBootstrap, generateRemoteGenesisBootstrap, GenesisBootstrapPresets, } from './genesis';
|
|
27
|
+
// Export UFW Firewall module
|
|
28
|
+
export { ufwFirewallPackages, ufwFirewallWriteFiles, ufwFirewallRunCmd, DEFAULT_UFW_WORKER_OPTIONS, DEFAULT_UFW_GENESIS_OPTIONS, generateUFWFirewallForGenesis, generateUFWFirewallForWorker, } from './firewall';
|
|
29
|
+
// Export Kernel Hardening module
|
|
30
|
+
export { kernelHardeningPackages, kernelHardeningWriteFiles, kernelHardeningRunCmd, } from './kernel-hardening';
|
|
31
|
+
// Export SSH Hardening module
|
|
32
|
+
export { sshdHardeningPackages, sshdHardeningWriteFiles, sshdHardeningRunCmd, } from './ssh-hardening';
|
|
33
|
+
// Export Security Audit module
|
|
34
|
+
export { securityAuditPackages, securityAuditWriteFiles, securityAuditRunCmd, } from './security-audit';
|
|
35
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bootstrap Security Modules
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive security hardening for cloud-init server provisioning.
|
|
5
|
+
* All modules are composable and can be integrated independently.
|
|
6
|
+
*
|
|
7
|
+
* Security Module Order:
|
|
8
|
+
* 1. UFW Firewall (network-level defense)
|
|
9
|
+
* 2. Kernel Hardening (system-level hardening)
|
|
10
|
+
* 3. SSH Hardening (service-level hardening)
|
|
11
|
+
* 4. Security Audit (verification and reporting)
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { generateSeedBootstrap } from './bootstrap';
|
|
16
|
+
*
|
|
17
|
+
* const cloudInit = generateSeedBootstrap({
|
|
18
|
+
* enableSecurity: true,
|
|
19
|
+
* seedRepo: 'https://github.com/ebowwa/seed',
|
|
20
|
+
* seedBranch: 'dev',
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
// Export all bootstrap generators
|
|
26
|
+
export {
|
|
27
|
+
generateSeedBootstrap,
|
|
28
|
+
generateRemoteBootstrap,
|
|
29
|
+
BootstrapPresets,
|
|
30
|
+
type BootstrapOptions,
|
|
31
|
+
} from './cloud-init';
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
generateGenesisBootstrap,
|
|
35
|
+
generateRemoteGenesisBootstrap,
|
|
36
|
+
GenesisBootstrapPresets,
|
|
37
|
+
type GenesisBootstrapOptions,
|
|
38
|
+
} from './genesis';
|
|
39
|
+
|
|
40
|
+
// Export UFW Firewall module
|
|
41
|
+
export {
|
|
42
|
+
ufwFirewallPackages,
|
|
43
|
+
ufwFirewallWriteFiles,
|
|
44
|
+
ufwFirewallRunCmd,
|
|
45
|
+
DEFAULT_UFW_WORKER_OPTIONS,
|
|
46
|
+
DEFAULT_UFW_GENESIS_OPTIONS,
|
|
47
|
+
generateUFWFirewallForGenesis,
|
|
48
|
+
generateUFWFirewallForWorker,
|
|
49
|
+
type UFWFirewallOptions,
|
|
50
|
+
} from './firewall';
|
|
51
|
+
|
|
52
|
+
// Export Kernel Hardening module
|
|
53
|
+
export {
|
|
54
|
+
kernelHardeningPackages,
|
|
55
|
+
kernelHardeningWriteFiles,
|
|
56
|
+
kernelHardeningRunCmd,
|
|
57
|
+
} from './kernel-hardening';
|
|
58
|
+
|
|
59
|
+
// Export SSH Hardening module
|
|
60
|
+
export {
|
|
61
|
+
sshdHardeningPackages,
|
|
62
|
+
sshdHardeningWriteFiles,
|
|
63
|
+
sshdHardeningRunCmd,
|
|
64
|
+
} from './ssh-hardening';
|
|
65
|
+
|
|
66
|
+
// Export Security Audit module
|
|
67
|
+
export {
|
|
68
|
+
securityAuditPackages,
|
|
69
|
+
securityAuditWriteFiles,
|
|
70
|
+
securityAuditRunCmd,
|
|
71
|
+
} from './security-audit';
|