proxy

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package proxy reverse-proxies authenticated requests to kcp.

Index

Constants

This section is empty.

Variables

View Source
var ErrIdentifyNoBearer = errors.New("no Authorization: Bearer token")

ErrIdentifyNoBearer is returned by IdentifyUser when the request carries no Authorization: Bearer header. Callers (e.g. the tenant middleware) translate this into a 401.

Functions

This section is empty.

Types

type KCPProxy

type KCPProxy struct {
	// contains filtered or unexported fields
}

KCPProxy is a reverse proxy that authenticates requests via OIDC and forwards them to the user's dedicated kcp tenant workspace.

func NewKCPProxy

func NewKCPProxy(kcpConfig *rest.Config, verifier *oidc.IDTokenVerifier, farosClient *farosclient.Client, bootstrapper *kcp.Bootstrapper, staticAuthTokens []string, hubExternalURL string, devMode bool) (*KCPProxy, error)

NewKCPProxy creates a reverse proxy to kcp. It validates bearer tokens as OIDC id_tokens before proxying. verifier may be nil when only static token auth is used.

func (*KCPProxy) BrowserIdentity

func (p *KCPProxy) BrowserIdentity(r *http.Request) (browsersession.Identity, error)

BrowserIdentity validates a portal bearer and resolves it to the stable platform user identity used by the shared browser-session store. The returned value contains no bearer, kubeconfig, or OIDC token.

func (*KCPProxy) HandleTokenLogin

func (p *KCPProxy) HandleTokenLogin(w http.ResponseWriter, r *http.Request)

HandleTokenLogin handles static token login requests. POST /auth/token-login with Authorization: Bearer <token> Returns a LoginResponse with kubeconfig pointing to the user's workspace. Note: This handler should be wrapped with rate limiting using HandleTokenLoginRateLimited when registering routes to prevent brute force attacks.

func (*KCPProxy) HandleTokenLoginRateLimited

func (p *KCPProxy) HandleTokenLoginRateLimited(w http.ResponseWriter, r *http.Request)

HandleTokenLoginRateLimited wraps HandleTokenLogin with rate limiting. This should be used when registering the route to protect against brute force attacks. In devMode the limiter is bypassed: dev clusters share a single client IP (localhost) across many test/CLI invocations, which trivially exhausts the per-IP bucket and is not a realistic threat model for dev.

func (*KCPProxy) IdentifyUser

func (p *KCPProxy) IdentifyUser(r *http.Request) (string, error)

IdentifyUser extracts the caller's User CR name from r's bearer token, using the same auth schemes as ServeHTTP (static token, OIDC). Used by hub REST endpoints behind the tenant middleware so they can identify the caller without duplicating the proxy's auth dispatch.

Returns ErrIdentifyNoBearer for missing/unparseable Authorization headers, and other errors for verification failures. kcp ServiceAccount tokens are intentionally not accepted here — REST endpoints are addressed by humans (or by their portal session) and not by edge-side bots.

func (*KCPProxy) ServeHTTP

func (p *KCPProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP validates the bearer token and proxies the request to kcp. Two token types are supported:

  • OIDC id_tokens (from Dex): resolved to a tenant workspace via User CRD lookup, forwarded with admin credentials.
  • kcp ServiceAccount tokens: the clusterName claim identifies the workspace, forwarded with the original SA token so kcp handles authn/authz natively.

func (*KCPProxy) SetBrowserSessionStore

func (p *KCPProxy) SetBrowserSessionStore(store *browsersession.Store)

SetBrowserSessionStore wires the hub-wide opaque browser-session store used by static-token portal login. The proxy never places the static bearer in that store or in the cookie; it records only the resolved User identity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL