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
Exercise uninstall rollback at the credential publication boundary
pulse-triage[bot]4fc752b4243d
diff --git a/internal/api/host_agent_removal_lifecycle_integration_test.go b/internal/api/host_agent_removal_lifecycle_integration_test.goindex ebbb74d911..76291a4527 100644--- a/internal/api/host_agent_removal_lifecycle_integration_test.go+++ b/internal/api/host_agent_removal_lifecycle_integration_test.go@@ -349,7 +349,7 @@ func TestCollectorUninstallTransactionFailsClosedAndRetriesAfterRestart(t *testireturn filepath.Join(dataPath, "host_continuity.json.tmp")}},{name: "credential persistence", blockedPath: func(dataPath string) string {- return filepath.Join(dataPath, "api_tokens.json.tmp")+ return filepath.Join(dataPath, "api_tokens.json")}},} {credentialShapes := []struct {@@ -395,6 +395,17 @@ func TestCollectorUninstallTransactionFailsClosedAndRetriesAfterRestart(t *testi}blocker := failure.blockedPath(dataPath)+ // Credential writes use exclusively owned, unpredictable temporary+ // files. Block their final rename while retaining the original+ // inventory for restart, rather than guessing a temporary pathname.+ retainedCredentials := ""+ if failure.name == "credential persistence" {+ retainedCredentials = filepath.Join(dataPath, "api_tokens.fixture-retained")+ if err := os.Rename(blocker, retainedCredentials); err != nil {+ runtime.stop()+ t.Fatalf("retain original credential inventory: %v", err)+ }+ }if err := os.Mkdir(blocker, 0o700); err != nil {runtime.stop()t.Fatalf("create persistence blocker: %v", err)@@ -405,9 +416,13 @@ func TestCollectorUninstallTransactionFailsClosedAndRetriesAfterRestart(t *testit.Fatal(err)}failed := serveHostRemovalLifecycleRequest(t, runtime, http.MethodPost, "/api/agents/agent/uninstall", rawToken, uninstallBody)- if failed.Code == http.StatusOK {+ if failed.Code != http.StatusInternalServerError || !strings.Contains(failed.Body.String(), "agent_uninstall_failed") {+ runtime.stop()+ t.Fatalf("persistence failure status = %d, want uninstall failure: %s", failed.Code, failed.Body.String())+ }+ if leftovers, err := filepath.Glob(filepath.Join(dataPath, ".api_tokens.json.*.tmp")); err != nil || len(leftovers) != 0 {runtime.stop()- t.Fatalf("persistence failure authorized teardown: %s", failed.Body.String())+ t.Fatalf("failed publication left temporary credentials: %v (glob error: %v)", leftovers, err)}if hosts := runtime.monitor.GetLiveHostsSnapshot(); len(hosts) != 1 || hosts[0].ID != hostID {runtime.stop()@@ -422,11 +437,20 @@ func TestCollectorUninstallTransactionFailsClosedAndRetriesAfterRestart(t *testiruntime.stop()t.Fatalf("remove persistence blocker: %v", err)}+ if retainedCredentials != "" {+ if err := os.Rename(retainedCredentials, blocker); err != nil {+ runtime.stop()+ t.Fatalf("restore original credential inventory: %v", err)+ }+ }runtime.stop()reloaded, err := config.NewConfigPersistence(dataPath).LoadAPITokens()if err != nil {t.Fatalf("LoadAPITokens after failed transaction: %v", err)}+ if len(reloaded) != 1 || reloaded[0].ID != record.ID {+ t.Fatalf("failed uninstall did not retain durable retry credential: %+v", reloaded)+ }runtime = newHostRemovalLifecycleHTTPRuntime(t, dataPath, reloaded)t.Cleanup(runtime.stop)diff --git a/internal/monitoring/monitor_host_agent_removal_lifecycle_test.go b/internal/monitoring/monitor_host_agent_removal_lifecycle_test.goindex 145614f83e..da3e11503a 100644--- a/internal/monitoring/monitor_host_agent_removal_lifecycle_test.go+++ b/internal/monitoring/monitor_host_agent_removal_lifecycle_test.go@@ -233,15 +233,26 @@ func TestCollectorUninstallHostAgentTransactionRollsBackAndRetries(t *testing.T)t.Fatalf("initial ApplyHostReport: %v", err)}- // Block only the credential inventory's atomic replacement. The removal- // tombstone can still be written first, so this exercises the rollback- // half of the durable uninstall transaction rather than a preflight error.- credentialBlocker := filepath.Join(dataPath, "api_tokens.json.tmp")+ // Block the final replacement, not a temporary filename: credential writes+ // now own an unpredictable temporary file. Retain the original inventory+ // so recovery never needs to reconstruct it from the failed transaction.+ // The separate continuity file remains writable, exercising rollback after+ // the removal tombstone has been persisted rather than a preflight error.+ credentialBlocker := filepath.Join(dataPath, "api_tokens.json")+ retainedCredentials := filepath.Join(dataPath, "api_tokens.fixture-retained")+ if err := os.Rename(credentialBlocker, retainedCredentials); err != nil {+ t.Fatalf("retain original credential inventory: %v", err)+ }if err := os.Mkdir(credentialBlocker, 0o700); err != nil {t.Fatalf("create credential persistence blocker: %v", err)}- if _, err := monitor.UninstallHostAgent(host.ID, token.ID); err == nil {- t.Fatal("UninstallHostAgent authorized teardown without durable credential revocation")+ _, uninstallErr := monitor.UninstallHostAgent(host.ID, token.ID)+ var renameErr *os.LinkError+ if !errors.As(uninstallErr, &renameErr) || renameErr.Op != "rename" || renameErr.New != credentialBlocker {+ t.Fatalf("UninstallHostAgent error = %v, want credential publication rename failure", uninstallErr)+ }+ if leftovers, err := filepath.Glob(filepath.Join(dataPath, ".api_tokens.json.*.tmp")); err != nil || len(leftovers) != 0 {+ t.Fatalf("failed publication left temporary credentials: %v (glob error: %v)", leftovers, err)}if hosts := monitor.GetLiveHostsSnapshot(); len(hosts) != 1 || hosts[0].ID != host.ID {t.Fatalf("failed uninstall changed live host state: %+v", hosts)@@ -257,6 +268,13 @@ func TestCollectorUninstallHostAgentTransactionRollsBackAndRetries(t *testing.T)if err := os.Remove(credentialBlocker); err != nil {t.Fatalf("remove credential persistence blocker: %v", err)}+ if err := os.Rename(retainedCredentials, credentialBlocker); err != nil {+ t.Fatalf("restore original credential inventory: %v", err)+ }+ persistedBeforeRetry, err := monitor.persistence.LoadAPITokens()+ if err != nil || len(persistedBeforeRetry) != 1 || persistedBeforeRetry[0].ID != token.ID {+ t.Fatalf("failed uninstall did not retain durable retry credential: %+v (error: %v)", persistedBeforeRetry, err)+ }removed, err := monitor.UninstallHostAgent(host.ID, token.ID)if err != nil {t.Fatalf("retry UninstallHostAgent: %v", err)