appauth

package
v0.1.10 Latest Latest
Warning

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

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

Documentation

Overview

Package appauth is the hub's login-time authorization endpoint for published applications.

The design deliberately keeps the hub OFF the per-request data path:

  • Public apps never contact the hub at all.
  • Private apps redirect an unauthenticated browser here exactly once. The hub reuses the shared portal browser session (or bounces through the normal /login flow), evaluates ONE SubjectAccessReview against the tenant workspace, and hands the app's access proxy a one-use code. The proxy exchanges the code server-to-server and then maintains its own bounded local session; the hub is not consulted again until that session expires.

Access policy is plain kcp RBAC in the tenant workspace: visiting a private app requires `get` on the instance resource with subresource `access` (e.g. `applications/my-shop` + subresource `access`). Granting a member access is creating a ClusterRole/ClusterRoleBinding pair; revoking is deleting it. The hub carries no knowledge of any provider CRD schema — only resource coordinates supplied by the (controller-authored) proxy config, validated syntactically here.

Index

Constants

View Source
const (
	// AuthorizePath is the browser-facing entry point the access proxy
	// redirects to when a private app has no session.
	AuthorizePath = "/auth/apps/authorize"
	// ExchangePath is the server-to-server endpoint the access proxy calls to
	// turn a one-use code into a session grant.
	ExchangePath = "/auth/apps/exchange"
	// CallbackPath is the reserved path on the app host that authorize
	// redirects back to. It must stay in lockstep with the access proxy's
	// callback route (providers/infrastructure/accessproxy).
	CallbackPath = "/__faros/auth/callback"

	// AccessSubresource is the RBAC convention gating private apps: a visitor
	// needs `get` on `<resource>/<name>` with this subresource in the tenant
	// workspace. The subresource is never served; it exists only as an
	// authorization tuple.
	AccessSubresource = "access"
	// AccessVerb is the verb checked against the access subresource.
	AccessVerb = "get"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeRecord added in v0.1.2

type CodeRecord struct {
	Ref          InstanceRef
	RedirectHost string
	Identity     browsersession.Identity
	ExpiresAt    time.Time
}

CodeRecord is what authorize binds a code to and exchange verifies against. It carries identity metadata only — never a credential.

type CodeStore added in v0.1.2

type CodeStore interface {
	Put(ctx context.Context, code string, record CodeRecord) error
	Take(ctx context.Context, code string) (CodeRecord, bool)
}

CodeStore persists one-use authorization codes between the browser's authorize hop and the access proxy's server-to-server exchange.

Take MUST be atomic across every hub replica: a code that two callers can redeem is a replayable app sign-in.

type Config

type Config struct {
	// Sessions is the shared hub browser-session store (portal SSO).
	Sessions *browsersession.Store
	// SARClient resolves per-workspace SubjectAccessReview clients.
	SARClient SARFactory
	// AppsDomain is the DNS zone published apps live under
	// (e.g. "apps.faros.example"). Redirects are only issued to hosts
	// directly under this zone. Empty disables the endpoints.
	AppsDomain string
	// Codes persists the one-use authorization codes. It defaults to a
	// bounded process-local map, which is only correct for a single hub
	// replica: authorize and exchange are separate requests and a scaled hub
	// serves them from different pods. Supply a shared store (see
	// pkg/hub/sharedstore) whenever the hub runs more than one replica.
	Codes CodeStore
	// LoginPath is the hub-relative path of the interactive login page an
	// unauthenticated browser is sent to. Defaults to "/ui/login" (the
	// portal SPA is mounted under /ui/).
	LoginPath string
	// Now and Random are test seams.
	Now    func() time.Time
	Random io.Reader
}

Config assembles a Handler.

type ExchangeResponse

type ExchangeResponse struct {
	Allowed           bool   `json:"allowed"`
	UserID            string `json:"userId"`
	Email             string `json:"email,omitempty"`
	Name              string `json:"name,omitempty"`
	SessionTTLSeconds int64  `json:"sessionTtlSeconds"`
}

ExchangeResponse is returned to the proxy on a successful exchange. It contains identity metadata only — never a credential of any kind.

type Handler

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

Handler serves the authorize and exchange endpoints.

func New

func New(cfg Config) (*Handler, error)

New validates cfg and returns a Handler.

func (*Handler) HandleAuthorize

func (h *Handler) HandleAuthorize(w http.ResponseWriter, r *http.Request)

HandleAuthorize is the browser entry point.

GET /auth/apps/authorize?cluster=&group=&resource=&name=&redirect_uri=&state=

func (*Handler) HandleExchange

func (h *Handler) HandleExchange(w http.ResponseWriter, r *http.Request)

HandleExchange consumes a one-use code.

POST /auth/apps/exchange  {"code":..., "host":..., "cluster":..., ...}

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(router *mux.Router, limit func(http.HandlerFunc) http.HandlerFunc)

RegisterRoutes mounts the endpoints. limit wraps each handler with the hub's auth rate limiter; pass nil to mount unwrapped (tests).

type InstanceRef

type InstanceRef struct {
	Cluster  string // logical cluster ID of the tenant workspace
	Group    string // API group of the instance CRD
	Resource string // REST plural of the instance CRD
	Name     string // instance name
}

InstanceRef are the resource coordinates of a published template instance. They are authorization inputs only; the hub never reads the object.

type SARFactory

type SARFactory func(clusterID string) (authorizationv1client.SubjectAccessReviewInterface, error)

SARFactory returns a SubjectAccessReview client scoped to one logical cluster. The hub wires this from its kcp admin config; tests use fakes.

Jump to

Keyboard shortcuts

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