Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

fix(auth): honor hosted org management membership

rcourtman0ed613548b13
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 3ee3912325..4a8240a164 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -221,11 +221,12 @@ 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-mobile
credentials 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 same setup boundary also depends on canonical org-management 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's
+owner/admin membership 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 this
lifecycle 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.md
index 8e292fcf65..e5b5198b8a 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -140,7 +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.
+18. Keep tenant settings-scope authorization aligned with org management: `internal/api/security_setup_fix.go`, `internal/api/contract_test.go`, and settings-bound hosted callers must allow the current non-default org owner/admin membership to exercise privileged tenant routes, rather than requiring a separate configured local admin identity after hosted handoff.
## Forbidden Paths
@@ -1583,12 +1583,12 @@ session before any no-local-auth anonymous fallback is considered, so hosted
protected routes such as relay-mobile token minting, onboarding reads, and
billing-admin/API surfaces stay reachable after cloud handoff instead of
flattening 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.
+That same shared settings-scope contract must then preserve canonical
+org-management 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 honor the org's owner/admin membership model 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 metadata
reads. `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.md
index cabbf6ca7e..9f66e7f25a 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -870,9 +870,9 @@ surfaces may run without local auth configured, but a valid tenant
`pulse_session` must still authenticate before the anonymous optional-auth
fallback so hosted recovery, onboarding, and support flows do not silently
degrade 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.
+That same shared settings helper layer must then preserve canonical
+org-management privilege for non-default tenant requests. Storage- and
+recovery-adjacent hosted flows that reuse settings-bound helpers must allow
+the current org owner/admin membership 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.go
index f905a32e15..d7580fd33b 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -875,7 +875,7 @@ func TestContract_HostedSessionAuthPrecedesAnonymousFallback(t *testing.T) {
}
}
-func TestContract_HostedOrgOwnerSessionCanMintRelayMobileToken(t *testing.T) {
+func TestContract_HostedOrgManagerSessionCanMintRelayMobileToken(t *testing.T) {
defer SetMultiTenantEnabled(false)
SetMultiTenantEnabled(true)
t.Setenv("PULSE_DEV", "true")
@@ -897,9 +897,10 @@ func TestContract_HostedOrgOwnerSessionCanMintRelayMobileToken(t *testing.T) {
org := &models.Organization{
ID: "org-a",
DisplayName: "Org A",
- OwnerUserID: "alice",
+ OwnerUserID: "operator-owner",
Members: []models.OrganizationMember{
- {UserID: "alice", Role: models.OrgRoleOwner, AddedAt: time.Now()},
+ {UserID: "legacy-owner", Role: models.OrgRoleOwner, AddedAt: time.Now()},
+ {UserID: "operator-owner", Role: models.OrgRoleOwner, AddedAt: time.Now()},
},
}
if err := mtp.SaveOrganization(org); err != nil {
@@ -909,7 +910,7 @@ func TestContract_HostedOrgOwnerSessionCanMintRelayMobileToken(t *testing.T) {
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")
+ GetSessionStore().CreateSession(sessionToken, time.Hour, "agent", "127.0.0.1", "legacy-owner")
req := httptest.NewRequest(http.MethodPost, "/api/security/tokens/relay-mobile", strings.NewReader(`{}`))
req.Header.Set("Content-Type", "application/json")
@@ -934,8 +935,8 @@ func TestContract_HostedOrgOwnerSessionCanMintRelayMobileToken(t *testing.T) {
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 payload.Record.OwnerUserID != "legacy-owner" {
+ t.Fatalf("ownerUserId = %q, want legacy-owner", payload.Record.OwnerUserID)
}
if len(cfg.APITokens) != 1 {
t.Fatalf("expected one stored token, got %d", len(cfg.APITokens))
diff --git a/internal/api/security_setup_fix.go b/internal/api/security_setup_fix.go
index f39a93c899..4813c4a205 100644
--- a/internal/api/security_setup_fix.go
+++ b/internal/api/security_setup_fix.go
@@ -65,12 +65,11 @@ func ensureAdminSession(cfg *config.Config, w http.ResponseWriter, req *http.Req
return true
}
- // Org-scoped tenant sessions preserve the org owner as the canonical
- // privileged actor for settings-bound routes.
+ // Org-scoped tenant sessions preserve canonical org management
+ // privileges 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) {
+ if orgID != "" && orgID != "default" && org.CanUserManage(sessionUser) {
return true
}
}
diff --git a/internal/api/security_setup_fix_test.go b/internal/api/security_setup_fix_test.go
index c6691bbfb9..657fdf2722 100644
--- a/internal/api/security_setup_fix_test.go
+++ b/internal/api/security_setup_fix_test.go
@@ -507,30 +507,34 @@ func TestEnsureSettingsWriteScopeAllowsConfiguredAdminSession(t *testing.T) {
}
}
-func TestEnsureSettingsWriteScopeAllowsOrgOwnerSession(t *testing.T) {
+func TestEnsureSettingsWriteScopeAllowsOrgManagerSession(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")
+ GetSessionStore().CreateSession(sessionToken, time.Hour, "agent", "127.0.0.1", "legacy-owner")
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",
+ OwnerUserID: "operator-owner",
+ Members: []models.OrganizationMember{
+ {UserID: "legacy-owner", Role: models.OrgRoleOwner},
+ {UserID: "operator-owner", Role: models.OrgRoleOwner},
+ },
}))
rr := httptest.NewRecorder()
result := ensureSettingsWriteScope(cfg, rr, req)
if !result {
- t.Fatal("ensureSettingsWriteScope should allow org owner session users")
+ t.Fatal("ensureSettingsWriteScope should allow org manager session users")
}
if rr.Code != http.StatusOK {
- t.Fatalf("expected 200 for org owner session, got %d", rr.Code)
+ t.Fatalf("expected 200 for org manager session, got %d", rr.Code)
}
}