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): prefer hosted sessions over anonymous fallback

rcourtman4f2290d251d6
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index da5c46dbd4..3274e6653a 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -215,6 +215,12 @@ relay, the shared backend helper must auto-bootstrap the canonical relay
runtime state that onboarding and relay-status reads consume, while still
preserving explicit operator-owned disablement when a real relay config was
already written.
+That same hosted setup boundary also depends on tenant browser sessions staying
+canonical after cloud handoff. Lifecycle-adjacent mobile pairing and hosted
+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 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 5a4ee7fd16..2891bc8f29 100644
--- a/docs/release-control/v6/internal/subsystems/api-contracts.md
+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md
@@ -139,6 +139,7 @@ Own canonical runtime payload shapes between backend and frontend.
14. Keep Patrol quickstart transport semantics explicit as well: zero remaining quickstart credits are inventory data, not a standalone runtime-state override, so frontend consumers may only present the exhausted quickstart warning when the payload still reports `using_quickstart` or a runtime state that is blocked by quickstart exhaustion.
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`.
## Forbidden Paths
@@ -1574,6 +1575,13 @@ when hosted auth handoff preserves a non-default tenant org like `t-...`,
instance-level hosted billing lease from `default` if that tenant org has no
org-local billing state of its own, rather than failing closed into
`subscription_required` on first entry.
+That same hosted browser-session contract must also remain authoritative once
+the handoff lands on the tenant runtime: when a valid `pulse_session` cookie
+is present, shared `internal/api/auth.go` helpers must authenticate that
+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`.
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 6f2dd01f59..4844bf1a85 100644
--- a/docs/release-control/v6/internal/subsystems/storage-recovery.md
+++ b/docs/release-control/v6/internal/subsystems/storage-recovery.md
@@ -864,3 +864,9 @@ billing state grants relay, the shared runtime helper must persist the
canonical hosted relay config and keep subsequent reads on that same
machine-owned state instead of letting adjacent surfaces invent their own
fallback bootstrap or disable heuristics.
+That same shared `internal/api/` boundary also owns hosted browser-session
+precedence for adjacent protected reads. Storage- and recovery-adjacent hosted
+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.
diff --git a/internal/api/auth.go b/internal/api/auth.go
index 32c82d8614..8083bb97d2 100644
--- a/internal/api/auth.go
+++ b/internal/api/auth.go
@@ -511,20 +511,6 @@ func CheckAuth(cfg *config.Config, w http.ResponseWriter, r *http.Request) bool
}
}
- // If no auth is configured at all, allow access unless SSO is enabled.
- if cfg.AuthUser == "" && cfg.AuthPass == "" && !cfg.HasAPITokens() && cfg.ProxyAuthSecret == "" {
- if hasEnabledSSOProvidersForAuth(cfg) {
- log.Debug().Msg("SSO enabled without local credentials, authentication required")
- } else {
- log.Debug().Msg("No auth configured, allowing access as 'anonymous'")
- if w != nil {
- w.Header().Set("X-Authenticated-User", "anonymous")
- w.Header().Set("X-Auth-Method", "none")
- }
- return true
- }
- }
-
// API-only mode: when only API token is configured (no password auth)
if cfg.AuthUser == "" && cfg.AuthPass == "" && cfg.HasAPITokens() {
if providedToken, provided := explicitAPITokenFromRequest(r); provided {
@@ -618,6 +604,22 @@ func CheckAuth(cfg *config.Config, w http.ResponseWriter, r *http.Request) bool
Msg("No session cookie found")
}
+ // If no auth is configured at all, allow access unless SSO is enabled.
+ // A valid session still wins above, so hosted/cloud-handoff browser sessions
+ // do not get flattened into anonymous access.
+ if cfg.AuthUser == "" && cfg.AuthPass == "" && !cfg.HasAPITokens() && cfg.ProxyAuthSecret == "" {
+ if hasEnabledSSOProvidersForAuth(cfg) {
+ log.Debug().Msg("SSO enabled without local credentials, authentication required")
+ } else {
+ log.Debug().Msg("No auth configured, allowing access as 'anonymous'")
+ if w != nil {
+ w.Header().Set("X-Authenticated-User", "anonymous")
+ w.Header().Set("X-Auth-Method", "none")
+ }
+ return true
+ }
+ }
+
// Check basic auth
if cfg.AuthUser != "" && cfg.AuthPass != "" {
auth := r.Header.Get("Authorization")
diff --git a/internal/api/auth_helpers_test.go b/internal/api/auth_helpers_test.go
index 7a9439cb6b..4018c00f96 100644
--- a/internal/api/auth_helpers_test.go
+++ b/internal/api/auth_helpers_test.go
@@ -913,6 +913,12 @@ func TestCheckAuth_ValidSessionWithSlidingExpiration(t *testing.T) {
if !result {
t.Error("CheckAuth should return true for valid session with sliding expiration")
}
+ if got := w.Header().Get("X-Authenticated-User"); got != "testuser" {
+ t.Fatalf("X-Authenticated-User = %q, want testuser", got)
+ }
+ if got := w.Header().Get("X-Auth-Method"); got != "session" {
+ t.Fatalf("X-Auth-Method = %q, want session", got)
+ }
}
func TestCheckAuth_NoAuthConfigured(t *testing.T) {
diff --git a/internal/api/contract_test.go b/internal/api/contract_test.go
index 41b302131e..608b371beb 100644
--- a/internal/api/contract_test.go
+++ b/internal/api/contract_test.go
@@ -847,6 +847,34 @@ func TestContract_PersistentAuthStoresRequireExplicitInitialization(t *testing.T
assertPanics("recovery token store", func() { _ = GetRecoveryTokenStore() })
}
+func TestContract_HostedSessionAuthPrecedesAnonymousFallback(t *testing.T) {
+ resetPersistentAuthStoresForTests()
+ t.Cleanup(resetPersistentAuthStoresForTests)
+
+ InitSessionStore(t.TempDir())
+
+ store := GetSessionStore()
+ sessionToken := generateSessionToken()
+ store.CreateSession(sessionToken, 24*time.Hour, "contract-test", "127.0.0.1", "[email protected]")
+
+ req := httptest.NewRequest(http.MethodGet, "/api/security/tokens/relay-mobile", nil)
+ req.AddCookie(&http.Cookie{
+ Name: "pulse_session",
+ Value: sessionToken,
+ })
+ rec := httptest.NewRecorder()
+
+ if !CheckAuth(&config.Config{}, rec, req) {
+ t.Fatal("CheckAuth() = false, want true for valid hosted browser session")
+ }
+ if got := rec.Header().Get("X-Authenticated-User"); got != "[email protected]" {
+ t.Fatalf("X-Authenticated-User = %q, want [email protected]", got)
+ }
+ if got := rec.Header().Get("X-Auth-Method"); got != "session" {
+ t.Fatalf("X-Auth-Method = %q, want session", got)
+ }
+}
+
func TestContract_UnifiedAgentReportResponseJSONSnapshot(t *testing.T) {
payload := map[string]any{
"success": true,