Files
Pulse/internal/api/websocket_auth.go
rcourtman f37c102535 Limit the default organization in multi-org mode
In self-hosted multi-organization mode the tenant check let every
signed-in session or proxy user into the default organization, so a
user invited only to another organization could read the default
estate by selecting it with the org header or cookie.

The default organization is now open there only to instance
administrators (local admin, an RBAC admin grant evaluated with
inheritance and deny precedence, or a proxy user admitted with the
admin role) and to explicit members recorded in its org.json, loaded
strictly. Having no other membership is never treated as access.
Single-tenant and hosted runtimes keep the open default organization.

One context-aware policy now serves tenant selection, action
authority, the organization handlers and the WebSocket hub, which
also checks the default organization. WebSocket, SSE and agent-event
streams re-check it every 10 seconds, so revoked access ends live
reads. Handlers that re-derive the org from the request now follow
the authorized org.

A request that names no organization lands in the user's first
organization. A refused default selection answers
default_org_access_denied; the browser clears it and retries reads
only. A user with no usable organization sees their pending
invitations instead of a connection failure.

Instance administrators manage default members from Organization
access. Members are viewers, membership is the only entitlement (an
owner field grants nothing), and every save of the default
organization keeps its current members, so a share or invitation
change made from an older snapshot cannot restore a revoked one. The first
start in this mode seeds RBAC-assigned users who belong to no other
organization, and retries rather than completing on unreadable
tenant metadata or RBAC data.

Listing an organization's invitations now returns [] instead of null
when none are pending; the Organization access panel rejected null and
showed "Organization access unavailable" to any org admin without
pending invitations.
2026-11-03 15:57:34 +00:00

24 lines
792 B
Go

package api
import (
"net/http"
"github.com/rcourtman/pulse-go-rewrite/internal/config"
)
func monitoringWebSocketAuthorization(cfg *config.Config, req *http.Request) func() bool {
// The socket writer outlives this HTTP request. Give it an immutable
// request copy, not one its returning middleware may still be observing.
revalidate := monitoringTokenSnapshotRevalidator(cfg, req.Clone(req.Context()))
// A signed-in user's socket also follows the organization access policy,
// so membership removal or lost default-organization access ends it.
orgAccess := orgAccessRevalidator(req)
if revalidate == nil {
return combineAuthorization(sessionReadRevalidator(req), orgAccess)
}
return combineAuthorization(func() bool {
_, ok := revalidate()
return ok
}, orgAccess)
}