user

package
v1.13.0-rc.2 Latest Latest
Warning

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

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

Documentation

Overview

Package user describes who a request to the Kargo API server is from.

The authentication middleware resolves a bearer token to an Identity and binds it to the request context. Handlers and the authorizing Kubernetes client read it back to decide what the request may do and to record who did it. Each kind of Identity knows how it is authorized, so nothing else in the server has to tell them apart.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BearerTokenFromContext

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

BearerTokenFromContext returns the raw bearer token bound to the context, if any.

func ContextWithBearerToken

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

ContextWithBearerToken returns a context carrying the raw bearer token the request authenticated with. It is kept apart from the Identity, which describes who the request is from and may outlive the request, e.g. in a cache; the token is this request's credential and nothing more.

The token is only ever sent elsewhere as the token for AnalysisRun log requests, and only when the operator has not configured a dedicated token for those and has explicitly opted into the feature.

func ContextWithIdentity

func ContextWithIdentity(ctx context.Context, id Identity) context.Context

ContextWithIdentity returns a context carrying the Identity.

Types

type Admin

type Admin struct{}

Admin is the Kargo API server's own admin user, authenticated by a token the server itself issued.

func (Admin) Actor

func (Admin) Actor() string

func (Admin) IsAdmin

func (Admin) IsAdmin() bool

func (Admin) MemberOf

func (Admin) MemberOf(string) bool

MemberOf returns false: an Admin belongs to every Project, so none is singled out as theirs.

func (Admin) Subjects

func (Admin) Subjects(authv1.ResourceAttributes) []Subject

Subjects returns nothing: an Admin is allowed without review.

type Identity

type Identity interface {
	// IsAdmin reports whether this is the Kargo API server's own admin user,
	// who may do everything the server can do and is never reviewed.
	IsAdmin() bool
	// Subjects returns the Kubernetes subjects whose permissions stand in
	// for this identity when performing the described operation. The
	// operation is allowed if any one of them is allowed. An identity with
	// no subjects is allowed nothing.
	Subjects(ra authv1.ResourceAttributes) []Subject
	// Actor names the identity the way events and audit annotations record
	// it.
	Actor() string
	// MemberOf reports whether the identity has a presence in the Project
	// namespace, such that the Project counts as one of theirs. It implies no
	// permission in it. Only an OIDCUser, through a mapped ServiceAccount,
	// ever does; nothing is recorded about which Projects anyone else belongs
	// to.
	MemberOf(namespace string) bool
}

Identity is who a request is from.

func IdentityFromContext

func IdentityFromContext(ctx context.Context) (Identity, bool)

IdentityFromContext returns the Identity bound to the context, if any.

type KubernetesUser

type KubernetesUser struct {
	authnv1.UserInfo
}

KubernetesUser is the holder of a bearer token that Kubernetes itself recognized, through a TokenReview: a ServiceAccount, such as a Kargo API token or a controller, or a user of the cluster's own identity provider.

func (KubernetesUser) Actor

func (u KubernetesUser) Actor() string

func (KubernetesUser) IsAdmin

func (KubernetesUser) IsAdmin() bool

func (KubernetesUser) MemberOf

func (KubernetesUser) MemberOf(string) bool

MemberOf returns false: Kubernetes vouches for who the user is, not for which Projects are theirs.

func (KubernetesUser) Subjects

Subjects returns the user as Kubernetes reported them. Groups, UID and extras are all carried across, because omitting them would ask a different question: whether the user is permitted on the strength of their username alone.

type OIDCUser

type OIDCUser struct {
	// Claims are the verified claims of the user's token.
	Claims map[string]any
	// UsernameClaim names the claim the Username was taken from.
	UsernameClaim string
	// Username is the user's name as the configured claim states it. It is
	// often an email address, but may be anything the identity provider
	// sends.
	Username string
	// ServiceAccountsByNamespace maps namespaces to the ServiceAccounts in
	// them that the user's claims map to.
	ServiceAccountsByNamespace map[string]map[types.NamespacedName]struct{}
	// GlobalServiceAccountNamespaces are the namespaces, besides a Project's
	// own, in which a mapped ServiceAccount may grant access to the Project.
	GlobalServiceAccountNamespaces []string
}

OIDCUser is a user authenticated by Kargo's OpenID Connect identity provider. Such a user holds no Kubernetes identity of their own; they act through the ServiceAccounts their claims map them to.

func (OIDCUser) Actor

func (u OIDCUser) Actor() string

Actor names the user by the configured username claim when the token carried it, else by email, else by subject. Identity providers are not guaranteed to send every claim tied to a requested scope, but "sub" is always present, so it is the final backstop.

func (OIDCUser) IsAdmin

func (OIDCUser) IsAdmin() bool

func (OIDCUser) MemberOf

func (u OIDCUser) MemberOf(namespace string) bool

MemberOf reports whether the user's claims map them to at least one ServiceAccount in the namespace.

func (OIDCUser) Subjects

func (u OIDCUser) Subjects(ra authv1.ResourceAttributes) []Subject

Subjects returns the user's mapped ServiceAccounts in the namespaces that may grant the operation: the resource's own namespace first, where a ServiceAccount with the required permissions is most likely to be found, then the global ServiceAccount namespaces. A cluster-scoped Project is the one resource whose own namespace is its name.

type Subject

type Subject struct {
	Username string
	UID      string
	Groups   []string
	Extra    map[string]authv1.ExtraValue
}

Subject is a Kubernetes identity whose access can be reviewed.

func ServiceAccountSubject

func ServiceAccountSubject(name types.NamespacedName) Subject

ServiceAccountSubject is the subject a ServiceAccount is reviewed as.

Jump to

Keyboard shortcuts

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