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 cross-site auto-registration identity matching

rcourtmane196a1f50fd8
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 3cb8632de2..00b22696df 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -2069,6 +2069,13 @@ command transport, update policy, or fleet lifecycle authority.
registration and update paths must not depend on package-global mutable test
seams that can leak between concurrent agent sessions or tests.
5. Preserve canonical /api/auto-register node identity continuity when canonical hosts shift between hostname and IP forms for the same node, and keep runtime-side Proxmox setup host ordering aligned with the contract: explicit report-IP override, route-aware local IP, resolvable hostname fallback, then heuristic local IP fallback.
+ Continuity matches inferred from resolved addresses, a changed-address
+ node-name/token pair, or cluster-member identity must fail safe when both
+ sides carry different TOFU TLS fingerprints. That contradiction identifies
+ distinct PVE or PBS machines and must preserve separate connections even
+ when MSP-managed sites reuse node names, token names, or private address
+ ranges. An exact stored endpoint remains authoritative so a certificate
+ rotation at the same URL can refresh its pin in place.
That same lifecycle-adjacent shared-API boundary now covers relay and
command-target hostname resolution too. When lifecycle flows reuse
`internal/api/router_routes_ai_relay.go`, `internal/agentexec/server.go`,
diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.md
index e9b8a45655..a868db5cef 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -6700,6 +6700,12 @@ continuity semantics: when `/api/auto-register` receives the same
canonical node name together with the deterministic Pulse-managed token ID for
that node, it must update the existing PVE or PBS entry in place even if the
host IP has changed, rather than duplicating the node under a second endpoint.
+That inferred continuity is valid only when captured TLS identity does not
+contradict it. Different known TOFU fingerprints must veto resolved-address,
+changed-address node-name/token, and cluster-member continuity matches so
+independent sites that reuse node and token names remain separate connections.
+An exact stored endpoint remains an authoritative rerun and may refresh its
+fingerprint after certificate rotation.
That same `/api/auto-register` payload contract must now also accept ordered
`candidateHosts` from runtime-side Proxmox callers and treat `host` as the
preferred candidate, not an untouchable answer. The backend must normalize the
diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.md
index 465edcdab1..3403af1c44 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -1105,6 +1105,11 @@ recovery scope, or a storage/recovery-owned secret source.
delete so adjacent recovery/storage surfaces do not retain stale provider
context after Pulse credentials have been removed from the host.
14. Preserve canonical /api/auto-register DHCP continuity in those shared helpers so a PVE or PBS node that reruns registration from a new IP with the same canonical node name and deterministic Pulse-managed token identity updates in place instead of duplicating the inventory record.
+ Known contradictory TLS fingerprints must veto inferred resolved-address,
+ changed-address name/token, and cluster-member continuity matches so
+ separate protected sources are not overwritten when sites reuse node
+ names, token identities, or private address ranges. An exact stored
+ endpoint remains authoritative for in-place certificate rotation.
That same shared helper boundary now also owns runtime-side Proxmox
`candidateHosts` selection from Pulse's network view: storage and
recovery-adjacent transport flows may not bypass server-side reachable-host
diff --git a/internal/api/config_handlers_canonical_auto_register_test.go b/internal/api/config_handlers_canonical_auto_register_test.go
index edea6a8037..f5b2e8b24f 100644
--- a/internal/api/config_handlers_canonical_auto_register_test.go
+++ b/internal/api/config_handlers_canonical_auto_register_test.go
@@ -1175,6 +1175,200 @@ func TestHandleCanonicalAutoRegister_PVEUpdatesExistingNodeOnDHCPHostChange(t *t
}
}
+func TestHandleCanonicalAutoRegister_PVEKeepsDistinctSameNameTokenWhenFingerprintsConflict(t *testing.T) {
+ tempDir := t.TempDir()
+ t.Setenv("PULSE_DATA_DIR", tempDir)
+
+ server := newIPv4TLSServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer server.Close()
+
+ incomingFingerprint, err := tlsutil.FetchFingerprint(server.URL)
+ if err != nil {
+ t.Fatalf("fetch incoming fingerprint: %v", err)
+ }
+ existingFingerprint := strings.Repeat("a", 64)
+ if strings.EqualFold(existingFingerprint, incomingFingerprint) {
+ existingFingerprint = strings.Repeat("b", 64)
+ }
+ tokenID := "pulse-monitor@pve!" + buildPulseMonitorTokenName("pulse.example.com")
+ cfg := &config.Config{
+ DataPath: tempDir,
+ ConfigPath: tempDir,
+ PVEInstances: []config.PVEInstance{
+ {
+ Name: "pve01",
+ Host: "https://10.0.0.10:8006",
+ TokenName: tokenID,
+ TokenValue: "site-one-token",
+ Fingerprint: existingFingerprint,
+ Source: "script",
+ },
+ },
+ }
+ handler := newTestConfigHandlers(t, cfg)
+
+ reqBody := AutoRegisterRequest{
+ Type: "pve",
+ Host: server.URL,
+ ServerName: "pve01",
+ TokenID: tokenID,
+ TokenValue: "site-two-token",
+ Source: "script",
+ }
+ req := httptest.NewRequest(http.MethodPost, "/api/auto-register", nil)
+ req.Host = "pulse.example.com"
+ rec := httptest.NewRecorder()
+
+ handler.handleCanonicalAutoRegister(rec, req, &reqBody, "127.0.0.1")
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200: %s", rec.Code, rec.Body.String())
+ }
+ if len(handler.defaultConfig.PVEInstances) != 2 {
+ t.Fatalf("PVE instances = %#v, want both sites to remain configured", handler.defaultConfig.PVEInstances)
+ }
+
+ existing := handler.defaultConfig.PVEInstances[0]
+ if existing.Host != "https://10.0.0.10:8006" || existing.TokenValue != "site-one-token" || existing.Fingerprint != existingFingerprint {
+ t.Fatalf("existing site was mutated: %#v", existing)
+ }
+ registered := handler.defaultConfig.PVEInstances[1]
+ if registered.Host != server.URL || registered.TokenValue != "site-two-token" || registered.Fingerprint != incomingFingerprint {
+ t.Fatalf("new site = %#v, want independently registered endpoint", registered)
+ }
+ if strings.EqualFold(registered.Name, existing.Name) {
+ t.Fatalf("new site name = %q, want disambiguation from existing %q", registered.Name, existing.Name)
+ }
+}
+
+func TestHandleCanonicalAutoRegister_PVERotatesFingerprintAtExactHost(t *testing.T) {
+ tempDir := t.TempDir()
+ t.Setenv("PULSE_DATA_DIR", tempDir)
+
+ server := newIPv4TLSServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer server.Close()
+
+ incomingFingerprint, err := tlsutil.FetchFingerprint(server.URL)
+ if err != nil {
+ t.Fatalf("fetch incoming fingerprint: %v", err)
+ }
+ tokenID := "pulse-monitor@pve!" + buildPulseMonitorTokenName("pulse.example.com")
+ cfg := &config.Config{
+ DataPath: tempDir,
+ ConfigPath: tempDir,
+ PVEInstances: []config.PVEInstance{
+ {
+ Name: "pve01",
+ Host: server.URL,
+ TokenName: tokenID,
+ TokenValue: "old-token",
+ Fingerprint: strings.Repeat("a", 64),
+ },
+ },
+ }
+ handler := newTestConfigHandlers(t, cfg)
+
+ reqBody := AutoRegisterRequest{
+ Type: "pve",
+ Host: server.URL,
+ ServerName: "pve01",
+ TokenID: tokenID,
+ TokenValue: "rotated-token",
+ Source: "script",
+ }
+ req := httptest.NewRequest(http.MethodPost, "/api/auto-register", nil)
+ rec := httptest.NewRecorder()
+
+ handler.handleCanonicalAutoRegister(rec, req, &reqBody, "127.0.0.1")
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200: %s", rec.Code, rec.Body.String())
+ }
+ if len(handler.defaultConfig.PVEInstances) != 1 {
+ t.Fatalf("expected exact-host rerun to remain one PVE instance, got %d", len(handler.defaultConfig.PVEInstances))
+ }
+ instance := handler.defaultConfig.PVEInstances[0]
+ if instance.TokenValue != "rotated-token" || instance.Fingerprint != incomingFingerprint {
+ t.Fatalf("exact-host rerun = %#v, want refreshed token and fingerprint", instance)
+ }
+}
+
+func TestHandleCanonicalAutoRegister_PVEKeepsDistinctClusterMemberWhenFingerprintsConflict(t *testing.T) {
+ tempDir := t.TempDir()
+ t.Setenv("PULSE_DATA_DIR", tempDir)
+
+ server := newIPv4TLSServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer server.Close()
+
+ incomingFingerprint, err := tlsutil.FetchFingerprint(server.URL)
+ if err != nil {
+ t.Fatalf("fetch incoming fingerprint: %v", err)
+ }
+ existingFingerprint := strings.Repeat("a", 64)
+ if strings.EqualFold(existingFingerprint, incomingFingerprint) {
+ existingFingerprint = strings.Repeat("b", 64)
+ }
+ tokenID := "pulse-monitor@pve!" + buildPulseMonitorTokenName("pulse.example.com")
+ cfg := &config.Config{
+ DataPath: tempDir,
+ ConfigPath: tempDir,
+ PVEInstances: []config.PVEInstance{
+ {
+ Name: "site-one",
+ Host: "https://10.0.0.10:8006",
+ TokenName: tokenID,
+ TokenValue: "site-one-token",
+ IsCluster: true,
+ ClusterName: "production",
+ ClusterEndpoints: []config.ClusterEndpoint{
+ {
+ NodeName: "pve01",
+ Host: "https://10.0.0.11:8006",
+ IP: "10.0.0.11",
+ Fingerprint: existingFingerprint,
+ },
+ },
+ },
+ },
+ }
+ handler := newTestConfigHandlers(t, cfg)
+
+ reqBody := AutoRegisterRequest{
+ Type: "pve",
+ Host: server.URL,
+ ServerName: "pve01",
+ TokenID: tokenID,
+ TokenValue: "site-two-token",
+ Source: "script",
+ }
+ req := httptest.NewRequest(http.MethodPost, "/api/auto-register", nil)
+ req.Host = "pulse.example.com"
+ rec := httptest.NewRecorder()
+
+ handler.handleCanonicalAutoRegister(rec, req, &reqBody, "127.0.0.1")
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200: %s", rec.Code, rec.Body.String())
+ }
+ if len(handler.defaultConfig.PVEInstances) != 2 {
+ t.Fatalf("PVE instances = %#v, want existing cluster and new site", handler.defaultConfig.PVEInstances)
+ }
+ existing := handler.defaultConfig.PVEInstances[0]
+ if existing.TokenValue != "site-one-token" || existing.ClusterEndpoints[0].Fingerprint != existingFingerprint || existing.ClusterEndpoints[0].IPOverride != "" {
+ t.Fatalf("existing cluster member was mutated: %#v", existing)
+ }
+ registered := handler.defaultConfig.PVEInstances[1]
+ if registered.Name != "pve01" || registered.Host != server.URL || registered.TokenValue != "site-two-token" || registered.Fingerprint != incomingFingerprint {
+ t.Fatalf("new site = %#v, want independent pve01 registration", registered)
+ }
+}
+
func TestHandleCanonicalAutoRegister_PBSPreservesExistingHostnameWhenRequestUsesSameIP(t *testing.T) {
tempDir := t.TempDir()
t.Setenv("PULSE_DATA_DIR", tempDir)
@@ -1297,3 +1491,69 @@ func TestHandleCanonicalAutoRegister_PBSUpdatesExistingNodeOnDHCPHostChange(t *t
t.Fatalf("token value = %q, want reused Pulse-managed token", instance.TokenValue)
}
}
+
+func TestHandleCanonicalAutoRegister_PBSKeepsDistinctSameNameTokenWhenFingerprintsConflict(t *testing.T) {
+ tempDir := t.TempDir()
+ t.Setenv("PULSE_DATA_DIR", tempDir)
+
+ server := newIPv4TLSServer(t, http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ }))
+ defer server.Close()
+
+ incomingFingerprint, err := tlsutil.FetchFingerprint(server.URL)
+ if err != nil {
+ t.Fatalf("fetch incoming fingerprint: %v", err)
+ }
+ existingFingerprint := strings.Repeat("a", 64)
+ if strings.EqualFold(existingFingerprint, incomingFingerprint) {
+ existingFingerprint = strings.Repeat("b", 64)
+ }
+ tokenID := "pulse-monitor@pbs!" + buildPulseMonitorTokenName("pulse.example.com")
+ cfg := &config.Config{
+ DataPath: tempDir,
+ ConfigPath: tempDir,
+ PBSInstances: []config.PBSInstance{
+ {
+ Name: "pbs01",
+ Host: "https://10.0.0.20:8007",
+ TokenName: tokenID,
+ TokenValue: "site-one-token",
+ Fingerprint: existingFingerprint,
+ },
+ },
+ }
+ handler := newTestConfigHandlers(t, cfg)
+
+ reqBody := AutoRegisterRequest{
+ Type: "pbs",
+ Host: server.URL,
+ ServerName: "pbs01",
+ TokenID: tokenID,
+ TokenValue: "site-two-token",
+ Source: "script",
+ }
+ req := httptest.NewRequest(http.MethodPost, "/api/auto-register", nil)
+ req.Host = "pulse.example.com"
+ rec := httptest.NewRecorder()
+
+ handler.handleCanonicalAutoRegister(rec, req, &reqBody, "127.0.0.1")
+
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200: %s", rec.Code, rec.Body.String())
+ }
+ if len(handler.defaultConfig.PBSInstances) != 2 {
+ t.Fatalf("PBS instances = %#v, want both sites to remain configured", handler.defaultConfig.PBSInstances)
+ }
+ existing := handler.defaultConfig.PBSInstances[0]
+ if existing.Host != "https://10.0.0.20:8007" || existing.TokenValue != "site-one-token" || existing.Fingerprint != existingFingerprint {
+ t.Fatalf("existing site was mutated: %#v", existing)
+ }
+ registered := handler.defaultConfig.PBSInstances[1]
+ if registered.Host != server.URL || registered.TokenValue != "site-two-token" || registered.Fingerprint != incomingFingerprint {
+ t.Fatalf("new site = %#v, want independently registered endpoint", registered)
+ }
+ if strings.EqualFold(registered.Name, existing.Name) {
+ t.Fatalf("new site name = %q, want disambiguation from existing %q", registered.Name, existing.Name)
+ }
+}
diff --git a/internal/api/config_setup_handlers.go b/internal/api/config_setup_handlers.go
index bbde27f99f..6b7b545b3c 100644
--- a/internal/api/config_setup_handlers.go
+++ b/internal/api/config_setup_handlers.go
@@ -1022,6 +1022,20 @@ func (h *ConfigHandlers) adoptCanonicalAutoRegisterClusterMember(ctx context.Con
}
instance := &instances[i]
endpoint := &instance.ClusterEndpoints[j]
+ selectedIdentity := clusterMemberOverrideIdentity(selectedHost)
+ effectiveIdentity := clusterMemberOverrideIdentity(endpoint.EffectiveIP())
+ willAdoptSelectedAddress := selectedIdentity != "" &&
+ selectedIdentity != effectiveIdentity &&
+ shouldAdoptClusterMemberAutoRegisterAddress(endpoint.IPOverride, candidateHosts)
+ if willAdoptSelectedAddress && config.ProxmoxFingerprintsConflict(endpoint.Fingerprint, fingerprint) {
+ log.Warn().
+ Str("cluster", instance.Name).
+ Str("node", endpoint.NodeName).
+ Str("existingHost", endpoint.EffectiveIP()).
+ Str("newHost", selectedHost).
+ Msg("Canonical auto-register rejected inferred cluster member match because TLS fingerprints conflict")
+ return false
+ }
switch {
case tokenID != "" && instance.TokenName == tokenID:
@@ -1036,8 +1050,6 @@ func (h *ConfigHandlers) adoptCanonicalAutoRegisterClusterMember(ctx context.Con
instance.Source = strings.TrimSpace(source)
}
- selectedIdentity := clusterMemberOverrideIdentity(selectedHost)
- effectiveIdentity := clusterMemberOverrideIdentity(endpoint.EffectiveIP())
switch {
case selectedIdentity == "":
return true
@@ -2065,6 +2077,14 @@ func (h *ConfigHandlers) handleCanonicalAutoRegister(w http.ResponseWriter, r *h
existingIndex = i
break
}
+ if config.ProxmoxFingerprintsConflict(node.Fingerprint, fingerprint) {
+ log.Warn().
+ Str("existingHost", node.Host).
+ Str("newHost", host).
+ Str("type", "pve").
+ Msg("Canonical auto-register rejected inferred node match because TLS fingerprints conflict")
+ continue
+ }
if hostsShareResolvedIdentity(node.Host, host) {
existingIndex = i
preserveHost = shouldPreserveExistingAutoRegisterHost(node.Host, candidateHosts)
@@ -2148,6 +2168,14 @@ func (h *ConfigHandlers) handleCanonicalAutoRegister(w http.ResponseWriter, r *h
existingIndex = i
break
}
+ if config.ProxmoxFingerprintsConflict(node.Fingerprint, fingerprint) {
+ log.Warn().
+ Str("existingHost", node.Host).
+ Str("newHost", host).
+ Str("type", "pbs").
+ Msg("Canonical auto-register rejected inferred node match because TLS fingerprints conflict")
+ continue
+ }
if hostsShareResolvedIdentity(node.Host, host) {
existingIndex = i
preserveHost = shouldPreserveExistingAutoRegisterHost(node.Host, candidateHosts)
diff --git a/internal/config/pve_instances.go b/internal/config/pve_instances.go
index b018eaa61e..44fcc2fee3 100644
--- a/internal/config/pve_instances.go
+++ b/internal/config/pve_instances.go
@@ -62,22 +62,22 @@ func (instance PVEInstance) DeepCopy() PVEInstance {
return clonePVEInstances([]PVEInstance{instance})[0]
}
-// normalizePVEFingerprint reduces a TLS certificate fingerprint to a
+// normalizeProxmoxFingerprint reduces a TLS certificate fingerprint to a
// comparable form. Comparison-only: unknown stays empty, no validation.
-func normalizePVEFingerprint(raw string) string {
+func normalizeProxmoxFingerprint(raw string) string {
normalized := strings.ToLower(strings.TrimSpace(raw))
normalized = strings.TrimPrefix(normalized, "sha256:")
normalized = strings.ReplaceAll(normalized, ":", "")
return strings.ReplaceAll(normalized, " ", "")
}
-// pveFingerprintsConflict reports whether two TLS fingerprints are both known
-// and disagree. Contradicting fingerprints identify two different machines,
-// which outweighs any name or address coincidence between sites that reuse
-// node hostnames and RFC1918 ranges.
-func pveFingerprintsConflict(a, b string) bool {
- fpA := normalizePVEFingerprint(a)
- fpB := normalizePVEFingerprint(b)
+// ProxmoxFingerprintsConflict reports whether two TLS fingerprints are both
+// known and disagree. Contradicting fingerprints identify two different
+// machines, which outweighs inferred name or address coincidence between
+// sites that reuse node hostnames, token identities, and RFC1918 ranges.
+func ProxmoxFingerprintsConflict(a, b string) bool {
+ fpA := normalizeProxmoxFingerprint(a)
+ fpB := normalizeProxmoxFingerprint(b)
return fpA != "" && fpB != "" && fpA != fpB
}
@@ -90,14 +90,14 @@ func pveFingerprintsConflict(a, b string) bool {
// certificate rotated between discoveries stays as two views rather than two
// distinct clusters being silently folded into one.
func pveClusterInstancesHaveFingerprintConflict(a, b PVEInstance) bool {
- if pveFingerprintsConflict(a.Fingerprint, b.Fingerprint) {
+ if ProxmoxFingerprintsConflict(a.Fingerprint, b.Fingerprint) {
return true
}
indexEndpoints := func(instance PVEInstance) (byNode, byKey map[string]string) {
byNode = make(map[string]string)
byKey = make(map[string]string)
for _, endpoint := range instance.ClusterEndpoints {
- fp := normalizePVEFingerprint(endpoint.Fingerprint)
+ fp := normalizeProxmoxFingerprint(endpoint.Fingerprint)
if fp == "" {
continue
}
@@ -519,7 +519,7 @@ func mergeStandalonePVEIntoClusters(instances []PVEInstance) bool {
}
endpoint := &instances[ref.clusterIdx].ClusterEndpoints[ref.endpointIdx]
- if pveFingerprintsConflict(instances[idx].Fingerprint, endpoint.Fingerprint) {
+ if ProxmoxFingerprintsConflict(instances[idx].Fingerprint, endpoint.Fingerprint) {
continue
}
mergeClusterEndpointData(endpoint, ClusterEndpoint{