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
Add FormatCloudSafeContext: PII-free discovery context for cloud models
rcourtman92f08a1f16ea
diff --git a/internal/servicediscovery/formatters.go b/internal/servicediscovery/formatters.goindex 7d32122183..2fb85aeb77 100644--- a/internal/servicediscovery/formatters.go+++ b/internal/servicediscovery/formatters.go@@ -3,6 +3,7 @@ package servicediscoveryimport ("fmt""sort"+ "strconv""strings""time"@@ -41,6 +42,66 @@ func FormatSingleForAIContext(d *ResourceDiscovery) string {return formatSingleDiscovery(d)}+// FormatCloudSafeContext returns the operational discovery context that is safe+// to send to a CLOUD model: service identity, the access pattern, and+// operational paths — WITHOUT PII (hostname, IP, bind addresses, alias). It is+// intended for the chat sanitizer to include in cloud-routed summaries so the+// Assistant stays useful on cloud models while genuinely sensitive fields stay+// redacted. Local routing should keep using FormatForAIContext (full context).+//+// Safe by construction: it reads only non-identifying fields and never emits+// Hostname or any address. Port numbers are included without their bind+// addresses. Returns "" when there is no usable identity.+func FormatCloudSafeContext(d *ResourceDiscovery) string {+ if d == nil {+ return ""+ }++ name := strings.TrimSpace(d.ServiceName)+ if name == "" {+ name = strings.TrimSpace(d.ServiceType)+ }+ if name == "" {+ return ""+ }++ var sb strings.Builder+ sb.WriteString("Service: " + name)+ if v := strings.TrimSpace(d.ServiceVersion); v != "" {+ sb.WriteString(" (" + v + ")")+ }+ sb.WriteString("\n")++ if d.Category != "" && d.Category != CategoryUnknown {+ sb.WriteString("Category: " + string(d.Category) + "\n")+ }+ if access := strings.TrimSpace(d.CLIAccess); access != "" {+ sb.WriteString("Access: " + access + "\n")+ }+ if len(d.ConfigPaths) > 0 {+ sb.WriteString("Config paths: " + strings.Join(d.ConfigPaths, ", ") + "\n")+ }+ if len(d.DataPaths) > 0 {+ sb.WriteString("Data paths: " + strings.Join(d.DataPaths, ", ") + "\n")+ }+ if len(d.LogPaths) > 0 {+ sb.WriteString("Log paths: " + strings.Join(d.LogPaths, ", ") + "\n")+ }+ if len(d.Ports) > 0 {+ nums := make([]string, 0, len(d.Ports))+ for _, p := range d.Ports {+ if p.Port > 0 {+ nums = append(nums, strconv.Itoa(p.Port))+ }+ }+ if len(nums) > 0 {+ sb.WriteString("Ports: " + strings.Join(nums, ", ") + "\n")+ }+ }++ return strings.TrimSpace(sb.String())+}+// formatSingleDiscovery formats a single discovery entry.func formatSingleDiscovery(d *ResourceDiscovery) string {var sb strings.Builderdiff --git a/internal/servicediscovery/formatters_test.go b/internal/servicediscovery/formatters_test.goindex e5ed770e15..456e722591 100644--- a/internal/servicediscovery/formatters_test.go+++ b/internal/servicediscovery/formatters_test.go@@ -286,3 +286,33 @@ func TestFilterImportantFactsLimit(t *testing.T) {t.Fatalf("service-control fact was dropped by the cap")}}++func TestFormatCloudSafeContext(t *testing.T) {+ if FormatCloudSafeContext(nil) != "" {+ t.Fatalf("expected empty cloud-safe context for nil discovery")+ }++ d := &ResourceDiscovery{+ Hostname: "ha-prod.internal",+ ServiceType: "home-assistant",+ ServiceName: "Home Assistant",+ Category: CategoryHomeAuto,+ CLIAccess: "pct exec 101 -- docker exec homeassistant bash",+ ConfigPaths: []string{"/config/automations.yaml"},+ Ports: []PortInfo{{Port: 8123, Protocol: "tcp", Address: "192.168.0.127"}},+ }+ out := FormatCloudSafeContext(d)++ // Operational context the cloud Assistant needs to be useful.+ for _, want := range []string{"Home Assistant", "docker exec homeassistant", "/config/automations.yaml", "8123"} {+ if !strings.Contains(out, want) {+ t.Errorf("cloud-safe context missing %q\n--- output ---\n%s", want, out)+ }+ }+ // PII must NEVER reach a cloud model.+ for _, bad := range []string{"ha-prod.internal", "192.168.0.127"} {+ if strings.Contains(out, bad) {+ t.Errorf("cloud-safe context leaked PII %q\n--- output ---\n%s", bad, out)+ }+ }+}