Documentation
¶
Overview ¶
Package browsersession owns the hub's shared browser login session.
A browser receives only a random, host-only cookie. The value is never a user identity or a platform credential: the store keeps a SHA-256 lookup key and the identity server-side. This package deliberately has no OIDC, Kubernetes, or hub dependencies so every HTTP boundary can share the same session contract without creating an import cycle.
Index ¶
- Constants
- Variables
- func ClearCookie(w http.ResponseWriter)
- func ConstantTimeEqual(a, b string) bool
- type Config
- type Identity
- type Session
- type Store
- func (s *Store) Issue(identity Identity) (string, Session, error)
- func (s *Store) IssueHTTP(w http.ResponseWriter, identity Identity) (Session, error)
- func (s *Store) Resolve(value string) (Session, error)
- func (s *Store) ResolveRequest(r *http.Request) (Session, error)
- func (s *Store) Revoke(value string) error
- func (s *Store) RevokeRequest(w http.ResponseWriter, r *http.Request)
- func (s *Store) TTL() time.Duration
Constants ¶
const ( // CookieName is the one shared portal/browser session cookie. The __Host- // prefix requires Secure, Path=/, and no Domain attribute, which makes the // cookie host-only even when an app is served from a sibling subdomain. CookieName = "__Host-faros-session" // SessionCookieName is retained as a descriptive alias for callers that // already use the access-proxy naming convention. SessionCookieName = CookieName )
Variables ¶
Functions ¶
func ClearCookie ¶
func ClearCookie(w http.ResponseWriter)
ClearCookie writes an expired shared cookie without touching server state.
func ConstantTimeEqual ¶
ConstantTimeEqual is a small helper for callers comparing a cookie value against a request-bound value without introducing a second implementation.
Types ¶
type Config ¶
Config configures a Store. Now and Random are test seams; production uses time.Now and crypto/rand.Reader. MaxEntries bounds process-local memory so an unbounded stream of logins cannot grow the store indefinitely.
type Identity ¶
type Identity struct {
UserID string
Email string
Name string
// RBACIdentity is the kcp username this account authenticates as inside
// tenant workspaces (User.Spec.RBACIdentity, e.g. "faros:<email>"). All
// workspace RBAC — admin ClusterRoleBindings and app-access grants — is
// written against this string, so authorization checks (SAR) must use it,
// never the User CR name. Not a credential.
RBACIdentity string
Issuer string
Subject string
AuthType string
}
Identity is the minimum server-side identity needed by hub and provider authorization. Credentials, ID tokens, refresh tokens, and kubeconfigs are intentionally not representable here.
type Session ¶
Session is the server-side representation associated with the opaque browser cookie. ID is returned to trusted hub callers for diagnostics; it is never serialized into the cookie itself.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a concurrency-safe, process-local browser-session store. It is intentionally an in-memory implementation: deployments that need durable sessions can replace the store behind the same HTTP integration without changing the browser contract.
func (*Store) Issue ¶
Issue stores identity and returns the opaque cookie value plus its server-side view. It rejects empty stable identities so callers cannot accidentally mint an anonymous session.
func (*Store) ResolveRequest ¶
ResolveRequest resolves the shared cookie from an HTTP request.
func (*Store) Revoke ¶
Revoke invalidates a session immediately. Repeated revocation is idempotent, which makes logout safe to retry.
func (*Store) RevokeRequest ¶
func (s *Store) RevokeRequest(w http.ResponseWriter, r *http.Request)
RevokeRequest revokes the shared cookie, if one is present, and emits an expired cookie. It is safe for anonymous requests.