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
fix(auth): synchronise local admin permissions during setup
pulse-triage[bot]7dd5982ace56
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex b8cea596c2..372beea0b1 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -723,6 +723,8 @@ installer download and the agent's subsequent Pulse TLS connection.## Shared Boundaries+- Local administrator setup synchronises the router authorizer before returning a browser session, so API Access remains available to manage agent credentials. This changes neither agent token scopes nor command-policy intent, and must not grant an unrelated identity access to credential management.+### Notification recovery reload ownershipNotification recovery handler ownership is refreshed alongside agent anddiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 545a8e1bec..6f705e0e3a 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -524,6 +524,8 @@ enums locally.## Shared Boundaries+- Quick security setup must synchronise the router-captured configurable authorizer when committing the local administrator identity, before establishing its session. The resulting Settings capabilities must grant both administrator-session surfaces and API Access/Pulse Intelligence permission surfaces without requiring a process restart. Permission checks and token scopes remain enforced for other identities.+### Notification recovery reload ownershipQueue recovery routes retain stable handler objects across router reloads, butdiff --git a/docs/release-control/v6/internal/subsystems/security-privacy.md b/docs/release-control/v6/internal/subsystems/security-privacy.mdindex dc5ce3dd8d..0d4af3a7d2 100644--- a/docs/release-control/v6/internal/subsystems/security-privacy.md+++ b/docs/release-control/v6/internal/subsystems/security-privacy.md@@ -289,6 +289,8 @@ invisible to operators reviewing exactly what Pulse sends.## Shared Boundaries+- Configured local-admin synchronisation is a runtime identity replacement, not an additive role grant: changing the configured identity removes the previous bypass, and clearing it during first-run reset clears that bypass. Configurable authorizers must synchronise identity updates with concurrent authorization reads; other users still require their own policy grants.+### Notification recovery reload ownershipRefreshing the notification queue handler on reload changes only its defaultdiff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 0bc007278e..e9d0a6bbb2 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -305,6 +305,8 @@ command-capable profile.## Shared Boundaries+- After password configuration has been persisted and the runtime local-admin identity changes, authorizer synchronisation must also occur if subsequent API-token persistence fails. Development first-run reset must clear the configured-admin bypass only on successful auth reset, not on its persistence-failure rollback path. No role-store deletion or migration is part of this recovery.+### PBS host history correlationBackups hydrates type=pbs,agent with source=pbs and reuses Overview guest inventory. Deduplicate combined snapshots by canonical ID before correlation, avoiding false ambiguity for agents in both queries. Standalone non-PVE PBS telemetry remains available without downloading the guest estate twice.diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 49656c1e6d..cd5c3d3fe2 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -42,6 +42,7 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/api/chartapi""github.com/rcourtman/pulse-go-rewrite/internal/api/configapi""github.com/rcourtman/pulse-go-rewrite/internal/api/resourceapi"+ "github.com/rcourtman/pulse-go-rewrite/internal/bootstrap""github.com/rcourtman/pulse-go-rewrite/internal/config""github.com/rcourtman/pulse-go-rewrite/internal/license/entitlements""github.com/rcourtman/pulse-go-rewrite/internal/mock"@@ -24831,3 +24832,61 @@ func TestRouterSetMonitorRefreshesNotificationQueue(t *testing.T) {})}}++// Exercise first-run setup with a real policy authorizer and an empty file-backed+// role manager. No persistence fault or customer data is needed to reproduce the+// split between administrator-session and permission-gated Settings surfaces.+func TestContract_QuickSetupSynchronizesConfiguredAdminCapabilities(t *testing.T) {+ t.Setenv("PULSE_DOCKER", "true")+ t.Setenv("INVOCATION_ID", "")+ t.Setenv("PULSE_TRUSTED_PROXY_CIDRS", "")+ resetTrustedProxyConfig()+ dir := t.TempDir()+ InitPersistentAuthStores(dir)+ manager, err := authpkg.NewFileManager(dir)+ if err != nil {+ t.Fatal(err)+ }+ authorizer := authpkg.NewRBACAuthorizer(manager)+ cfg := &config.Config{DataPath: dir, ConfigPath: dir}+ router := &Router{config: cfg, persistence: config.NewConfigPersistence(dir), authorizer: authorizer}+ router.initializeBootstrapToken()+ token, _, _, err := bootstrap.Load(dir)+ if err != nil {+ t.Fatal(err)+ }+ authLimiter.Reset("198.51.100.81")+ req := httptest.NewRequest(http.MethodPost, "/api/security/quick-setup", strings.NewReader(`{"username":"local-admin","password":"StrongPass!1","apiToken":"`+strings.Repeat("ab", 32)+`"}`))+ req.RemoteAddr = "198.51.100.81:54321"+ req.Header.Set(bootstrapTokenHeader, token)+ rec := httptest.NewRecorder()+ handleQuickSecuritySetupFixed(router)(rec, req)+ if rec.Code != http.StatusOK {+ t.Fatalf("setup status = %d", rec.Code)+ }+ cookie := findCookie(rec.Result().Cookies(), sessionCookieName(false))+ if cookie == nil {+ t.Fatal("no session cookie")+ }+ statusReq := httptest.NewRequest(http.MethodGet, "/api/security/status", nil)+ statusReq.AddCookie(cookie)+ snapshot := router.buildSecurityStatusAuthSnapshot(statusReq)+ caps := router.securityStatusSettingsCapabilitiesFromSnapshot(snapshot)+ if !caps.InfrastructureRead || !caps.SystemSettingsRead || !caps.DiagnosticsRead || !caps.SystemLogsRead || !caps.AuthenticationRead {+ t.Fatalf("configured administrator lost admin-session settings: %+v", caps)+ }+ if !caps.APIAccessRead || !caps.PulseIntelligenceRead {+ t.Errorf("configured administrator has split Settings capabilities after setup: %+v", caps)+ }+ allowed, err := authorizer.Authorize(authpkg.WithUser(req.Context(), "outsider"), authpkg.ActionAdmin, authpkg.ResourceUsers)+ if err != nil || allowed {+ t.Fatalf("outsider permission = %v, %v", allowed, err)+ }+ // Reapply the startup synchronisation: a restart is sufficient for this+ // specific stale-admin condition without changing roles or deleting state.+ authorizer.SetAdminUser(cfg.AuthUser)+ caps = router.securityStatusSettingsCapabilitiesFromSnapshot(snapshot)+ if !caps.APIAccessRead || !caps.PulseIntelligenceRead {+ t.Fatal("startup synchronisation did not restore capabilities")+ }+}diff --git a/internal/api/router.go b/internal/api/router.goindex 39ab4600a6..1bdba5ae80 100644--- a/internal/api/router.go+++ b/internal/api/router.go@@ -270,9 +270,7 @@ func NewRouter(cfg *config.Config, monitor *monitoring.Monitor, mtMonitor *monit)// Sync the configured admin user to the authorizer (if supported)- if cfg.AuthUser != "" {- auth.SetAdminUser(cfg.AuthUser)- }+ r.syncConfiguredAdminAuthorizer()// The tenant provider is the sole owner of v6 RBAC persistence. Initialize// the default manager before SSO services and routes so settings, SSO rolediff --git a/internal/api/security_first_run_reset.go b/internal/api/security_first_run_reset.goindex 69e12c7d36..2fab57d67a 100644--- a/internal/api/security_first_run_reset.go+++ b/internal/api/security_first_run_reset.go@@ -89,6 +89,7 @@ func (r *Router) handleResetFirstRunSecurity(w http.ResponseWriter, req *http.Re}}r.config.AuthUser = ""+ r.syncConfiguredAdminAuthorizer()r.config.AuthPass = ""r.config.APIToken = ""r.config.APITokens = nildiff --git a/internal/api/security_first_run_reset_test.go b/internal/api/security_first_run_reset_test.goindex 37f481a59f..8521046e12 100644--- a/internal/api/security_first_run_reset_test.go+++ b/internal/api/security_first_run_reset_test.go@@ -11,6 +11,7 @@ import ("time""github.com/rcourtman/pulse-go-rewrite/internal/config"+ "github.com/rcourtman/pulse-go-rewrite/pkg/auth")func TestResetFirstRunSecurityRequiresDevMode(t *testing.T) {@@ -45,6 +46,13 @@ func TestResetFirstRunSecurityClearsAuthAndReturnsBootstrapToken(t *testing.T) {}router := NewRouter(cfg, nil, nil, nil, nil, "1.0.0")+ manager, err := auth.NewFileManager(t.TempDir())+ if err != nil {+ t.Fatal(err)+ }+ authorizer := auth.NewRBACAuthorizer(manager)+ authorizer.SetAdminUser(cfg.AuthUser)+ router.authorizer = authorizerreq := httptest.NewRequest(http.MethodPost, "/api/security/dev/reset-first-run", nil)req.Header.Set("X-API-Token", "reset-first-run-token-234.12345678")rec := httptest.NewRecorder()@@ -53,6 +61,9 @@ func TestResetFirstRunSecurityClearsAuthAndReturnsBootstrapToken(t *testing.T) {t.Fatalf("expected 200, got %d (%s)", rec.Code, rec.Body.String())}+ if allowed, err := authorizer.Authorize(auth.WithUser(req.Context(), "admin"), auth.ActionAdmin, auth.ResourceUsers); allowed || err != nil {+ t.Fatalf("reset retained configured-admin permission: allowed=%v err=%v", allowed, err)+ }var payload firstRunResetResponseif err := json.Unmarshal(rec.Body.Bytes(), &payload); err != nil {t.Fatalf("decode response: %v", err)diff --git a/internal/api/security_setup_admin_sync_test.go b/internal/api/security_setup_admin_sync_test.gonew file mode 100644index 0000000000..39197bc02e--- /dev/null+++ b/internal/api/security_setup_admin_sync_test.go@@ -0,0 +1,31 @@+package api++import (+ "net/http"+ "net/http/httptest"+ "testing"++ "github.com/rcourtman/pulse-go-rewrite/internal/config"+ "github.com/rcourtman/pulse-go-rewrite/pkg/auth"+)++func TestConfiguredAdminAuthorizerSyncReplacesAndClearsIdentity(t *testing.T) {+ manager, err := auth.NewFileManager(t.TempDir())+ if err != nil {+ t.Fatal(err)+ }+ authorizer := auth.NewRBACAuthorizer(manager)+ cfg := &config.Config{}+ router := &Router{config: cfg, authorizer: authorizer}+ for _, current := range []string{"original-admin", "replacement-admin", ""} {+ cfg.AuthUser = current+ router.syncConfiguredAdminAuthorizer()+ for _, user := range []string{"original-admin", "replacement-admin", "outsider"} {+ req := httptest.NewRequest(http.MethodGet, "/", nil)+ allowed, err := authorizer.Authorize(auth.WithUser(req.Context(), user), auth.ActionAdmin, auth.ResourceUsers)+ if err != nil || allowed != (user == current) {+ t.Fatalf("configured %q, user %q: allowed=%v err=%v", current, user, allowed, err)+ }+ }+ }+}diff --git a/internal/api/security_setup_fix.go b/internal/api/security_setup_fix.goindex 56f461ac2c..b1b1d52ae8 100644--- a/internal/api/security_setup_fix.go+++ b/internal/api/security_setup_fix.go@@ -502,6 +502,10 @@ func handleQuickSecuritySetupFixed(r *Router) http.HandlerFunc {config.Mu.Lock()previousTokens := append([]config.APITokenRecord(nil), r.config.APITokens...)r.config.AuthUser = setupRequest.Username+ // Keep permission-gated routes aligned with the configured administrator+ // immediately, including when token persistence below fails after the+ // password configuration has already been saved.+ r.syncConfiguredAdminAuthorizer()r.config.AuthPass = hashedPasswordr.config.APITokens = []config.APITokenRecord{*tokenRecord}r.config.SortAPITokens()@@ -844,3 +848,13 @@ func (r *Router) HandleValidateAPIToken(w http.ResponseWriter, rq *http.Request)w.Header().Set("Content-Type", "application/json")json.NewEncoder(w).Encode(response)}++// syncConfiguredAdminAuthorizer updates the same authorizer captured by this+// router's permission gates. Call while changing AuthUser under config.Mu, or+// during router construction before serving requests. Empty clears a prior+// configured-admin grant; it must not survive first-run reset.+func (r *Router) syncConfiguredAdminAuthorizer() {+ if configurable, ok := r.authorizer.(internalauth.AdminConfigurable); ok {+ configurable.SetAdminUser(r.config.AuthUser)+ }+}diff --git a/pkg/auth/admin_sync_concurrency_test.go b/pkg/auth/admin_sync_concurrency_test.gonew file mode 100644index 0000000000..0de37df0de--- /dev/null+++ b/pkg/auth/admin_sync_concurrency_test.go@@ -0,0 +1,33 @@+package auth++import (+ "context"+ "sync"+ "testing"+)++func TestRBACAdminIdentityConcurrentUpdates(t *testing.T) {+ manager, err := NewFileManager(t.TempDir())+ if err != nil {+ t.Fatal(err)+ }+ a := NewRBACAuthorizer(manager)+ var wg sync.WaitGroup+ for worker := 0; worker < 4; worker++ {+ wg.Go(func() {+ for i := 0; i < 100; i++ {+ a.SetAdminUser("configured-admin")+ a.Authorize(WithUser(context.Background(), "configured-admin"), ActionAdmin, ResourceUsers)+ if allowed, err := a.Authorize(WithUser(context.Background(), "outsider"), ActionAdmin, ResourceUsers); allowed || err != nil {+ t.Errorf("outsider allowed=%v err=%v", allowed, err)+ }+ a.SetAdminUser("")+ }+ })+ }+ wg.Wait()+ a.SetAdminUser("")+ if allowed, err := a.Authorize(WithUser(context.Background(), "configured-admin"), ActionAdmin, ResourceUsers); allowed || err != nil {+ t.Fatalf("cleared admin allowed=%v err=%v", allowed, err)+ }+}diff --git a/pkg/auth/authorizer.go b/pkg/auth/authorizer.goindex c037e2ce5e..90f9b84bd8 100644--- a/pkg/auth/authorizer.go+++ b/pkg/auth/authorizer.go@@ -69,6 +69,8 @@ func SetAuthorizer(auth Authorizer) {}// AdminConfigurable is an optional interface for authorizers that can have an admin user set.+// SetAdminUser must be safe alongside Authorize calls; an empty username clears+// the previously configured identity.type AdminConfigurable interface {SetAdminUser(username string)}diff --git a/pkg/auth/policy_evaluator.go b/pkg/auth/policy_evaluator.goindex 80dad7de37..55c52e56d0 100644--- a/pkg/auth/policy_evaluator.go+++ b/pkg/auth/policy_evaluator.go@@ -3,6 +3,7 @@ package authimport ("context""strings"+ "sync")// PolicyEvaluator implements Authorizer with advanced policy evaluation.@@ -151,6 +152,7 @@ func (e *PolicyEvaluator) substituteVariables(value, username string, attributes// RBACAuthorizer wraps PolicyEvaluator to implement Authorizer for the RBAC system.type RBACAuthorizer struct {evaluator *PolicyEvaluator+ adminMu sync.RWMutexadminUser string}@@ -166,7 +168,10 @@ func (a *RBACAuthorizer) Authorize(ctx context.Context, action string, resourceusername := GetUser(ctx)// Admin user bypass- if a.adminUser != "" && username == a.adminUser {+ a.adminMu.RLock()+ isAdmin := a.adminUser != "" && username == a.adminUser+ a.adminMu.RUnlock()+ if isAdmin {return true, nil}@@ -175,7 +180,9 @@ func (a *RBACAuthorizer) Authorize(ctx context.Context, action string, resource// SetAdminUser sets the admin user who has full access.func (a *RBACAuthorizer) SetAdminUser(username string) {+ a.adminMu.Lock()a.adminUser = username+ a.adminMu.Unlock()}// AttributeAuthorizer extends Authorizer with attribute-based authorization.