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.

Probe web-UI root so PVE/PBS/PMG detection survives the 3s auth delay

rcourtmanf221a715690a
diff --git a/internal/api/connections_probe.go b/internal/api/connections_probe.go
index c0d2d0ad48..5783819904 100644
--- a/internal/api/connections_probe.go
+++ b/internal/api/connections_probe.go
@@ -5,7 +5,6 @@ import (
"crypto/sha256"
"crypto/tls"
"encoding/hex"
- "encoding/json"
"fmt"
"io"
"net"
@@ -56,20 +55,24 @@ type probeTarget struct {
identifyFn func(resp *http.Response, body []byte) (match bool, hints map[string]string)
}
+// PVE, PBS, and PMG all delay auth-required 401 responses by ~3 seconds as a
+// timing-attack mitigation. /api2/json/version requires auth, so probing it
+// costs the full probe budget on every attempt. The web-UI root at / returns
+// the login page in <100ms and carries the same identifying Server banner
+// (PVE/PMG) or an unambiguous HTML title (PBS, which omits Server on /).
var defaultProbeTargets = []probeTarget{
{
Type: ConnectionTypePVE,
Scheme: "https",
Port: 8006,
- Path: "/api2/json/version",
+ Path: "/",
identifyFn: func(resp *http.Response, body []byte) (bool, map[string]string) {
server := strings.ToLower(resp.Header.Get("Server"))
if strings.Contains(server, "pve-api-daemon") {
- return true, versionHintsFromProxmoxBody(body, "Proxmox VE")
+ return true, map[string]string{"product": "Proxmox VE"}
}
- if strings.Contains(string(body), `"repoid"`) && strings.Contains(string(body), `"version"`) &&
- !strings.Contains(string(body), `"product":"pmg"`) {
- return true, versionHintsFromProxmoxBody(body, "Proxmox VE")
+ if strings.Contains(string(body), "Proxmox Virtual Environment") {
+ return true, map[string]string{"product": "Proxmox VE"}
}
return false, nil
},
@@ -78,11 +81,14 @@ var defaultProbeTargets = []probeTarget{
Type: ConnectionTypePBS,
Scheme: "https",
Port: 8007,
- Path: "/api2/json/version",
+ Path: "/",
identifyFn: func(resp *http.Response, body []byte) (bool, map[string]string) {
server := strings.ToLower(resp.Header.Get("Server"))
- if strings.Contains(server, "proxmox-backup-api") {
- return true, versionHintsFromProxmoxBody(body, "Proxmox Backup Server")
+ if strings.Contains(server, "proxmox-backup") {
+ return true, map[string]string{"product": "Proxmox Backup Server"}
+ }
+ if strings.Contains(string(body), "Proxmox Backup Server") {
+ return true, map[string]string{"product": "Proxmox Backup Server"}
}
return false, nil
},
@@ -91,14 +97,14 @@ var defaultProbeTargets = []probeTarget{
Type: ConnectionTypePMG,
Scheme: "https",
Port: 8006,
- Path: "/api2/json/version",
+ Path: "/",
identifyFn: func(resp *http.Response, body []byte) (bool, map[string]string) {
server := strings.ToLower(resp.Header.Get("Server"))
if strings.Contains(server, "pmg-api-daemon") {
- return true, versionHintsFromProxmoxBody(body, "Proxmox Mail Gateway")
+ return true, map[string]string{"product": "Proxmox Mail Gateway"}
}
- if strings.Contains(string(body), `"product":"pmg"`) {
- return true, versionHintsFromProxmoxBody(body, "Proxmox Mail Gateway")
+ if strings.Contains(string(body), "Proxmox Mail Gateway") {
+ return true, map[string]string{"product": "Proxmox Mail Gateway"}
}
return false, nil
},
@@ -130,30 +136,6 @@ var defaultProbeTargets = []probeTarget{
},
}
-// versionHintsFromProxmoxBody pulls the minimum fields out of a Proxmox API
-// /version response so the frontend can show the user something useful
-// beyond "we think this is PVE." Any shape mismatch just yields the product
-// name alone — we never fail a probe on a hint-parse error.
-func versionHintsFromProxmoxBody(body []byte, productName string) map[string]string {
- hints := map[string]string{"product": productName}
- var wrapper struct {
- Data struct {
- Version string `json:"version"`
- Release string `json:"release"`
- Repoid string `json:"repoid"`
- } `json:"data"`
- }
- if err := json.Unmarshal(body, &wrapper); err == nil {
- if wrapper.Data.Version != "" {
- hints["version"] = wrapper.Data.Version
- }
- if wrapper.Data.Release != "" {
- hints["release"] = wrapper.Data.Release
- }
- }
- return hints
-}
-
// parseProbeAddress normalizes user input into (host, explicitPort).
// Accepted forms: "host", "host:port", "ip", "ip:port", "scheme://host[:port]".
// explicitPort == 0 means "probe all defaults"; otherwise only probe targets
diff --git a/internal/api/connections_probe_test.go b/internal/api/connections_probe_test.go
index a9b7460f9a..ef3dfec79d 100644
--- a/internal/api/connections_probe_test.go
+++ b/internal/api/connections_probe_test.go
@@ -99,7 +99,7 @@ func probeTestServer(t *testing.T, handler http.HandlerFunc) (host string, port
func pveHandler(body string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Server", "pve-api-daemon/3.4")
- w.Header().Set("Content-Type", "application/json")
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprint(w, body)
}
}
@@ -107,7 +107,7 @@ func pveHandler(body string) http.HandlerFunc {
func pbsHandler(body string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Server", "proxmox-backup-api/3.2")
- w.Header().Set("Content-Type", "application/json")
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprint(w, body)
}
}
@@ -115,7 +115,7 @@ func pbsHandler(body string) http.HandlerFunc {
func pmgHandler(body string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Server", "pmg-api-daemon/8.1")
- w.Header().Set("Content-Type", "application/json")
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
fmt.Fprint(w, body)
}
}
@@ -157,14 +157,14 @@ func withSingleTarget(t *testing.T, tgt probeTarget) func() {
}
func TestProbeOne_DetectsPVE(t *testing.T) {
- host, port, done := probeTestServer(t, pveHandler(`{"data":{"version":"8.2.4","release":"8.2","repoid":"abc"}}`))
+ host, port, done := probeTestServer(t, pveHandler(`<html><title>delly - Proxmox Virtual Environment</title></html>`))
defer done()
tgt := probeTarget{
Type: ConnectionTypePVE,
Scheme: "https",
Port: port,
- Path: "/api2/json/version",
+ Path: "/",
identifyFn: defaultProbeTargets[0].identifyFn,
}
cand, ok := probeOne(context.Background(), host, tgt, testProbeClient())
@@ -174,13 +174,13 @@ func TestProbeOne_DetectsPVE(t *testing.T) {
if cand.Type != ConnectionTypePVE {
t.Fatalf("type = %q, want pve", cand.Type)
}
- if cand.Hints["version"] != "8.2.4" {
- t.Fatalf("version hint not propagated: %+v", cand.Hints)
+ if cand.Hints["product"] != "Proxmox VE" {
+ t.Fatalf("product hint not set: %+v", cand.Hints)
}
}
func TestProbeOne_DetectsPBS(t *testing.T) {
- host, port, done := probeTestServer(t, pbsHandler(`{"data":{"version":"3.2.1","release":"3.2"}}`))
+ host, port, done := probeTestServer(t, pbsHandler(`<html><title>pbs-docker - Proxmox Backup Server</title></html>`))
defer done()
// Find the PBS identifyFn from defaults.
@@ -193,17 +193,18 @@ func TestProbeOne_DetectsPBS(t *testing.T) {
if pbsFn == nil {
t.Fatal("pbs target not in defaults")
}
- tgt := probeTarget{Type: ConnectionTypePBS, Scheme: "https", Port: port, Path: "/api2/json/version", identifyFn: pbsFn}
+ tgt := probeTarget{Type: ConnectionTypePBS, Scheme: "https", Port: port, Path: "/", identifyFn: pbsFn}
if _, ok := probeOne(context.Background(), host, tgt, testProbeClient()); !ok {
t.Fatal("expected PBS detection")
}
}
-func TestProbeOne_DetectsPMGByProductField(t *testing.T) {
- // Simulate a server that serves PMG content but with no distinctive Server header.
+func TestProbeOne_DetectsPMGByTitle(t *testing.T) {
+ // Simulate a PMG root that omits the Server banner but still advertises the
+ // product via HTML title.
host, port, done := probeTestServer(t, func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Content-Type", "application/json")
- fmt.Fprint(w, `{"data":{"product":"pmg","version":"8.1.2"}}`)
+ w.Header().Set("Content-Type", "text/html; charset=utf-8")
+ fmt.Fprint(w, `<html><title>mail01 - Proxmox Mail Gateway</title></html>`)
})
defer done()
@@ -213,9 +214,9 @@ func TestProbeOne_DetectsPMGByProductField(t *testing.T) {
pmgFn = tgt.identifyFn
}
}
- tgt := probeTarget{Type: ConnectionTypePMG, Scheme: "https", Port: port, Path: "/api2/json/version", identifyFn: pmgFn}
+ tgt := probeTarget{Type: ConnectionTypePMG, Scheme: "https", Port: port, Path: "/", identifyFn: pmgFn}
if _, ok := probeOne(context.Background(), host, tgt, testProbeClient()); !ok {
- t.Fatal("expected PMG detection via product field")
+ t.Fatal("expected PMG detection via HTML title")
}
}
@@ -268,7 +269,7 @@ func TestProbeOne_RejectsNonMatchingServer(t *testing.T) {
}
func TestProbeOne_DoesNotConfusePVEForPMG(t *testing.T) {
- host, port, done := probeTestServer(t, pveHandler(`{"data":{"version":"8.2.4","release":"8.2","repoid":"abc"}}`))
+ host, port, done := probeTestServer(t, pveHandler(`<html><title>delly - Proxmox Virtual Environment</title></html>`))
defer done()
var pmgFn func(*http.Response, []byte) (bool, map[string]string)
@@ -277,7 +278,7 @@ func TestProbeOne_DoesNotConfusePVEForPMG(t *testing.T) {
pmgFn = tgt.identifyFn
}
}
- tgt := probeTarget{Type: ConnectionTypePMG, Scheme: "https", Port: port, Path: "/api2/json/version", identifyFn: pmgFn}
+ tgt := probeTarget{Type: ConnectionTypePMG, Scheme: "https", Port: port, Path: "/", identifyFn: pmgFn}
if _, ok := probeOne(context.Background(), host, tgt, testProbeClient()); ok {
t.Fatal("PMG identifyFn should not match a PVE server")
}
@@ -286,7 +287,7 @@ func TestProbeOne_DoesNotConfusePVEForPMG(t *testing.T) {
func TestRunProbe_ReturnsSortedCandidates(t *testing.T) {
// Spin up one PVE server; runProbe should invoke all candidates but only
// detect PVE. Shorten the budget for the test.
- host, port, done := probeTestServer(t, pveHandler(`{"data":{"version":"8.2.4","release":"8.2","repoid":"abc"}}`))
+ host, port, done := probeTestServer(t, pveHandler(`<html><title>delly - Proxmox Virtual Environment</title></html>`))
defer done()
// Override defaultProbeTargets to only the PVE target at our ephemeral port.
@@ -296,7 +297,7 @@ func TestRunProbe_ReturnsSortedCandidates(t *testing.T) {
pveFn = tgt.identifyFn
}
}
- restore := withSingleTarget(t, probeTarget{Type: ConnectionTypePVE, Scheme: "https", Port: port, Path: "/api2/json/version", identifyFn: pveFn})
+ restore := withSingleTarget(t, probeTarget{Type: ConnectionTypePVE, Scheme: "https", Port: port, Path: "/", identifyFn: pveFn})
defer restore()
results, elapsed := runProbe(context.Background(), host, port, testProbeClient())
@@ -314,7 +315,7 @@ func TestRunProbe_TotalBudgetEnforced(t *testing.T) {
Type: ConnectionTypePVE,
Scheme: "https",
Port: 1, // unlikely open
- Path: "/api2/json/version",
+ Path: "/",
identifyFn: func(*http.Response, []byte) (bool, map[string]string) {
return true, nil
},