Documentation
¶
Overview ¶
Package oidcjwt verifies JWTs using OIDC discovery.
Index ¶
- Variables
- func NewHTTPClient(issuer, certificateAuthorityFile, discoveryTokenFile string) (*http.Client, error)
- func NewHTTPClientWithRoots(loadRoots func() (*x509.CertPool, error)) (*http.Client, error)
- type Claims
- type KeyAndID
- type KeySource
- type KubernetesClaims
- type Option
- type SubstrateClaims
- type Verifier
Constants ¶
This section is empty.
Variables ¶
ErrSigningKeysUnavailable is wrapped by Verify errors that come from not having the issuer's keys, rather than from the token: a failed fetch with no cached key for the token, the backoff that follows one, or the backoff after a fetch for an unknown key ID that did not complete.
Functions ¶
func NewHTTPClient ¶
func NewHTTPClient(issuer, certificateAuthorityFile, discoveryTokenFile string) (*http.Client, error)
NewHTTPClient returns a client for OIDC discovery and JWKS requests.
certificateAuthorityFile, when set, replaces the system roots. The client re-reads the file when it changes and verifies new connections against its current contents. A failed re-read keeps the last pool and logs a warning.
func NewHTTPClientWithRoots ¶ added in v1.0.0
NewHTTPClientWithRoots returns a client for OIDC discovery and JWKS requests that verifies servers against the pool loadRoots returns. It calls loadRoots for each request and builds a new transport only when the pool changes, as for NewHTTPClient's CA file.
Types ¶
type Claims ¶
type Claims struct {
// Claims from RFC7519
Issuer string
Subject string
Audiences []string
Expiration time.Time
NotBefore time.Time
IssuedAt time.Time
JTI string
KubernetesClaims
SubstrateClaims
}
Claims contains standard JWT claims and, when present, Kubernetes ServiceAccount claims and Substrate's own claims.
type KeySource ¶
KeySource supplies the public keys a Verifier checks signatures with. The Verifier calls Keys on Refresh, on first use, every jwksRefreshInterval, and once per jwksRefreshRetryInterval when a token names a key ID it does not have, so a source may read its backing store on every call.
type KubernetesClaims ¶
type KubernetesClaims struct {
Namespace string
ServiceAccountName string
ServiceAccountUID string
PodName string
PodUID string
SecretName string
SecretUID string
NodeName string
NodeUID string
WarnAfter time.Time
}
KubernetesClaims contains claims added to Kubernetes ServiceAccount tokens.
type Option ¶
type Option func(*Verifier)
Option configures a Verifier.
func WithSubstrateClaims ¶
func WithSubstrateClaims() Option
WithSubstrateClaims makes Verify decode Substrate's claims into Claims.SubstrateClaims and refuse a token that carries both or a malformed one. It is for the verifier of the actor-id JWT issuer, whose tokens are the only ones those claims mean anything on.
type SubstrateClaims ¶
type SubstrateClaims struct {
Kind actoridjwt.Kind
Substrate *actoridjwt.WireSubstrateClaims
}
SubstrateClaims are the claims the actor-id JWT issuer adds to the tokens it mints. Kind says which claim the token carried, KindActor for the actor's own token or KindWorkerForActor for a Substrate component acting on the actor's behalf, and Substrate holds it. A token carrying neither has KindUnspecified and a nil Substrate. A token carrying both is refused.
Only a Verifier built with WithSubstrateClaims fills these in. Any issuer can put the claim names in a token, so a verifier for another issuer leaves them alone, whatever they hold.
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier verifies JWTs from one trusted OIDC issuer and caches its signing keys. Keys are refreshed periodically and, at a bounded rate, when a token names an unknown key ID.
func NewVerifier ¶
NewVerifier returns a verifier for issuer. A token is accepted when at least one of its audiences matches audiences.