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.

fix(sensor-proxy): fix remaining unsafe config writers

rcourtmand6084e29dd4e
diff --git a/scripts/install-sensor-proxy.sh b/scripts/install-sensor-proxy.sh
index f0494d2d84..47858b5133 100755
--- a/scripts/install-sensor-proxy.sh
+++ b/scripts/install-sensor-proxy.sh
@@ -3094,6 +3094,7 @@ else
set -euo pipefail
SERVICE="pulse-sensor-proxy"
+BINARY_PATH="/opt/pulse/sensor-proxy/bin/pulse-sensor-proxy"
INSTALLER="/opt/pulse/sensor-proxy/install-sensor-proxy.sh"
CTID_FILE="/etc/pulse-sensor-proxy/ctid"
PENDING_FILE="/etc/pulse-sensor-proxy/pending-control-plane.env"
diff --git a/scripts/migrate-sensor-proxy-control-plane.sh b/scripts/migrate-sensor-proxy-control-plane.sh
index 335ea30bd3..4c70bd915e 100644
--- a/scripts/migrate-sensor-proxy-control-plane.sh
+++ b/scripts/migrate-sensor-proxy-control-plane.sh
@@ -92,14 +92,20 @@ echo "$CONTROL_TOKEN" > "$TOKEN_FILE"
chmod 600 "$TOKEN_FILE"
chown pulse-sensor-proxy:pulse-sensor-proxy "$TOKEN_FILE"
-remove_control_block() {
- python3 - "$CONFIG_FILE" <<'PY'
+update_config_atomically() {
+ # Phase 2: Use atomic write to prevent corruption
+ local temp_file
+ temp_file=$(mktemp)
+
+ # Remove old control plane blocks and add new one atomically
+ python3 - "$CONFIG_FILE" "$temp_file" <<'PY'
from pathlib import Path
import sys
-path = Path(sys.argv[1])
-if not path.exists():
+config_path = Path(sys.argv[1])
+temp_path = Path(sys.argv[2])
+if not config_path.exists():
sys.exit(0)
-lines = path.read_text().splitlines(keepends=True)
+lines = config_path.read_text().splitlines(keepends=True)
result = []
i = 0
while i < len(lines):
@@ -116,13 +122,11 @@ while i < len(lines):
continue
result.append(line)
i += 1
-path.write_text("".join(result))
+temp_path.write_text("".join(result))
PY
-}
-log "Updating config..."
-remove_control_block
-cat >> "$CONFIG_FILE" <<EOF
+ # Append new control plane config
+ cat >> "$temp_file" <<EOF
# Pulse control plane configuration (added by migrate-sensor-proxy-control-plane.sh)
pulse_control_plane:
@@ -131,6 +135,15 @@ pulse_control_plane:
refresh_interval: $REFRESH_INTERVAL
EOF
+ # Atomic rename
+ mv "$temp_file" "$CONFIG_FILE"
+ chmod 644 "$CONFIG_FILE"
+ chown pulse-sensor-proxy:pulse-sensor-proxy "$CONFIG_FILE" 2>/dev/null || true
+}
+
+log "Updating config..."
+update_config_atomically
+
if [[ "$SKIP_RESTART" == false ]]; then
log "Restarting pulse-sensor-proxy..."
systemctl restart pulse-sensor-proxy