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 ¶
- Variables
- func DexClientSubject(clientID string) string
- func DexSubject(userID, connID string) string
- func HTTPClient(caFile string) (*http.Client, error)
- func HashRunnerKey(key string) string
- func IsClientSubject(sub, clientID string) bool
- func IsJWT(bearer string) bool
- func NewRunnerKey() (key, hash string, err error)
- func VerifierConfig(audience string, now func() time.Time) *oidc.Config
- type AccessReviewer
- type Authenticator
- type Caller
- type Classifier
- type HostToken
- type IssuerVerifier
- type Kind
- type OIDCVerifier
- type SubjectAccessReviewer
- type Token
- 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 HashRunnerKey ¶
HashRunnerKey is the SHA-256 of a runner key in hex, as `spec.keyHash` holds it.
func IsClientSubject ¶
IsClientSubject reports whether sub is the client's own subject: Dex's IDTokenSubject with user_id clientID and an empty connector.
func IsJWT ¶
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 ¶
NewRunnerKey returns a new runner key, 32 random bytes in unpadded base64url, and its hash. Only the hash is stored.
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.
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) IsPrincipalOf ¶
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 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 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.