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.

Retain reader authority across delayed agent snapshots

pulse-triage[bot]49db768487db
diff --git a/internal/api/agent_command_redaction.go b/internal/api/agent_command_redaction.go
index 214ebdc050..00e6f3b0a4 100644
--- a/internal/api/agent_command_redaction.go
+++ b/internal/api/agent_command_redaction.go
@@ -8,6 +8,24 @@ import (
unified "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
)
+// Context and history can wait for stores or providers after authentication.
+// Keep both the read authority and any command-disclosure authority used by
+// their projections until disclosure. Never refresh an old request into a
+// different reader or retry its lookup with wider/different authority.
+func retainAgentCommandResponseAuthority(cfg *config.Config, next http.HandlerFunc) http.HandlerFunc {
+ read := retainTokenResponseAuthority(cfg, config.ScopeMonitoringRead, false, next)
+ // These scopes are BOTH required for a command-bearing projection, not
+ // interchangeable alternatives. Monitoring-only reads keep redaction.
+ commandRead := retainTokenResponseAuthority(cfg, config.ScopeAIExecute, false, read)
+ return func(w http.ResponseWriter, r *http.Request) {
+ if token := getAPITokenRecordFromRequest(r); token != nil && token.HasScope(config.ScopeAIExecute) {
+ commandRead(w, r)
+ return
+ }
+ read(w, r)
+ }
+}
+
func requestCanReadAgentCommandPayloads(r *http.Request) bool {
token := getAPITokenRecordFromRequest(r)
if token == nil {
diff --git a/internal/api/agent_recent_changes.go b/internal/api/agent_recent_changes.go
index e732f996b2..ea929dabea 100644
--- a/internal/api/agent_recent_changes.go
+++ b/internal/api/agent_recent_changes.go
@@ -8,28 +8,9 @@ import (
"time"
"github.com/rcourtman/pulse-go-rewrite/internal/agentcapabilities"
- "github.com/rcourtman/pulse-go-rewrite/internal/config"
unified "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"
)
-// History can wait for its store and current inventory after authentication.
-// Keep both the read authority and any command-disclosure authority used by
-// that projection until the response is written. Do not refresh an old request
-// into a different reader or retry its lookup with wider/different authority.
-func retainAgentHistoryResponseAuthority(cfg *config.Config, next http.HandlerFunc) http.HandlerFunc {
- read := retainTokenResponseAuthority(cfg, config.ScopeMonitoringRead, false, next)
- // Compose the existing synchronous guards: these scopes are BOTH required
- // for a command-bearing projection, not interchangeable alternatives.
- commandRead := retainTokenResponseAuthority(cfg, config.ScopeAIExecute, false, read)
- return func(w http.ResponseWriter, r *http.Request) {
- if token := getAPITokenRecordFromRequest(r); token != nil && token.HasScope(config.ScopeAIExecute) {
- commandRead(w, r)
- return
- }
- read(w, r)
- }
-}
-
// AgentRecentChange is one observed resource change as an agent reads it:
// the canonical change record plus the resource's current name and type,
// which the store does not keep. ResourceName and ResourceType are empty when
diff --git a/internal/api/router_routes_monitoring.go b/internal/api/router_routes_monitoring.go
index 7fac26305a..a972730acc 100644
--- a/internal/api/router_routes_monitoring.go
+++ b/internal/api/router_routes_monitoring.go
@@ -108,7 +108,7 @@ func (r *Router) registerMonitoringResourceRoutes(
// resource + operator-state + findings + audit calls.
r.mux.HandleFunc("/api/agent/resource-context/{id}", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.withExternalAgentCapabilityActivity(
agentcapabilities.ResourceContextCapabilityName,
- r.agentContextHandler.HandleResourceContext,
+ retainAgentCommandResponseAuthority(r.config, r.agentContextHandler.HandleResourceContext),
))))
// Agent-consumable structured capability surface for a single resource.
// Companion to the resource-context bundle above: that renders capabilities
@@ -117,7 +117,7 @@ func (r *Router) registerMonitoringResourceRoutes(
// and params without guessing.
r.mux.HandleFunc("/api/agent/resource-capabilities/{id}", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.withExternalAgentCapabilityActivity(
agentcapabilities.ListResourceCapabilitiesCapabilityName,
- r.agentContextHandler.HandleResourceCapabilities,
+ retainTokenResponseAuthority(r.config, config.ScopeMonitoringRead, false, r.agentContextHandler.HandleResourceCapabilities),
))))
// Agent-consumable fleet triage view — thin per-resource rollups
// across the org so an agent can pick a focus in one read instead
@@ -126,14 +126,14 @@ func (r *Router) registerMonitoringResourceRoutes(
// is "tell me everything about this one."
r.mux.HandleFunc("/api/agent/fleet-context", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.withExternalAgentCapabilityActivity(
agentcapabilities.FleetContextCapabilityName,
- r.agentContextHandler.HandleFleetContext,
+ retainTokenResponseAuthority(r.config, config.ScopeMonitoringRead, false, r.agentContextHandler.HandleFleetContext),
))))
// Agent-consumable change history — "what happened?" across the fleet,
// read from the existing resource change store. Companion to the fleet
// triage view above, which answers "where do I look now?".
r.mux.HandleFunc(agentcapabilities.RecentChangesCapabilityPath, RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.withExternalAgentCapabilityActivity(
agentcapabilities.ListRecentChangesCapabilityName,
- retainAgentHistoryResponseAuthority(r.config, r.agentContextHandler.HandleRecentChanges),
+ retainAgentCommandResponseAuthority(r.config, r.agentContextHandler.HandleRecentChanges),
))))
// Agent-consumable metric history — "how did it move?" for one resource,
// served by the same history read the charts use.
@@ -146,13 +146,13 @@ func (r *Router) registerMonitoringResourceRoutes(
// readiness projection for native UI and external agents.
r.mux.HandleFunc(agentcapabilities.PatrolControlStatusCapabilityPath, RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.withExternalAgentCapabilityActivity(
agentcapabilities.PatrolControlStatusCapabilityName,
- r.agentContextHandler.HandleOperationsLoopStatus,
+ retainTokenResponseAuthority(r.config, config.ScopeMonitoringRead, false, r.agentContextHandler.HandleOperationsLoopStatus),
))))
// Legacy operations-loop route kept for older external-agent clients. New
// clients should discover the Patrol control route from the manifest.
r.mux.HandleFunc(agentcapabilities.OperationsLoopStatusCompatibilityPath, RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.withExternalAgentCapabilityActivity(
agentcapabilities.OperationsLoopStatusCapabilityName,
- r.agentContextHandler.HandleOperationsLoopStatus,
+ retainTokenResponseAuthority(r.config, config.ScopeMonitoringRead, false, r.agentContextHandler.HandleOperationsLoopStatus),
))))
// Agent capabilities manifest — discovery document. Unauthenticated
// because it only describes the agent surface; the capabilities