auth

package
v1.0.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 25 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 key and its host's token. 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 HashRunnerKey

func HashRunnerKey(key string) string

HashRunnerKey is the SHA-256 of a runner key in hex, as `spec.keyHash` holds it.

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 IsJWT

func IsJWT(bearer string) bool

IsJWT reports whether a bearer credential has a JWT's shape rather than a runner key's: a runner key has no dots.

func NewRunnerKey

func NewRunnerKey() (key, hash string, err error)

NewRunnerKey returns a new runner key, 32 random bytes in unpadded base64url, and its hash. Only the hash is stored.

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, c *config.Config, clk clock.PassiveClock) *Authenticator

NewAuthenticator verifies tokens with v, classifies them with the configuration and checks expiry against clk.

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) Host

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

Host verifies a runner's host token, which must be a person's. An expired token still says who the host is: the coordinator keeps it, and refuses offers while it is expired.

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.
	Organization string
	Namespace    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.
	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.

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 HostToken

type HostToken struct {
	Caller
	Expiry time.Time
}

HostToken is the identity a runner's host token proves, and until when.

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 runs
	// 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"
)

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 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, for tests.
Package authtest signs tokens the way Dex does, for tests.

Jump to

Keyboard shortcuts

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