Documentation
¶
Overview ¶
Package auth resolves who is making a status-server request. It owns the sign-in surface — the OIDC authorization-code flow (the server itself is the OAuth2 client), the encrypted chunked session cookies, and the small SPA-visible state cookies — and hands the rest of the server a bare Identity. The package deliberately imports nothing from Kubernetes: what an identity may do is internal/web/authz's concern.
Four modes exist, selected by the mounted configuration file: "unconfigured" (no file: no session is ever resolved and no sign-in routes are registered, leaving only the public surface), "none" (a fixed identity with authorization bypassed — development), "anonymous" (a fixed identity that still passes through RBAC access reviews), and "oidc" (the real SSO flow).
Index ¶
Constants ¶
const ( // ModeNone disables authentication entirely: every request is a fixed // development identity and authorization is bypassed. ModeNone = "none" // ModeAnonymous serves every request as one fixed identity that still // passes through RBAC access reviews. ModeAnonymous = "anonymous" // ModeOIDC runs the SSO authorization-code flow. ModeOIDC = "oidc" )
Modes the configuration file selects between.
const ( // CookieProvider tells the SPA whether and how sign-in works: // {"provider","authenticated","autoLogin"}, base64url JSON. CookieProvider = "patchy-auth-provider" // CookieAuthError carries a human-readable sign-in failure to the SPA. CookieAuthError = "patchy-auth-error" // CookieLogout marks an explicit sign-out so autoLogin pauses for it. CookieLogout = "patchy-auth-logout" )
Cookie names. The session and state cookies are HttpOnly and carry sealed data; the provider/error/logout cookies are SPA-visible and carry no secrets — they only tell the client what the sign-in surface looks like.
const DefaultSessionDuration = 7 * 24 * time.Hour
DefaultSessionDuration bounds a session when the configuration does not.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnonymousConfig ¶
type AnonymousConfig struct {
// Username of the fixed identity.
Username string `yaml:"username"`
// Groups of the fixed identity.
Groups []string `yaml:"groups"`
}
AnonymousConfig is the fixed identity every request resolves to in mode anonymous. Access reviews still run for it, so cluster RBAC decides what the identity may see and do.
type Authenticator ¶
type Authenticator interface {
// Identify resolves the current session. It may write cookies (token
// refresh, SPA state) — hence the ResponseWriter. (nil, nil) means "no
// session"; callers map that to 401 on protected routes.
Identify(w http.ResponseWriter, r *http.Request) (*Identity, error)
// Register adds the sign-in routes (/oauth2/*, /logout) to mux. Modes
// without a sign-in surface register nothing.
Register(mux *http.ServeMux)
}
Authenticator resolves the requester of an HTTP request.
type ClaimsConfig ¶
type ClaimsConfig struct {
// Username claim access reviews run for (default email).
Username string `yaml:"username"`
// Groups claim (default groups).
Groups string `yaml:"groups"`
// DisplayName claim the UI shows (default name).
DisplayName string `yaml:"displayName"`
}
ClaimsConfig names the token claims the identity is read from. These are claim names, not expressions.
type Config ¶
type Config struct {
// Mode is none, anonymous, or oidc.
Mode string `yaml:"mode"`
// SessionDuration caps a session's lifetime (default 168h).
SessionDuration Duration `yaml:"sessionDuration"`
// Insecure drops the Secure flag from cookies for plain-HTTP local
// development. Never set it behind a real ingress.
Insecure bool `yaml:"insecure"`
// Anonymous configures the fixed identity of mode anonymous.
Anonymous *AnonymousConfig `yaml:"anonymous"`
// OIDC configures the SSO provider of mode oidc.
OIDC *OIDCConfig `yaml:"oidc"`
}
Config is the mounted authentication configuration.
func LoadConfig ¶
LoadConfig reads and validates the configuration at path. An empty path or a missing file returns (nil, nil) — the unconfigured posture; the caller logs the consequence. A present-but-invalid file is an error: a broken configuration must not silently downgrade to no authentication.
type Duration ¶
Duration is a time.Duration that unmarshals from Go duration strings ("168h", "30m") — the YAML decoder has no native duration notion.
type Identity ¶
type Identity struct {
// Username is the subject access reviews run for.
Username string
// Groups are the subject's groups for access reviews.
Groups []string
// DisplayName is the human-facing name (falls back to Username).
DisplayName string
// Session reports whether the identity is backed by a sign-in session
// (the UI renders the user menu and sign-out only for sessions).
Session bool
}
Identity is the resolved requester. Username and Groups feed access reviews; DisplayName is what the UI shows.
type OIDCConfig ¶
type OIDCConfig struct {
// IssuerURL is the provider's issuer for discovery.
IssuerURL string `yaml:"issuerURL"`
// ClientID of the registered client.
ClientID string `yaml:"clientID"`
// ClientSecret of the registered client. The secret also keys the
// cookie/state encryption, so rotating it invalidates live sessions.
ClientSecret string `yaml:"clientSecret"`
// ClientSecretFile reads the client secret from a file (e.g. a projected
// Secret key) instead of inline.
ClientSecretFile string `yaml:"clientSecretFile"`
// Scopes requested at authorization (default: openid, offline_access,
// profile, email, groups).
Scopes []string `yaml:"scopes"`
// AuthURLParams are extra authorize-endpoint query parameters.
AuthURLParams map[string]string `yaml:"authURLParams"`
// AutoLogin redirects an unauthenticated browser straight to the
// provider instead of showing the sign-in panel.
AutoLogin bool `yaml:"autoLogin"`
// RedirectURL overrides the derived callback URL for deployments where
// the fronting proxy's forwarded headers cannot be trusted.
RedirectURL string `yaml:"redirectURL"`
// Claims maps token claims onto the identity.
Claims ClaimsConfig `yaml:"claims"`
}
OIDCConfig is the SSO provider for mode oidc.