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
Fix standalone Proxmox agent identity reuse
pulse-triage[bot]3640f4f2aa24
diff --git a/internal/models/models.go b/internal/models/models.goindex d515b4f2c3..1a260abe7d 100644--- a/internal/models/models.go+++ b/internal/models/models.go@@ -3706,10 +3706,18 @@ func nodeCrossViewMergeProven(a, b Node) bool {clusterA := normalizeNodeIdentityPart(a.ClusterName)clusterB := normalizeNodeIdentityPart(b.ClusterName)if clusterA == "" && clusterB == "" {- // Two unclassified standalone views still dedup on the shared- // evidence alone: with no cluster identity in play there is no- // established cluster slot to steal.- return true+ fpA := normalizeNodeTLSFingerprint(a.TLSFingerprint)+ fpB := normalizeNodeTLSFingerprint(b.TLSFingerprint)+ if fpA != "" && fpA == fpB {+ return true+ }+ // Standalone connection instances are provider scopes too. They may+ // reuse the same native node name, so only the exact endpoint (or the+ // fingerprint above) proves that two unclassified views are the same+ // machine. A shared short hostname or guessed agent link is not proof.+ endpointA := extractHostEndpoint(a.Host)+ endpointB := extractHostEndpoint(b.Host)+ return endpointA != "" && endpointA == endpointB}if clusterA == clusterB {return true@@ -3972,6 +3980,7 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {hostAgentByHostname := make(map[string]map[string]struct{}) // lowercase hostname -> hostAgentIDshostAgentByIP := make(map[string]map[string]struct{}) // normalized ip -> hostAgentIDsvalidHostAgentIDs := make(map[string]bool) // set of existing host agent IDs+ hostHostnameByID := make(map[string]string) // hostAgentID -> normalized full hostnameaddHostAlias := func(name, hostID string) {name = strings.TrimSpace(strings.ToLower(name))if name == "" || hostID == "" {@@ -4006,6 +4015,7 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {for _, host := range s.Hosts {if host.ID != "" {validHostAgentIDs[host.ID] = true+ hostHostnameByID[host.ID] = strings.TrimSpace(strings.ToLower(host.Hostname))addHostAlias(host.Hostname, host.ID)// Also index by short hostnameif idx := strings.Index(host.Hostname, "."); idx > 0 {@@ -4020,6 +4030,45 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {}}+ // sharedAgentProvesNodePair applies the stronger boundary required when a+ // host agent is already linked to a node from another provider instance.+ // A unique short hostname is only unique in the current snapshot, not in+ // the operator's estate: during sequential setup, the first pve01 agent+ // must not be lent to a later pve01 from another standalone connection.+ // Preserve legitimate split views when the same agent strongly bridges+ // both endpoints through an exact IP or a full (dotted) hostname.+ hostStronglyCorroboratesNode := func(hostID string, node Node) bool {+ endpoint := extractHostEndpoint(node.Host)+ if endpoint == "" {+ return false+ }+ if ip := normalizeIPAddress(endpoint); ip != "" {+ _, ok := hostIPsByID[hostID][ip]+ return ok+ }+ hostname := hostHostnameByID[hostID]+ return strings.Contains(endpoint, ".") && endpoint == hostname+ }+ sharedAgentProvesNodePair := func(hostID string, existing, candidate Node) bool {+ if nodeCrossViewMergeProven(existing, candidate) {+ return true+ }+ if normalizeNodeIdentityPart(existing.ClusterName) != "" ||+ normalizeNodeIdentityPart(candidate.ClusterName) != "" {+ return false+ }+ return hostStronglyCorroboratesNode(hostID, existing) &&+ hostStronglyCorroboratesNode(hostID, candidate)+ }+ hostAlreadyClaimsDifferentNode := func(hostID string, node Node) bool {+ linkedKey := linkedHostToKey[strings.TrimSpace(hostID)]+ if linkedKey == "" {+ return false+ }+ existing, ok := nodeMap[linkedKey]+ return ok && !sharedAgentProvesNodePair(hostID, existing, node)+ }+// Hostname and address matches are weak evidence: two clusters can reuse// the same node names, and sites that reuse RFC1918 ranges can present the// same endpoint IP for different machines. Reject a candidate agent when@@ -4028,6 +4077,9 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {// fingerprint, or the node's endpoint IP is absent from the IPs the agent// reports.hostContradictsNode := func(hostID string, node Node) bool {+ if hostAlreadyClaimsDifferentNode(hostID, node) {+ return true+ }if hints := agentClusterHints[hostID]; len(hints) > 0 {if cluster := normalizeNodeIdentityPart(node.ClusterName); cluster != "" {if _, sameCluster := hints[cluster]; !sameCluster {@@ -4056,7 +4108,7 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {for _, node := range dedupedNodes {// Preserve existing link if we had one, but only if the host agent still existsif existingLink, ok := existingNodeLinks[node.ID]; ok {- if validHostAgentIDs[existingLink] {+ if validHostAgentIDs[existingLink] && !hostContradictsNode(existingLink, node) {node.LinkedAgentID = existingLink}// If host agent no longer exists, leave LinkedAgentID empty (stale reference cleared)@@ -4064,7 +4116,7 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {// Fallback: preserve link by logical identity when node IDs changed across polls.if node.LinkedAgentID == "" {if existingLink, ok := existingNodeLinksByLogicalKey[nodeLogicalKey(node)]; ok {- if validHostAgentIDs[existingLink] {+ if validHostAgentIDs[existingLink] && !hostContradictsNode(existingLink, node) {node.LinkedAgentID = existingLink}}@@ -4149,7 +4201,7 @@ func (s *State) UpdateNodesForInstance(instanceName string, nodes []Node) {// across unrelated machines, a cross-instance fold needs// positive same-machine proof, not just the absence of a// contradiction.- if existing, ok := nodeMap[linkedKey]; !ok || nodeCrossViewMergeProven(existing, node) {+ if existing, ok := nodeMap[linkedKey]; !ok || sharedAgentProvesNodePair(node.LinkedAgentID, existing, node) {targetKey = linkedKey}}diff --git a/internal/models/state_host_test.go b/internal/models/state_host_test.goindex 210b38198e..90710adb20 100644--- a/internal/models/state_host_test.go+++ b/internal/models/state_host_test.go@@ -1563,6 +1563,85 @@ func TestUpdateNodesForInstanceKeepsClustersWithSharedNodeNamesApart(t *testing.}}+// Standalone PVE connections have no cluster metadata, so sequential setup is+// the dangerous variant of the shared-name case: while only the first site's+// agent exists, a second pve01 must not borrow that agent through the short+// endpoint alias and collapse both provider instances into one node slot.+// Refs #1753.+func TestUpdateNodesForInstanceKeepsSequentialSameNameStandaloneSitesApart(t *testing.T) {+ state := &State{+ Hosts: []Host{+ {+ ID: "agent-staging-pve01",+ Hostname: "pve01",+ ReportIP: "192.0.2.11",+ NetworkInterfaces: []HostNetworkInterface{+ {Name: "eth0", Addresses: []string{"192.0.2.11/24"}},+ },+ },+ },+ Nodes: []Node{+ {+ ID: "staging-pve01",+ Name: "pve01",+ Instance: "staging",+ Host: "https://pve01.staging.example:8006",+ LinkedAgentID: "agent-staging-pve01",+ Status: "online",+ },+ },+ }++ state.UpdateNodesForInstance("production", []Node{+ {+ ID: "production-pve01",+ Name: "pve01",+ Instance: "production",+ Host: "https://pve01.production.example:8006",+ Status: "online",+ },+ })++ if len(state.Nodes) != 2 {+ t.Fatalf("nodes = %#v, want 2 standalone sites", state.Nodes)+ }+ byID := make(map[string]Node, len(state.Nodes))+ for _, node := range state.Nodes {+ byID[node.ID] = node+ }+ if byID["staging-pve01"].LinkedAgentID != "agent-staging-pve01" {+ t.Fatalf("staging link = %q, want agent-staging-pve01", byID["staging-pve01"].LinkedAgentID)+ }+ if byID["production-pve01"].LinkedAgentID != "" {+ t.Fatalf("production link = %q, want no guessed cross-site agent", byID["production-pve01"].LinkedAgentID)+ }++ // Existing installations may already hold the bad many-nodes-to-one-agent+ // link in memory. The next provider poll must discard it, not preserve it.+ for i := range state.Nodes {+ if state.Nodes[i].ID == "production-pve01" {+ state.Nodes[i].LinkedAgentID = "agent-staging-pve01"+ }+ }+ state.UpdateNodesForInstance("production", []Node{+ {+ ID: "production-pve01",+ Name: "pve01",+ Instance: "production",+ Host: "https://pve01.production.example:8006",+ Status: "online",+ },+ })+ if len(state.Nodes) != 2 {+ t.Fatalf("self-heal nodes = %#v, want 2 standalone sites", state.Nodes)+ }+ for _, node := range state.Nodes {+ if node.ID == "production-pve01" && node.LinkedAgentID != "" {+ t.Fatalf("self-healed production link = %q, want empty", node.LinkedAgentID)+ }+ }+}+// When TLS settings degrade node endpoints to the bare node name, the// endpoint-host merge alias is identical for both clusters. The alias must// not merge nodes whose named clusters contradict each other.