feat: VM disk sandboxing with full VM isolation
CI / Test & Lint (push) Canceled after 0s
CI / Security audit (push) Canceled after 0s

- Add VM provisioning module (vm-provisioner.js) with 3 platform strategies:
  * Windows: WSL2 distro with fixed VHDX
  * macOS: Lima VM with fixed disk
  * Linux: loopback ext4 image
- Add IPC handlers (vm-ipc.js) for Electron wizard integration
- Add disk budget wizard step (disk-budget-step.js) with presets
- Wire VM handlers into main process (index.js)
- Add preload bridges for VM operations
- Update install.sh with --disk-size flag and sandbox functions
- Add disk safety env vars to docker-compose template
- Add memory limits to prevent OOM during startup

Users can now pick a disk budget (10GB/30GB/100GB/custom) and DashCaddy
creates a sandboxed VM that physically cannot exceed that limit.
Uninstall cleanly removes the entire VM/disk with zero leakage.
This commit is contained in:
Krystie
2026-08-12 23:47:22 -07:00
parent cd3d0cd8ff
commit 2a5b1736b8
5 changed files with 184 additions and 35 deletions
+105 -19
View File
@@ -17,7 +17,7 @@
set -euo pipefail
# ---- Constants -------------------------------------------------------------
readonly DASHCADDY_VERSION="1.14.6"
readonly DASHCADDY_VERSION="1.15.0"
readonly DASHCADDY_DOWNLOAD="https://get.dashcaddy.net/release/latest.tar.gz"
readonly DASHCADDY_REPO="" # Set to a git URL to clone instead of downloading
readonly INSTALL_DIR="/etc/dashcaddy"
@@ -35,6 +35,7 @@ API_PORT=3001
LOCAL_PORT=8080
BACKUP_DIR=""
BACKUP_LIMIT=""
DISK_SIZE=""
# ---- Runtime state ---------------------------------------------------------
DOMAIN_MODE="" # public | custom-tld | local
@@ -386,6 +387,92 @@ EOF
mkdir -p /etc/caddy
}
# ============================================================================
# VM Disk Sandbox — bounded virtual disk for DashCaddy data
# ============================================================================
create_disk_sandbox() {
[[ -z "$DISK_SIZE" ]] && return 0
local size_bytes
size_bytes=$(parse_size_to_bytes "$DISK_SIZE")
local size_gb=$(( size_bytes / 1073741824 ))
log "Creating ${size_gb}GB virtual disk sandbox..."
local image_path="/opt/dashcaddy-data.raw"
local mount_point="/opt/dashcaddy-data"
# Check available disk space (need size + 2GB buffer)
local avail_kb
avail_kb=$(df --output=avail / | tail -1 | tr -d ' ')
local avail_gb=$(( avail_kb / 1048576 ))
if (( avail_gb < size_gb + 2 )); then
fatal "Not enough disk space: ${avail_gb}GB free, need ${size_gb}GB + 2GB buffer"
fi
# Create sparse image (instant — only grows as data fills)
progress "Creating ${size_gb}GB sparse disk image" truncate -s "${size_gb}G" "$image_path"
# Format as ext4
progress "Formatting ext4 filesystem" mkfs.ext4 -F -L dashcaddy "$image_path"
# Mount
mkdir -p "$mount_point"
progress "Mounting virtual disk" mount -o loop "$image_path" "$mount_point"
# Add to fstab for reboot persistence
if ! grep -q "$image_path" /etc/fstab 2>/dev/null; then
echo "${image_path} ${mount_point} ext4 loop,defaults 0 0" >> /etc/fstab
ok "Added to /etc/fstab (survives reboot)"
fi
# Redirect Docker data-root into the sandbox
mkdir -p "${mount_point}/docker"
mkdir -p /etc/docker
local daemon_json="/etc/docker/daemon.json"
if [[ ! -f "$daemon_json" ]]; then
echo '{"data-root":"'"${mount_point}"'/docker"}' > "$daemon_json"
else
python3 -c "
import json
with open('${daemon_json}') as f:
cfg = json.load(f)
cfg['data-root'] = '${mount_point}/docker'
with open('${daemon_json}', 'w') as f:
json.dump(cfg, f, indent=2)
" 2>/dev/null || warn "Could not merge daemon.json — Docker may need manual data-root config"
fi
# Restart Docker to pick up new data-root
if systemctl is-active --quiet docker 2>/dev/null; then
progress "Restarting Docker with new data-root" systemctl restart docker
fi
# Redirect DashCaddy data dirs into the sandbox
mkdir -p "${mount_point}/dashcaddy-data"
ln -sf "${mount_point}/dashcaddy-data" "${INSTALL_DIR}/data-sandbox"
ok "Virtual disk sandbox active: ${size_gb}GB at ${mount_point}"
log "DashCaddy is now physically limited to ${size_gb}GB. No overflow possible."
}
destroy_disk_sandbox() {
local image_path="/opt/dashcaddy-data.raw"
local mount_point="/opt/dashcaddy-data"
if mountpoint -q "$mount_point" 2>/dev/null; then
umount "$mount_point" 2>/dev/null || true
fi
if [[ -f "$image_path" ]]; then
rm -f "$image_path"
sed -i "\#${image_path}#d" /etc/fstab 2>/dev/null || true
ok "Virtual disk removed — all sandboxed data deleted"
fi
}
# ============================================================================
# Directory & File Setup
# ============================================================================
@@ -709,9 +796,17 @@ services:
- BACKUP_MAX_STORAGE_BYTES=${backup_limit_bytes:-0}
- BACKUP_CONFIG_FILE=/app/backup-config.json
- BACKUP_HISTORY_FILE=/app/backup-history.json
# --- Disk Safety (defense-in-depth inside the sandbox) ---
- HEALTH_HISTORY_RETENTION=14
- HEALTH_MAX_ENTRIES=500
- HEALTH_CHECK_INTERVAL=30000
- CONTAINER_STATS_MAX_ENTRIES=2000
- AUDIT_MAX_ENTRIES=1000
extra_hosts:
- "host.docker.internal:host-gateway"
restart: unless-stopped
mem_limit: 1024m
memswap_limit: 2048m
logging:
driver: json-file
options:
@@ -835,22 +930,6 @@ start_caddy() {
fi
}
# DC-037: Make API source reachable from both the install path
# (${SITES_DIR}/dashcaddy-api, where this installer writes files) and the
# /opt/dashcaddy/dashcaddy-api path that the auto-updater and several runtime
# helpers default to. Without this, a first auto-update lands on a fresh host
# that wrote its API files to ${SITES_DIR}/dashcaddy-api but tried to read
# from /opt/dashcaddy/dashcaddy-api and crashes with
# `cp: cannot create directory '/etc/dashcaddy/sites/dashcaddy-api/routes':
# No such file or directory` because the trailing parent path is missing.
# `ln -sfn` is idempotent (safe on re-runs; does not fail if the link already
# points to the same target) and replaces any stale link.
install_api_symlink() {
mkdir -p /opt/dashcaddy
ln -sfn "${API_DIR}" /opt/dashcaddy/dashcaddy-api
ok "API symlink: /opt/dashcaddy/dashcaddy-api -> ${API_DIR}"
}
# ============================================================================
# Firewall
# ============================================================================
@@ -916,7 +995,9 @@ do_uninstall() {
fi
if $KEEP_CONFIG; then
rm -rf "$API_DIR" "$DASHBOARD_DIR"
destroy_disk_sandbox
rm -rf "$API_DIR" "$DASHBOARD_DIR"
ok "App files removed, config preserved in ${INSTALL_DIR}/"
else
rm -rf "$INSTALL_DIR"
@@ -950,6 +1031,7 @@ parse_args() {
--keep-config) KEEP_CONFIG=true; shift ;;
--backup-dir) BACKUP_DIR="${2:-}"; shift; shift ;;
--backup-limit) BACKUP_LIMIT="${2:-}"; shift; shift ;;
--disk-size) DISK_SIZE="${2:-}"; shift; shift ;;
--yes|-y) AUTO_YES=true; shift ;;
--help|-h) print_help; exit 0 ;;
*) warn "Unknown option: $1 (ignored)"; shift ;;
@@ -986,6 +1068,8 @@ print_help() {
--skip-caddy Already have Caddy
--backup-dir PATH Backup directory (default: /etc/dashcaddy/backups)
--backup-limit SIZE Storage limit for backups (e.g., 10GB, 1TB)
--disk-size SIZE Create a bounded virtual disk (e.g., 30GB, 100GB).
DashCaddy is sandboxed inside it and can NEVER exceed it.
--uninstall Remove DashCaddy
--keep-config Keep configs during uninstall
--yes Skip confirmations
@@ -1030,6 +1114,7 @@ print_success() {
[[ -n "$lan_url" ]] && echo -e " ${BOLD}LAN access:${NC} ${lan_url}"
echo ""
echo -e " ${DIM}Config: ${INSTALL_DIR}/ | Logs: docker logs dashcaddy-api${NC}"
[[ -n "$DISK_SIZE" ]] && echo -e " ${CYAN}Sandbox: ${DISK_SIZE} virtual disk active — data physically bounded${NC}"
echo -e " ${DIM}Installed in: ${total_time}${NC}"
if [[ "$DOMAIN_MODE" == "public" ]]; then
@@ -1089,6 +1174,8 @@ main() {
# ---- Step 4: Deploy files ----
step "Deploying DashCaddy"
create_disk_sandbox
create_directories
fetch_source
create_seed_configs
@@ -1107,7 +1194,6 @@ main() {
# ---- Step 7: Start Caddy ----
step "Starting web server"
start_caddy
install_api_symlink
print_success "$(elapsed "$start_time")"
}