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
Prevent mixed-auth configuration deadlock
rcourtmandf59f210e583
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 1d919f96ce..51199125cb 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -4588,3 +4588,11 @@ adjacent entitlement boundary, not agent authority. It may stop a backgroundreport before generation when the current license lacks `advanced_reporting`,but it must not mint agent credentials, dispatch agent work, reinterpret anagent receipt, or expand any lifecycle capability.++The adjacent shared authentication boundary must also preserve agent liveness+while an operator or qualification client uses local Basic authentication.+Agent API-token validation may update the token usage record under the global+configuration write lock; a simultaneous local credential check must not take+a recursive read lock while already inside `checkAuth`'s read-locked decision.+The server must continue accepting reports and command registrations under+that mixed-auth load rather than allowing a queued writer to freeze the API.diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex e147358cbd..5be02344e1 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -7709,3 +7709,14 @@ license service as the HTTP reporting routes. `runReportSchedule` must checkmissing resolver service fails closed in the routed runtime. Downgrade cleanupis an internal scheduled side effect only: it does not add a public report API,change report payload schemas, or delete schedule definitions.++Local Basic authentication and agent API-token authentication share the global+mutable configuration boundary. `checkAuth` holds one read lock across an+authentication decision; a credential snapshot inside that boundary must use+a lock-free, caller-locked helper and must not recursively acquire `config.Mu`.+API-token validation may temporarily release its read lock and queue for the+write lock to update token usage. A second Basic-auth read lock behind that+queued writer would create a circular wait and freeze every API consumer,+including live agent reporting and Patrol qualification. Contract proof pins+the single-lock boundary, and concurrency proof queues the writer before+exercising the local credential snapshot.diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex b9d2796dd6..ac52e76f9e 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -2132,6 +2132,14 @@ while storage detail drawers and filter controls must route summary series IDs,source tones, and disk metrics through the shared storage helpers instead ofreconstructing them from local table state.+The adjacent shared authentication boundary must remain live when storage or+recovery browser reads authenticated with local credentials overlap agent+API-token reports. Local credential snapshots inside `checkAuth` use the+already-held global configuration read lock and must not recursively acquire+it, because token usage validation may be waiting for the corresponding write+lock. This concurrency rule changes no storage/recovery payload, authority, or+support claim; it prevents mixed-auth traffic from stalling those surfaces.+Storage and recovery consumers must not treat confirmed agent-attested actionreadback as independently verified restoration. The canonical result retainsits confirmation and evidence class, while the legacy Patrol finding outcomediff --git a/internal/api/auth.go b/internal/api/auth.goindex ed9f5d1f6a..1f7f5a60e6 100644--- a/internal/api/auth.go+++ b/internal/api/auth.go@@ -650,6 +650,15 @@ func CheckAuth(cfg *config.Config, w http.ResponseWriter, r *http.Request) boolreturn checkAuth(cfg, w, r, true)}+// snapshotLocalAuthCredentialsLocked returns the local credentials while the+// caller holds config.Mu for reading or writing. It deliberately does not take+// the lock itself: checkAuth keeps a read lock across its authentication+// decision, and recursively taking an RWMutex read lock can deadlock once an+// API-token validation is waiting to upgrade to the write lock.+func snapshotLocalAuthCredentialsLocked(cfg *config.Config) (string, string) {+ return cfg.AuthUser, cfg.AuthPass+}+func checkAuth(cfg *config.Config, w http.ResponseWriter, r *http.Request, writeDefaultFailure bool) bool {// Dev mode bypass for all auth (disabled by default)if adminBypassEnabled() {@@ -866,10 +875,7 @@ func checkAuth(cfg *config.Config, w http.ResponseWriter, r *http.Request, write}return false}- config.Mu.RLock()- cfgAuthUser := cfg.AuthUser- cfgAuthPass := cfg.AuthPass- config.Mu.RUnlock()+ cfgAuthUser, cfgAuthPass := snapshotLocalAuthCredentialsLocked(cfg)userMatch := constantTimeStringEqual(parts[0], cfgAuthUser)passMatch := internalauth.CheckPasswordHash(parts[1], cfgAuthPass)diff --git a/internal/api/auth_additional_coverage_test.go b/internal/api/auth_additional_coverage_test.goindex 1cd8742044..53d6c2a337 100644--- a/internal/api/auth_additional_coverage_test.go+++ b/internal/api/auth_additional_coverage_test.go@@ -3,6 +3,7 @@ package apiimport ("net/http""net/http/httptest"+ "runtime""strings""testing""time"@@ -10,6 +11,62 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/config")+func TestSnapshotLocalAuthCredentialsLockedDoesNotReenterConfigLock(t *testing.T) {+ cfg := &config.Config{AuthUser: "admin", AuthPass: "hash"}++ // Hold the same outer read lock as checkAuth, then queue a writer exactly as+ // API-token validation does. Go's RWMutex blocks any new reader behind that+ // writer, so a recursive RLock in the snapshot would never return.+ config.Mu.RLock()+ outerLocked := true+ defer func() {+ if outerLocked {+ config.Mu.RUnlock()+ }+ }()++ writerAttempting := make(chan struct{})+ writerAcquired := make(chan struct{})+ writerDone := make(chan struct{})+ go func() {+ close(writerAttempting)+ config.Mu.Lock()+ close(writerAcquired)+ config.Mu.Unlock()+ close(writerDone)+ }()+ <-writerAttempting+ runtime.Gosched()++ snapshotDone := make(chan [2]string, 1)+ go func() {+ user, pass := snapshotLocalAuthCredentialsLocked(cfg)+ snapshotDone <- [2]string{user, pass}+ }()++ select {+ case got := <-snapshotDone:+ if got != [2]string{"admin", "hash"} {+ t.Fatalf("credential snapshot = %#v, want admin/hash", got)+ }+ case <-writerAcquired:+ t.Fatal("writer acquired config.Mu while the outer read lock was held")+ case <-time.After(250 * time.Millisecond):+ config.Mu.RUnlock()+ outerLocked = false+ <-writerDone+ t.Fatal("credential snapshot blocked behind a pending config writer; recursive RLock deadlock regressed")+ }++ config.Mu.RUnlock()+ outerLocked = false+ select {+ case <-writerDone:+ case <-time.After(time.Second):+ t.Fatal("queued config writer did not complete after releasing outer read lock")+ }+}+func TestCheckAuth_APIOnlyModeRequiresToken(t *testing.T) {record, err := config.NewAPITokenRecord("token-required-123.12345678", "api", []string{config.ScopeMonitoringRead})if err != nil {diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 434f1cc47b..8b37ea0c05 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -20872,13 +20872,15 @@ func TestContract_ProxyAuthConfiguredRoleHeaderMissingIsNonAdmin(t *testing.T) {}// TestContract_LocalAuthConfigReadsUseSharedLock pins the shared mutable-config-// boundary for local username/password checks. Auth handlers may snapshot-// credentials under the config lock, but must not read mutable auth fields-// directly while hashing passwords or mutating sessions.+// boundary for local username/password checks. checkAuth holds the shared read+// lock across its decision, so its credential snapshot must not recursively+// acquire that RWMutex while an API-token validation may be waiting to write.func TestContract_LocalAuthConfigReadsUseSharedLock(t *testing.T) {expectations := map[string][]string{"auth.go": {- "config.Mu.RLock()\n\t\t\t\t\t\tcfgAuthUser := cfg.AuthUser\n\t\t\t\t\t\tcfgAuthPass := cfg.AuthPass\n\t\t\t\t\t\tconfig.Mu.RUnlock()",+ "config.Mu.RLock()\n\tdefer config.Mu.RUnlock()",+ "func snapshotLocalAuthCredentialsLocked(cfg *config.Config) (string, string) {\n\treturn cfg.AuthUser, cfg.AuthPass\n}",+ "cfgAuthUser, cfgAuthPass := snapshotLocalAuthCredentialsLocked(cfg)","constantTimeStringEqual(parts[0], cfgAuthUser)","internalauth.CheckPasswordHash(parts[1], cfgAuthPass)",},@@ -20902,6 +20904,14 @@ func TestContract_LocalAuthConfigReadsUseSharedLock(t *testing.T) {}}}++ authSourceBytes, err := os.ReadFile("auth.go")+ if err != nil {+ t.Fatalf("read auth.go: %v", err)+ }+ if strings.Contains(string(authSourceBytes), "config.Mu.RLock()\n\t\t\t\t\t\tcfgAuthUser") {+ t.Fatal("auth.go must not recursively acquire config.Mu while snapshotting local credentials")+ }}func TestContract_StateBroadcastsUseLazyCurrentStateInvalidation(t *testing.T) {