auth

package
v1.0.0-rc.17 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: Apache-2.0 Imports: 26 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 auth says who calls Beekeeper.

Every caller presents a bearer JWT from the configured OIDC issuer whose aud contains Beekeeper's client ID. A Verifier checks its signature, issuer and audience; Classify says whether it is an organization's principal or a person. A runner presents its host's token, or its projected ServiceAccount token for Beekeeper's audience, which a TokenReview checks. A SubjectAccessReview says whether a person may use an organization's namespace.

Index

Constants

This section is empty.

Variables

View Source
var ErrExpiredToken = errors.New("expired token")

ErrExpiredToken is a token past its expiry.

View Source
var ErrInvalidToken = errors.New("invalid token")

ErrInvalidToken is a token that doesn't verify or names no one Beekeeper knows. It is permanent: the same token never verifies.

View Source
var ErrIssuerUnavailable = errors.New("token issuer unavailable")

ErrIssuerUnavailable is an issuer that didn't answer: its discovery or keys timed out, refused the connection or failed with a 5xx. The caller may try again.

Functions

func DexClientSubject

func DexClientSubject(clientID string) string

DexClientSubject is the sub of a client's own token at Dex: unpadded base64url of the protobuf IDTokenSubject{user_id: clientID} without a connector.

func DexSubject

func DexSubject(userID, connID string) string

DexSubject is Dex's sub for a user of a connector: unpadded base64url of the protobuf IDTokenSubject{user_id, conn_id}, an empty connector omitted.

func HTTPClient

func HTTPClient(caFile string) (*http.Client, error)

HTTPClient is the client for an issuer's discovery and keys. caFile, when set, is a PEM bundle trusted besides the system's roots, such as a lab issuer's own CA. No address is filtered: a private or loopback issuer is as good as any.

func IsClientSubject

func IsClientSubject(sub, clientID string) bool

IsClientSubject reports whether sub is the client's own subject: Dex's IDTokenSubject with user_id clientID and an empty connector.

func VerifierConfig

func VerifierConfig(audience string, now func() time.Time) *oidc.Config

VerifierConfig is go-oidc's configuration for Beekeeper's audience. Expiry is checked by the caller.

Types

type AccessReviewer

type AccessReviewer interface {
	// Review returns whether the person may, and why not.
	Review(ctx context.Context, person Caller, namespace string) (allowed bool, reason string, err error)
}

AccessReviewer says whether a person may use an organization's namespace: whether they are a member, and so may register runners and be a host.

type Authenticator

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

Authenticator verifies and classifies bearer tokens.

func NewAuthenticator

func NewAuthenticator(v Verifier, accounts *TokenReviewer, c *config.Config, clk clock.PassiveClock) *Authenticator

NewAuthenticator verifies the configured issuer's tokens with v, reviews a runner's other tokens with accounts, classifies them with the configuration and checks expiry against clk. A nil accounts refuses every ServiceAccount.

func (*Authenticator) Caller

func (a *Authenticator) Caller(ctx context.Context, raw string) (Caller, error)

Caller verifies an unexpired caller's token and says who it is.

func (*Authenticator) Runner

func (a *Authenticator) Runner(ctx context.Context, raw string) (Credential, error)

Runner says who a runner's bearer is. Its unverified iss routes it: a token of the configured issuer must verify, be unexpired and be a person's; any other token is a ServiceAccount's, which a TokenReview checks. An organization's principal is never a runner.

type Caller

type Caller struct {
	Kind Kind
	// Organization and Namespace are a principal's organization. A person's
	// membership is a SubjectAccessReview, not a claim. Namespace is also a
	// ServiceAccount's namespace.
	Organization string
	Namespace    string
	// ServiceAccount is a ServiceAccount's name.
	ServiceAccount string
	// Username and Groups are a person's, mapped from the token's claims the
	// way the kube-apiserver maps them.
	Username string
	Groups   []string
	// Subject names the caller in logs: `client:<id>` for a principal, the
	// username for a person and for a ServiceAccount.
	Subject string
}

Caller is who calls.

func (Caller) IsPerson

func (c Caller) IsPerson() bool

IsPerson reports whether the caller is a person.

func (Caller) IsPrincipalOf

func (c Caller) IsPrincipalOf(namespace string) bool

IsPrincipalOf reports whether the caller is the principal of the organization that owns namespace.

func (Caller) IsServiceAccount

func (c Caller) IsServiceAccount() bool

IsServiceAccount reports whether the caller is a ServiceAccount.

type Classifier

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

Classifier says who a verified token is.

func NewClassifier

func NewClassifier(c *config.Config) Classifier

NewClassifier classifies tokens with the configuration's organizations and claim mapping.

func (Classifier) Classify

func (c Classifier) Classify(t *Token) (Caller, error)

Classify says whether a verified token is an organization's principal or a person. It is the one place that knows the principal's token shape:

  • azp is a principal's client ID, which maps to exactly one organization. Nothing else selects the organization;
  • sub is that client's own subject in Dex's encoding (DexClientSubject), not a person who signed in through the client;
  • there is no act claim.

Every other token is a person's, whose username and groups come from the configured claims. A token that delegates (act) is refused, and so is one without a username.

type Credential

type Credential struct {
	Caller
	Expiry time.Time
}

Credential is who a runner's bearer proves the runner acts as, and until when. A person's is also the host token Beekeeper keeps for the runner. A ServiceAccount's has no Expiry: its token is reviewed again once the cached review lapses.

type IssuerVerifier

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

IssuerVerifier verifies the tokens of an issuer it discovers on first use. Discovery and the JWKS share one HTTP client. Discovery is retried only after an outage: an issuer that doesn't answer fails with ErrIssuerUnavailable, one that answers wrongly (a certificate it doesn't trust, a 4xx, a different issuer) with ErrInvalidToken.

func NewIssuerVerifier

func NewIssuerVerifier(ctx context.Context, issuerURL, audience string, client *http.Client, now func() time.Time) *IssuerVerifier

NewIssuerVerifier verifies tokens of issuerURL for audience. ctx bounds discovery and every key fetch, which use client.

func (*IssuerVerifier) Discover

func (v *IssuerVerifier) Discover() (*oidc.IDTokenVerifier, error)

Discover reads the issuer's discovery document, unless it already did.

func (*IssuerVerifier) Verify

func (v *IssuerVerifier) Verify(ctx context.Context, raw string) (*Token, error)

Verify implements Verifier.

type Kind

type Kind string

Kind is the kind of caller.

const (
	// KindPrincipal is an organization's own identity, as which its workflows
	// offer and cancel tasks. It never starts a session.
	KindPrincipal Kind = "principal"
	// KindPerson is a person, such as a runner's host.
	KindPerson Kind = "person"
	// KindServiceAccount is a Kubernetes ServiceAccount, such as a cluster
	// runner's.
	KindServiceAccount Kind = "serviceaccount"
)

type OIDCVerifier

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

OIDCVerifier verifies tokens with a go-oidc verifier, such as one made by oidc.NewVerifier with a static key set.

func NewOIDCVerifier

func NewOIDCVerifier(v *oidc.IDTokenVerifier) *OIDCVerifier

NewOIDCVerifier wraps a go-oidc verifier.

func (*OIDCVerifier) Verify

func (v *OIDCVerifier) Verify(ctx context.Context, raw string) (*Token, error)

Verify implements Verifier.

type SubjectAccessReviewer

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

SubjectAccessReviewer asks the Kubernetes API with a SubjectAccessReview.

func NewSubjectAccessReviewer

func NewSubjectAccessReviewer(c client.Client, attrs config.HostAccess) *SubjectAccessReviewer

NewSubjectAccessReviewer reviews access with the configured resource attributes.

func (*SubjectAccessReviewer) Review

func (s *SubjectAccessReviewer) Review(ctx context.Context, person Caller, namespace string) (bool, string, error)

Review implements AccessReviewer.

type Token

type Token struct {
	Issuer   string
	Subject  string
	Audience []string
	Expiry   time.Time
	// Claims are all of the token's claims.
	Claims map[string]json.RawMessage
}

Token is a token whose signature, issuer and audience verified.

type TokenReviewer

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

TokenReviewer says which ServiceAccount a token is, with a TokenReview for Beekeeper's audience. A cluster runner presents its projected ServiceAccount token. A review that succeeds is kept by the token's SHA-256 for at most a minute, and never past the token's exp.

func NewTokenReviewer

func NewTokenReviewer(c client.Client, audience string, clk clock.PassiveClock) *TokenReviewer

NewTokenReviewer reviews tokens for audience through c.

func (*TokenReviewer) Review

func (r *TokenReviewer) Review(ctx context.Context, raw string) (Caller, error)

Review returns the ServiceAccount a token is. A token the API doesn't authenticate, not for the audience, or of anyone but a ServiceAccount fails with ErrInvalidToken; an API that didn't answer with ErrIssuerUnavailable.

type Verifier

type Verifier interface {
	Verify(ctx context.Context, raw string) (*Token, error)
}

Verifier verifies a token's signature, issuer and audience. It does not check expiry: the caller does, against its own clock, because a runner's host token is kept past its expiry to say why the runner gets no offer.

Directories

Path Synopsis
Package authtest signs tokens the way Dex does, and reviews ServiceAccount tokens the way the Kubernetes API does, for tests.
Package authtest signs tokens the way Dex does, and reviews ServiceAccount tokens the way the Kubernetes API does, for tests.

Jump to

Keyboard shortcuts

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