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
Keep unusable guest measurements distinct from foreign replies
pulse-triage[bot]81d16def55a2
diff --git a/pkg/proxmox/client_api_more3_test.go b/pkg/proxmox/client_api_more3_test.goindex db03647575..3d4f1a3bbb 100644--- a/pkg/proxmox/client_api_more3_test.go+++ b/pkg/proxmox/client_api_more3_test.go@@ -293,11 +293,8 @@ func TestClientVMFSInfoObjectResult(t *testing.T) {ctx := context.Background()filesystems, err := client.GetVMFSInfo(ctx, "node1", 100)- if err != nil {- t.Fatalf("GetVMFSInfo error: %v", err)- }- if len(filesystems) != 0 {- t.Fatalf("expected empty filesystem list, got %d", len(filesystems))+ if GuestAgentDeferredReason(err) != "agent-completion-unverified" || len(filesystems) != 0 {+ t.Fatalf("HTTP 200 error payload became a current empty inventory: %+v / %v", filesystems, err)}}diff --git a/pkg/proxmox/guest_agent_command_response_test.go b/pkg/proxmox/guest_agent_command_response_test.goindex 4e40cca38a..668d2ce463 100644--- a/pkg/proxmox/guest_agent_command_response_test.go+++ b/pkg/proxmox/guest_agent_command_response_test.go@@ -175,6 +175,35 @@ func TestGuestAgentForeignReplySharesUnrenewedFenceAndResumes(t *testing.T) {}}+func TestGuestAgentDuplicateForeignEvidenceCannotBeErased(t *testing.T) {+ for name, result := range map[string]string{+ "duplicate": `{"name":"eth0","ip-addresses":[],"ip-addresses":null}`,+ "escaped": `{"name":"eth0","ip-addresses":[],"\u0069p-addresses":null}`,+ "case": `{"name":"eth0","IP-Addresses":[],"ip-addresses":null}`,+ "array-row": `[{"name":"eth0","ip-addresses":[],"ip-addresses":null}]`,+ } {+ t.Run(name, func(t *testing.T) {+ var commands atomic.Int32+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ if strings.HasSuffix(r.URL.Path, "/config") {+ fmt.Fprint(w, `{"data":{}}`)+ return+ }+ commands.Add(1)+ fmt.Fprintf(w, `{"data":{"result":%s}}`, result)+ }))+ defer server.Close()+ c := commandReplyTestClient(t, server.URL+"/duplicate-foreign/"+name)+ if _, err := c.GetVMFSInfo(context.Background(), "node", 105); GuestAgentDeferredReason(err) != "agent-completion-unverified" {+ t.Fatalf("later null erased foreign interface evidence: %v", err)+ }+ if _, err := c.GetVMAgentInfo(context.Background(), "node", 105); GuestAgentDeferredReason(err) != "agent-cooldown" || commands.Load() != 1 {+ t.Fatalf("foreign duplicate permitted another command: %v / %d", err, commands.Load())+ }+ })+ }+}+func TestGuestAgentCommandReplyPreservesCompatibleEmptyAndPartialData(t *testing.T) {replies := map[string][]string{"os": {`{"data":{"name":"Linux","version":"fixture","future":{"enabled":true}}}`, `{"data":{"result":{"id":"linux","version-id":"1"}}}`},diff --git a/pkg/proxmox/guest_agent_response.go b/pkg/proxmox/guest_agent_response.goindex 13bd072acf..ace2a987bc 100644--- a/pkg/proxmox/guest_agent_response.go+++ b/pkg/proxmox/guest_agent_response.go@@ -198,8 +198,7 @@ func guestAgentCommandResponse(path string, body []byte) bool {return false // file-read returns content/truncated, not a result payload.}if result[0] == '{' {- fields, valid := guestAgentResponseFields(result)- return valid && guestAgentReplyFieldsCompatible(fields, command)+ return guestAgentReplyDictionaryCompatible(result, command)}if command == "get-osinfo" || command == "info" {return false // Both information commands return dictionaries, not lists.@@ -215,8 +214,8 @@ func guestAgentCommandResponse(path string, body []byte) bool {}// Existing inventory decoders own malformed/partial rows. Only a// recognizable foreign dictionary contradicts the command here.- fields, valid := guestAgentResponseFields(row)- if valid && !guestAgentReplyFieldsCompatible(fields, command) {+ row = bytes.TrimSpace(row)+ if len(row) > 0 && row[0] == '{' && !guestAgentReplyDictionaryCompatible(row, command) {return false}}@@ -226,31 +225,59 @@ func guestAgentCommandResponse(path string, body []byte) bool {func guestAgentReplyFieldsCompatible(fields map[string]json.RawMessage, command string) bool {for name, value := range fields {- // Null foreign fields carry no affirmative payload identity; keep- // the established null-field and completed-empty semantics.- if bytes.Equal(bytes.TrimSpace(value), []byte("null")) {- continue+ if !guestAgentReplyFieldCompatible(name, value, command) {+ return false}- var owner string- switch strings.ToLower(name) {- case "content", "truncated":- owner = "file-read"- case "id", "kernel-release", "kernel-version", "machine", "pretty-name", "version-id":- owner = "get-osinfo"- case "qemu-ga", "supported-commands", "supported_commands":- owner = "info"- case "mountpoint", "total-bytes", "total-bytes-privileged", "used-bytes", "disk":- owner = "get-fsinfo"- case "hardware-address", "ip-addresses", "statistics", "has-ipv4-synth-gateway", "has-ipv6-synth-gateway":- owner = "network-get-interfaces"- case "error", "errors":+ }+ return true+}++func guestAgentReplyDictionaryCompatible(body []byte, command string) bool {+ decoder := json.NewDecoder(bytes.NewReader(body))+ if start, err := decoder.Token(); err != nil || start != json.Delim('{') {+ return false+ }+ for decoder.More() {+ key, err := decoder.Token()+ if err != nil {return false}- if owner != "" && owner != command {+ name, valid := key.(string)+ var value json.RawMessage+ if !valid || decoder.Decode(&value) != nil || !guestAgentReplyFieldCompatible(name, value, command) {return false}}- return true+ // Do not add another uniqueness/measurement policy inside a result. The+ // existing filesystem decoder rejects duplicate counters as unusable+ // completed readings and preserves valid peers. Inspect every field here+ // instead of last-key-wins, so a later null cannot erase foreign evidence.+ end, err := decoder.Token()+ return err == nil && end == json.Delim('}')+}++func guestAgentReplyFieldCompatible(name string, value json.RawMessage, command string) bool {+ // Null foreign fields carry no affirmative payload identity; keep+ // the established null-field and completed-empty semantics.+ if bytes.Equal(bytes.TrimSpace(value), []byte("null")) {+ return true+ }+ var owner string+ switch strings.ToLower(name) {+ case "content", "truncated":+ owner = "file-read"+ case "id", "kernel-release", "kernel-version", "machine", "pretty-name", "version-id":+ owner = "get-osinfo"+ case "qemu-ga", "supported-commands", "supported_commands":+ owner = "info"+ case "mountpoint", "total-bytes", "total-bytes-privileged", "used-bytes", "disk":+ owner = "get-fsinfo"+ case "hardware-address", "ip-addresses", "statistics", "has-ipv4-synth-gateway", "has-ipv6-synth-gateway":+ owner = "network-get-interfaces"+ case "error", "errors":+ return false+ }+ return owner == "" || owner == command}// Reject ambiguous envelopes (including duplicate keys and trailing values)