tokenauth

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 9 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 tokenauth authenticates in-cluster callers by their projected ServiceAccount token. The caller sends an audience-bound token in a request header; the Authenticator reviews it with the API server (TokenReview), accepts only the configured ServiceAccount subjects, and caches each verdict by token hash for a short TTL. Denials are cached too, so a caller retrying a bad token does not turn into API-server QPS.

The egress broker authenticates agent pods with it, and the integration-controller's internal endpoint authenticates the status server. A token is an identity document, not a capability: whoever accepts it still decides what that identity may do.

Index

Constants

View Source
const DefaultTTL = time.Minute

DefaultTTL is how long a verdict is cached when Config.TTL is unset.

View Source
const PodNameExtraKey = "authentication.kubernetes.io/pod-name"

PodNameExtraKey is where the API server reports the bound pod of a pod-bound projected token on the TokenReview user info.

Variables

This section is empty.

Functions

func ServiceAccount

func ServiceAccount(namespace, name string) string

ServiceAccount renders the TokenReview username of a ServiceAccount.

Types

type Authenticator

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

Authenticator validates caller tokens via TokenReview, caching verdicts by token hash for the configured TTL.

func New

New builds an Authenticator; cs performs the TokenReviews.

func (*Authenticator) Authenticate

func (a *Authenticator) Authenticate(r *http.Request, header string) (Identity, error)

Authenticate resolves the token in the request's header to an identity, reviewing it with the API server on a cache miss. The error string is safe to return to the caller (it never echoes the token).

type Config

type Config struct {
	// Audience is the projected-token audience callers must present.
	Audience string
	// Subjects are the only accepted usernames, e.g.
	// system:serviceaccount:patchy:patchy-status-server.
	Subjects []string
	// TTL is how long one token's verdict is cached; <= 0 means DefaultTTL.
	TTL time.Duration
}

Config configures an Authenticator.

type Identity

type Identity struct {
	// User is the TokenReview username.
	User string
	// Pod is the bound pod name, for audit; empty for a token not bound to
	// a pod.
	Pod string
}

Identity is who a validated caller token belongs to.

Jump to

Keyboard shortcuts

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