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
Govern API token deletion durability
pulse-triage[bot]d15181e96033
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex fb46b54b05..f654949d24 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -6624,3 +6624,14 @@ still holds the block. A state-only block with a durable store attached iscleared rather than read as already-consumed, so a fresh token minted afterremoval always re-enrolls the host instead of rejecting its reportsindefinitely with 400s that no reinstall can escape (#1772).++### Agent token revocation remains continuous across persistence failure++The shared API-token deletion boundary may mark an agent credential revoked+only after the reduced token inventory is durably committed. If persistence+fails, the complete prior inventory and primary-token projection are restored+and the request fails, so connected agents do not become unauthenticated only+in the live process or regain a supposedly revoked credential after restart.+The lifecycle proof deletes one exact token from a three-token inventory and+forces a failed persistence commit in+`internal/api/security_tokens_lifecycle_test.go`.diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex de39853998..cb8b88202e 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -9903,3 +9903,15 @@ facet on the wire. `internal/models/metrics_types_test.go`,`frontend-modern/src/hooks/__tests__/useUnifiedResources.test.ts`, and`frontend-modern/src/utils/__tests__/resourceStateAdapters.test.ts` pin thewire shape and both client projections.++### API token deletion commits durable state before reporting success++`DELETE /api/security/tokens/{id}` removes exactly the requested token and+returns `204` only after the resulting token inventory is durably persisted.+If persistence fails, the runtime restores the complete prior inventory,+recomputes its legacy primary-token projection, records a failed audit event,+and returns `500`; it must not report a revocation that will reverse on restart.+`TestSecurityTokensDeletePersistsOnlyRequestedRemoval` and+`TestSecurityTokensDeleteRollsBackWhenPersistenceFails` in+`internal/api/security_tokens_lifecycle_test.go` pin both the multi-token+identity boundary and the failed-commit response.diff --git a/docs/release-control/v6/internal/subsystems/security-privacy.md b/docs/release-control/v6/internal/subsystems/security-privacy.mdindex 7f3701a341..d438caf6fa 100644--- a/docs/release-control/v6/internal/subsystems/security-privacy.md+++ b/docs/release-control/v6/internal/subsystems/security-privacy.md@@ -2335,3 +2335,13 @@ profile and is relaxed only when a sudo grant is active, because NNP blockssudo outright; that relaxation is part of the grant's declared cost. The agent-reported privilege profile isinformational: the fleet doctor presents it descriptively and must not treata non-root agent as unhealthy on that evidence alone.++### API token revocation is a durable credential transition++Revocation may not create different live and restart-time credential sets.+The token-management API therefore retains a complete pre-mutation inventory+until the reduced inventory is persisted. A failed write restores the prior+tokens and primary-token projection, emits only a failed `token_deleted` audit+event, and returns an error; a successful response identifies a deletion that+will survive restart. Exact multi-token removal and persistence-failure+rollback are exercised in `internal/api/security_tokens_lifecycle_test.go`.diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 02b2d863c5..4a096864c9 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -5588,3 +5588,14 @@ not storage inventory, recovery evidence, or an action capability; it grantsno backup, snapshot, restore, retention, cleanup, or verification authority.The storage/recovery resource query and its admission, freshness, andpersistence contracts are unchanged.++### Token deletion preserves restart-time persistence truth++The shared `internal/api` token revocation path treats its persisted inventory+as the commit boundary. It snapshots the complete in-memory inventory before+removal, persists only the intended reduced set, and restores the snapshot and+legacy primary-token projection if that write fails. This adds no backup,+restore, or recovery authority; it prevents a successful API response from+describing credential state that the next restart would undo. The exact-token+and forced-write-failure proofs live in+`internal/api/security_tokens_lifecycle_test.go`.diff --git a/internal/api/security_tokens_delete_test.go b/internal/api/security_tokens_delete_test.godeleted file mode 100644index c06bda0147..0000000000--- a/internal/api/security_tokens_delete_test.go+++ /dev/null@@ -1,85 +0,0 @@-package api--import (- "net/http"- "net/http/httptest"- "os"- "path/filepath"- "testing"- "time"-- "github.com/rcourtman/pulse-go-rewrite/internal/config"-)--func TestSecurityTokensDeletePersistsOnlyRequestedRemoval(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.ScopeWildcard}},- {ID: "oldest", Name: "oldest", Hash: "hash-oldest", CreatedAt: now.Add(-2 * time.Minute), Scopes: []string{config.ScopeWildcard}},- }- persistence := config.NewConfigPersistence(t.TempDir())- if err := persistence.SaveAPITokens(tokens); err != nil {- t.Fatalf("save initial tokens: %v", err)- }- cfg := &config.Config{APITokens: append([]config.APITokenRecord(nil), tokens...)}- router := &Router{config: cfg, persistence: persistence}-- req := httptest.NewRequest(http.MethodDelete, "/api/security/tokens/target", nil)- rec := httptest.NewRecorder()- router.handleDeleteAPIToken(rec, req)-- if rec.Code != http.StatusNoContent {- t.Fatalf("status = %d, want %d (body=%q)", rec.Code, http.StatusNoContent, rec.Body.String())- }- assertAPITokenIDs(t, cfg.APITokens, "newest", "oldest")- persisted, err := persistence.LoadAPITokens()- if err != nil {- t.Fatalf("load persisted tokens: %v", err)- }- assertAPITokenIDs(t, persisted, "newest", "oldest")-}--func TestSecurityTokensDeleteRollsBackWhenPersistenceFails(t *testing.T) {- now := time.Now().UTC()- tokens := []config.APITokenRecord{- {ID: "keep", Name: "keep", Hash: "hash-keep", CreatedAt: now, Scopes: []string{config.ScopeWildcard}},- {ID: "target", Name: "target", Hash: "hash-target", CreatedAt: now.Add(-time.Minute), Scopes: []string{config.ScopeWildcard}},- }- cfg := &config.Config{APITokens: append([]config.APITokenRecord(nil), tokens...)}- cfg.SortAPITokens()-- stateDir := filepath.Join(t.TempDir(), "state")- persistence := config.NewConfigPersistence(stateDir)- 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)- }- router := &Router{config: cfg, persistence: persistence}-- req := httptest.NewRequest(http.MethodDelete, "/api/security/tokens/target", nil)- rec := httptest.NewRecorder()- router.handleDeleteAPIToken(rec, req)-- if rec.Code != http.StatusInternalServerError {- t.Fatalf("status = %d, want %d (body=%q)", rec.Code, http.StatusInternalServerError, rec.Body.String())- }- assertAPITokenIDs(t, cfg.APITokens, "keep", "target")- if cfg.APIToken != "hash-keep" {- t.Fatalf("legacy primary token = %q, want rollback to %q", cfg.APIToken, "hash-keep")- }-}--func assertAPITokenIDs(t *testing.T, tokens []config.APITokenRecord, want ...string) {- t.Helper()- if len(tokens) != len(want) {- t.Fatalf("token count = %d, want %d: %+v", len(tokens), len(want), tokens)- }- for index, id := range want {- if tokens[index].ID != id {- t.Fatalf("token[%d].ID = %q, want %q", index, tokens[index].ID, id)- }- }-}diff --git a/internal/api/security_tokens_lifecycle_test.go b/internal/api/security_tokens_lifecycle_test.goindex 77028a37aa..4a2fb95909 100644--- a/internal/api/security_tokens_lifecycle_test.go+++ b/internal/api/security_tokens_lifecycle_test.go@@ -3,6 +3,8 @@ package apiimport ("net/http""net/http/httptest"+ "os"+ "path/filepath""strings""testing""time"@@ -10,6 +12,79 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/config")+func TestSecurityTokensDeletePersistsOnlyRequestedRemoval(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.ScopeWildcard}},+ {ID: "oldest", Name: "oldest", Hash: "hash-oldest", CreatedAt: now.Add(-2 * time.Minute), Scopes: []string{config.ScopeWildcard}},+ }+ persistence := config.NewConfigPersistence(t.TempDir())+ if err := persistence.SaveAPITokens(tokens); err != nil {+ t.Fatalf("save initial tokens: %v", err)+ }+ cfg := &config.Config{APITokens: append([]config.APITokenRecord(nil), tokens...)}+ router := &Router{config: cfg, persistence: persistence}++ req := httptest.NewRequest(http.MethodDelete, "/api/security/tokens/target", nil)+ rec := httptest.NewRecorder()+ router.handleDeleteAPIToken(rec, req)++ if rec.Code != http.StatusNoContent {+ t.Fatalf("status = %d, want %d (body=%q)", rec.Code, http.StatusNoContent, rec.Body.String())+ }+ assertLifecycleAPITokenIDs(t, cfg.APITokens, "newest", "oldest")+ persisted, err := persistence.LoadAPITokens()+ if err != nil {+ t.Fatalf("load persisted tokens: %v", err)+ }+ assertLifecycleAPITokenIDs(t, persisted, "newest", "oldest")+}++func TestSecurityTokensDeleteRollsBackWhenPersistenceFails(t *testing.T) {+ now := time.Now().UTC()+ tokens := []config.APITokenRecord{+ {ID: "keep", Name: "keep", Hash: "hash-keep", CreatedAt: now, Scopes: []string{config.ScopeWildcard}},+ {ID: "target", Name: "target", Hash: "hash-target", CreatedAt: now.Add(-time.Minute), Scopes: []string{config.ScopeWildcard}},+ }+ cfg := &config.Config{APITokens: append([]config.APITokenRecord(nil), tokens...)}+ cfg.SortAPITokens()++ stateDir := filepath.Join(t.TempDir(), "state")+ persistence := config.NewConfigPersistence(stateDir)+ 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)+ }+ router := &Router{config: cfg, persistence: persistence}++ req := httptest.NewRequest(http.MethodDelete, "/api/security/tokens/target", nil)+ rec := httptest.NewRecorder()+ router.handleDeleteAPIToken(rec, req)++ if rec.Code != http.StatusInternalServerError {+ t.Fatalf("status = %d, want %d (body=%q)", rec.Code, http.StatusInternalServerError, rec.Body.String())+ }+ assertLifecycleAPITokenIDs(t, cfg.APITokens, "keep", "target")+ if cfg.APIToken != "hash-keep" {+ t.Fatalf("legacy primary token = %q, want rollback to %q", cfg.APIToken, "hash-keep")+ }+}++func assertLifecycleAPITokenIDs(t *testing.T, tokens []config.APITokenRecord, want ...string) {+ t.Helper()+ if len(tokens) != len(want) {+ t.Fatalf("token count = %d, want %d: %+v", len(tokens), len(want), tokens)+ }+ for index, id := range want {+ if tokens[index].ID != id {+ t.Fatalf("token[%d].ID = %q, want %q", index, tokens[index].ID, id)+ }+ }+}+// TestSecurityTokens_DeleteFailsAuthImmediately verifies that after deleting an API token,// subsequent requests using that token receive 401 Unauthorized.// Covers acceptance test checklist item 2.4: "Delete token — verify it no longer authenticates".