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.

Make the inventory resource context obey the cloud_context_privacy dial (increment 2 completion)

rcourtmanbc5da3f4c51f
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 64a07327eb..bb34895b65 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -115,10 +115,18 @@ deriving an older display status from `workflowStatusHistory`.
off/absent → `redacted`) without mutating the boolean, so existing installs
keep their current cloud behavior. A fresh install defaults to `full` so a
self-hosted Pulse answers with real resource detail out of the box.
- The redaction seam reads the dial directly at `internal/ai/chat/service.go`,
- resolving `cloudPrivacyLevel` once per turn (failing closed to `redacted` when
- no config snapshot is available) and threading it into both the proactive
- prefetch and the model-boundary sanitizer:
+ The redaction seam reads the dial directly across THREE model-bound paths,
+ each resolving the dial and failing closed to `redacted` when no config
+ snapshot is available: the proactive prefetch and the model-boundary sanitizer
+ (`internal/ai/chat/service.go`, `cloudPrivacyLevel` once per turn), AND the
+ broad inventory-context builder (`internal/ai/resource_context.go`
+ `buildUnifiedResourceContextForModel` → `unifiedResourcePolicyContext.resourceLabel`).
+ The inventory builder MUST render resource display names through the dial, not
+ the unconditional `unifiedresources.ResourcePolicyLabel`: known-local (Ollama)
+ destinations always get real names; cloud destinations get real names only at
+ `full` and only for resources not routed `ResourceRoutingScopeLocalOnly` (the
+ same hard floor); an unknown/empty destination fails closed to the governed
+ label. All three paths enforce the same posture:
- `full`: the model-bound resource-policy sanitizer is invoked with
`modelboundary.RedactLocalOnlyResourcesOnly()`, so real identifiers (hostname,
IP, alias, name) for ordinary (Internal) and Sensitive (local-first) resources
diff --git a/internal/ai/resource_context.go b/internal/ai/resource_context.go
index 80c0f4ae8a..63b57883c9 100644
--- a/internal/ai/resource_context.go
+++ b/internal/ai/resource_context.go
@@ -5,6 +5,7 @@ import (
"sort"
"strings"
+ "github.com/rcourtman/pulse-go-rewrite/internal/config"
unifiedresources "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
"github.com/rs/zerolog/log"
)
@@ -51,8 +52,17 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
urp := s.unifiedResourceProvider
ap := s.alertProvider
agentServer := s.agentServer
+ cfg := s.cfg
s.mu.RUnlock()
+ // Resolve the cloud_context_privacy dial for inventory-context redaction.
+ // Fail closed to "redacted" when no config snapshot is available so a missing
+ // setting never widens what reaches a cloud model.
+ cloudPrivacy := config.CloudContextPrivacyRedacted
+ if cfg != nil {
+ cloudPrivacy = cfg.GetCloudContextPrivacy()
+ }
+
if urp != nil {
var sections []string
stats := urp.GetStats()
@@ -102,7 +112,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
workloads := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetWorkloads())
allResources := unifiedresources.RefreshCanonicalMetadataSlice(urp.GetAll())
policyPosture := unifiedresources.SummarizePolicyPosture(allResources)
- policyContext := buildUnifiedResourcePolicyContext(policyPosture, destinationModel)
+ policyContext := buildUnifiedResourcePolicyContext(policyPosture, destinationModel, cloudPrivacy)
detailedInfrastructure := policyContext.filterDetailedResources(infrastructure)
detailedWorkloads := policyContext.filterDetailedResources(workloads)
byResourceID := make(map[string]unifiedresources.Resource, len(allResources))
@@ -179,7 +189,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s** (%s)%s%s [%s]",
- unifiedresources.ResourcePolicyLabel(node.Name, node.AISafeSummary, node.Policy), agentStatus, clusterInfo, metrics, node.Status))
+ policyContext.resourceLabel(node.Name, node.AISafeSummary, node.Policy), agentStatus, clusterInfo, metrics, node.Status))
}
}
@@ -200,7 +210,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s**%s%s [%s]",
- unifiedresources.ResourcePolicyLabel(host.Name, host.AISafeSummary, host.Policy), ips, metrics, host.Status))
+ policyContext.resourceLabel(host.Name, host.AISafeSummary, host.Policy), ips, metrics, host.Status))
}
}
@@ -217,7 +227,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s**%s [%s]",
- unifiedresources.ResourcePolicyLabel(host.Name, host.AISafeSummary, host.Policy), metrics, host.Status))
+ policyContext.resourceLabel(host.Name, host.AISafeSummary, host.Policy), metrics, host.Status))
}
}
@@ -240,7 +250,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s** (%d/%d containers running) [%s]",
- unifiedresources.ResourcePolicyLabel(host.Name, host.AISafeSummary, host.Policy), runningCount, containerCount, host.Status))
+ policyContext.resourceLabel(host.Name, host.AISafeSummary, host.Policy), runningCount, containerCount, host.Status))
}
}
@@ -259,7 +269,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
clusterInfo = fmt.Sprintf(" [cluster: %s]", name)
}
sections = append(sections, fmt.Sprintf("- **%s** (Cluster%s, %d nodes) [%s]",
- unifiedresources.ResourcePolicyLabel(cluster.Name, cluster.AISafeSummary, cluster.Policy), clusterInfo, nodeCount, cluster.Status))
+ policyContext.resourceLabel(cluster.Name, cluster.AISafeSummary, cluster.Policy), clusterInfo, nodeCount, cluster.Status))
}
for _, node := range k8sNodes {
@@ -285,7 +295,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s** (Node, %s)%s%s [%s]",
- unifiedresources.ResourcePolicyLabel(node.Name, node.AISafeSummary, node.Policy), agentStatus, clusterInfo, metrics, node.Status))
+ policyContext.resourceLabel(node.Name, node.AISafeSummary, node.Policy), agentStatus, clusterInfo, metrics, node.Status))
}
}
}
@@ -317,7 +327,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
for _, parentID := range parentIDs {
parentName := "unresolved parent resource"
if parent, ok := infraMap[parentID]; ok {
- parentName = unifiedresources.ResourcePolicyLabel(parent.Name, parent.AISafeSummary, parent.Policy)
+ parentName = policyContext.resourceLabel(parent.Name, parent.AISafeSummary, parent.Policy)
}
sections = append(sections, fmt.Sprintf("\n**On %s:**", parentName))
@@ -345,7 +355,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
ips := unifiedresources.ResourceIPSummary(workload, 2)
sections = append(sections, fmt.Sprintf(" - **%s** (%s%s)%s [%s]",
- unifiedresources.ResourcePolicyLabel(workload.Name, workload.AISafeSummary, workload.Policy), typeLabel, vmidInfo, ips, workload.Status))
+ policyContext.resourceLabel(workload.Name, workload.AISafeSummary, workload.Policy), typeLabel, vmidInfo, ips, workload.Status))
}
}
@@ -357,7 +367,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
for _, workload := range noParent {
ips := unifiedresources.ResourceIPSummary(workload, 2)
sections = append(sections, fmt.Sprintf(" - **%s** (%s)%s [%s]",
- unifiedresources.ResourcePolicyLabel(workload.Name, workload.AISafeSummary, workload.Policy), workload.Type, ips, workload.Status))
+ policyContext.resourceLabel(workload.Name, workload.AISafeSummary, workload.Policy), workload.Type, ips, workload.Status))
}
}
}
@@ -401,7 +411,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s**%s%s [%s]",
- unifiedresources.ResourcePolicyLabel(pool.Name, pool.AISafeSummary, pool.Policy), typeLabel, usage, pool.Status))
+ policyContext.resourceLabel(pool.Name, pool.AISafeSummary, pool.Policy), typeLabel, usage, pool.Status))
}
}
@@ -441,7 +451,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
}
sections = append(sections, fmt.Sprintf("- **%s**%s%s [%s]",
- unifiedresources.ResourcePolicyLabel(disk.Name, disk.AISafeSummary, disk.Policy), healthSummary, temperature, disk.Status))
+ policyContext.resourceLabel(disk.Name, disk.AISafeSummary, disk.Policy), healthSummary, temperature, disk.Status))
}
}
}
@@ -464,7 +474,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
omittedLocalOnlyAlerts++
continue
}
- displayName = unifiedresources.ResourcePolicyLabel(resource.Name, resource.AISafeSummary, resource.Policy)
+ displayName = policyContext.resourceLabel(resource.Name, resource.AISafeSummary, resource.Policy)
message = unifiedresources.ResourcePolicyRedactedText(message, resource)
} else if displayName == "" {
displayName = resourceID
@@ -552,7 +562,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
cpuPercent = unifiedMetricPercent(resource.Metrics.CPU)
}
sections = append(sections, fmt.Sprintf("%d. **%s** (%s): %.1f%%",
- i+1, unifiedresources.ResourcePolicyLabel(resource.Name, resource.AISafeSummary, resource.Policy), resource.Type, cpuPercent))
+ i+1, policyContext.resourceLabel(resource.Name, resource.AISafeSummary, resource.Policy), resource.Type, cpuPercent))
}
}
@@ -565,7 +575,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
memPercent = unifiedMetricPercent(resource.Metrics.Memory)
}
sections = append(sections, fmt.Sprintf("%d. **%s** (%s): %.1f%%",
- i+1, unifiedresources.ResourcePolicyLabel(resource.Name, resource.AISafeSummary, resource.Policy), resource.Type, memPercent))
+ i+1, policyContext.resourceLabel(resource.Name, resource.AISafeSummary, resource.Policy), resource.Type, memPercent))
}
}
@@ -578,7 +588,7 @@ func (s *Service) buildUnifiedResourceContextForModel(destinationModel string) s
diskPercent = unifiedMetricPercent(resource.Metrics.Disk)
}
sections = append(sections, fmt.Sprintf("%d. **%s** (%s): %.1f%%",
- i+1, unifiedresources.ResourcePolicyLabel(resource.Name, resource.AISafeSummary, resource.Policy), resource.Type, diskPercent))
+ i+1, policyContext.resourceLabel(resource.Name, resource.AISafeSummary, resource.Policy), resource.Type, diskPercent))
}
}
diff --git a/internal/ai/resource_context_policy_model.go b/internal/ai/resource_context_policy_model.go
index ecc82f860a..7545e226a8 100644
--- a/internal/ai/resource_context_policy_model.go
+++ b/internal/ai/resource_context_policy_model.go
@@ -12,6 +12,8 @@ import (
type unifiedResourcePolicyContext struct {
posture *unifiedresources.PolicyPostureSummary
externalModel bool
+ localModel bool
+ cloudPrivacy string
sensitivityCounts map[unifiedresources.ResourceSensitivity]int
routingCounts map[unifiedresources.ResourceRoutingScope]int
localOnlyCount int
@@ -19,9 +21,12 @@ type unifiedResourcePolicyContext struct {
redactionLabels []string
}
-func buildUnifiedResourcePolicyContext(posture *unifiedresources.PolicyPostureSummary, destinationModel string) unifiedResourcePolicyContext {
+func buildUnifiedResourcePolicyContext(posture *unifiedresources.PolicyPostureSummary, destinationModel, cloudPrivacy string) unifiedResourcePolicyContext {
+ normalizedPrivacy, _ := config.NormalizeCloudContextPrivacy(cloudPrivacy)
context := unifiedResourcePolicyContext{
externalModel: unifiedResourceContextUsesExternalModel(destinationModel),
+ localModel: unifiedResourceContextUsesLocalModel(destinationModel),
+ cloudPrivacy: normalizedPrivacy,
posture: posture,
sensitivityCounts: map[unifiedresources.ResourceSensitivity]int{},
routingCounts: map[unifiedresources.ResourceRoutingScope]int{},
@@ -54,6 +59,18 @@ func unifiedResourceContextUsesExternalModel(destinationModel string) bool {
return provider != config.AIProviderOllama
}
+// unifiedResourceContextUsesLocalModel reports whether the destination is a KNOWN
+// local (Ollama) model. An empty/unknown destination is neither external nor
+// local, so it fails closed to redaction rather than being treated as local.
+func unifiedResourceContextUsesLocalModel(destinationModel string) bool {
+ destinationModel = strings.TrimSpace(destinationModel)
+ if destinationModel == "" {
+ return false
+ }
+ provider, _ := config.ParseModelString(destinationModel)
+ return provider == config.AIProviderOllama
+}
+
func (context unifiedResourcePolicyContext) hasGovernedResources() bool {
return context.posture != nil && context.posture.TotalResources > 0
}
@@ -65,6 +82,43 @@ func (context unifiedResourcePolicyContext) includeResourceDetails(resource unif
return resource.Policy.Routing.Scope != unifiedresources.ResourceRoutingScopeLocalOnly
}
+// resourceLabel renders a resource's display name for the model-bound inventory
+// context, honoring the cloud_context_privacy dial. Local models always get the
+// real name (local is always full). For cloud models, the "full" dial shows real
+// names EXCEPT for resources the engine routes local-only (the hard floor, which
+// stays redacted even at full); "redacted"/"local_only" fall back to the governed
+// label. This is the inventory-context half of the dial — the prefetch and the
+// model-boundary sanitizer enforce the same posture on their paths.
+func (context unifiedResourcePolicyContext) resourceLabel(name, aiSafeSummary string, policy *unifiedresources.ResourcePolicy) string {
+ if context.allowsRealIdentifier(policy) {
+ if trimmed := strings.TrimSpace(name); trimmed != "" {
+ return trimmed
+ }
+ }
+ return unifiedresources.ResourcePolicyLabel(name, aiSafeSummary, policy)
+}
+
+// allowsRealIdentifier reports whether the real resource identifier may be shown
+// for this destination given the dial. Known-local (Ollama) => always. Cloud =>
+// only at "full" and only when the resource is not routed local-only. An
+// unknown/empty destination fails closed to redaction (it could reach a cloud
+// model), preserving the historical safe default for the no-destination path.
+func (context unifiedResourcePolicyContext) allowsRealIdentifier(policy *unifiedresources.ResourcePolicy) bool {
+ if context.localModel {
+ return true
+ }
+ if !context.externalModel {
+ return false
+ }
+ if context.cloudPrivacy != config.CloudContextPrivacyFull {
+ return false
+ }
+ if policy != nil && policy.Routing.Scope == unifiedresources.ResourceRoutingScopeLocalOnly {
+ return false
+ }
+ return true
+}
+
func (context unifiedResourcePolicyContext) filterDetailedResources(resources []unifiedresources.Resource) []unifiedresources.Resource {
if !context.externalModel || len(resources) == 0 {
return resources
diff --git a/internal/ai/resource_context_policy_model_test.go b/internal/ai/resource_context_policy_model_test.go
index d778509e43..9bd24da202 100644
--- a/internal/ai/resource_context_policy_model_test.go
+++ b/internal/ai/resource_context_policy_model_test.go
@@ -49,7 +49,7 @@ func TestBuildUnifiedResourcePolicyContext(t *testing.T) {
},
})
- context := buildUnifiedResourcePolicyContext(unifiedresources.SummarizePolicyPosture(resources), "")
+ context := buildUnifiedResourcePolicyContext(unifiedresources.SummarizePolicyPosture(resources), "", "redacted")
if !context.hasGovernedResources() {
t.Fatal("expected governed posture")
@@ -104,7 +104,7 @@ func TestBuildUnifiedResourcePolicyContextExternalModel(t *testing.T) {
}
resources := unifiedresources.RefreshCanonicalMetadataSlice([]unifiedresources.Resource{localOnly, cloudSummary})
- context := buildUnifiedResourcePolicyContext(unifiedresources.SummarizePolicyPosture(resources), "openai:gpt-4o")
+ context := buildUnifiedResourcePolicyContext(unifiedresources.SummarizePolicyPosture(resources), "openai:gpt-4o", "redacted")
if !context.externalModel {
t.Fatal("expected external model handling")
@@ -124,7 +124,7 @@ func TestBuildUnifiedResourcePolicyContextExternalModel(t *testing.T) {
t.Fatalf("expected external handling summary, got %q", joined)
}
- localContext := buildUnifiedResourcePolicyContext(unifiedresources.SummarizePolicyPosture(resources), "ollama:llama3")
+ localContext := buildUnifiedResourcePolicyContext(unifiedresources.SummarizePolicyPosture(resources), "ollama:llama3", "redacted")
if localContext.externalModel {
t.Fatal("expected ollama destination to stay local")
}
@@ -132,3 +132,70 @@ func TestBuildUnifiedResourcePolicyContextExternalModel(t *testing.T) {
t.Fatal("expected local model context to include local-only resource details")
}
}
+
+func TestUnifiedResourcePolicyContext_ResourceLabelDialAware(t *testing.T) {
+ resources := unifiedresources.RefreshCanonicalMetadataSlice([]unifiedresources.Resource{
+ { // Sensitive -> local-first (shown at full)
+ ID: "vm-1", Name: "finance-vm", Type: unifiedresources.ResourceTypeVM,
+ Status: unifiedresources.StatusOnline, Tags: []string{"sensitive"},
+ Identity: unifiedresources.ResourceIdentity{Hostnames: []string{"finance.lan"}},
+ },
+ { // Restricted -> local-only (hard floor, redacted even at full)
+ ID: "agent-1", Name: "vault", Type: unifiedresources.ResourceTypeAgent,
+ Status: unifiedresources.StatusOnline, Tags: []string{"secret"},
+ Identity: unifiedresources.ResourceIdentity{Hostnames: []string{"vault.lan"}},
+ },
+ { // Internal -> cloud-summary (real name everywhere)
+ ID: "vm-2", Name: "web", Type: unifiedresources.ResourceTypeVM,
+ Status: unifiedresources.StatusOnline,
+ },
+ })
+ sens, restr, intern := resources[0], resources[1], resources[2]
+ posture := unifiedresources.SummarizePolicyPosture(resources)
+ label := func(ctx unifiedResourcePolicyContext, r unifiedresources.Resource) string {
+ return ctx.resourceLabel(r.Name, r.AISafeSummary, r.Policy)
+ }
+ // The governed (non-real-name) rendering for a redacted resource — the AI-safe
+ // summary when present, else the bare placeholder. The real-resource name must
+ // never equal this.
+ governed := func(r unifiedresources.Resource) string {
+ return unifiedresources.ResourcePolicyLabel(r.Name, r.AISafeSummary, r.Policy)
+ }
+ if governed(sens) == "finance-vm" || governed(restr) == "vault" {
+ t.Fatalf("test fixture invalid: governed labels should not be the real names (sens=%q restr=%q)", governed(sens), governed(restr))
+ }
+
+ // Local model: everything shows its real name (local is always full).
+ local := buildUnifiedResourcePolicyContext(posture, "ollama:llama3", "redacted")
+ if got := label(local, sens); got != "finance-vm" {
+ t.Fatalf("local sensitive label = %q, want real name", got)
+ }
+ if got := label(local, restr); got != "vault" {
+ t.Fatalf("local restricted label = %q, want real name", got)
+ }
+
+ // Cloud + full: sensitive shows its real name, restricted stays governed
+ // (local-only hard floor), internal shows.
+ full := buildUnifiedResourcePolicyContext(posture, "openai:gpt-4o", "full")
+ if got := label(full, sens); got != "finance-vm" {
+ t.Fatalf("cloud-full sensitive label = %q, want real name", got)
+ }
+ if got := label(full, restr); got != governed(restr) {
+ t.Fatalf("cloud-full restricted label = %q, want governed floor %q", got, governed(restr))
+ }
+ if got := label(full, intern); got != "web" {
+ t.Fatalf("cloud-full internal label = %q, want real name", got)
+ }
+
+ // Cloud + redacted: both governed resources are redacted; internal still shows.
+ red := buildUnifiedResourcePolicyContext(posture, "openai:gpt-4o", "redacted")
+ if got := label(red, sens); got != governed(sens) {
+ t.Fatalf("cloud-redacted sensitive label = %q, want governed %q", got, governed(sens))
+ }
+ if got := label(red, restr); got != governed(restr) {
+ t.Fatalf("cloud-redacted restricted label = %q, want governed %q", got, governed(restr))
+ }
+ if got := label(red, intern); got != "web" {
+ t.Fatalf("cloud-redacted internal label = %q, want real name", got)
+ }
+}