serviceaccount

package
v1.19.15 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: Apache-2.0 Imports: 28 Imported by: 858

Documentation

Index

Constants

View Source
const (
	// Injected bound service account token expiration which triggers monitoring of its time-bound feature.
	WarnOnlyBoundTokenExpirationSeconds = 60*60 + 7

	// Extended expiration for those modifed tokens involved in safe rollout if time-bound feature.
	ExpirationExtensionSeconds = 24 * 365 * 60 * 60
)
View Source
const (
	// OpenIDConfigPath is the URL path at which the API server serves
	// an OIDC Provider Configuration Information document, corresponding
	// to the Kubernetes Service Account key issuer.
	// https://openid.net/specs/openid-connect-discovery-1_0.html
	OpenIDConfigPath = "/.well-known/openid-configuration"

	// JWKSPath is the URL path at which the API server serves a JWKS
	// containing the public keys that may be used to sign Kubernetes
	// Service Account keys.
	JWKSPath = "/openid/v1/jwks"
)
View Source
const (
	// PodNameKey is the key used in a user's "extra" to specify the pod name of
	// the authenticating request.
	PodNameKey = "authentication.kubernetes.io/pod-name"
	// PodUIDKey is the key used in a user's "extra" to specify the pod UID of
	// the authenticating request.
	PodUIDKey = "authentication.kubernetes.io/pod-uid"
)
View Source
const LegacyIssuer = "kubernetes/serviceaccount"

Variables

This section is empty.

Functions

func Claims added in v1.10.0

func Claims(sa core.ServiceAccount, pod *core.Pod, secret *core.Secret, expirationSeconds, warnafter int64, audience []string) (*jwt.Claims, interface{})

func IsServiceAccountToken added in v1.2.0

func IsServiceAccountToken(secret *v1.Secret, sa *v1.ServiceAccount) bool

IsServiceAccountToken returns true if the secret is a valid api token for the service account

func JWTTokenAuthenticator

func JWTTokenAuthenticator(iss string, keys []interface{}, implicitAuds authenticator.Audiences, validator Validator) authenticator.Token

JWTTokenAuthenticator authenticates tokens as JWT tokens produced by JWTTokenGenerator Token signatures are verified using each of the given public keys until one works (allowing key rotation) If lookup is true, the service account and secret referenced as claims inside the token are retrieved and verified with the provided ServiceAccountTokenGetter

func LegacyClaims added in v1.10.0

func LegacyClaims(serviceAccount v1.ServiceAccount, secret v1.Secret) (*jwt.Claims, interface{})

func RegisterMetrics added in v1.19.0

func RegisterMetrics()

func UserInfo added in v1.2.0

func UserInfo(namespace, name, uid string) user.Info

UserInfo returns a user.Info interface for the given namespace, service account name and UID

Types

type OpenIDMetadata added in v1.18.0

type OpenIDMetadata struct {
	ConfigJSON       []byte
	PublicKeysetJSON []byte
}

OpenIDMetadata contains the pre-rendered responses for OIDC discovery endpoints.

func NewOpenIDMetadata added in v1.18.0

func NewOpenIDMetadata(issuerURL, jwksURI, defaultExternalAddress string, pubKeys []interface{}) (*OpenIDMetadata, error)

NewOpenIDMetadata returns the pre-rendered JSON responses for the OIDC discovery endpoints, or an error if they could not be constructed. Callers should note that this function may perform additional validation on inputs that is not backwards-compatible with all command-line validation. The recommendation is to log the error and skip installing the OIDC discovery endpoints.

type ServiceAccountInfo added in v1.12.0

type ServiceAccountInfo struct {
	Name, Namespace, UID string
	PodName, PodUID      string
}

func (*ServiceAccountInfo) UserInfo added in v1.12.0

func (sa *ServiceAccountInfo) UserInfo() user.Info

type ServiceAccountTokenGetter

type ServiceAccountTokenGetter interface {
	GetServiceAccount(namespace, name string) (*v1.ServiceAccount, error)
	GetPod(namespace, name string) (*v1.Pod, error)
	GetSecret(namespace, name string) (*v1.Secret, error)
}

ServiceAccountTokenGetter defines functions to retrieve a named service account and secret

type TokenGenerator

type TokenGenerator interface {
	// GenerateToken generates a token which will identify the given
	// ServiceAccount. privateClaims is an interface that will be
	// serialized into the JWT payload JSON encoding at the root level of
	// the payload object. Public claims take precedent over private
	// claims i.e. if both claims and privateClaims have an "exp" field,
	// the value in claims will be used.
	GenerateToken(claims *jwt.Claims, privateClaims interface{}) (string, error)
}

func JWTTokenGenerator

func JWTTokenGenerator(iss string, privateKey interface{}) (TokenGenerator, error)

JWTTokenGenerator returns a TokenGenerator that generates signed JWT tokens, using the given privateKey. privateKey is a PEM-encoded byte array of a private RSA key.

type Validator added in v1.10.0

type Validator interface {
	// Validate validates a token and returns user information or an error.
	// Validator can assume that the issuer and signature of a token are already
	// verified when this function is called.
	Validate(ctx context.Context, tokenData string, public *jwt.Claims, private interface{}) (*ServiceAccountInfo, error)
	// NewPrivateClaims returns a struct that the authenticator should
	// deserialize the JWT payload into. The authenticator may then pass this
	// struct back to the Validator as the 'private' argument to a Validate()
	// call. This struct should contain fields for any private claims that the
	// Validator requires to validate the JWT.
	NewPrivateClaims() interface{}
}

Validator is called by the JWT token authenticator to apply domain specific validation to a token and extract user information.

func NewLegacyValidator added in v1.10.0

func NewLegacyValidator(lookup bool, getter ServiceAccountTokenGetter) Validator

func NewValidator added in v1.10.0

func NewValidator(getter ServiceAccountTokenGetter) Validator

Jump to

Keyboard shortcuts

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