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 ¶
- Variables
- func DexClientSubject(clientID string) string
- func DexSubject(userID, connID string) string
- func HTTPClient(caFile string) (*http.Client, error)
- func IsClientSubject(sub, clientID string) bool
- func VerifierConfig(audience string, now func() time.Time) *oidc.Config
- type AccessReviewer
- type Authenticator
- type Caller
- type Classifier
- type Credential
- type IssuerVerifier
- type Kind
- type OIDCVerifier
- type SubjectAccessReviewer
- type Token
- type TokenReviewer
- type Verifier
Constants ¶
This section is empty.
Variables ¶
var ErrExpiredToken = errors.New("expired token")
ErrExpiredToken is a token past its expiry.
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.
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 ¶
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 ¶
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 ¶
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 ¶
IsClientSubject reports whether sub is the client's own subject: Dex's IDTokenSubject with user_id clientID and an empty connector.
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) 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) IsPrincipalOf ¶
IsPrincipalOf reports whether the caller is the principal of the organization that owns namespace.
func (Caller) IsServiceAccount ¶
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 ¶
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.
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.
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.
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.