oidcjwt

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 23 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 oidcjwt verifies JWTs using OIDC discovery.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPClient

func NewHTTPClient(issuer, certificateAuthorityFile, discoveryTokenFile string) (*http.Client, error)

NewHTTPClient returns a client for OIDC discovery and JWKS requests.

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 KeyAndID

type KeyAndID struct {
	KeyID     string
	PublicKey crypto.PublicKey
}

KeyAndID wraps a crypto.PublicKey and its JWK key ID.

type KeySource

type KeySource interface {
	Keys(ctx context.Context) ([]*KeyAndID, error)
}

KeySource supplies the public keys a Verifier checks signatures with. The Verifier calls Keys 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.

func FileKeySource

func FileKeySource(path string) KeySource

FileKeySource reads a JWK set from a file, for a verifier that is handed the issuer's public keys directly rather than fetching them over discovery. The file is re-read on every call, so a rotated set is picked up on the verifier's next refresh. For that to work the file must be replaced atomically, as a projected volume mounted without subPath is: an in-place rewrite can be read half-written, and a subPath mount never sees the rotation. The file holds public keys only.

func HTTPKeySource

func HTTPKeySource(issuer string, client *http.Client) KeySource

HTTPKeySource fetches the issuer's keys through OpenID Connect Discovery: <issuer>/.well-known/openid-configuration, then its jwks_uri.

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

func NewVerifier(issuer string, audiences []string, source KeySource, opts ...Option) *Verifier

NewVerifier returns a verifier for issuer. A token is accepted when at least one of its audiences matches audiences.

func (*Verifier) Verify

func (v *Verifier) Verify(ctx context.Context, jwt string, now time.Time) (*Claims, error)

Verify verifies and extracts claims from a JWT.

Jump to

Keyboard shortcuts

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