identity

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package identity carries the authenticated caller through a request: who the OAuth layer validated (subject, email, groups) and, when the server acts on the caller's behalf towards the Kubernetes API, the caller's own IdP token. agent-manager does nothing without a caller — every Kubernetes call belongs to a request — so a context without an identity only exists in tests and in a server that runs without OAuth (the ServiceAccount then).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Caller

func Caller(ctx context.Context) string

Caller is the caller's String(), or "" without one.

func ContextWith

func ContextWith(ctx context.Context, id *Identity) context.Context

ContextWith returns ctx carrying id.

func ContextWithToken

func ContextWithToken(ctx context.Context, token string) context.Context

ContextWithToken returns ctx carrying the caller's IdP token for downstream Kubernetes API calls. Only set when the server runs with downstream OAuth on.

func LogAttr

func LogAttr(ctx context.Context) slog.Attr

LogAttr is the structured-log attribute every mutation carries: the caller, or the ServiceAccount marker when the server runs without OAuth.

func TokenExpiry

func TokenExpiry(token string) time.Time

TokenExpiry reads the `exp` claim of a JWT without verifying it — the token was validated when the request came in; this only bounds how long the per-caller Kubernetes clients built from it are worth keeping. Zero when the token is not a JWT or carries no exp.

func TokenFromContext

func TokenFromContext(ctx context.Context) (string, bool)

TokenFromContext returns the caller's IdP token, if any.

Types

type Identity

type Identity struct {
	// Subject is the IdP's stable user id (the `sub` claim).
	Subject string
	// Email is the caller's email when the IdP provided one.
	Email string
	// Name is the display name when the IdP provided one.
	Name string
	// Groups are the IdP group claims (Dex `groups`; empty for Google).
	Groups []string
	// Source is how the token was validated.
	Source Source
}

Identity is the authenticated caller.

func FromContext

func FromContext(ctx context.Context) (*Identity, bool)

FromContext returns the caller, if any.

func (*Identity) String

func (id *Identity) String() string

String is the caller as logged and reported on results: the email, else the subject.

type Source

type Source string

Source says how the caller was authenticated.

const (
	// SourceSSO is an IdP id_token forwarded by a trusted aggregator (muster)
	// or sent by the portal through the gateway, validated against the IdP's
	// JWKS.
	SourceSSO Source = "sso"
	// SourceOAuth is an access token issued by this server's own OAuth 2.1
	// flow (a client that authenticated directly, e.g. mcp-debug).
	SourceOAuth Source = "oauth"
)

Jump to

Keyboard shortcuts

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