session

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package session provides a session manager for creating and verifying JWT tokens.

Index

Constants

View Source
const (
	// SessionManagerClaimsIssuer fills the "iss" field of the token.
	SessionManagerClaimsIssuer = "everest"
)

Variables

This section is empty.

Functions

func ClientCacheOptions added in v1.7.0

func ClientCacheOptions() *cache.Options

ClientCacheOptions returns the cache options for the session manager k8s client. To avoid overwhelming k8s API with requests, the client should cache the accounts secret, because every authenticated API request checks the secret. It also defines a rule for the system namespace which gets requested otherwise the ByObject won't allow to read the ns.

Types

type Blocklist added in v1.7.0

type Blocklist interface {
	// Block invalidates the token from the context by adding it to blocklist.
	Block(ctx context.Context, token *jwt.Token) error
	// IsBlocked checks if the token from the context is blocked.
	IsBlocked(ctx context.Context, token *jwt.Token) (bool, error)
}

Blocklist represents interface to block JWT tokens and check if a token is blocked.

func NewBlocklist added in v1.7.0

func NewBlocklist(ctx context.Context, logger *zap.SugaredLogger) (Blocklist, error)

NewBlocklist creates a new block list.

type JWTContent added in v1.7.0

type JWTContent struct {
	Payload map[string]any `json:"payload"`
}

JWTContent represents the JWT token structure that is used by blocklist.

type Manager

type Manager struct {
	Blocklist
	// contains filtered or unexported fields
}

Manager provides functionality for creating and managing JWT tokens.

func New

func New(ctx context.Context, l *zap.SugaredLogger, options ...Option) (*Manager, error)

New creates a new session manager with the given options.

func (*Manager) Authenticate

func (mgr *Manager) Authenticate(ctx context.Context, username string, password string) error

Authenticate verifies the given username and password.

func (*Manager) BlocklistMiddleWare added in v1.7.0

func (mgr *Manager) BlocklistMiddleWare(skipperFunc func() (echomiddleware.Skipper, error)) (echo.MiddlewareFunc, error)

BlocklistMiddleWare returns an echo middleware that rejects requests carrying a blocked JWT token. The provided skipperFunc builds a skipper that decides which requests bypass the check.

func (*Manager) Create

func (mgr *Manager) Create(subject string, secondsBeforeExpiry int64, id string) (string, error)

Create creates a new token for a given subject (user) and returns it as a string. Passing a value of `0` for secondsBeforeExpiry creates a token that never expires. The id parameter holds an optional unique JWT token identifier and stored as a standard claim "jti" in the JWT token.

func (*Manager) CreateSSO added in v1.17.0

func (mgr *Manager) CreateSSO(subject string, secondsBeforeExpiry int64, id, oidcIssuer string, identity SSOIdentity) (string, error)

CreateSSO creates a new Everest-signed token for an SSO user whose identity was validated against the OIDC provider. The oidcIssuer is stored as a custom claim so that extractUsername() treats the resulting session as an external (non-built-in) user.

func (*Manager) IsBlocked added in v1.7.0

func (mgr *Manager) IsBlocked(ctx context.Context, token *jwt.Token) (bool, error)

IsBlocked checks if the given token is blocked. In addition to the blocklist check, tokens of built-in users are considered blocked if the account no longer exists or if the token was issued before the account's password was last updated.

func (*Manager) KeyFunc

func (mgr *Manager) KeyFunc() jwt.Keyfunc

KeyFunc retruns a function for getting the public RSA keys used for verifying the JWT tokens signed by everest.

type Option

type Option func(*Manager)

Option is a function that modifies a SessionManager.

func WithAccountManager

func WithAccountManager(i accounts.Interface) Option

WithAccountManager sets the account manager to use for verifying user credentials.

type SSOClaims added in v1.17.0

type SSOClaims struct {
	jwt.RegisteredClaims

	OIDCIssuer        string   `json:"oidc_issuer"`
	Email             string   `json:"email,omitempty"`
	Name              string   `json:"name,omitempty"`
	PreferredUsername string   `json:"preferred_username,omitempty"`
	Groups            []string `json:"groups,omitempty"`
}

SSOClaims extends the standard registered claims with the original OIDC issuer. extractUsername() uses the oidc_issuer claim to distinguish SSO sessions from built-in ones.

type SSOIdentity added in v1.17.0

type SSOIdentity struct {
	Email             string
	Name              string
	PreferredUsername string
	// Groups is read by rbac.GetUser from the token's "groups" claim for group-based policies.
	Groups []string
}

SSOIdentity holds the human-readable identity claims mirrored from the OIDC provider into the Everest token, so that the UI can show a display name instead of the raw subject.

type TokenStore added in v1.7.0

type TokenStore interface {
	// Add adds the shortened token to the blocklist
	Add(ctx context.Context, shortenedToken string) error
	// Exists checks if the shortened token is in the blocklist
	Exists(ctx context.Context, shortenedToken string) (bool, error)
}

TokenStore represents an abstraction for storage, hiding details about how the data is actually stored.

type TokenStoreClient added in v1.7.0

type TokenStoreClient interface {
	// GetSecret returns a secret that matches the criteria.
	GetSecret(ctx context.Context, key client.ObjectKey) (*corev1.Secret, error)
	// CreateSecret creates a secret.
	CreateSecret(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)
	// UpdateSecret updates a secret.
	UpdateSecret(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)
}

TokenStoreClient contains the methods that are needed for the token store management.

Jump to

Keyboard shortcuts

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