auth

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Forget

func Forget(cfg Config) error

Forget removes the cached tokens.

func Save

func Save(cfg Config, t *Tokens) error

Save caches t, readable by the user only.

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.

func Claims

func Claims(idToken string) (*IDClaims, error)

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

func BrowserLogin(ctx context.Context, cfg Config, open func(url string)) (*Tokens, error)

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

func DeviceLogin(ctx context.Context, cfg Config, prompt func(url, code string)) (*Tokens, error)

DeviceLogin logs in with the device code flow. prompt is told where to go and which code to enter.

func Load

func Load(cfg Config) (*Tokens, error)

Load returns the cached tokens, nil if there are none.

func Refresh

func Refresh(ctx context.Context, cfg Config, t *Tokens) (*Tokens, error)

Refresh gets a new ID token with the refresh token.

func (*Tokens) Valid

func (t *Tokens) Valid(now time.Time) bool

Valid reports whether the ID token is good for at least another minute.

Jump to

Keyboard shortcuts

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