auth

package
v0.17.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Claims

type Claims struct {
	jwt.RegisteredClaims
	// Cloud service accounts carry a numeric database ID; user tokens omit it.
	// Older callers may carry a string. This claim is diagnostic, not RBAC scope.
	OrganizationID string   `json:"organization_id,omitempty"`
	GroupIDs       []string `json:"group_ids,omitempty"`
	// Email and Name describe the user at the time cloud minted the token.
	// Service-account tokens, and user tokens from older clouds, carry neither.
	Email string `json:"email,omitempty"`
	Name  string `json:"name,omitempty"`
}

Claims represents the JWT claims from miren.cloud

func ParseUnverifiedClaims

func ParseUnverifiedClaims(token string) (*Claims, error)

ParseUnverifiedClaims parses JWT claims without verification This is only for client-side display purposes and should NOT be used for authentication

func (*Claims) UnmarshalJSON added in v0.17.0

func (c *Claims) UnmarshalJSON(data []byte) error

UnmarshalJSON preserves the diagnostic string API while accepting cloud's numeric organization claim without losing int64 precision.

type JWK

type JWK struct {
	Kty string `json:"kty"` // Key type (OKP for Ed25519)
	Kid string `json:"kid"` // Key ID
	Use string `json:"use"` // Key use (sig)
	Alg string `json:"alg"` // Algorithm (EdDSA)
	Crv string `json:"crv"` // Curve (Ed25519)
	X   string `json:"x"`   // X coordinate (public key for Ed25519)
}

JWK represents a JSON Web Key

type JWKS

type JWKS struct {
	Keys []JWK `json:"keys"`
}

JWKS represents a JSON Web Key Set

type JWTValidator

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

JWTValidator validates JWT tokens from miren.cloud using EdDSA signatures. It fetches public keys from the JWKS endpoint at {cloudURL}/.well-known/jwks.json and caches them for efficient validation. Only Ed25519 keys are supported.

Cloud's last published keys stay trusted until cloud publishes different ones. An unreachable cloud is not news that a key was withdrawn, and treating it as such would lock every cloud user out of a cluster that cannot reach it.

func NewJWTValidator

func NewJWTValidator(cloudURL string, logger *slog.Logger) *JWTValidator

NewJWTValidator creates a new JWT validator

func (*JWTValidator) Start added in v0.17.0

func (v *JWTValidator) Start(ctx context.Context)

Start runs the refresher until ctx ends. It fetches cloud's keys at once unless fresh ones were restored, again each refreshInterval, and after a failure retries each retryInterval until a fetch succeeds. Requests never refresh known keys themselves, so nothing about an unreachable cloud costs them anything.

func (*JWTValidator) UseKeyCache added in v0.17.0

func (v *JWTValidator) UseKeyCache(path string)

UseKeyCache saves cloud's keys at path after each fetch, and restores any saved there now, so a restart while cloud is unreachable can still validate tokens. Call it before the validator is shared.

func (*JWTValidator) ValidateToken

func (v *JWTValidator) ValidateToken(ctx context.Context, tokenString string) (*Claims, error)

ValidateToken validates a JWT token and returns the claims

type TokenCache

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

TokenCache caches validated tokens to reduce validation overhead

func NewTokenCache

func NewTokenCache(ctx context.Context) *TokenCache

NewTokenCache creates a new token cache

func (*TokenCache) Get

func (tc *TokenCache) Get(token string) (*Claims, bool)

Get retrieves claims from cache if valid

func (*TokenCache) Set

func (tc *TokenCache) Set(token string, claims *Claims)

Set stores claims in cache

Jump to

Keyboard shortcuts

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