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
Refuse action execution when approved plan hash drifts from payload
rcourtmana9e652e05bad
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 28f029fa80..1b03badd44 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -288,6 +288,21 @@ runtime cost control, and shared AI transport surfaces.and to leave `impact` empty rather than fabricate one when theconsequence is genuinely unknown; the runtime must not synthesize adefault in that case.+ The action broker enforces a plan-hash drift check at the execute+ boundary: when an approval ID resolves to a stored plan with a+ PlanHash, the freshly-recomputed approval-equivalent hash from the+ actual payload (using `approvalPlanHash`, the same function used at+ approval-creation time) must match. Mismatch returns+ `ErrActionPlanDrift` and refuses dispatch; the contract is "the+ operator approved exactly this (command, target, reason)+ combination" and a different one cannot run under the stale+ approval. When `approvedHash` is empty (older approval records, or+ contract paths that did not author one), validation is skipped to+ preserve existing behavior. The check is currently wired in+ `executeCommandWithAudit` for shell-command actions; the native-+ action path uses a different hash function (`actionPlanHashForParams`)+ so a coherent canonical-hash refactor must precede adding the same+ check there.`FindingsStore.GetTrustSummary` returns a snapshot of how currentlytracked findings have resolved (tracked, currently-active, resolved,auto-resolved, fix-verified, fix-failed, dismissed-as-noise,diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.mdindex 5fcd3d1a1b..b181182c12 100644--- a/docs/release-control/v6/internal/subsystems/unified-resources.md+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md@@ -492,6 +492,23 @@ AI-only summary payloads, or page-local heuristics.`frontend-modern/src/features/infrastructure/useInfrastructurePageState.ts`and the unified-resource selectors it composes. The header must not becomea second state owner, scope banner, or provider-local filter surface.+20. Keep governed-action drift refusal canonical in+ `internal/unifiedresources/actions.go`. `ErrActionPlanDrift` is the+ error any broker must return when the payload presented at execute+ time hashes to anything different than the approval-recorded+ `planHash`. Brokers must refuse rather than silently downgrade drift+ into a generic execution error or "plan expired" outcome — those+ are distinct refusal kinds (operator never approved vs operator+ approved a different action vs approval window passed) and audit+ review and operator UI surfaces should treat them differently. The+ drift contract is "the operator approved exactly this (command,+ target, reason) combination"; the freshly-recomputed+ approval-equivalent hash and the recorded `planHash` are how we+ enforce that. New broker call sites that introduce additional+ governed-action paths must either reuse the existing approval-+ equivalent hash or extend the canonical hash set in+ `internal/ai/tools/action_audit.go` rather than adding ad-hoc+ comparison logic.## Current State@@ -2155,6 +2172,20 @@ Action plans in `actions.go` still keep stale-plan protection to the canonical`resourceVersion`, `policyVersion`, and `planHash` fields, so stale executionchecks stay in the shared resource action model rather than provider-localhelpers.++`actions.go` also owns the canonical drift error vocabulary for the+governed-action broker. `ErrActionPlanDrift` is returned by brokers when+the payload presented at execute time hashes to anything different than+the approval-recorded `planHash`. Brokers must refuse execution rather+than silently downgrade drift into a generic execution error or a+"plan expired" outcome: the contract is "the operator approved exactly+this (command, target, reason) combination" and a different combination+cannot run under the stale approval. The error sits alongside+`ErrActionNotApproved`, `ErrActionPlanExpired`, and the other governed+refusal kinds so callers can distinguish "operator never approved" from+"operator approved a different action" from "approval window passed" —+each is a distinct safety failure that audit review and operator UI+surfaces should treat differently.The shared change presentation helper also owns the canonical kind, sourcetype, and source adapter labels for those timeline entries, so summary cardsand drawer history surfaces both read the same badge vocabulary instead ofdiff --git a/internal/ai/tools/action_audit.go b/internal/ai/tools/action_audit.goindex 0006b23915..40040a16a8 100644--- a/internal/ai/tools/action_audit.go+++ b/internal/ai/tools/action_audit.go@@ -74,6 +74,32 @@ func (e *PulseToolExecutor) executeCommandWithAudit(}approvalRecords := approvalRecordsForID(approvalID)+ // Plan-drift check: the operator approved a specific command + target ++ // reason combination, and the broker must refuse to run a different one+ // even when the approval ID resolves. Compares the approved hash against+ // a freshly-recomputed approval-equivalent hash from the actual payload.+ if planFromApproval {+ if driftErr := validateApprovedCommandPlanHash(+ plan.PlanHash,+ plan.ActionID,+ plan.RequestID,+ capabilityName,+ resourceID,+ payload.Command,+ payload.TargetType,+ payload.TargetID,+ reason,+ ); driftErr != nil {+ log.Warn().+ Str("action_id", plan.ActionID).+ Str("approval_id", approvalID).+ Str("capability", capabilityName).+ Err(driftErr).+ Msg("Refusing action execution: payload does not match approved plan hash")+ return nil, driftErr+ }+ }+record := unifiedresources.ActionAuditRecord{ID: actionID,CreatedAt: now,@@ -725,6 +751,34 @@ func approvalAuditResourceID(targetType, targetID, targetName string) string {return targetType + ":" + targetID}+// validateApprovedCommandPlanHash recomputes the approval-equivalent plan+// hash from the actual payload presented at execute time and compares it to+// the hash recorded at approval time. If approvedHash is empty (older+// approval records, or contract paths that did not author one), validation+// is skipped and existing behavior is preserved. If the hashes differ, the+// broker must refuse execution: the operator approved a specific command ++// target + reason combination, and a different one is now being requested.+//+// The hash function used here matches `approvalPlanHash` (the function+// invoked at approval-creation time) so direct comparison is meaningful.+// `actionPlanHash` shape differs slightly (no field-level whitespace+// trimming) and would produce false-positive drift on legitimate payloads.+func validateApprovedCommandPlanHash(+ approvedHash string,+ actionID, requestID, capabilityName, resourceID string,+ command, targetType, targetID, reason string,+) error {+ approvedHash = strings.TrimSpace(approvedHash)+ if approvedHash == "" {+ return nil+ }+ fresh := approvalPlanHash(actionID, requestID, capabilityName, resourceID, command, targetType, targetID, reason)+ if fresh == approvedHash {+ return nil+ }+ return fmt.Errorf("%w (approved %s, payload %s)", unifiedresources.ErrActionPlanDrift, approvedHash, fresh)+}+func actionPlanHash(actionID, requestID, capabilityName, resourceID string, payload agentexec.ExecuteCommandPayload, reason string) string {sum := sha256.Sum256([]byte(strings.Join([]string{actionID,diff --git a/internal/ai/tools/action_audit_execution_test.go b/internal/ai/tools/action_audit_execution_test.goindex ccfa1aceef..63b38cfb44 100644--- a/internal/ai/tools/action_audit_execution_test.go+++ b/internal/ai/tools/action_audit_execution_test.go@@ -470,6 +470,184 @@ func TestRecordApprovalDecisionDoesNotRegressExecutingAudit(t *testing.T) {}}+// TestExecuteCommandWithAuditRefusesPayloadDriftAgainstApprovedPlan covers the+// safety guarantee that the operator approved exactly one (command, target,+// reason) combination. If the payload presented at execute time hashes to+// anything different than the approved plan, the broker must refuse rather+// than dispatch a drifted command under a stale approval.+func TestExecuteCommandWithAuditRefusesPayloadDriftAgainstApprovedPlan(t *testing.T) {+ actionStore := unifiedresources.NewMemoryStore()+ approvalStore, err := approval.NewStore(approval.StoreConfig{+ DataDir: t.TempDir(),+ DisablePersistence: true,+ })+ if err != nil {+ t.Fatalf("NewStore: %v", err)+ }+ previousApprovalStore := approval.GetStore()+ approval.SetStore(approvalStore)+ t.Cleanup(func() { approval.SetStore(previousApprovalStore) })++ now := time.Now().UTC()+ approvedHash := approvalPlanHash(+ "act-drift",+ "approval-drift",+ "pulse_control",+ "agent-1",+ "systemctl restart workload",+ "agent",+ "agent-1",+ "restart workload service",+ )+ plan := unifiedresources.ActionPlan{+ ActionID: "act-drift",+ RequestID: "approval-drift",+ Allowed: true,+ RequiresApproval: true,+ ApprovalPolicy: unifiedresources.ApprovalAdmin,+ PlannedAt: now,+ ExpiresAt: now.Add(5 * time.Minute),+ PlanHash: approvedHash,+ }+ req := &approval.ApprovalRequest{+ ID: "approval-drift",+ Command: "systemctl restart workload",+ TargetType: "agent",+ TargetID: "agent-1",+ TargetName: "agent-1",+ Context: "restart workload service",+ Plan: &plan,+ }+ if err := approvalStore.CreateApproval(req); err != nil {+ t.Fatalf("CreateApproval: %v", err)+ }+ if _, err := approvalStore.Approve("approval-drift", "[email protected]"); err != nil {+ t.Fatalf("Approve: %v", err)+ }++ agentServer := &mockAgentServer{}+ executor := NewPulseToolExecutor(ExecutorConfig{+ AgentServer: agentServer,+ ActionAuditStore: actionStore,+ })+ executor.recordPendingApprovalAction(req)++ // Payload deliberately differs from the approved command. The hash check+ // must catch this and refuse.+ result, err := executor.executeCommandWithAudit(+ context.Background(),+ "pulse_control",+ "agent-1",+ "approval-drift",+ true,+ "agent-1",+ agentexec.ExecuteCommandPayload{+ Command: "rm -rf /var/log/pulse",+ TargetType: "agent",+ TargetID: "agent-1",+ },+ "pulse_control",+ "restart workload service",+ )+ if !errors.Is(err, unifiedresources.ErrActionPlanDrift) {+ t.Fatalf("executeCommandWithAudit error = %v, want ErrActionPlanDrift", err)+ }+ if result != nil {+ t.Fatalf("expected nil result on drift refusal, got %#v", result)+ }+ agentServer.AssertNotCalled(t, "ExecuteCommand", mock.Anything, mock.Anything, mock.Anything)+}++// TestExecuteCommandWithAuditAllowsMatchingPlanHash covers the positive case:+// when the payload at execute time hashes identically to the approved plan,+// dispatch proceeds normally.+func TestExecuteCommandWithAuditAllowsMatchingPlanHash(t *testing.T) {+ actionStore := unifiedresources.NewMemoryStore()+ approvalStore, err := approval.NewStore(approval.StoreConfig{+ DataDir: t.TempDir(),+ DisablePersistence: true,+ })+ if err != nil {+ t.Fatalf("NewStore: %v", err)+ }+ previousApprovalStore := approval.GetStore()+ approval.SetStore(approvalStore)+ t.Cleanup(func() { approval.SetStore(previousApprovalStore) })++ now := time.Now().UTC()+ approvedHash := approvalPlanHash(+ "act-match",+ "approval-match",+ "pulse_control",+ "agent-1",+ "uptime",+ "agent",+ "agent-1",+ "check uptime",+ )+ plan := unifiedresources.ActionPlan{+ ActionID: "act-match",+ RequestID: "approval-match",+ Allowed: true,+ RequiresApproval: true,+ ApprovalPolicy: unifiedresources.ApprovalAdmin,+ PlannedAt: now,+ ExpiresAt: now.Add(5 * time.Minute),+ PlanHash: approvedHash,+ }+ req := &approval.ApprovalRequest{+ ID: "approval-match",+ Command: "uptime",+ TargetType: "agent",+ TargetID: "agent-1",+ TargetName: "agent-1",+ Context: "check uptime",+ Plan: &plan,+ }+ if err := approvalStore.CreateApproval(req); err != nil {+ t.Fatalf("CreateApproval: %v", err)+ }+ if _, err := approvalStore.Approve("approval-match", "[email protected]"); err != nil {+ t.Fatalf("Approve: %v", err)+ }++ agentServer := &mockAgentServer{}+ agentServer.On("ExecuteCommand", mock.Anything, "agent-1", mock.Anything).Return(&agentexec.CommandResultPayload{+ Success: true,+ Stdout: "up 4 days",+ ExitCode: 0,+ }, nil).Once()++ executor := NewPulseToolExecutor(ExecutorConfig{+ AgentServer: agentServer,+ ActionAuditStore: actionStore,+ })+ executor.recordPendingApprovalAction(req)++ result, err := executor.executeCommandWithAudit(+ context.Background(),+ "pulse_control",+ "agent-1",+ "approval-match",+ true,+ "agent-1",+ agentexec.ExecuteCommandPayload{+ Command: "uptime",+ TargetType: "agent",+ TargetID: "agent-1",+ },+ "pulse_control",+ "check uptime",+ )+ if err != nil {+ t.Fatalf("executeCommandWithAudit: %v", err)+ }+ if result == nil || result.Stdout != "up 4 days" {+ t.Fatalf("command result = %#v", result)+ }+ agentServer.AssertExpectations(t)+}+func TestExecuteCommandWithDeniedApprovalDoesNotDispatch(t *testing.T) {actionStore := unifiedresources.NewMemoryStore()approvalStore, err := approval.NewStore(approval.StoreConfig{@@ -484,6 +662,20 @@ func TestExecuteCommandWithDeniedApprovalDoesNotDispatch(t *testing.T) {t.Cleanup(func() { approval.SetStore(previousApprovalStore) })now := time.Now().UTC()+ // PlanHash is the approval-equivalent hash of the (command, target,+ // reason) the operator approved. This test covers the denial path, so+ // the hash must match the executing payload to isolate denial as the+ // reason for refusal — otherwise the broker's drift check fires first.+ deniedHash := approvalPlanHash(+ "act-denied-command",+ "approval-denied-command",+ "pulse_control",+ "agent-1",+ "rm -rf /tmp/pulse-test",+ "agent",+ "agent-1",+ "unsafe cleanup command",+ )plan := unifiedresources.ActionPlan{ActionID: "act-denied-command",RequestID: "approval-denied-command",@@ -494,7 +686,7 @@ func TestExecuteCommandWithDeniedApprovalDoesNotDispatch(t *testing.T) {ExpiresAt: now.Add(5 * time.Minute),ResourceVersion: "resource:sha256:test",PolicyVersion: "policy:sha256:test",- PlanHash: "sha256:test",+ PlanHash: deniedHash,}req := &approval.ApprovalRequest{ID: "approval-denied-command",diff --git a/internal/ai/tools/control_run_command_test.go b/internal/ai/tools/control_run_command_test.goindex eccfa5e8c7..5c54c5d06f 100644--- a/internal/ai/tools/control_run_command_test.go+++ b/internal/ai/tools/control_run_command_test.go@@ -158,6 +158,22 @@ func TestPulseToolExecutor_ExecuteRunCommand(t *testing.T) {approval.SetStore(store)defer approval.SetStore(nil)+ // PlanHash is the approval-equivalent hash of the (command, target,+ // reason) the operator approved. The broker's drift check refuses+ // execution when the executing payload hashes to anything different.+ // For this happy-path test, compute the hash with the exact inputs+ // executeCommandWithAudit will see when executeRunCommand routes the+ // approved "uptime" command to the resolved tower agent.+ approvedHash := approvalPlanHash(+ "action-1",+ "approval-1",+ "pulse_control",+ "tower",+ "uptime",+ "agent",+ "",+ `run command "uptime" on tower`,+ )req := &approval.ApprovalRequest{ID: "approval-1",Command: "uptime",@@ -170,7 +186,7 @@ func TestPulseToolExecutor_ExecuteRunCommand(t *testing.T) {RequiresApproval: true,ApprovalPolicy: unifiedresources.ApprovalAdmin,Message: "run command",- PlanHash: "hash-1",+ PlanHash: approvedHash,},}require.NoError(t, store.CreateApproval(req))@@ -222,7 +238,7 @@ func TestPulseToolExecutor_ExecuteRunCommand(t *testing.T) {require.Len(t, audits, 1)assert.Equal(t, "action-1", audits[0].ID)assert.Equal(t, unifiedresources.ActionStateCompleted, audits[0].State)- assert.Equal(t, "hash-1", audits[0].Plan.PlanHash)+ assert.Equal(t, approvedHash, audits[0].Plan.PlanHash)})t.Run("ExecuteSuccess", func(t *testing.T) {diff --git a/internal/unifiedresources/actions.go b/internal/unifiedresources/actions.goindex 943c45f253..74e667646b 100644--- a/internal/unifiedresources/actions.go+++ b/internal/unifiedresources/actions.go@@ -127,8 +127,14 @@ type ActionEngine interface {}var (- ErrActionNotPending = errors.New("action is not pending approval")- ErrActionNotApproved = errors.New("action is not approved for execution")+ ErrActionNotPending = errors.New("action is not pending approval")+ ErrActionNotApproved = errors.New("action is not approved for execution")+ // ErrActionPlanDrift is returned when the payload presented at execute+ // time does not match the plan hash recorded at approval time. The hash+ // is the contract for "the operator approved exactly this action"; if+ // it does not match, the broker must refuse execution rather than run a+ // drifted plan under a stale approval.+ ErrActionPlanDrift = errors.New("approved plan hash does not match execution payload; refusing to run drifted plan")ErrActionNotExecuting = errors.New("action is not executing")ErrActionAlreadyExecuting = errors.New("action is already executing")ErrActionExecutionFinal = errors.New("action execution is already final")diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.goindex 9fe5c9458a..e7ba7adc5f 100644--- a/internal/unifiedresources/code_standards_test.go+++ b/internal/unifiedresources/code_standards_test.go@@ -353,6 +353,12 @@ func TestActionExecutionContractStaysAPIOwned(t *testing.T) {"func BeginActionExecution(record ActionAuditRecord, actor string, now time.Time)","func CompleteActionExecution(record ActionAuditRecord, result *ExecutionResult, actor string, now time.Time)","func ValidateActionExecutionStart(record ActionAuditRecord, now time.Time) error",+ // ErrActionPlanDrift is the canonical error returned when the+ // payload at execute time does not match the PlanHash recorded+ // at approval time. Pinning it here keeps the broker contract+ // honest: drift refusal cannot silently turn into another error+ // kind that callers fail to detect.+ "ErrActionPlanDrift = errors.New(",},filepath.Join(".", "store.go"): {"RecordActionExecutionStart(record ActionAuditRecord, event ActionLifecycleEvent) error",