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 alert durability and watchdog isolation

Pulse Test9ce4b7e20f21
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index e384836570..6a88d9dd05 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -1063,6 +1063,13 @@ read authority. A new or recreated database imports the readable mirror. A
failed SQLite checkpoint writes a durable degraded marker, and the next startup
uses the mirror once to repair SQLite before clearing that marker. Without a
degraded marker, an initialized SQLite projection wins over a stale mirror.
+Lifecycle append failure first checkpoints a lock-independent active-state
+projection to the recovery mirror synchronously, then writes the degraded
+marker. The projection is updated at the canonical set/remove and lifecycle
+event seams so event emission remains safe even when its caller holds the
+manager lock. A checkpoint that overlaps a lifecycle failure must observe the
+failure epoch and retry before it can restore SQLite authority or clear the
+marker; stale periodic work can never overwrite the failure recovery snapshot.
An unreadable or malformed mirror is write-blocked and preserved for manual
recovery even when healthy SQLite can continue serving current state; startup
must never silently replace a recoverable source with an empty snapshot.
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 28d01461e9..da05d21101 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -3367,6 +3367,11 @@ watchdog. A separate worker emits one success signal per minute, while a
proves that the polling scheduler itself is still progressing. A stale marker
causes the worker to send the provider's `/fail` signal and raise a critical
system alert; the worker's own timer can never count as monitoring progress.
+Every DNS answer is compared with all Pulse host interface addresses before
+dialing, in addition to the loopback, unspecified, and link-local exclusions.
+Local-interface enumeration failure rejects the signal rather than weakening
+the different-host guarantee, so a hostname or LAN address that resolves back
+to Pulse cannot masquerade as an external watchdog.
The runtime persists a privacy-minimized `alerts/deadman-state.json` record
through fsync, atomic replacement, and directory sync. It stores endpoint
diff --git a/docs/release-control/v6/internal/subsystems/notifications.md b/docs/release-control/v6/internal/subsystems/notifications.md
index 092c8e31f9..7b734eb577 100644
--- a/docs/release-control/v6/internal/subsystems/notifications.md
+++ b/docs/release-control/v6/internal/subsystems/notifications.md
@@ -462,6 +462,11 @@ passphrase-encrypted configuration bundle, and represented to API clients by a
redacted sentinel. URLs are bounded to HTTP(S), exclude userinfo, fragments,
localhost, loopback, unspecified, and link-local targets, and must name the
base success endpoint rather than `/start`, `/fail`, or `/log`.
+Literal addresses are also compared against every Pulse host interface, while
+the monitoring dialer repeats that comparison after DNS resolution. Failure to
+enumerate local interfaces fails closed. A private LAN watchdog remains valid
+only when its resolved address belongs to a different machine; pointing a
+hostname or normal LAN address back at Pulse is rejected as same-host.
The monitoring-owned sender uses a dedicated transport that bypasses ambient
HTTP proxies, revalidates DNS answers at dial time, never follows redirects,
diff --git a/internal/alerts/active_lifecycle.go b/internal/alerts/active_lifecycle.go
index 1ea0c699cf..6b90e6ec6d 100644
--- a/internal/alerts/active_lifecycle.go
+++ b/internal/alerts/active_lifecycle.go
@@ -663,6 +663,7 @@ func (m *Manager) removeActiveAlertNoLock(alertID string) {
}
if exists {
delete(m.activeAlerts, key)
+ m.removeActiveRecoveryAlert(currentAlert, key)
}
// Preserve acknowledgement state so quick alert rebuilds keep user intent.
diff --git a/internal/alerts/active_persistence.go b/internal/alerts/active_persistence.go
index 1e14927135..14b4c98bd9 100644
--- a/internal/alerts/active_persistence.go
+++ b/internal/alerts/active_persistence.go
@@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
+ "sort"
"strconv"
"strings"
"time"
@@ -53,6 +54,7 @@ func (m *Manager) SaveActiveAlerts() error {
const maxCheckpointAttempts = 8
for attempt := 0; attempt < maxCheckpointAttempts; attempt++ {
+ failureEpoch := m.activeStateFailureEpoch.Load()
store := m.eventLogStore()
revision := int64(0)
if store != nil {
@@ -94,6 +96,12 @@ func (m *Manager) SaveActiveAlerts() error {
// the manager's current state instead of overwriting that newer event.
continue
}
+ if m.activeStateFailureEpoch.Load() != failureEpoch {
+ // A lifecycle append failed while this checkpoint was in flight.
+ // Retry from current manager state so a stale snapshot cannot clear
+ // the degradation marker or replace the recovery projection.
+ continue
+ }
m.activeStateAuthoritative.Store(true)
m.clearActiveStateDegraded()
if err := errors.Join(mirrorErr, intentErr); err != nil {
@@ -123,6 +131,12 @@ func (m *Manager) snapshotActiveAlerts() []*Alert {
}
func (m *Manager) writeActiveAlertsRecoveryMirror(alerts []*Alert) error {
+ m.recoveryMirrorMu.Lock()
+ defer m.recoveryMirrorMu.Unlock()
+ return m.writeActiveAlertsRecoveryMirrorLocked(alerts)
+}
+
+func (m *Manager) writeActiveAlertsRecoveryMirrorLocked(alerts []*Alert) error {
if m.activeRecoveryWriteBlock.Load() {
return fmt.Errorf("active alert recovery mirror is write-blocked because its startup source was unreadable")
}
@@ -194,6 +208,85 @@ func (m *Manager) writeActiveAlertsRecoveryMirror(alerts []*Alert) error {
return nil
}
+func (m *Manager) setActiveRecoveryAlert(alert *Alert, fallback string) {
+ if m == nil || alert == nil {
+ return
+ }
+ clone := alert.Clone()
+ backfillCanonicalIdentity(clone)
+ clone.ID = exportedAlertID(clone, clone.ID)
+ storageKey := activeAlertStorageKey(clone, fallback)
+ if storageKey == "" {
+ return
+ }
+
+ m.activeRecoveryMu.Lock()
+ if m.activeRecoveryState == nil {
+ m.activeRecoveryState = make(map[string]*Alert)
+ }
+ identity := effectiveAlertID(clone, storageKey)
+ for key, existing := range m.activeRecoveryState {
+ if key == storageKey || key == fallback ||
+ (existing != nil && effectiveAlertID(existing, key) == identity) {
+ delete(m.activeRecoveryState, key)
+ }
+ }
+ m.activeRecoveryState[storageKey] = clone
+ m.activeRecoveryMu.Unlock()
+}
+
+func (m *Manager) removeActiveRecoveryAlert(alert *Alert, fallback string) {
+ if m == nil {
+ return
+ }
+ identity := effectiveAlertID(alert, fallback)
+ canonicalState := ""
+ if alert != nil {
+ canonicalState = deriveCanonicalIdentity(alert).State
+ }
+
+ m.activeRecoveryMu.Lock()
+ for key, existing := range m.activeRecoveryState {
+ if key == fallback || key == identity || key == canonicalState ||
+ (existing != nil && effectiveAlertID(existing, key) == identity) {
+ delete(m.activeRecoveryState, key)
+ }
+ }
+ m.activeRecoveryMu.Unlock()
+}
+
+func (m *Manager) activeRecoverySnapshot() []*Alert {
+ m.activeRecoveryMu.RLock()
+ keys := make([]string, 0, len(m.activeRecoveryState))
+ for key := range m.activeRecoveryState {
+ keys = append(keys, key)
+ }
+ sort.Strings(keys)
+ alerts := make([]*Alert, 0, len(keys))
+ for _, key := range keys {
+ if alert := m.activeRecoveryState[key]; alert != nil {
+ alerts = append(alerts, alert.Clone())
+ }
+ }
+ m.activeRecoveryMu.RUnlock()
+ return alerts
+}
+
+func (m *Manager) checkpointActiveRecoveryAfterDurableFailure(cause error) error {
+ if m == nil {
+ return nil
+ }
+ m.recoveryMirrorMu.Lock()
+ alerts := m.activeRecoverySnapshot()
+ err := m.writeActiveAlertsRecoveryMirrorLocked(alerts)
+ m.recoveryMirrorMu.Unlock()
+ if err != nil {
+ return err
+ }
+ m.markActiveStateDegraded(cause)
+ return nil
+}
+
// LoadActiveAlerts restores active alerts from disk.
func (m *Manager) LoadActiveAlerts() error {
m.activeRecoveryReadable.Store(false)
diff --git a/internal/alerts/active_state_bootstrap_test.go b/internal/alerts/active_state_bootstrap_test.go
index 3a3a96ae8f..f6e471f9f3 100644
--- a/internal/alerts/active_state_bootstrap_test.go
+++ b/internal/alerts/active_state_bootstrap_test.go
@@ -103,6 +103,85 @@ func TestAtomicResolutionBeatsStaleRecoveryMirror(t *testing.T) {
}
}
+func TestDurableLifecycleFailureSynchronouslyCheckpointsRecoveryMirror(t *testing.T) {
+ t.Run("fired while manager lock is held", func(t *testing.T) {
+ dataDir := t.TempDir()
+ m := NewManagerWithDataDir(dataDir)
+ m.EnableEventLog()
+ store := m.eventLogStore()
+ if store == nil {
+ t.Fatal("event log was not enabled")
+ }
+ store.Close()
+
+ alert := durableRestoreAlert(time.Now().UTC())
+ m.mu.Lock()
+ m.setActiveAlertNoLock(alert.ID, alert)
+ m.recordAlertEvent(eventlog.TypeFired, alert, alert.ID, "threshold", "Alert fired.", nil)
+ m.mu.Unlock()
+
+ data, err := os.ReadFile(filepath.Join(dataDir, "alerts", "active-alerts.json"))
+ if err != nil {
+ t.Fatalf("read recovery mirror: %v", err)
+ }
+ var recovered []*Alert
+ if err := json.Unmarshal(data, &recovered); err != nil {
+ t.Fatalf("decode recovery mirror: %v", err)
+ }
+ if len(recovered) != 1 || recovered[0].ID != alert.ID {
+ t.Fatalf("recovery mirror after failed fire = %+v", recovered)
+ }
+ if _, err := os.Stat(filepath.Join(dataDir, "alerts", activeStateDegradedMarker)); err != nil {
+ t.Fatalf("degraded marker missing after failed fire: %v", err)
+ }
+
+ m.SetEventLog(nil)
+ m.Stop()
+ })
+
+ t.Run("resolved before restart", func(t *testing.T) {
+ dataDir := t.TempDir()
+ alert := durableRestoreAlert(time.Now().Add(-2 * time.Hour).UTC())
+ writeActiveRecoveryFixture(t, dataDir, []*Alert{alert})
+
+ m := NewManagerWithDataDir(dataDir)
+ m.EnableEventLog()
+ if err := m.SaveActiveAlerts(); err != nil {
+ t.Fatalf("seed active state: %v", err)
+ }
+ store := m.eventLogStore()
+ if store == nil {
+ t.Fatal("event log was not enabled")
+ }
+ store.Close()
+
+ m.clearAlert(alert.ID)
+ data, err := os.ReadFile(filepath.Join(dataDir, "alerts", "active-alerts.json"))
+ if err != nil {
+ t.Fatalf("read recovery mirror: %v", err)
+ }
+ var recovered []*Alert
+ if err := json.Unmarshal(data, &recovered); err != nil {
+ t.Fatalf("decode recovery mirror: %v", err)
+ }
+ if len(recovered) != 0 {
+ t.Fatalf("failed resolution remained in recovery mirror: %+v", recovered)
+ }
+
+ m.SetEventLog(nil)
+ m.Stop()
+ restarted := NewManagerWithDataDir(dataDir)
+ t.Cleanup(restarted.Stop)
+ restarted.EnableEventLog()
+ restarted.mu.RLock()
+ _, exists := testLookupActiveAlert(t, restarted, alert.ID)
+ restarted.mu.RUnlock()
+ if exists {
+ t.Fatal("failed durable resolution was resurrected after restart")
+ }
+ })
+}
+
func TestDegradedMarkerRepairsSQLiteFromRecoveryMirror(t *testing.T) {
dataDir := t.TempDir()
original := durableRestoreAlert(time.Now().Add(-2 * time.Hour).UTC())
diff --git a/internal/alerts/alert_store.go b/internal/alerts/alert_store.go
index e5fe15f9c9..bd670a954e 100644
--- a/internal/alerts/alert_store.go
+++ b/internal/alerts/alert_store.go
@@ -118,10 +118,12 @@ func (m *Manager) setActiveAlertNoLock(storageKey string, alert *Alert) {
if existing, ok := m.activeAlerts[staleKey]; ok {
delete(m.activeAlerts, staleKey)
m.unregisterActiveAlertAliasNoLock(staleKey, existing)
+ m.removeActiveRecoveryAlert(existing, staleKey)
}
}
m.activeAlerts[storageKey] = alert
m.registerActiveAlertAliasNoLock(storageKey, alert)
+ m.setActiveRecoveryAlert(alert, storageKey)
if m.historyManager != nil {
m.historyManager.UpdateAlertOperationalContractForAlert(alert)
}
diff --git a/internal/alerts/event_emission.go b/internal/alerts/event_emission.go
index fceb2eda8d..e08e6c8260 100644
--- a/internal/alerts/event_emission.go
+++ b/internal/alerts/event_emission.go
@@ -150,13 +150,26 @@ func (m *Manager) recordAlertEvent(eventType string, alert *Alert, alertID, reas
if event.AlertID == "" {
return
}
+ if eventCarriesAlertSnapshot(eventType) {
+ if eventType == eventlog.TypeResolved {
+ m.removeActiveRecoveryAlert(alert, event.AlertID)
+ } else if alert != nil {
+ m.setActiveRecoveryAlert(alert, event.AlertID)
+ }
+ }
persisted := false
if store := m.eventLogStore(); store != nil {
if eventCarriesAlertSnapshot(eventType) {
if err := store.AppendDurable(event); err != nil {
m.eventHistoryAuthoritative.Store(false)
- m.markActiveStateDegraded(err)
+ m.activeStateFailureEpoch.Add(1)
+ if mirrorErr := m.checkpointActiveRecoveryAfterDurableFailure(err); mirrorErr != nil {
+ log.Error().Err(mirrorErr).
+ Str("alertID", event.AlertID).
+ Str("eventType", eventType).
+ Msg("failed to checkpoint active alert recovery after lifecycle write failure")
+ }
log.Error().Err(err).
Str("alertID", event.AlertID).
Str("eventType", eventType).
diff --git a/internal/alerts/guest_metric_migration.go b/internal/alerts/guest_metric_migration.go
index 89676e3d51..a24d3f516b 100644
--- a/internal/alerts/guest_metric_migration.go
+++ b/internal/alerts/guest_metric_migration.go
@@ -178,6 +178,7 @@ func (m *Manager) migrateGuestAlertNoLock(storageKey, specID, kind, resourceID,
oldTrackingKey := canonicalTrackingKeyOrFallback(matchedAlert, matchedStorageKey)
delete(m.activeAlerts, matchedStorageKey)
m.unregisterActiveAlertAliasNoLock(matchedStorageKey, matchedAlert)
+ m.removeActiveRecoveryAlert(matchedAlert, matchedStorageKey)
matchedAlert.ID = storageKey
matchedAlert.ResourceID = resourceID
diff --git a/internal/alerts/manager.go b/internal/alerts/manager.go
index 7968188f56..2cecbea626 100644
--- a/internal/alerts/manager.go
+++ b/internal/alerts/manager.go
@@ -34,14 +34,20 @@ import (
type Manager struct {
mu sync.RWMutex
saveMu sync.Mutex
+ recoveryMirrorMu sync.Mutex
+ activeRecoveryMu sync.RWMutex
callbacks callbackBus
alertsDir string
config AlertConfig
activeAlerts map[string]*Alert
activeAlertAlias map[string]string
- historyManager *HistoryManager
- escalationStop chan struct{}
- alertRateLimit map[string][]time.Time // Track alert times for rate limiting
+ // activeRecoveryState is a lock-independent projection of activeAlerts.
+ // Lifecycle emission can run while m.mu is held, so durable-store failure
+ // recovery must never reacquire m.mu to produce the JSON recovery mirror.
+ activeRecoveryState map[string]*Alert
+ historyManager *HistoryManager
+ escalationStop chan struct{}
+ alertRateLimit map[string][]time.Time // Track alert times for rate limiting
// New fields for deduplication and suppression
recentAlerts map[string]*Alert // Track recent alerts for deduplication
suppressedUntil map[string]time.Time // Track suppression windows
@@ -117,6 +123,7 @@ type Manager struct {
// active-alerts.json remains an atomic recovery mirror, never a competing
// source while the SQLite projection is healthy.
activeStateAuthoritative atomic.Bool
+ activeStateFailureEpoch atomic.Uint64
skipPersistedRestore bool
activeRecoveryReadable atomic.Bool
activeRecoveryWriteBlock atomic.Bool
@@ -197,6 +204,7 @@ func NewManagerWithDataDir(dataDir string, options ...ManagerOption) *Manager {
alertsDir: alertsDir,
activeAlerts: make(map[string]*Alert),
activeAlertAlias: make(map[string]string),
+ activeRecoveryState: make(map[string]*Alert),
historyManager: NewHistoryManager(alertsDir),
callbacks: newCallbackBus(),
escalationStop: make(chan struct{}),
diff --git a/internal/monitoring/deadman.go b/internal/monitoring/deadman.go
index 0f325faed8..e18f6c8525 100644
--- a/internal/monitoring/deadman.go
+++ b/internal/monitoring/deadman.go
@@ -758,7 +758,11 @@ func deadManDialContext(ctx context.Context, network, address string) (net.Conn,
}
for _, candidate := range addresses {
ip := candidate.IP
- if ip == nil || ip.IsLoopback() || ip.IsUnspecified() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {
+ sameHost, localErr := notifications.IsDeadManSameHostIP(ip)
+ if localErr != nil {
+ return nil, fmt.Errorf("verify watchdog host separation")
+ }
+ if sameHost {
return nil, fmt.Errorf("watchdog host resolved to a same-host address")
}
}
diff --git a/internal/monitoring/deadman_test.go b/internal/monitoring/deadman_test.go
index f2a240cfd6..af42158add 100644
--- a/internal/monitoring/deadman_test.go
+++ b/internal/monitoring/deadman_test.go
@@ -3,6 +3,7 @@ package monitoring
import (
"context"
"io"
+ "net"
"net/http"
"strings"
"sync"
@@ -288,3 +289,26 @@ func TestDeadManDialRejectsLoopbackResolution(t *testing.T) {
t.Fatal("loopback watchdog dial unexpectedly returned no error")
}
}
+
+func TestDeadManDialRejectsPulseInterfaceAddress(t *testing.T) {
+ addresses, err := net.InterfaceAddrs()
+ if err != nil {
+ t.Fatalf("enumerate local interfaces: %v", err)
+ }
+ for _, address := range addresses {
+ ip, _, err := net.ParseCIDR(address.String())
+ if err != nil || ip.IsLoopback() || ip.IsUnspecified() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {
+ continue
+ }
+ connection, dialErr := deadManDialContext(context.Background(), "tcp", net.JoinHostPort(ip.String(), "80"))
+ if connection != nil {
+ _ = connection.Close()
+ t.Fatalf("same-host watchdog dial to %s unexpectedly succeeded", ip)
+ }
+ if dialErr == nil {
+ t.Fatalf("same-host watchdog dial to %s unexpectedly returned no error", ip)
+ }
+ return
+ }
+ t.Skip("no non-loopback interface address available")
+}
diff --git a/internal/notifications/deadman_config.go b/internal/notifications/deadman_config.go
index 6fd6fba7bd..6d5d817363 100644
--- a/internal/notifications/deadman_config.go
+++ b/internal/notifications/deadman_config.go
@@ -22,9 +22,10 @@ func NormalizeDeadManConfig(config DeadManConfig) DeadManConfig {
// ValidateDeadManPingURL validates a healthchecks-compatible base ping URL.
// Private-network destinations remain supported for separately hosted LAN
-// watchdogs, but same-host addresses are rejected because they cannot detect
-// loss of the Pulse host. The runtime rejects redirects so the secret URL path
-// cannot be forwarded to another origin.
+// watchdogs, but literal same-host addresses are rejected because they cannot
+// detect loss of the Pulse host. The runtime repeats the check after DNS
+// resolution and rejects redirects so the secret URL path cannot be forwarded
+// to another origin.
func ValidateDeadManPingURL(value string) error {
value = strings.TrimSpace(value)
if value == "" {
@@ -58,8 +59,14 @@ func ValidateDeadManPingURL(value string) error {
if hostname == "localhost" || strings.HasSuffix(hostname, ".localhost") {
return fmt.Errorf("dead-man monitoring must use a different host from Pulse")
}
- if ip := net.ParseIP(hostname); ip != nil && (ip.IsLoopback() || ip.IsUnspecified() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast()) {
- return fmt.Errorf("dead-man monitoring must use a different host from Pulse")
+ if ip := net.ParseIP(hostname); ip != nil {
+ sameHost, err := IsDeadManSameHostIP(ip)
+ if err != nil {
+ return fmt.Errorf("could not verify dead-man host separation: %w", err)
+ }
+ if sameHost {
+ return fmt.Errorf("dead-man monitoring must use a different host from Pulse")
+ }
}
path := strings.TrimSuffix(strings.ToLower(parsed.EscapedPath()), "/")
@@ -70,3 +77,42 @@ func ValidateDeadManPingURL(value string) error {
}
return nil
}
+
+// IsDeadManSameHostIP reports whether an endpoint address belongs to the
+// Pulse machine. Dead-man delivery calls this after DNS resolution as well as
+// during literal-IP configuration validation, so aliases and LAN addresses
+// cannot silently point the watchdog back at Pulse itself.
+func IsDeadManSameHostIP(ip net.IP) (bool, error) {
+ if ip == nil {
+ return true, nil
+ }
+ if ip.IsLoopback() || ip.IsUnspecified() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {
+ return true, nil
+ }
+ addresses, err := net.InterfaceAddrs()
+ if err != nil {
+ return false, fmt.Errorf("enumerate Pulse host addresses: %w", err)
+ }
+ return isDeadManSameHostIP(ip, addresses), nil
+}
+
+func isDeadManSameHostIP(ip net.IP, addresses []net.Addr) bool {
+ for _, address := range addresses {
+ var localIP net.IP
+ switch value := address.(type) {
+ case *net.IPNet:
+ localIP = value.IP
+ case *net.IPAddr:
+ localIP = value.IP
+ default:
+ host, _, err := net.ParseCIDR(address.String())
+ if err == nil {
+ localIP = host
+ }
+ }
+ if localIP != nil && ip.Equal(localIP) {
+ return true
+ }
+ }
+ return false
+}
diff --git a/internal/notifications/deadman_config_test.go b/internal/notifications/deadman_config_test.go
index 7559b623ed..81b98847d6 100644
--- a/internal/notifications/deadman_config_test.go
+++ b/internal/notifications/deadman_config_test.go
@@ -1,6 +1,8 @@
package notifications
import (
+ "fmt"
+ "net"
"strings"
"testing"
)
@@ -57,3 +59,39 @@ func TestNormalizeDeadManConfig(t *testing.T) {
t.Fatalf("normalized URL = %q", got.PingURL)
}
}
+
+func TestIsDeadManSameHostIPIncludesNonLoopbackInterfaces(t *testing.T) {
+ local := net.ParseIP("192.168.50.20")
+ addresses := []net.Addr{
+ &net.IPNet{IP: net.ParseIP("127.0.0.1"), Mask: net.CIDRMask(8, 32)},
+ &net.IPNet{IP: local, Mask: net.CIDRMask(24, 32)},
+ }
+ if !isDeadManSameHostIP(local, addresses) {
+ t.Fatal("non-loopback Pulse interface address was not classified as same-host")
+ }
+ if isDeadManSameHostIP(net.ParseIP("192.168.50.21"), addresses) {
+ t.Fatal("different LAN host was classified as same-host")
+ }
+}
+
+func TestValidateDeadManPingURLRejectsPulseInterfaceAddress(t *testing.T) {
+ addresses, err := net.InterfaceAddrs()
+ if err != nil {
+ t.Fatalf("enumerate local interfaces: %v", err)
+ }
+ for _, address := range addresses {
+ ip, _, err := net.ParseCIDR(address.String())
+ if err != nil || ip.IsLoopback() || ip.IsUnspecified() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {
+ continue
+ }
+ host := ip.String()
+ if ip.To4() == nil {
+ host = "[" + host + "]"
+ }
+ if err := ValidateDeadManPingURL(fmt.Sprintf("http://%s:8000/ping/token", host)); err == nil {
+ t.Fatalf("Pulse interface address %s was accepted as an external watchdog", ip)
+ }
+ return
+ }
+ t.Skip("no non-loopback interface address available")
+}