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
Keep agent removal token revocation atomic
pulse-triage[bot]7e3c624900b7
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex e6bb50bc20..926607e3d9 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -6702,6 +6702,15 @@ The lifecycle proofs cover failed creation, delete one exact token from athree-token inventory, and force failed persistence commits in`internal/api/security_tokens_lifecycle_test.go`.+Agent-owned removal follows the same revocation boundary for host agents,+Docker hosts, and Kubernetes clusters. The resource tombstone may still+commit when credential persistence is unavailable, but token removal occurs+under the shared configuration lock and rolls the complete inventory back if+its write fails. The credential therefore remains consistently active rather+than appearing revoked until restart silently restores it. Shared success and+forced-write-failure proofs live in+`internal/monitoring/monitor_host_agent_removal_lifecycle_test.go`.+### External watchdog wiring does not widen agent lifecycle authority`internal/monitoring/monitor.go` now starts and stops the external dead-mandiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 2018139f7d..4c27758e10 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -10032,6 +10032,14 @@ and returns `500`; it must not report a revocation that will reverse on restart.`internal/api/security_tokens_lifecycle_test.go` pin both the multi-tokenidentity boundary and the failed-commit response.+The host-agent, Docker-host, and Kubernetes-cluster removal endpoints use the+same durable token-revocation primitive. Resource removal can complete even+when token persistence fails, but the live token inventory is then restored+to its restart-time state and the failure is logged rather than reporting a+credential revocation.+`internal/monitoring/monitor_host_agent_removal_lifecycle_test.go` forces that+write failure and pins the exact successful reduced inventory.+### External watchdog configuration and status are separate secret boundaries`GET /api/alerts/deadman/config` requires monitoring-read scope and returnsdiff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.mdindex 6fa2aee574..a6348e815c 100644--- a/docs/release-control/v6/internal/subsystems/monitoring.md+++ b/docs/release-control/v6/internal/subsystems/monitoring.md@@ -3371,6 +3371,19 @@ revoked endpoint receives no trailing heartbeat and a removed destinationbecomes disabled immediately. State corruption and write failure are visiblesystem conditions rather than silent loss of future outage evidence.+### Agent removal keeps credential truth continuous across restart++Host-agent, Docker-host, and Kubernetes-cluster removal may clean up a+dedicated API token only through the shared monitoring revocation boundary.+That boundary holds the global configuration lock across mutation and+persistence, snapshots the complete prior inventory, and restores both the+records and legacy primary-token projection if the reduced inventory cannot+commit. Resource tombstones remain authoritative when credential persistence+fails, but the token stays consistently active instead of disappearing only+from the live process and silently returning after restart. Success and+forced-write-failure coverage lives in+`internal/monitoring/monitor_host_agent_removal_lifecycle_test.go`.+### Escalation callbacks preserve exact routing intentThe monitoring callback resolves the configured escalation level and forwardsdiff --git a/docs/release-control/v6/internal/subsystems/security-privacy.md b/docs/release-control/v6/internal/subsystems/security-privacy.mdindex a2befd3a6e..6725250056 100644--- a/docs/release-control/v6/internal/subsystems/security-privacy.md+++ b/docs/release-control/v6/internal/subsystems/security-privacy.md@@ -2386,6 +2386,15 @@ will survive restart. Creation rollback, exact multi-token removal, andrevocation persistence-failure rollback are exercised in`internal/api/security_tokens_lifecycle_test.go`.+Automatic credential cleanup after host-agent, Docker-host, or Kubernetes+cluster removal obeys the same rule. One shared lock protects mutation and+persistence; a failed reduced-inventory write restores all prior records and+the primary-token projection. The resource remains removed, but Pulse keeps+the orphaned credential visibly active so restart cannot silently reverse a+claimed revocation.+`internal/monitoring/monitor_host_agent_removal_lifecycle_test.go` proves both+commit and rollback outcomes.+### Deploy enrollment never exposes an uncommitted credentialThe deploy bootstrap secret is single-use only at the durable API-token commitdiff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 860bf5ab6b..34673647da 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -5660,6 +5660,14 @@ describing credential state that the next restart would undo. The creation,exact-token deletion, and forced-write-failure proofs live in`internal/api/security_tokens_lifecycle_test.go`.+Monitoring-owned agent removal uses that same commit boundary when it cleans+up dedicated host, Docker, or Kubernetes credentials. Failed persistence+restores the complete live inventory and primary-token projection while the+resource tombstone remains authoritative. This is credential-state recovery,+not storage recovery authority: it prevents restart from reactivating a token+that the live process had already discarded. The shared proof is+`internal/monitoring/monitor_host_agent_removal_lifecycle_test.go`.+### Dead-man persistence is availability evidence, not recovery authorityThe shared configuration persistence and alert API now store the encrypteddiff --git a/internal/monitoring/api_token_lifecycle.go b/internal/monitoring/api_token_lifecycle.gonew file mode 100644index 0000000000..7b3e2165f8--- /dev/null+++ b/internal/monitoring/api_token_lifecycle.go@@ -0,0 +1,42 @@+package monitoring++import (+ "fmt"+ "strings"++ "github.com/rcourtman/pulse-go-rewrite/internal/config"+)++// revokeAPIToken removes one credential from both live and restart-time state.+// Agent removal itself remains authoritative when persistence is unavailable,+// but the credential must remain live if its reduced inventory cannot commit;+// otherwise a restart would silently reactivate a token Pulse reported revoked.+func (m *Monitor) revokeAPIToken(tokenID string) (*config.APITokenRecord, error) {+ tokenID = strings.TrimSpace(tokenID)+ if tokenID == "" {+ return nil, nil+ }+ if m == nil || m.config == nil {+ return nil, fmt.Errorf("configuration unavailable")+ }++ config.Mu.Lock()+ defer config.Mu.Unlock()++ previousTokens := append([]config.APITokenRecord(nil), m.config.APITokens...)+ removed := m.config.RemoveAPIToken(tokenID)+ if removed == nil {+ return nil, nil+ }+ m.config.SortAPITokens()++ if m.persistence != nil {+ if err := m.persistence.SaveAPITokens(m.config.APITokens); err != nil {+ m.config.APITokens = previousTokens+ m.config.SortAPITokens()+ return nil, fmt.Errorf("persist API token revocation: %w", err)+ }+ }++ return removed, nil+}diff --git a/internal/monitoring/kubernetes_agents.go b/internal/monitoring/kubernetes_agents.goindex cf7a17979c..a707990ebd 100644--- a/internal/monitoring/kubernetes_agents.go+++ b/internal/monitoring/kubernetes_agents.go@@ -1071,17 +1071,11 @@ func (m *Monitor) RemoveKubernetesCluster(clusterID string) (models.KubernetesCl// Revoke the API token associated with this Kubernetes clusterif cluster.TokenID != "" {- tokenRemoved := m.config.RemoveAPIToken(cluster.TokenID)- if tokenRemoved != nil {- m.config.SortAPITokens()-- if m.persistence != nil {- if err := m.persistence.SaveAPITokens(m.config.APITokens); err != nil {- log.Warn().Err(err).Str("tokenID", cluster.TokenID).Msg("failed to persist API token revocation after Kubernetes cluster removal")- } else {- log.Info().Str("tokenID", cluster.TokenID).Str("tokenName", cluster.TokenName).Msg("API token revoked for removed Kubernetes cluster")- }- }+ tokenRemoved, err := m.revokeAPIToken(cluster.TokenID)+ if err != nil {+ log.Warn().Err(err).Str("tokenID", cluster.TokenID).Msg("API token revocation rolled back after Kubernetes cluster removal")+ } else if tokenRemoved != nil {+ log.Info().Str("tokenID", cluster.TokenID).Str("tokenName", cluster.TokenName).Msg("API token revoked for removed Kubernetes cluster")}}diff --git a/internal/monitoring/monitor_agents.go b/internal/monitoring/monitor_agents.goindex ee7dbfe21e..569773f66a 100644--- a/internal/monitoring/monitor_agents.go+++ b/internal/monitoring/monitor_agents.go@@ -268,17 +268,11 @@ func (m *Monitor) RemoveDockerHost(hostID string) (models.DockerHost, error) {// Revoke the API token associated with this Docker hostif host.TokenID != "" {- tokenRemoved := m.config.RemoveAPIToken(host.TokenID)- if tokenRemoved != nil {- m.config.SortAPITokens()-- if m.persistence != nil {- if err := m.persistence.SaveAPITokens(m.config.APITokens); err != nil {- log.Warn().Err(err).Str("tokenID", host.TokenID).Msg("failed to persist API token revocation after Docker host removal")- } else {- log.Info().Str("tokenID", host.TokenID).Str("tokenName", host.TokenName).Msg("API token revoked for removed Docker host")- }- }+ tokenRemoved, err := m.revokeAPIToken(host.TokenID)+ if err != nil {+ log.Warn().Err(err).Str("tokenID", host.TokenID).Msg("API token revocation rolled back after Docker host removal")+ } else if tokenRemoved != nil {+ log.Info().Str("tokenID", host.TokenID).Str("tokenName", host.TokenName).Msg("API token revoked for removed Docker host")}}@@ -470,17 +464,12 @@ func (m *Monitor) RemoveHostAgent(hostID string) (models.Host, error) {var tokenRemoved *config.APITokenRecordif tokenID != "" && !tokenStillUsed {- tokenRemoved = m.config.RemoveAPIToken(tokenID)- if tokenRemoved != nil {- m.config.SortAPITokens()-- if m.persistence != nil {- if err := m.persistence.SaveAPITokens(m.config.APITokens); err != nil {- log.Warn().Err(err).Str("tokenID", tokenID).Msg("failed to persist API token revocation after host agent removal")- } else {- log.Info().Str("tokenID", tokenID).Str("tokenName", host.TokenName).Msg("API token revoked for removed host agent")- }- }+ var err error+ tokenRemoved, err = m.revokeAPIToken(tokenID)+ if err != nil {+ log.Warn().Err(err).Str("tokenID", tokenID).Msg("API token revocation rolled back after host agent removal")+ } else if tokenRemoved != nil {+ log.Info().Str("tokenID", tokenID).Str("tokenName", host.TokenName).Msg("API token revoked for removed host agent")}} else if tokenID != "" && tokenStillUsed {log.Info().diff --git a/internal/monitoring/monitor_host_agent_removal_lifecycle_test.go b/internal/monitoring/monitor_host_agent_removal_lifecycle_test.goindex ec02382e72..91903701be 100644--- a/internal/monitoring/monitor_host_agent_removal_lifecycle_test.go+++ b/internal/monitoring/monitor_host_agent_removal_lifecycle_test.go@@ -197,6 +197,82 @@ func TestHostAgentRemovalLifecycleRevokesDedicatedCredentialAndRetainsDenial(t *}}+func TestRevokeAPITokenRollsBackCompleteInventoryWhenPersistenceFails(t *testing.T) {+ now := time.Now().UTC()+ tokens := []config.APITokenRecord{+ {ID: "newest", Name: "newest", Hash: "hash-newest", CreatedAt: now, Scopes: []string{config.ScopeWildcard}},+ {ID: "target", Name: "target", Hash: "hash-target", CreatedAt: now.Add(-time.Minute), Scopes: []string{config.ScopeAgentReport}},+ {ID: "oldest", Name: "oldest", Hash: "hash-oldest", CreatedAt: now.Add(-2 * time.Minute), Scopes: []string{config.ScopeMonitoringRead}},+ }+ stateDir := filepath.Join(t.TempDir(), "state")+ persistence := config.NewConfigPersistence(stateDir)+ if err := persistence.SaveAPITokens(tokens); err != nil {+ t.Fatalf("save initial tokens: %v", err)+ }+ if err := os.RemoveAll(stateDir); err != nil {+ t.Fatalf("remove persistence directory: %v", err)+ }+ if err := os.WriteFile(stateDir, []byte("not a directory"), 0o600); err != nil {+ t.Fatalf("create persistence blocker: %v", err)+ }++ monitor := &Monitor{+ config: &config.Config{APITokens: append([]config.APITokenRecord(nil), tokens...)},+ persistence: persistence,+ }+ monitor.config.SortAPITokens()++ removed, err := monitor.revokeAPIToken("target")+ if err == nil {+ t.Fatal("revokeAPIToken succeeded despite persistence failure")+ }+ if removed != nil {+ t.Fatalf("failed revocation returned removed token: %#v", removed)+ }+ if len(monitor.config.APITokens) != len(tokens) {+ t.Fatalf("token count = %d, want %d: %#v", len(monitor.config.APITokens), len(tokens), monitor.config.APITokens)+ }+ for index, want := range tokens {+ if monitor.config.APITokens[index].ID != want.ID {+ t.Fatalf("token[%d].ID = %q, want %q", index, monitor.config.APITokens[index].ID, want.ID)+ }+ }+ if monitor.config.APIToken != "hash-newest" {+ t.Fatalf("legacy primary token = %q, want %q", monitor.config.APIToken, "hash-newest")+ }+}++func TestRevokeAPITokenCommitsExactReducedInventory(t *testing.T) {+ stateDir := t.TempDir()+ persistence := config.NewConfigPersistence(stateDir)+ monitor := &Monitor{+ config: &config.Config{APITokens: []config.APITokenRecord{+ {ID: "keep", Name: "keep", Hash: "hash-keep", CreatedAt: time.Now().UTC(), Scopes: []string{config.ScopeWildcard}},+ {ID: "remove", Name: "remove", Hash: "hash-remove", CreatedAt: time.Now().UTC().Add(-time.Minute), Scopes: []string{config.ScopeAgentReport}},+ }},+ persistence: persistence,+ }+ monitor.config.SortAPITokens()++ removed, err := monitor.revokeAPIToken("remove")+ if err != nil {+ t.Fatalf("revokeAPIToken: %v", err)+ }+ if removed == nil || removed.ID != "remove" {+ t.Fatalf("removed token = %#v", removed)+ }+ if len(monitor.config.APITokens) != 1 || monitor.config.APITokens[0].ID != "keep" {+ t.Fatalf("live token inventory = %#v", monitor.config.APITokens)+ }+ persisted, err := persistence.LoadAPITokens()+ if err != nil {+ t.Fatalf("LoadAPITokens: %v", err)+ }+ if len(persisted) != 1 || persisted[0].ID != "keep" {+ t.Fatalf("persisted token inventory = %#v", persisted)+ }+}+func TestHostAgentRemovalLifecycleRepublishesUnifiedReadState(t *testing.T) {monitor := newHostRemovalLifecycleMonitor(t, t.TempDir())adapter := unifiedresources.NewMonitorAdapter(unifiedresources.NewRegistry(nil))