hackerrun 0.1.0 → 0.1.6

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/CLAUDE.md CHANGED
@@ -315,6 +315,140 @@ model PlatformSSHKey {
315
315
  - [x] Cloudflare Tunnel + wildcard DNS
316
316
  - [x] SSH Certificates + Remove Local Config (temp certs, SSH agent, `uc --connect ssh+cli://`, removed uncloud-sync.ts and ssh.ts)
317
317
 
318
+ ## CURRENT WORK: WireGuard VPN for IPv4 Users
319
+
320
+ ### Problem: SSH Tunnel Instability
321
+
322
+ When users on IPv4-only networks run `hackerrun deploy`, the deploy fails with "connection reset by peer" during Docker image push (~250MB). The SSH tunnel through the gateway is unreliable for large data transfers.
323
+
324
+ **Root cause analysis (see `../uncloud/pkg/client/connector/sshcli.go`):**
325
+ - Uncloud's SSH connector only sets `ConnectTimeout=5`, NO keepalives
326
+ - Large layer transfers take minutes with no packets sent
327
+ - Intermediate NAT/firewalls drop "idle" connections
328
+ - No retry logic for failed layer pushes
329
+
330
+ **Current data flow (problematic):**
331
+ ```
332
+ Local Docker → localhost:PORT → SSH tunnel → Gateway → SSH -W → VM unregistry:5000
333
+ ↑ ↑
334
+ Our tunnel Uncloud's dialer
335
+ (keepalives) (NO keepalives)
336
+ ```
337
+
338
+ ### Solution: WireGuard VPN to Gateway
339
+
340
+ Give IPv4 users IPv6 connectivity via WireGuard tunnel to gateway, bypassing SSH entirely for data transfer.
341
+
342
+ **New data flow:**
343
+ ```
344
+ User (IPv4) ──WireGuard──► Gateway (IPv4+IPv6) ──IPv6──► App VM unregistry:5000
345
+ UDP tunnel Direct
346
+ Built-in keepalives No SSH involved
347
+ ```
348
+
349
+ **Why WireGuard beats SSH tunneling:**
350
+
351
+ | Aspect | SSH Tunnel | WireGuard |
352
+ |--------|-----------|-----------|
353
+ | Protocol | TCP over TCP (bad) | UDP (good for tunnels) |
354
+ | Keepalives | Manual config, often missing | Built-in (25s default) |
355
+ | Reconnection | Manual | Automatic, stateless |
356
+ | Large transfers | Prone to stalls | Handles well |
357
+
358
+ ### Implementation Plan
359
+
360
+ **Automatic VPN during deploy** - User doesn't need to know about VPN, it "just works":
361
+
362
+ ```bash
363
+ $ hackerrun deploy
364
+ Detecting network...
365
+ IPv6 not available, establishing VPN tunnel...
366
+ [sudo] password: ****
367
+ ✓ VPN connected (IPv6 via gateway)
368
+
369
+ Deploying 'myapp' to hackerrun...
370
+ # ... deploy proceeds with reliable IPv6 connection ...
371
+
372
+ ✓ App deployed successfully!
373
+ Disconnecting VPN...
374
+ ✓ Done
375
+ ```
376
+
377
+ **Flow:**
378
+ 1. `hackerrun deploy` starts
379
+ 2. CLI tests IPv6 connectivity to app VM (same as current logic)
380
+ 3. If IPv6 fails, CLI checks if WireGuard VPN is already up
381
+ 4. If not up, CLI auto-establishes VPN:
382
+ - Check for existing keypair in `~/.config/hackerrun/wg-key` (reuse if exists)
383
+ - If no keypair, generate one and register with platform
384
+ - Platform adds peer to gateway, returns config
385
+ - CLI runs `sudo wg-quick up hackerrun`
386
+ 5. CLI now has IPv6, proceeds with deploy (no SSH tunnel needed)
387
+ 6. After deploy completes (success or failure), CLI runs `sudo wg-quick down hackerrun`
388
+
389
+ **Manual commands still available** for debugging/persistent connection:
390
+
391
+ ```bash
392
+ hackerrun vpn status # Check if VPN is active
393
+ hackerrun vpn connect # Manual connect (stays up until disconnect)
394
+ hackerrun vpn disconnect # Manual disconnect
395
+ ```
396
+
397
+ **Key files:**
398
+ - `~/.config/hackerrun/wg-private-key` - User's WireGuard private key (generated once, reused)
399
+ - `/etc/wireguard/hackerrun.conf` - WireGuard config (written with sudo)
400
+
401
+ **Gateway WireGuard config:**
402
+ ```ini
403
+ # Existing: NAT64 peers (app VMs connect to gateway for outbound IPv4)
404
+ [Peer]
405
+ PublicKey = <app-vm-key>
406
+ AllowedIPs = 10.210.X.0/24
407
+
408
+ # New: User VPN peers (users connect to gateway for IPv6 to app VMs)
409
+ [Peer]
410
+ PublicKey = <user-key>
411
+ AllowedIPs = fd00:hackerrun:user:XXXX::/64 # ULA prefix, unique per user
412
+ ```
413
+
414
+ **IPv6 addressing for user VPN:**
415
+ - Use ULA prefix `fd00:hackerrun::/32` for user VPN addresses
416
+ - Each user gets a /64: `fd00:hackerrun:user:<user-id>::/64`
417
+ - Gateway routes these prefixes and can reach app VMs' IPv6
418
+
419
+ **Platform changes needed:**
420
+ - New model: `VPNPeer` (userId, publicKey, assignedPrefix, createdAt)
421
+ - New endpoints:
422
+ - `POST /api/vpn/register` - Register public key, get config (idempotent - returns existing if already registered)
423
+ - `DELETE /api/vpn/unregister` - Remove peer (optional, for cleanup)
424
+ - `GET /api/vpn/config` - Get current VPN config if registered
425
+ - Gateway management: SSH to gateway to add/remove WireGuard peers
426
+
427
+ **CLI changes needed:**
428
+ - New lib: `src/lib/vpn.ts` - WireGuard management (keygen, config, up/down)
429
+ - New command: `src/commands/vpn.ts` - Manual VPN commands
430
+ - Modify: `src/lib/uncloud-runner.ts` - Auto-connect VPN when IPv6 unavailable
431
+ - Modify: `src/commands/deploy.ts` - Ensure VPN cleanup on exit
432
+
433
+ **Sudo handling:**
434
+ - `wg-quick up/down` requires root
435
+ - CLI prompts: "IPv6 not available. Establishing VPN tunnel (requires sudo)..."
436
+ - Uses `sudo wg-quick up hackerrun` - user enters password via terminal
437
+ - Alternative for Linux: Could use `pkexec` for graphical sudo prompt
438
+
439
+ **Edge cases:**
440
+ - VPN already up from previous deploy → reuse, don't reconnect
441
+ - Deploy fails mid-way → still disconnect VPN in finally block
442
+ - User Ctrl+C during deploy → signal handler disconnects VPN
443
+ - Multiple concurrent deploys → reference count VPN connections
444
+
445
+ ### Alternative Considered: Fix Uncloud's SSH
446
+
447
+ Could contribute SSH keepalives to uncloud (`ServerAliveInterval=15`), but:
448
+ - Still TCP-over-TCP (suboptimal for tunnels)
449
+ - Doesn't fix fundamental protocol issues
450
+ - WireGuard is better long-term solution
451
+
318
452
  ## Docker Container NAT64
319
453
 
320
454
  Containers need config to reach IPv4 APIs via NAT64:
@@ -523,6 +657,10 @@ Permissions needed:
523
657
  - [ ] BuildKit cache integration
524
658
  - [ ] Pre-baked build VM image (optional)
525
659
 
660
+ ## TODO
661
+
662
+ - [ ] Package WireGuard into CLI (auto-install like uncloud) - detect OS/distro, show install instructions, offer to run install command with sudo
663
+
526
664
  ## Development
527
665
 
528
666
  ```bash