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.

Centralize export decision helpers

rcourtmanec5ea5ec2c25
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 82eb9510a2..b6e1de58dd 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -141,6 +141,10 @@ boundary. When the AI service assembles unified-resource context for a model
request, it must record a durable export audit with the active destination
model and governed redaction decision instead of treating the prompt boundary
as a transient formatting step.
+That export decision must come from the shared unified-resource privacy
+helpers, so sensitivity floors and redaction-triggered routing stay aligned
+with the canonical policy contract instead of being recomputed in AI-local
+code.
The same AI runtime boundary now also consumes the canonical unified-resource
timeline when it assembles rich resource or incident context. Recent-change
context should come from the shared resource store first so AI prompts reflect
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 3b825ba9c2..126d4d419c 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -432,6 +432,10 @@ redaction hints for hostname, IP, platform-identity, alias, and path-bearing
surfaces. Downstream API, AI, and frontend consumers may read those fields,
but they must not replace them with local sensitivity inference or ad hoc
privacy heuristics.
+Shared privacy helpers also own the export sensitivity floor and route
+decision derived from those canonical policy counts, so AI export audits and
+route decisions reuse the same governed boundary logic instead of rebuilding
+it in consumer packages.
The AI runtime now also uses the canonical policy presentation helpers to
surface those routing and redaction labels in shared context output, so the
same policy model is reflected in prompt summaries instead of being
diff --git a/internal/ai/resource_export.go b/internal/ai/resource_export.go
index 0fbeda5dca..03985080cc 100644
--- a/internal/ai/resource_export.go
+++ b/internal/ai/resource_export.go
@@ -53,8 +53,8 @@ func (s *Service) recordUnifiedResourceExport(destinationModel, summary string,
sort.Strings(redactions)
redactions = uniqueStrings(redactions)
- sensitivityFloor := unifiedResourceExportSensitivityFloor(sensitivityCounts)
- decision, reason := unifiedResourceExportDecision(sensitivityFloor, localOnlyCount, len(redactions))
+ sensitivityFloor := unifiedresources.ExportSensitivityFloor(sensitivityCounts)
+ decision, reason := unifiedresources.ExportDecisionForContext(sensitivityFloor, localOnlyCount, len(redactions))
infraCount := stats.ByType[unifiedresources.ResourceTypeAgent] +
stats.ByType[unifiedresources.ResourceTypeK8sCluster] +
@@ -123,37 +123,6 @@ func (s *Service) recordUnifiedResourceExport(destinationModel, summary string,
}
}
-func unifiedResourceExportSensitivityFloor(counts map[unifiedresources.ResourceSensitivity]int) unifiedresources.DataSensitivity {
- if counts == nil {
- return unifiedresources.SensitivityPublic
- }
- if counts[unifiedresources.ResourceSensitivityRestricted] > 0 {
- return unifiedresources.SensitivityRestricted
- }
- if counts[unifiedresources.ResourceSensitivitySensitive] > 0 {
- return unifiedresources.SensitivitySensitive
- }
- if counts[unifiedresources.ResourceSensitivityInternal] > 0 {
- return unifiedresources.SensitivityInternal
- }
- return unifiedresources.SensitivityPublic
-}
-
-func unifiedResourceExportDecision(sensitivityFloor unifiedresources.DataSensitivity, localOnlyCount int, redactionCount int) (unifiedresources.ExportDecision, string) {
- if localOnlyCount > 0 || redactionCount > 0 {
- return unifiedresources.ExportRedacted, "governed unified resource context exported in redacted form"
- }
-
- switch sensitivityFloor {
- case unifiedresources.SensitivityRestricted, unifiedresources.SensitivitySensitive:
- return unifiedresources.ExportRedacted, "governed unified resource context exported in redacted form"
- case unifiedresources.SensitivityInternal:
- return unifiedresources.ExportRequiresConsent, "internal unified resource context requires export consent"
- default:
- return unifiedresources.ExportAllowed, "public unified resource context"
- }
-}
-
func uniqueStrings(values []string) []string {
if len(values) <= 1 {
return values
diff --git a/internal/ai/resource_export_test.go b/internal/ai/resource_export_test.go
new file mode 100644
index 0000000000..fa40b28a5d
--- /dev/null
+++ b/internal/ai/resource_export_test.go
@@ -0,0 +1,110 @@
+package ai
+
+import (
+ "testing"
+ "time"
+
+ unifiedresources "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
+)
+
+func TestRecordUnifiedResourceExport_UsesCanonicalPrivacyHelpers(t *testing.T) {
+ cases := []struct {
+ name string
+ counts map[unifiedresources.ResourceSensitivity]int
+ localOnlyCount int
+ redactionHints []unifiedresources.ResourceRedactionHint
+ wantDecision unifiedresources.ExportDecision
+ wantReason string
+ wantRedactions []string
+ }{
+ {
+ name: "public",
+ counts: map[unifiedresources.ResourceSensitivity]int{unifiedresources.ResourceSensitivityPublic: 1},
+ wantDecision: unifiedresources.ExportAllowed,
+ wantReason: "public unified resource context",
+ wantRedactions: nil,
+ },
+ {
+ name: "internal",
+ counts: map[unifiedresources.ResourceSensitivity]int{unifiedresources.ResourceSensitivityInternal: 1},
+ wantDecision: unifiedresources.ExportRequiresConsent,
+ wantReason: "internal unified resource context requires export consent",
+ wantRedactions: nil,
+ },
+ {
+ name: "redacted",
+ counts: map[unifiedresources.ResourceSensitivity]int{unifiedresources.ResourceSensitivitySensitive: 1},
+ localOnlyCount: 1,
+ redactionHints: []unifiedresources.ResourceRedactionHint{
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionHostname,
+ unifiedresources.ResourceRedactionPath,
+ },
+ wantDecision: unifiedresources.ExportRedacted,
+ wantReason: "governed unified resource context exported in redacted form",
+ wantRedactions: []string{"hostname", "path"},
+ },
+ }
+
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ store := unifiedresources.NewMemoryStore()
+ svc := &Service{
+ orgID: "org-1",
+ resourceExportStore: store,
+ resourceExportStoreOrgID: "org-1",
+ }
+
+ svc.recordUnifiedResourceExport(
+ "anthropic:test-model",
+ "canonical summary",
+ unifiedresources.ResourceStats{
+ Total: 1,
+ ByType: map[unifiedresources.ResourceType]int{
+ unifiedresources.ResourceTypeAgent: 1,
+ },
+ },
+ tc.counts,
+ tc.localOnlyCount,
+ tc.redactionHints,
+ )
+
+ audits, err := store.GetExportAudits(time.Time{}, 10)
+ if err != nil {
+ t.Fatalf("GetExportAudits: %v", err)
+ }
+ if len(audits) != 1 {
+ t.Fatalf("expected 1 export audit, got %d", len(audits))
+ }
+ if audits[0].Decision != tc.wantDecision {
+ t.Fatalf("decision = %q, want %q", audits[0].Decision, tc.wantDecision)
+ }
+ if audits[0].Destination != "anthropic:test-model" {
+ t.Fatalf("destination = %q, want anthropic:test-model", audits[0].Destination)
+ }
+ if audits[0].EnvelopeHash == "" {
+ t.Fatal("expected envelope hash to be recorded")
+ }
+ if len(audits[0].Redactions) != len(tc.wantRedactions) {
+ t.Fatalf("redactions = %#v, want %#v", audits[0].Redactions, tc.wantRedactions)
+ }
+ for i := range tc.wantRedactions {
+ if audits[0].Redactions[i] != tc.wantRedactions[i] {
+ t.Fatalf("redactions = %#v, want %#v", audits[0].Redactions, tc.wantRedactions)
+ }
+ }
+
+ decision, reason := unifiedresources.ExportDecisionForContext(
+ unifiedresources.ExportSensitivityFloor(tc.counts),
+ tc.localOnlyCount,
+ len(tc.wantRedactions),
+ )
+ if decision != tc.wantDecision {
+ t.Fatalf("shared decision = %q, want %q", decision, tc.wantDecision)
+ }
+ if reason != tc.wantReason {
+ t.Fatalf("shared reason = %q, want %q", reason, tc.wantReason)
+ }
+ })
+ }
+}
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index 9b3d156140..d0fd5d4ee6 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -351,6 +351,40 @@ func TestResourcePolicyLabelHelpersUsedByAIConsumers(t *testing.T) {
}
}
+func TestExportDecisionHelpersUsedByAIConsumers(t *testing.T) {
+ data, err := os.ReadFile(filepath.Join("..", "ai", "resource_export.go"))
+ if err != nil {
+ t.Fatalf("failed to read resource_export.go: %v", err)
+ }
+ source := string(data)
+ requiredSnippets := []string{
+ "unifiedresources.ExportSensitivityFloor(sensitivityCounts)",
+ "unifiedresources.ExportDecisionForContext(sensitivityFloor, localOnlyCount, len(redactions))",
+ }
+ for _, snippet := range requiredSnippets {
+ if !strings.Contains(source, snippet) {
+ t.Fatalf("internal/ai/resource_export.go must pin canonical export decision snippet %q", snippet)
+ }
+ }
+}
+
+func TestExportDecisionHelpersCanonicalInUnifiedResources(t *testing.T) {
+ data, err := os.ReadFile(filepath.Join("privacy.go"))
+ if err != nil {
+ t.Fatalf("failed to read privacy.go: %v", err)
+ }
+ source := string(data)
+ requiredSnippets := []string{
+ "func ExportSensitivityFloor(counts map[ResourceSensitivity]int) DataSensitivity",
+ "func ExportDecisionForContext(sensitivityFloor DataSensitivity, localOnlyCount int, redactionCount int) (ExportDecision, string)",
+ }
+ for _, snippet := range requiredSnippets {
+ if !strings.Contains(source, snippet) {
+ t.Fatalf("internal/unifiedresources/privacy.go must pin canonical export helper snippet %q", snippet)
+ }
+ }
+}
+
func TestResourceDisplayNameUsedByInfrastructureConsumers(t *testing.T) {
requiredSnippets := map[string][]string{
filepath.Join("..", "monitoring", "connected_infrastructure.go"): {
diff --git a/internal/unifiedresources/privacy.go b/internal/unifiedresources/privacy.go
index fb5dc4fcb3..fee90d3f78 100644
--- a/internal/unifiedresources/privacy.go
+++ b/internal/unifiedresources/privacy.go
@@ -56,3 +56,38 @@ type ExportAuditRecord struct {
Destination string `json:"destination"`
Redactions []string `json:"redactions,omitempty"`
}
+
+// ExportSensitivityFloor returns the canonical highest data-sensitivity floor
+// represented by the supplied resource sensitivity counts.
+func ExportSensitivityFloor(counts map[ResourceSensitivity]int) DataSensitivity {
+ if counts == nil {
+ return SensitivityPublic
+ }
+ if counts[ResourceSensitivityRestricted] > 0 {
+ return SensitivityRestricted
+ }
+ if counts[ResourceSensitivitySensitive] > 0 {
+ return SensitivitySensitive
+ }
+ if counts[ResourceSensitivityInternal] > 0 {
+ return SensitivityInternal
+ }
+ return SensitivityPublic
+}
+
+// ExportDecisionForContext returns the canonical export decision and reason for
+// governed unified-resource context payloads.
+func ExportDecisionForContext(sensitivityFloor DataSensitivity, localOnlyCount int, redactionCount int) (ExportDecision, string) {
+ if localOnlyCount > 0 || redactionCount > 0 {
+ return ExportRedacted, "governed unified resource context exported in redacted form"
+ }
+
+ switch sensitivityFloor {
+ case SensitivityRestricted, SensitivitySensitive:
+ return ExportRedacted, "governed unified resource context exported in redacted form"
+ case SensitivityInternal:
+ return ExportRequiresConsent, "internal unified resource context requires export consent"
+ default:
+ return ExportAllowed, "public unified resource context"
+ }
+}
diff --git a/internal/unifiedresources/privacy_test.go b/internal/unifiedresources/privacy_test.go
new file mode 100644
index 0000000000..1ffb84be1d
--- /dev/null
+++ b/internal/unifiedresources/privacy_test.go
@@ -0,0 +1,52 @@
+package unifiedresources
+
+import "testing"
+
+func TestExportSensitivityFloor(t *testing.T) {
+ if got := ExportSensitivityFloor(nil); got != SensitivityPublic {
+ t.Fatalf("ExportSensitivityFloor(nil) = %q, want %q", got, SensitivityPublic)
+ }
+
+ counts := map[ResourceSensitivity]int{
+ ResourceSensitivityPublic: 2,
+ ResourceSensitivityInternal: 1,
+ ResourceSensitivitySensitive: 3,
+ ResourceSensitivityRestricted: 4,
+ }
+ if got := ExportSensitivityFloor(counts); got != SensitivityRestricted {
+ t.Fatalf("ExportSensitivityFloor(restricted) = %q, want %q", got, SensitivityRestricted)
+ }
+
+ delete(counts, ResourceSensitivityRestricted)
+ if got := ExportSensitivityFloor(counts); got != SensitivitySensitive {
+ t.Fatalf("ExportSensitivityFloor(sensitive) = %q, want %q", got, SensitivitySensitive)
+ }
+
+ delete(counts, ResourceSensitivitySensitive)
+ if got := ExportSensitivityFloor(counts); got != SensitivityInternal {
+ t.Fatalf("ExportSensitivityFloor(internal) = %q, want %q", got, SensitivityInternal)
+ }
+
+ delete(counts, ResourceSensitivityInternal)
+ if got := ExportSensitivityFloor(counts); got != SensitivityPublic {
+ t.Fatalf("ExportSensitivityFloor(public) = %q, want %q", got, SensitivityPublic)
+ }
+}
+
+func TestExportDecisionForContext(t *testing.T) {
+ if got, reason := ExportDecisionForContext(SensitivityPublic, 0, 0); got != ExportAllowed || reason != "public unified resource context" {
+ t.Fatalf("public decision = (%q, %q), want (%q, %q)", got, reason, ExportAllowed, "public unified resource context")
+ }
+ if got, reason := ExportDecisionForContext(SensitivityInternal, 0, 0); got != ExportRequiresConsent || reason != "internal unified resource context requires export consent" {
+ t.Fatalf("internal decision = (%q, %q), want (%q, %q)", got, reason, ExportRequiresConsent, "internal unified resource context requires export consent")
+ }
+ if got, reason := ExportDecisionForContext(SensitivitySensitive, 0, 0); got != ExportRedacted || reason != "governed unified resource context exported in redacted form" {
+ t.Fatalf("sensitive decision = (%q, %q), want (%q, %q)", got, reason, ExportRedacted, "governed unified resource context exported in redacted form")
+ }
+ if got, reason := ExportDecisionForContext(SensitivityPublic, 1, 0); got != ExportRedacted || reason != "governed unified resource context exported in redacted form" {
+ t.Fatalf("local-only decision = (%q, %q), want (%q, %q)", got, reason, ExportRedacted, "governed unified resource context exported in redacted form")
+ }
+ if got, reason := ExportDecisionForContext(SensitivityPublic, 0, 1); got != ExportRedacted || reason != "governed unified resource context exported in redacted form" {
+ t.Fatalf("redaction decision = (%q, %q), want (%q, %q)", got, reason, ExportRedacted, "governed unified resource context exported in redacted form")
+ }
+}