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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Self-test the new binary before the in-app update swaps it in
rcourtman0c91799e0fc9
diff --git a/docs/AUTO_UPDATE.md b/docs/AUTO_UPDATE.mdindex 09ada248e8..af1fc7b269 100644--- a/docs/AUTO_UPDATE.md+++ b/docs/AUTO_UPDATE.md@@ -26,11 +26,12 @@ Pulse supports one-click updates for supported deployment types, making it easy### Update Process-1. **Download**: New version is downloaded-2. **Backup**: Current installation is backed up-3. **Apply**: Files are updated-4. **Restart**: Service restarts automatically-5. **Verify**: Health check confirms success+1. **Download**: New version is downloaded, its signature and checksum are verified+2. **Validate**: The new binary is executed with `--version` to prove it runs on this host and reports the expected version, before anything is touched+3. **Backup**: Current installation is backed up+4. **Apply**: Files are updated+5. **Restart**: Service restarts automatically+6. **Verify**: Health check confirms success### Progress Trackingdiff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.mdindex c050b53280..80c9de45f3 100644--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md@@ -1612,6 +1612,18 @@ its `.sshsig` sidecar against the pinned `pulse-installer` ed25519 keyproceed if the sidecar is missing, malformed, or fails verification. Thein-app and unattended paths must share the same trust root so the UI's"Update now" button cannot run at a lower bar than the systemd timer.+The in-app apply pipeline additionally owns pre-install binary validation:+after extraction and before any backup or file replacement,+`internal/updates/manager.go::ApplyUpdate` must locate the extracted `pulse`+binary and prove it executes on this host and reports the apply-target+version, via the `--version` probe in+`internal/updates/selftest.go::selfTestNewBinary`. Checksum and signature+verification prove artifact integrity, not host runnability, so a+wrong-architecture, truncated-yet-published, or unstamped artifact must fail+the update with zero changes applied rather than being swapped in for systemd+to restart into. `internal/updates/selftest_test.go` and the corrupt-binary+apply subtest in `internal/updates/manager_pro_update_test.go` are the owned+proof surface for that validation.The unattended auto-update path is also fail-closed on prerelease channelcrossing: `scripts/pulse-auto-update.sh` must refuse to act on any tag thatcarries a semver prerelease suffix (`-rc.N`, `-beta.N`, `-alpha.N`,diff --git a/internal/updates/manager.go b/internal/updates/manager.goindex ab92431ea9..7a2cb4d807 100644--- a/internal/updates/manager.go+++ b/internal/updates/manager.go@@ -729,6 +729,25 @@ func (m *Manager) ApplyUpdate(ctx context.Context, req ApplyUpdateRequest) errorreturn runErr}+ m.updateStatus("verifying", 50, "Validating new binary...")++ // Checksum and signature prove download integrity, not that the binary can+ // run on this host or is the approved version. Probe it before anything is+ // backed up or replaced, so a bad artifact fails with zero changes applied.+ newBinary, err := locateExtractedPulseBinary(extractDir)+ if err != nil {+ m.updateStatus("error", 50, "Update package is missing the pulse binary", err)+ runErr = err+ return runErr+ }+ if err := selfTestNewBinary(ctx, newBinary, extractDir, artifact.version); err != nil {+ selfTestErr := fmt.Errorf("new binary failed pre-install validation: %w", err)+ m.updateStatus("error", 50, "New binary failed pre-install validation", selfTestErr)+ runErr = selfTestErr+ return runErr+ }+ log.Info().Str("version", artifact.version).Msg("New binary passed pre-install self-test")+m.updateStatus("backing-up", 60, "Creating backup...")// Create backup@@ -1709,15 +1728,24 @@ func (m *Manager) restoreBackup(backupDir string) error {}// applyUpdateFiles copies update files to the installation directory-func (m *Manager) applyUpdateFiles(extractDir string) error {- // Check for pulse binary in both old (root) and new (bin/) locations+// locateExtractedPulseBinary finds the pulse binary inside an extracted+// update, checking both the legacy root layout and the bin/ layout.+func locateExtractedPulseBinary(extractDir string) (string, error) {pulseBinary := filepath.Join(extractDir, "pulse")+ if _, err := os.Stat(pulseBinary); err == nil {+ return pulseBinary, nil+ }+ pulseBinary = filepath.Join(extractDir, "bin", "pulse")if _, err := os.Stat(pulseBinary); err != nil {- // Try new structure with bin/ directory- pulseBinary = filepath.Join(extractDir, "bin", "pulse")- if _, err := os.Stat(pulseBinary); err != nil {- return fmt.Errorf("pulse binary not found in extract (checked both / and /bin/): %w", err)- }+ return "", fmt.Errorf("pulse binary not found in extract (checked both / and /bin/): %w", err)+ }+ return pulseBinary, nil+}++func (m *Manager) applyUpdateFiles(extractDir string) error {+ pulseBinary, err := locateExtractedPulseBinary(extractDir)+ if err != nil {+ return err}// Detect where the current binary is running fromdiff --git a/internal/updates/manager_pro_update_test.go b/internal/updates/manager_pro_update_test.goindex 95425ecd0c..5ca49d7a7f 100644--- a/internal/updates/manager_pro_update_test.go+++ b/internal/updates/manager_pro_update_test.go@@ -242,10 +242,10 @@ func TestApplyUpdateProDownloadsFromBroker(t *testing.T) {err = manager.ApplyUpdate(context.Background(), ApplyUpdateRequest{DownloadURL: applyURL, Channel: "stable"})if err == nil {- t.Fatal("expected apply to fail at the binary-install stage (dummy tarball has no pulse binary)")+ t.Fatal("expected apply to fail at the pre-install validation stage (dummy tarball has no pulse binary)")}if !strings.Contains(err.Error(), "pulse binary not found") {- t.Fatalf("expected failure at the apply stage after all Pro verification stages passed, got: %v", err)+ t.Fatalf("expected failure at the validation stage after all Pro verification stages passed, got: %v", err)}if fixture.brokerCalls == 0 {t.Fatal("apply must re-resolve signed URLs from the broker")@@ -258,6 +258,25 @@ func TestApplyUpdateProDownloadsFromBroker(t *testing.T) {}})+ t.Run("corrupt pulse binary fails the pre-install self-test", func(t *testing.T) {+ fixture := newProBrokerFixture(t, "6.0.5", false)+ fixture.tarball = buildTarballWithPulseBinary(t, []byte{0x00, 0x01, 0x02, 0x03})+ digest := sha256.Sum256(fixture.tarball)+ fixture.sha256Hex = hex.EncodeToString(digest[:])+ manager := NewManager(&config.Config{DataPath: t.TempDir()})+ manager.SetProUpdateCredentialSource(fixture.credentialSource())++ applyURL, err := proUpdateApplyURL(fixture.server.URL, "6.0.5")+ if err != nil {+ t.Fatalf("proUpdateApplyURL: %v", err)+ }++ err = manager.ApplyUpdate(context.Background(), ApplyUpdateRequest{DownloadURL: applyURL, Channel: "stable"})+ if err == nil || !strings.Contains(err.Error(), "self-test") {+ t.Fatalf("expected the pre-install self-test to reject the corrupt binary, got: %v", err)+ }+ })+t.Run("manifest hash mismatch fails closed", func(t *testing.T) {fixture := newProBrokerFixture(t, "6.0.5", false)fixture.sha256Hex = strings.Repeat("0", 64)diff --git a/internal/updates/selftest.go b/internal/updates/selftest.gonew file mode 100644index 0000000000..ca50529846--- /dev/null+++ b/internal/updates/selftest.go@@ -0,0 +1,64 @@+package updates++import (+ "context"+ "fmt"+ "os"+ "os/exec"+ "regexp"+ "strings"+ "time"+)++// updateSelfTestTimeout bounds the --version probe so a hung artifact cannot+// stall the update pipeline indefinitely.+const updateSelfTestTimeout = 30 * time.Second++// updateSelfTestMaxOutput caps how much probe output is echoed into errors.+const updateSelfTestMaxOutput = 2048++// updateSelfTestCommandContext is swapped out by tests.+var updateSelfTestCommandContext = exec.CommandContext++// selfTestVersionTokenRegex matches version tokens in --version output, with+// or without the leading v (release builds print "Pulse vX.Y.Z").+var selfTestVersionTokenRegex = regexp.MustCompile(`v?\d+\.\d+\.\d+(?:-[A-Za-z0-9.]*\d[A-Za-z0-9.]*)?`)++// selfTestNewBinary runs the extracted update binary with --version before it+// replaces the running one. Checksum and signature verification prove the+// download matches the published artifact; they cannot prove the artifact+// runs on this host (wrong-arch fallback asset, incompatible libc) or that it+// is the version the user approved. --version exits before any server+// startup, so the probe is side-effect free.+func selfTestNewBinary(ctx context.Context, binaryPath, workDir, expectedVersion string) error {+ if err := os.Chmod(binaryPath, 0o755); err != nil {+ return fmt.Errorf("failed to mark new binary executable for self-test: %w", err)+ }++ ctx, cancel := context.WithTimeout(ctx, updateSelfTestTimeout)+ defer cancel()++ cmd := updateSelfTestCommandContext(ctx, binaryPath, "--version")+ // The tarball ships VERSION at its root; run from there so the probe sees+ // the same layout an installed binary would.+ cmd.Dir = workDir+ output, err := cmd.CombinedOutput()+ probeOutput := strings.TrimSpace(string(output))+ if len(probeOutput) > updateSelfTestMaxOutput {+ probeOutput = probeOutput[:updateSelfTestMaxOutput]+ }+ if err != nil {+ return fmt.Errorf("new pulse binary failed --version self-test: %w (output: %q)", err, probeOutput)+ }++ expected := strings.TrimPrefix(strings.TrimSpace(expectedVersion), "v")+ if expected == "" {+ return nil+ }+ for _, token := range selfTestVersionTokenRegex.FindAllString(probeOutput, -1) {+ if strings.TrimPrefix(token, "v") == expected {+ return nil+ }+ }+ return fmt.Errorf("new pulse binary self-test reported %q, which does not include expected version %s", probeOutput, expectedVersion)+}diff --git a/internal/updates/selftest_test.go b/internal/updates/selftest_test.gonew file mode 100644index 0000000000..04aff92823--- /dev/null+++ b/internal/updates/selftest_test.go@@ -0,0 +1,154 @@+package updates++import (+ "archive/tar"+ "bytes"+ "compress/gzip"+ "context"+ "os"+ "path/filepath"+ "strings"+ "testing"+)++// writeFakeVersionScript writes an executable script that mimics the pulse+// binary's --version output. It is deliberately NOT named "pulse" so local+// dev tooling that kills processes by that exact name can never race it.+func writeFakeVersionScript(t *testing.T, body string) string {+ t.Helper()+ path := filepath.Join(t.TempDir(), "fake-pulse")+ script := "#!/bin/sh\n" + body + "\n"+ if err := os.WriteFile(path, []byte(script), 0o644); err != nil {+ t.Fatalf("write fake binary: %v", err)+ }+ return path+}++func TestSelfTestNewBinaryAcceptsMatchingVersion(t *testing.T) {+ path := writeFakeVersionScript(t, `echo "Pulse v9.9.9"`)+ for _, expected := range []string{"v9.9.9", "9.9.9"} {+ if err := selfTestNewBinary(context.Background(), path, filepath.Dir(path), expected); err != nil {+ t.Fatalf("expected version %s to pass, got: %v", expected, err)+ }+ }+}++func TestSelfTestNewBinaryAcceptsPrereleaseVersion(t *testing.T) {+ path := writeFakeVersionScript(t, `echo "Pulse v9.9.9-rc.2"`)+ if err := selfTestNewBinary(context.Background(), path, filepath.Dir(path), "v9.9.9-rc.2"); err != nil {+ t.Fatalf("expected prerelease version to pass, got: %v", err)+ }+ if err := selfTestNewBinary(context.Background(), path, filepath.Dir(path), "v9.9.9"); err == nil {+ t.Fatal("expected v9.9.9 to be rejected when the binary reports v9.9.9-rc.2")+ }+}++func TestSelfTestNewBinaryRejectsVersionMismatch(t *testing.T) {+ path := writeFakeVersionScript(t, `echo "Pulse v9.9.9"`)+ err := selfTestNewBinary(context.Background(), path, filepath.Dir(path), "v1.2.3")+ if err == nil || !strings.Contains(err.Error(), "expected version v1.2.3") {+ t.Fatalf("expected version mismatch error, got: %v", err)+ }+}++func TestSelfTestNewBinaryRejectsUnstampedBuild(t *testing.T) {+ path := writeFakeVersionScript(t, `echo "Pulse dev"`)+ err := selfTestNewBinary(context.Background(), path, filepath.Dir(path), "v1.2.3")+ if err == nil {+ t.Fatal("expected an unstamped build to be rejected when a version is expected")+ }+}++func TestSelfTestNewBinarySkipsVersionCheckWithoutExpectation(t *testing.T) {+ path := writeFakeVersionScript(t, `echo "Pulse dev"`)+ if err := selfTestNewBinary(context.Background(), path, filepath.Dir(path), ""); err != nil {+ t.Fatalf("expected exec-only self-test to pass, got: %v", err)+ }+}++func TestSelfTestNewBinaryRejectsFailingBinary(t *testing.T) {+ path := writeFakeVersionScript(t, `exit 3`)+ err := selfTestNewBinary(context.Background(), path, filepath.Dir(path), "v1.2.3")+ if err == nil || !strings.Contains(err.Error(), "self-test") {+ t.Fatalf("expected self-test failure, got: %v", err)+ }+}++func TestSelfTestNewBinaryRejectsUnexecutableArtifact(t *testing.T) {+ path := filepath.Join(t.TempDir(), "fake-pulse")+ if err := os.WriteFile(path, []byte{0x00, 0x01, 0x02, 0x03}, 0o644); err != nil {+ t.Fatalf("write junk binary: %v", err)+ }+ err := selfTestNewBinary(context.Background(), path, filepath.Dir(path), "v1.2.3")+ if err == nil || !strings.Contains(err.Error(), "self-test") {+ t.Fatalf("expected exec-format self-test failure, got: %v", err)+ }+}++func TestLocateExtractedPulseBinary(t *testing.T) {+ t.Run("root layout", func(t *testing.T) {+ dir := t.TempDir()+ want := filepath.Join(dir, "pulse")+ if err := os.WriteFile(want, []byte("stub"), 0o755); err != nil {+ t.Fatalf("write stub: %v", err)+ }+ got, err := locateExtractedPulseBinary(dir)+ if err != nil || got != want {+ t.Fatalf("locate root layout: got %q, %v", got, err)+ }+ })++ t.Run("bin layout", func(t *testing.T) {+ dir := t.TempDir()+ if err := os.MkdirAll(filepath.Join(dir, "bin"), 0o755); err != nil {+ t.Fatalf("mkdir bin: %v", err)+ }+ want := filepath.Join(dir, "bin", "pulse")+ if err := os.WriteFile(want, []byte("stub"), 0o755); err != nil {+ t.Fatalf("write stub: %v", err)+ }+ got, err := locateExtractedPulseBinary(dir)+ if err != nil || got != want {+ t.Fatalf("locate bin layout: got %q, %v", got, err)+ }+ })++ t.Run("missing", func(t *testing.T) {+ _, err := locateExtractedPulseBinary(t.TempDir())+ if err == nil || !strings.Contains(err.Error(), "pulse binary not found") {+ t.Fatalf("expected not-found error, got: %v", err)+ }+ })+}++// buildTarballWithPulseBinary builds a gzipped tarball whose bin/pulse member+// holds the given bytes, for exercising the pre-install self-test through the+// full apply pipeline.+func buildTarballWithPulseBinary(t *testing.T, binary []byte) []byte {+ t.Helper()++ var buf bytes.Buffer+ gw := gzip.NewWriter(&buf)+ tw := tar.NewWriter(gw)++ hdr := &tar.Header{+ Name: "bin/pulse",+ Mode: 0o755,+ Size: int64(len(binary)),+ }+ if err := tw.WriteHeader(hdr); err != nil {+ t.Fatalf("write tar header: %v", err)+ }+ if _, err := tw.Write(binary); err != nil {+ t.Fatalf("write tar content: %v", err)+ }++ if err := tw.Close(); err != nil {+ t.Fatalf("close tar writer: %v", err)+ }+ if err := gw.Close(); err != nil {+ t.Fatalf("close gzip writer: %v", err)+ }++ return buf.Bytes()+}