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.

Prefer hostname endpoints for Proxmox auto-register

rcourtman82ce98f7cad8
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 38861359f8..dd3ee98061 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -614,6 +614,14 @@ generic commercial presentation helpers from the hosted infrastructure route.
That canonical /api/auto-register behavior now also includes hostname/IP continuity:
reruns that arrive through a different canonical host form must reuse the same
Pulse-managed node record and token instead of forking duplicate fleet entries.
+That same lifecycle contract also governs the runtime-side Proxmox setup host
+selection in `internal/hostagent/proxmox_setup.go`: when the system hostname
+resolves to a non-loopback, non-link-local address, the generated Proxmox
+registration host must stay on that canonical hostname instead of downgrading
+to a route-inferred interface IP. Route-aware IP detection remains the fallback
+only when hostname resolution is unusable, so multi-NIC and internal-CA
+deployments preserve canonical hostname continuity without losing an IP escape
+hatch for non-DNS installs.
That same canonical behavior also includes one auth transport for Proxmox
completion: runtime-side Unified Agent and script callers must send `/api/auto-register`
authentication through a one-time setup token in the request-body
diff --git a/internal/hostagent/proxmox_setup.go b/internal/hostagent/proxmox_setup.go
index ee82c13cb2..39d7496da5 100644
--- a/internal/hostagent/proxmox_setup.go
+++ b/internal/hostagent/proxmox_setup.go
@@ -686,7 +686,8 @@ func (p *ProxmoxSetup) parsePBSTokenValue(output string) string {
}
// getHostURL constructs the host URL for this Proxmox node.
-// Uses the local IP that can reach Pulse, falling back to intelligent IP selection.
+// Prefers canonical hostname continuity when it resolves to a real local address,
+// then falls back to route-aware IP detection and heuristic local IP selection.
func (p *ProxmoxSetup) getHostURL(ctx context.Context, ptype proxmoxProductType) string {
port := "8006"
if ptype == proxmoxProductPBS {
@@ -705,14 +706,27 @@ func (p *ProxmoxSetup) getHostURL(ctx context.Context, ptype proxmoxProductType)
return formatHTTPSURL(p.reportIP, port)
}
- // Priority 2: Try to determine which local IP is used to connect to Pulse
- // This ensures we pick an IP that can actually communicate with the Pulse server
+ // Priority 2: Prefer the system hostname when it resolves to a non-loopback,
+ // non-link-local address. This preserves admin-managed DNS names and matching
+ // TLS certificates instead of silently downgrading to an inferred IP address.
+ if hostname := strings.TrimSpace(p.hostname); hostname != "" {
+ if hostnameIP := p.getIPForHostname(); hostnameIP != "" && !isLoopbackOrLinkLocalIP(hostnameIP) {
+ p.logger.Debug().
+ Str("hostname", hostname).
+ Str("ip", hostnameIP).
+ Msg("Using resolvable hostname for Proxmox registration")
+ return formatHTTPSURL(hostname, port)
+ }
+ }
+
+ // Priority 3: Try to determine which local IP is used to connect to Pulse.
+ // This remains the best fallback when the hostname is not usable.
if reachableIP := p.getIPThatReachesPulse(); reachableIP != "" {
p.logger.Debug().Str("ip", reachableIP).Msg("Using IP that can reach Pulse server")
return formatHTTPSURL(reachableIP, port)
}
- // Fallback: Get all IPs and select the best one based on heuristics
+ // Priority 4: Get all IPs and select the best one based on heuristics.
hostnameCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
@@ -788,9 +802,9 @@ func (p *ProxmoxSetup) getIPThatReachesPulse() string {
}
ip := localAddr.IP.String()
- // If we found an IP that can reach Pulse, it's the most reliable one to report.
- // We only skip loopback/link-local which net.Dial UDP shouldn't return anyway.
- if ip != "" && ip != "127.0.0.1" && ip != "::1" && !strings.HasPrefix(ip, "fe80:") {
+ // If we found an IP that can reach Pulse, it's the most reliable IP fallback
+ // after a canonical hostname probe. Reject loopback and link-local addresses.
+ if ip != "" && !isLoopbackOrLinkLocalIP(ip) {
return ip
}
return ""
@@ -832,6 +846,14 @@ func (p *ProxmoxSetup) getIPForHostname() string {
return ""
}
+func isLoopbackOrLinkLocalIP(raw string) bool {
+ ip := net.ParseIP(strings.TrimSpace(raw))
+ if ip == nil {
+ return false
+ }
+ return ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast()
+}
+
// selectBestIP picks the most likely externally-reachable IP from a list.
// Prefers common LAN subnets (192.168.x.x, 10.x.x.x) and avoids internal
// cluster networks (like corosync's 172.20.x.x) and link-local addresses.
diff --git a/internal/hostagent/proxmox_setup_test.go b/internal/hostagent/proxmox_setup_test.go
index 5ca12db22c..ea1ab57791 100644
--- a/internal/hostagent/proxmox_setup_test.go
+++ b/internal/hostagent/proxmox_setup_test.go
@@ -314,9 +314,27 @@ func TestGetHostURL(t *testing.T) {
}
})
- t.Run("uses IP that reaches pulse", func(t *testing.T) {
+ t.Run("prefers resolvable hostname before inferred route IP", func(t *testing.T) {
p.reportIP = ""
p.pulseURL = "https://pulse:7655"
+ mc.lookupIPFn = func(h string) ([]net.IP, error) {
+ if h == "test-host" {
+ return []net.IP{net.ParseIP("10.9.0.10")}, nil
+ }
+ return nil, nil
+ }
+ mc.dialTimeoutFn = func(network, address string, timeout time.Duration) (net.Conn, error) {
+ return &mockConn{localAddr: &net.UDPAddr{IP: net.ParseIP("10.1.1.1")}}, nil
+ }
+ if got := p.getHostURL(context.Background(), "pve"); got != "https://test-host:8006" {
+ t.Errorf("got %s", got)
+ }
+ })
+
+ t.Run("uses IP that reaches pulse when hostname is not resolvable", func(t *testing.T) {
+ p.reportIP = ""
+ p.pulseURL = "https://pulse:7655"
+ mc.lookupIPFn = func(h string) ([]net.IP, error) { return nil, nil }
mc.dialTimeoutFn = func(network, address string, timeout time.Duration) (net.Conn, error) {
return &mockConn{localAddr: &net.UDPAddr{IP: net.ParseIP("10.1.1.1")}}, nil
}
@@ -336,7 +354,7 @@ func TestGetHostURL(t *testing.T) {
return "", nil
}
mc.hostnameFn = func() (string, error) { return "test-host", nil }
- mc.lookupIPFn = func(h string) ([]net.IP, error) { return nil, nil }
+ mc.lookupIPFn = func(h string) ([]net.IP, error) { return []net.IP{net.ParseIP("127.0.1.1")}, nil }
if got := p.getHostURL(context.Background(), "pbs"); got != "https://10.0.0.5:8007" {
t.Errorf("got %s", got)
@@ -346,6 +364,7 @@ func TestGetHostURL(t *testing.T) {
t.Run("final fallback to hostname", func(t *testing.T) {
p.pulseURL = ""
mc.dialTimeoutFn = func(n, a string, d time.Duration) (net.Conn, error) { return nil, fmt.Errorf("fail") }
+ mc.lookupIPFn = func(h string) ([]net.IP, error) { return nil, fmt.Errorf("fail") }
mc.commandCombinedOutputFn = func(ctx context.Context, name string, arg ...string) (string, error) {
return "", fmt.Errorf("fail")
}