Documentation
¶
Overview ¶
Package auth logs mcloud (and kubectl, through mcloud credential) in to the cluster with the homelab's OpenID Connect provider (Authelia): the cluster's API server trusts its ID tokens (UKS cluster authentication).
Two ways to log in: the device code flow (mcloud prints a code, you approve it in any browser; works over SSH), and the browser flow with PKCE on a fixed loopback port. The ID token, which the API server checks, and the refresh token are cached in ~/.cache/mcloud; the ID token is refreshed when it expires, and a new login is needed when the refresh token does.
Index ¶
- Constants
- func Forget(cfg Config) error
- func Save(cfg Config, t *Tokens) error
- type Config
- type IDClaims
- type Tokens
- func BrowserLogin(ctx context.Context, cfg Config, open func(url string)) (*Tokens, error)
- func DeviceLogin(ctx context.Context, cfg Config, prompt func(url, code string)) (*Tokens, error)
- func Load(cfg Config) (*Tokens, error)
- func Refresh(ctx context.Context, cfg Config, t *Tokens) (*Tokens, error)
Constants ¶
const ( DefaultIssuer = "https://auth.lab.gronblom.dev" DefaultClientID = "kubernetes" // The browser flow's redirect, registered exactly so in Authelia. CallbackAddr = "127.0.0.1:18000" CallbackPath = "/callback" )
Defaults for the homelab: Authelia, and the client the cluster's API server accepts tokens for (its audience).
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
Issuer string
ClientID string
// CacheDir holds the tokens (default ~/.cache/mcloud).
CacheDir string
HTTP *http.Client
}
Config says which provider and client to log in with.
type IDClaims ¶
type IDClaims struct {
Exp int64 `json:"exp"`
PreferredUsername string `json:"preferred_username"`
Groups []string `json:"groups"`
}
IDClaims are the ID token's claims mcloud shows. It doesn't check the signature: the API server does.
type Tokens ¶
type Tokens struct {
Issuer string `json:"issuer"`
ClientID string `json:"clientID"`
IDToken string `json:"idToken"`
RefreshToken string `json:"refreshToken,omitempty"`
Expiry time.Time `json:"expiry"` // the ID token's
User string `json:"user,omitempty"`
Groups []string `json:"groups,omitempty"`
}
Tokens is what's cached.
func BrowserLogin ¶
BrowserLogin logs in with the authorization code flow and PKCE: it listens on CallbackAddr for the redirect, and open is asked to show the login page.
func DeviceLogin ¶
DeviceLogin logs in with the device code flow. prompt is told where to go and which code to enter.