Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Harden installer and demo backup handling

rcourtmandc5f0a35c009
diff --git a/.github/workflows/update-demo-server.yml b/.github/workflows/update-demo-server.yml
index cf4548c2ee..da8af0c526 100644
--- a/.github/workflows/update-demo-server.yml
+++ b/.github/workflows/update-demo-server.yml
@@ -330,6 +330,54 @@ jobs:
echo "skip_current=false" >> "$GITHUB_OUTPUT"
fi
+ - name: Prepare demo host storage
+ if: steps.current.outputs.skip_current != 'true'
+ env:
+ DEMO_SERVER_HOST: ${{ secrets.DEMO_SERVER_HOST }}
+ DEMO_SERVER_USER: ${{ secrets.DEMO_SERVER_USER }}
+ run: |
+ set -euo pipefail
+ SERVICE_NAME="${{ steps.config.outputs.service_name }}"
+ REMOTE_SCRIPT=$(cat <<'EOF'
+ set -euo pipefail
+ SERVICE_NAME="$1"
+ CONFIG_DIR="/etc/${SERVICE_NAME:-pulse}"
+ BACKUP_PARENT="$(dirname "$CONFIG_DIR")"
+ BACKUP_BASENAME="$(basename "$CONFIG_DIR")"
+ KEEP_BACKUPS=2
+ BACKUP_MARGIN_KB=$((64 * 1024))
+
+ echo "Demo host filesystem before cleanup:"
+ df -h "$BACKUP_PARENT" /tmp || true
+
+ mapfile -t old_backups < <(
+ sudo find "$BACKUP_PARENT" -maxdepth 1 -type d -name "${BACKUP_BASENAME}.backup.*" -printf '%T@ %p\n' 2>/dev/null \
+ | sort -nr \
+ | awk -v keep="$KEEP_BACKUPS" 'NR > keep {sub(/^[^ ]+ /, ""); print}'
+ )
+ if ((${#old_backups[@]} > 0)); then
+ printf 'Removing %d old demo backup directorie(s).\n' "${#old_backups[@]}"
+ printf '%s\0' "${old_backups[@]}" | sudo xargs -0 rm -rf --
+ fi
+
+ if [[ -d "$CONFIG_DIR" ]]; then
+ config_kb="$(sudo du -sk "$CONFIG_DIR" | awk 'NR == 1 {print $1}')"
+ free_kb="$(df -Pk "$BACKUP_PARENT" | awk 'NR == 2 {print $4}')"
+ required_kb=$((config_kb + BACKUP_MARGIN_KB))
+ if ((free_kb < required_kb)); then
+ echo "::error::Demo host does not have enough free space to back up $CONFIG_DIR before install."
+ echo "Config: ${config_kb}KB, available: ${free_kb}KB, required: ${required_kb}KB"
+ sudo find "$BACKUP_PARENT" -maxdepth 1 -type d -name "${BACKUP_BASENAME}.backup.*" -printf '%TY-%Tm-%Td %TH:%TM %p\n' 2>/dev/null | sort || true
+ exit 1
+ fi
+ fi
+
+ echo "Demo host filesystem after cleanup:"
+ df -h "$BACKUP_PARENT" /tmp || true
+ EOF
+ )
+ ssh -i ~/.ssh/id_ed25519 "$DEMO_SERVER_USER@$DEMO_SERVER_HOST" "bash -s -- $(printf '%q ' "$SERVICE_NAME")" <<<"$REMOTE_SCRIPT"
+
- name: Upload tagged installer
if: steps.current.outputs.skip_current != 'true'
env:
diff --git a/install.sh b/install.sh
index 58fd14e02d..91b71abfc3 100755
--- a/install.sh
+++ b/install.sh
@@ -107,6 +107,7 @@ BUILD_FROM_SOURCE_MARKER="$INSTALL_DIR/BUILD_FROM_SOURCE"
DETECTED_CTID=""
UPDATE_MIN_TEMP_FREE_BYTES=$((900 * 1024 * 1024))
UPDATE_MIN_INSTALL_FREE_BYTES=$((256 * 1024 * 1024))
+CONFIG_BACKUP_MIN_EXTRA_BYTES=$((64 * 1024 * 1024))
release_signature_key_available() {
[[ -n "${PINNED_RELEASE_SSH_PUBLIC_KEY:-}" ]]
@@ -204,6 +205,18 @@ get_filesystem_device_for_path() {
printf '%s\n' "$filesystem"
}
+get_directory_size_bytes() {
+ local path="$1"
+ local used_kb=""
+
+ used_kb=$(du -sk "$path" 2>/dev/null | awk 'NR==1 {print $1}')
+ if [[ ! "$used_kb" =~ ^[0-9]+$ ]]; then
+ return 1
+ fi
+
+ printf '%s\n' $((used_kb * 1024))
+}
+
ensure_update_disk_headroom() {
local temp_path="${1:-/tmp}"
local install_path="${2:-$INSTALL_DIR}"
@@ -251,6 +264,38 @@ ensure_update_disk_headroom() {
return 0
}
+ensure_config_backup_headroom() {
+ local config_path="${1:-$CONFIG_DIR}"
+ local backup_parent=""
+ local free_bytes=""
+ local config_bytes=""
+ local required_bytes=""
+
+ if [[ ! -d "$config_path" ]]; then
+ return 0
+ fi
+
+ backup_parent="$(dirname "$config_path")"
+ free_bytes=$(get_available_bytes_for_path "$backup_parent" 2>/dev/null || true)
+ config_bytes=$(get_directory_size_bytes "$config_path" 2>/dev/null || true)
+
+ if [[ -z "$free_bytes" || -z "$config_bytes" ]]; then
+ print_warn "Could not determine disk headroom for configuration backup; continuing anyway"
+ return 0
+ fi
+
+ required_bytes=$((config_bytes + CONFIG_BACKUP_MIN_EXTRA_BYTES))
+ if (( free_bytes < required_bytes )); then
+ print_error "Not enough free disk space to back up the existing Pulse configuration"
+ print_info "Configuration size: $(bytes_to_human "$config_bytes")"
+ print_info "Available in $backup_parent: $(bytes_to_human "$free_bytes"), required: $(bytes_to_human "$required_bytes")"
+ print_info "Free disk space or remove old ${config_path}.backup.* directories, then retry the update"
+ return 1
+ fi
+
+ return 0
+}
+
get_latest_release_from_redirect() {
# Follow the GitHub "latest" redirect and extract the tag in a way that
# tolerates intermediate redirects that omit /tag/ (issue #698).
@@ -2746,7 +2791,12 @@ create_user() {
backup_existing() {
if [[ -d "$CONFIG_DIR" ]]; then
print_info "Backing up existing configuration..."
- cp -a "$CONFIG_DIR" "${CONFIG_DIR}.backup.$(date +%Y%m%d-%H%M%S)"
+ ensure_config_backup_headroom "$CONFIG_DIR" || return 1
+ local backup_dir="${CONFIG_DIR}.backup.$(date +%Y%m%d-%H%M%S)"
+ if ! cp -a "$CONFIG_DIR" "$backup_dir"; then
+ rm -rf "$backup_dir"
+ return 1
+ fi
fi
}
diff --git a/scripts/installtests/build_release_assets_test.go b/scripts/installtests/build_release_assets_test.go
index 5f30ff1eda..e380361346 100644
--- a/scripts/installtests/build_release_assets_test.go
+++ b/scripts/installtests/build_release_assets_test.go
@@ -757,6 +757,9 @@ func TestUpdateDemoWorkflowUsesGovernedNetworkPath(t *testing.T) {
`sed -i "s|^PINNED_RELEASE_SSH_PUBLIC_KEY=.*|PINNED_RELEASE_SSH_PUBLIC_KEY=\"${TRUSTED_SSH_PUBLIC_KEY}\"|" /tmp/pulse-install.sh`,
`Verify target host identity`,
`Demo environment points at host $REMOTE_HOSTNAME but expected $DEMO_EXPECTED_HOSTNAME.`,
+ `Prepare demo host storage`,
+ `KEEP_BACKUPS=2`,
+ `Demo host does not have enough free space to back up $CONFIG_DIR before install.`,
`Verify public browser smoke`,
`./scripts/run_demo_public_browser_smoke.sh`,
}
diff --git a/scripts/installtests/root_install_sh_test.go b/scripts/installtests/root_install_sh_test.go
index 59961dbcb8..4793f7d89a 100644
--- a/scripts/installtests/root_install_sh_test.go
+++ b/scripts/installtests/root_install_sh_test.go
@@ -210,6 +210,99 @@ func TestRootInstallScriptUpdateDiskHeadroomAcceptsSeparateFilesystems(t *testin
}
}
+func TestRootInstallScriptConfigBackupHeadroomRejectsLowSpace(t *testing.T) {
+ configDir := t.TempDir()
+ configParent := filepath.Dir(configDir)
+
+ script := `
+ set -euo pipefail
+ print_error() { :; }
+ print_info() { :; }
+ print_warn() { :; }
+ CONFIG_DIR="$CONFIG_DIR_UNDER_TEST"
+ CONFIG_BACKUP_MIN_EXTRA_BYTES=$((64 * 1024))
+` + extractRootInstallShellFunction(t, "bytes_to_human") + `
+` + extractRootInstallShellFunction(t, "get_available_bytes_for_path") + `
+` + extractRootInstallShellFunction(t, "get_directory_size_bytes") + `
+` + extractRootInstallShellFunction(t, "ensure_config_backup_headroom") + `
+ df() {
+ if [[ "$1" == "-Pk" && "$2" == "$CONFIG_PARENT_UNDER_TEST" ]]; then
+ printf 'Filesystem 1024-blocks Used Available Capacity Mounted on\n'
+ printf '/dev/root 1000 0 65 0%% /\n'
+ return 0
+ fi
+ command df "$@"
+ }
+ du() {
+ if [[ "$1" == "-sk" && "$2" == "$CONFIG_DIR_UNDER_TEST" ]]; then
+ printf '4\t%s\n' "$CONFIG_DIR_UNDER_TEST"
+ return 0
+ fi
+ command du "$@"
+ }
+ if ensure_config_backup_headroom "$CONFIG_DIR"; then
+ echo "ensure_config_backup_headroom unexpectedly passed with no backup margin" >&2
+ exit 1
+ fi
+ `
+
+ cmd := exec.Command("bash", "-c", script)
+ cmd.Env = append(os.Environ(),
+ "CONFIG_DIR_UNDER_TEST="+configDir,
+ "CONFIG_PARENT_UNDER_TEST="+configParent,
+ )
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("bash: %v\n%s", err, out)
+ }
+}
+
+func TestRootInstallScriptConfigBackupCleansPartialCopy(t *testing.T) {
+ configDir := t.TempDir()
+ backupDir := configDir + ".backup.20260704-141422"
+
+ script := `
+ set -euo pipefail
+ print_error() { :; }
+ print_info() { :; }
+ print_warn() { :; }
+ CONFIG_DIR="$CONFIG_DIR_UNDER_TEST"
+ CONFIG_BACKUP_MIN_EXTRA_BYTES=$((64 * 1024))
+` + extractRootInstallShellFunction(t, "bytes_to_human") + `
+` + extractRootInstallShellFunction(t, "get_available_bytes_for_path") + `
+` + extractRootInstallShellFunction(t, "get_directory_size_bytes") + `
+` + extractRootInstallShellFunction(t, "ensure_config_backup_headroom") + `
+` + extractRootInstallShellFunction(t, "backup_existing") + `
+ date() { printf '20260704-141422\n'; }
+ cp() {
+ if [[ "$1" == "-a" && "$2" == "$CONFIG_DIR_UNDER_TEST" ]]; then
+ mkdir -p "$3"
+ printf 'partial\n' > "$3/partial"
+ return 1
+ fi
+ command cp "$@"
+ }
+ if backup_existing; then
+ echo "backup_existing unexpectedly passed after a failed copy" >&2
+ exit 1
+ fi
+ if [[ -e "$BACKUP_DIR_UNDER_TEST" ]]; then
+ echo "partial backup was not removed" >&2
+ exit 1
+ fi
+ `
+
+ cmd := exec.Command("bash", "-c", script)
+ cmd.Env = append(os.Environ(),
+ "CONFIG_DIR_UNDER_TEST="+configDir,
+ "BACKUP_DIR_UNDER_TEST="+backupDir,
+ )
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("bash: %v\n%s", err, out)
+ }
+}
+
func TestRootInstallScriptV5ToV6PreflightWarnsWhenAgentScopeMissing(t *testing.T) {
configDir := t.TempDir()
if err := os.WriteFile(filepath.Join(configDir, "api_tokens.json"), []byte(`[{"id":"tok-1","name":"admin","hash":"hash","scopes":["settings:read"]}]`), 0600); err != nil {