authn

package
v0.24.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// RoleNode is the role for node agent tokens.
	RoleNode = "node"
	// RoleViewer is the role for viewer tokens.
	RoleViewer = "viewer"
	// HMACKeySize is the minimum key size in bytes for HMAC-SHA256 signing.
	HMACKeySize = 32
)

Variables

This section is empty.

Functions

func DiscoverKubernetesOIDCConfig added in v0.9.0

func DiscoverKubernetesOIDCConfig(token, audienceOverride string) (string, string, error)

DiscoverKubernetesOIDCConfig reads discovery hints from the controller's own trusted, mounted service account token. It must not be used on client tokens.

func ExtractNodeNameFromSAToken

func ExtractNodeNameFromSAToken(token string) (string, error)

ExtractNodeNameFromSAToken decodes the node binding without verifying the JWT.

func GenerateHMACKey

func GenerateHMACKey() ([]byte, error)

GenerateHMACKey returns HMACKeySize cryptographically random bytes suitable for use as an HMAC signing key.

Types

type Claims

type Claims struct {
	Subject   string   `json:"sub"`              // e.g. "system:serviceaccount:unbounded-net:unbounded-net-node"
	Role      string   `json:"role"`             // "node" or "viewer"
	NodeName  string   `json:"node,omitempty"`   // node name (node tokens only)
	Groups    []string `json:"groups,omitempty"` // user groups (for SAR checks)
	IssuedAt  int64    `json:"iat"`              // Unix timestamp
	ExpiresAt int64    `json:"exp"`              // Unix timestamp
}

Claims holds the payload of an HMAC-signed token.

type KubernetesOIDCVerifier added in v0.9.0

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

KubernetesOIDCVerifier validates Kubernetes service account JWTs locally using the cluster issuer's OIDC discovery document and JWKS.

func NewKubernetesOIDCVerifier added in v0.9.0

func NewKubernetesOIDCVerifier(ctx context.Context, issuerURL, audience string) (*KubernetesOIDCVerifier, error)

NewKubernetesOIDCVerifier initializes a verifier and loads its signing keys.

func (*KubernetesOIDCVerifier) Verify added in v0.9.0

Verify validates a service account JWT and returns its authenticated node identity.

type KubernetesServiceAccountIdentity added in v0.9.0

type KubernetesServiceAccountIdentity struct {
	Subject            string
	Namespace          string
	ServiceAccountName string
	ServiceAccountUID  string
	PodName            string
	PodUID             string
	NodeName           string
}

KubernetesServiceAccountIdentity is the authenticated identity and node binding carried by a Kubernetes service account token.

func DecodeKubernetesServiceAccountIdentity added in v0.9.0

func DecodeKubernetesServiceAccountIdentity(token string) (*KubernetesServiceAccountIdentity, error)

DecodeKubernetesServiceAccountIdentity decodes Kubernetes service account claims without verifying the JWT signature. Callers must authenticate the exact token through another trusted mechanism before using the result.

type KubernetesTokenReviewVerifier added in v0.9.0

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

KubernetesTokenReviewVerifier authenticates service account tokens through Kubernetes before trusting their embedded node identity.

func NewKubernetesTokenReviewVerifier added in v0.9.0

func NewKubernetesTokenReviewVerifier(client authenticationclient.AuthenticationV1Interface) *KubernetesTokenReviewVerifier

NewKubernetesTokenReviewVerifier creates a verifier using the Kubernetes TokenReview API.

func (*KubernetesTokenReviewVerifier) Verify added in v0.9.0

type PodBoundTokenVerifier added in v0.9.0

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

PodBoundTokenVerifier checks bound objects after cryptographic verification. It deliberately supports only Pod-bound node agents, not every Kubernetes service account token type, and never caches an authorization decision.

func NewPodBoundTokenVerifier added in v0.9.0

func NewPodBoundTokenVerifier(verifier interface {
	Verify(context.Context, string) (*KubernetesServiceAccountIdentity, error)
}, options PodBoundTokenVerifierOptions,
) *PodBoundTokenVerifier

NewPodBoundTokenVerifier decorates an OIDC verifier, not a TokenReview verifier.

func (*PodBoundTokenVerifier) Verify added in v0.9.0

Verify authenticates the token and rechecks its Pod and service account in the caches on every request, including when the signing keys are already cached.

type PodBoundTokenVerifierOptions added in v0.9.0

type PodBoundTokenVerifierOptions struct {
	Namespace       string
	ServiceAccount  string
	Pods            corelisters.PodLister
	ServiceAccounts corelisters.ServiceAccountLister
	Ready           func() bool
}

PodBoundTokenVerifierOptions supplies process-lifetime informer caches. Ready must reject unsynced or stopped caches. Informer reads are eventually consistent, not a strongly consistent substitute for TokenReview.

type TokenIssuer

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

TokenIssuer generates and validates HMAC-signed tokens.

func NewTokenIssuer

func NewTokenIssuer(hmacKey []byte) (*TokenIssuer, error)

NewTokenIssuer creates a TokenIssuer after validating that the key is at least HMACKeySize bytes.

func (*TokenIssuer) IssueNodeToken

func (ti *TokenIssuer) IssueNodeToken(subject, nodeName string, lifetime time.Duration) (string, time.Time, error)

IssueNodeToken creates an HMAC-signed token with RoleNode and the given node name. It returns the token string, its expiry time, and any error.

func (*TokenIssuer) IssueViewerToken

func (ti *TokenIssuer) IssueViewerToken(subject string, groups []string, lifetime time.Duration) (string, time.Time, error)

IssueViewerToken creates an HMAC-signed token with RoleViewer. It returns the token string, its expiry time, and any error. Groups are included in the token claims so downstream SAR checks can evaluate group-based RBAC.

func (*TokenIssuer) Validate

func (ti *TokenIssuer) Validate(tokenStr string) (*Claims, error)

Validate parses and verifies an HMAC-signed token. It returns the decoded claims or an error if the token is malformed, the signature is invalid, or the token has expired.

Jump to

Keyboard shortcuts

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