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): allow hosted org owners through settings scope
rcourtmane8adec541128
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.mdindex 3274e6653a..3ee3912325 100644--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md@@ -221,6 +221,11 @@ admin setup routes may run without local credentials configured, but shared`internal/api/auth.go` helpers must still honor a valid hosted `pulse_session`before any optional-auth anonymous fallback so operators can mint relay-mobilecredentials and continue onboarding from the hosted runtime itself.+The same setup boundary also depends on org-owned privilege surviving the next+step: once the request is scoped to a hosted tenant org, shared+`internal/api/security_setup_fix.go` helpers must allow that org owner session+to exercise settings-bound pairing routes instead of requiring a separate+configured local admin username that does not exist on hosted tenants.The direct Proxmox fallback workspace now also lives explicitly inside thislifecycle boundary: `InfrastructureWorkspace.tsx`,`infrastructureWorkspaceModel.ts`,diff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 2891bc8f29..8e292fcf65 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -140,6 +140,7 @@ Own canonical runtime payload shapes between backend and frontend.15. Keep Patrol intelligence summary transport semantics single-voiced: the canonical overall-health payload and Patrol run-history payload together must support one primary assessment plus one explicit verification explanation, and frontend consumers must not need to derive a second compact assessment or verification verdict row from the same payloads beneath the primary summary card.16. Keep Pulse Mobile relay credential minting and permission ownership on backend ownership: `internal/api/router_routes_auth_security.go`, `internal/api/security_tokens.go`, `internal/api/auth.go`, `internal/api/router_routes_ai_relay.go`, and `frontend-modern/src/api/security.ts` may expose the canonical mobile runtime token creator and governed route gates, but browser callers must only consume that route and must not define the mobile runtime scope, compatibility gate list, or token-purpose metadata locally.17. Keep hosted tenant browser-session precedence on the shared auth boundary: `internal/api/auth.go`, `internal/api/contract_test.go`, and hosted tenant callers must treat a valid `pulse_session` as authoritative before any no-local-auth anonymous fallback, so cloud handoff can continue into protected hosted routes without flattening the operator back to `anonymous`.+18. Keep tenant settings-scope authorization aligned with org ownership: `internal/api/security_setup_fix.go`, `internal/api/contract_test.go`, and settings-bound hosted callers must allow the current non-default org owner session to exercise privileged tenant routes, rather than requiring a separate configured local admin identity after hosted handoff.## Forbidden Paths@@ -1582,6 +1583,12 @@ session before any no-local-auth anonymous fallback is considered, so hostedprotected routes such as relay-mobile token minting, onboarding reads, andbilling-admin/API surfaces stay reachable after cloud handoff instead offlattening the operator back to `anonymous`.+That same shared settings-scope contract must then preserve org-owned+privilege on the tenant side: when a hosted or multi-tenant request is scoped+to a non-default org, `internal/api/security_setup_fix.go` must treat the+current org owner session as the canonical privileged actor for settings-bound+routes such as relay-mobile token minting, instead of requiring a separate+configured local admin username that hosted tenants do not carry.The shared security token contract now also includes single-record metadatareads. `internal/api/security_tokens.go`,`internal/api/router_routes_auth_security.go`,diff --git a/docs/release-control/v6/internal/subsystems/storage-recovery.md b/docs/release-control/v6/internal/subsystems/storage-recovery.mdindex 4844bf1a85..cabbf6ca7e 100644--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md@@ -870,3 +870,9 @@ surfaces may run without local auth configured, but a valid tenant`pulse_session` must still authenticate before the anonymous optional-authfallback so hosted recovery, onboarding, and support flows do not silentlydegrade into unauthenticated state after cloud handoff.+That same shared settings helper layer must then preserve org-owned privilege+for non-default tenant requests. Storage- and recovery-adjacent hosted flows+that reuse settings-bound helpers must allow the current org owner session to+continue through privileged tenant routes after cloud handoff instead of+requiring a separate configured local admin identity that hosted tenants do+not carry.diff --git a/internal/api/contract_test.go b/internal/api/contract_test.goindex 608b371beb..f905a32e15 100644--- a/internal/api/contract_test.go+++ b/internal/api/contract_test.go@@ -875,6 +875,76 @@ func TestContract_HostedSessionAuthPrecedesAnonymousFallback(t *testing.T) {}}+func TestContract_HostedOrgOwnerSessionCanMintRelayMobileToken(t *testing.T) {+ defer SetMultiTenantEnabled(false)+ SetMultiTenantEnabled(true)+ t.Setenv("PULSE_DEV", "true")++ dataDir := t.TempDir()+ hashed, err := authpkg.HashPassword("Password!1")+ if err != nil {+ t.Fatalf("hash password: %v", err)+ }++ cfg := &config.Config{+ DataPath: dataDir,+ ConfigPath: dataDir,+ AuthUser: "platform-admin",+ AuthPass: hashed,+ }++ mtp := config.NewMultiTenantPersistence(dataDir)+ org := &models.Organization{+ ID: "org-a",+ DisplayName: "Org A",+ OwnerUserID: "alice",+ Members: []models.OrganizationMember{+ {UserID: "alice", Role: models.OrgRoleOwner, AddedAt: time.Now()},+ },+ }+ if err := mtp.SaveOrganization(org); err != nil {+ t.Fatalf("save organization: %v", err)+ }++ router := newMultiTenantRouter(t, cfg)++ sessionToken := "relay-owner-session-" + strings.ReplaceAll(time.Now().UTC().Format(time.RFC3339Nano), ":", "-")+ GetSessionStore().CreateSession(sessionToken, time.Hour, "agent", "127.0.0.1", "alice")++ req := httptest.NewRequest(http.MethodPost, "/api/security/tokens/relay-mobile", strings.NewReader(`{}`))+ req.Header.Set("Content-Type", "application/json")+ req.Header.Set("X-CSRF-Token", generateCSRFToken(sessionToken))+ req.Header.Set("X-Pulse-Org-ID", "org-a")+ req.AddCookie(&http.Cookie{Name: cookieNameSession, Value: sessionToken})++ rec := httptest.NewRecorder()+ router.Handler().ServeHTTP(rec, req)++ if rec.Code != http.StatusOK {+ t.Fatalf("relay mobile token route status = %d, want %d: %s", rec.Code, http.StatusOK, rec.Body.String())+ }++ var payload struct {+ Token string `json:"token"`+ Record apiTokenDTO `json:"record"`+ }+ if err := json.NewDecoder(rec.Body).Decode(&payload); err != nil {+ t.Fatalf("decode relay mobile response: %v", err)+ }+ if payload.Token == "" {+ t.Fatal("expected relay mobile token in response")+ }+ if payload.Record.OwnerUserID != "alice" {+ t.Fatalf("ownerUserId = %q, want alice", payload.Record.OwnerUserID)+ }+ if len(cfg.APITokens) != 1 {+ t.Fatalf("expected one stored token, got %d", len(cfg.APITokens))+ }+ if cfg.APITokens[0].OrgID != "org-a" {+ t.Fatalf("stored token orgId = %q, want org-a", cfg.APITokens[0].OrgID)+ }+}+func TestContract_UnifiedAgentReportResponseJSONSnapshot(t *testing.T) {payload := map[string]any{"success": true,diff --git a/internal/api/security_setup_fix.go b/internal/api/security_setup_fix.goindex 17a71a1dcb..f39a93c899 100644--- a/internal/api/security_setup_fix.go+++ b/internal/api/security_setup_fix.go@@ -60,6 +60,21 @@ func ensureAdminSession(cfg *config.Config, w http.ResponseWriter, req *http.Reqif cfg != nil {configuredAdmin = strings.TrimSpace(cfg.AuthUser)}++ if configuredAdmin != "" && strings.EqualFold(sessionUser, configuredAdmin) {+ return true+ }++ // Org-scoped tenant sessions preserve the org owner as the canonical+ // privileged actor for settings-bound routes.+ if org := GetOrganization(req.Context()); org != nil {+ orgID := strings.TrimSpace(org.ID)+ orgOwner := strings.TrimSpace(org.OwnerUserID)+ if orgID != "" && orgID != "default" && orgOwner != "" && strings.EqualFold(sessionUser, orgOwner) {+ return true+ }+ }+if configuredAdmin == "" || !strings.EqualFold(sessionUser, configuredAdmin) {log.Warn().Str("path", req.URL.Path).diff --git a/internal/api/security_setup_fix_test.go b/internal/api/security_setup_fix_test.goindex e76118cb3e..c6691bbfb9 100644--- a/internal/api/security_setup_fix_test.go+++ b/internal/api/security_setup_fix_test.go@@ -1,6 +1,7 @@package apiimport (+ "context""errors""net/http""net/http/httptest"@@ -12,6 +13,7 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/bootstrap""github.com/rcourtman/pulse-go-rewrite/internal/config"+ "github.com/rcourtman/pulse-go-rewrite/internal/models"internalauth "github.com/rcourtman/pulse-go-rewrite/pkg/auth")@@ -505,6 +507,33 @@ func TestEnsureSettingsWriteScopeAllowsConfiguredAdminSession(t *testing.T) {}}+func TestEnsureSettingsWriteScopeAllowsOrgOwnerSession(t *testing.T) {+ cfg := &config.Config{+ AuthUser: "platform-admin",+ }++ sessionToken := "settings-write-owner-" + time.Now().Format("150405.000000002")+ GetSessionStore().CreateSession(sessionToken, time.Hour, "agent", "127.0.0.1", "alice")++ req := httptest.NewRequest(http.MethodPost, "/api/security/test", nil)+ req.AddCookie(&http.Cookie{Name: "pulse_session", Value: sessionToken})+ req = req.WithContext(context.WithValue(req.Context(), OrgContextKey, &models.Organization{+ ID: "org-a",+ DisplayName: "Org A",+ OwnerUserID: "alice",+ }))++ rr := httptest.NewRecorder()+ result := ensureSettingsWriteScope(cfg, rr, req)++ if !result {+ t.Fatal("ensureSettingsWriteScope should allow org owner session users")+ }+ if rr.Code != http.StatusOK {+ t.Fatalf("expected 200 for org owner session, got %d", rr.Code)+ }+}+func TestValidateBcryptHash(t *testing.T) {tests := []struct {name string