Documentation
¶
Index ¶
- Constants
- Variables
- func AlgorithmForPublicKey(pub crypto.PublicKey) string
- func BaseRegisteredClaims(subject string, audiences []string, ttl time.Duration) jwt.RegisteredClaims
- func JWKSToPublicKeys(ks JWKS) (map[string]crypto.PublicKey, error)
- func JWKToPublicKey(j JWK) (crypto.PublicKey, error)
- func ParsePublicKeyFromPEM(pemText string) (crypto.PublicKey, error)
- func ParsePublicKeyFromPEMBytes(pemBytes []byte) (crypto.PublicKey, error)
- func ServeJWKS(w http.ResponseWriter, r *http.Request, ks JWKS)
- func SetLogger(l Logger)
- type ClaimsBuilder
- type ECDSASigner
- func (s *ECDSASigner) Algorithm() string
- func (s *ECDSASigner) KID() string
- func (s *ECDSASigner) PublicKey() crypto.PublicKey
- func (s *ECDSASigner) Sign(_ context.Context, claims jwt.MapClaims) (string, error)
- func (s *ECDSASigner) SignWithHeaders(_ context.Context, claims jwt.MapClaims, headers map[string]any) (string, error)
- type Ed25519Signer
- func (s *Ed25519Signer) Algorithm() string
- func (s *Ed25519Signer) KID() string
- func (s *Ed25519Signer) PublicKey() crypto.PublicKey
- func (s *Ed25519Signer) Sign(_ context.Context, claims jwt.MapClaims) (string, error)
- func (s *Ed25519Signer) SignWithHeaders(_ context.Context, claims jwt.MapClaims, headers map[string]any) (string, error)
- type GeneratedKeySource
- type HeaderSigner
- type JWK
- type JWKS
- type KeyRing
- type KeySource
- type Logger
- type PublicKeySigner
- type RSASigner
- func (s *RSASigner) Algorithm() string
- func (s *RSASigner) KID() string
- func (s *RSASigner) PrivateKey() *rsa.PrivateKey
- func (s *RSASigner) PublicKey() crypto.PublicKey
- func (s *RSASigner) Sign(_ context.Context, claims jwt.MapClaims) (string, error)
- func (s *RSASigner) SignWithHeaders(_ context.Context, claims jwt.MapClaims, headers map[string]any) (string, error)
- type Signer
- type StaticKeySource
Constants ¶
const ( AccessTokenType = "access+jwt" DelegatedAccessTokenType = "delegated-access+jwt" )
AuthKit JOSE `typ` header values. These separate ordinary AuthKit access tokens from delegated access tokens before claims are mapped into principals.
const (
// DefaultAuthKeysPath is the default directory where External Secrets mounts auth keys
DefaultAuthKeysPath = "/vault/auth"
)
Variables ¶
var ErrUnsupportedJWK = errors.New("unsupported_jwk")
Functions ¶
func AlgorithmForPublicKey ¶ added in v0.12.3
AlgorithmForPublicKey returns a default JWS alg for a public key when none is specified.
func BaseRegisteredClaims ¶
func BaseRegisteredClaims(subject string, audiences []string, ttl time.Duration) jwt.RegisteredClaims
Helper to make base registered claims.
func JWKSToPublicKeys ¶ added in v0.12.3
JWKSToPublicKeys parses all supported keys in a JWKS document.
func JWKToPublicKey ¶ added in v0.12.3
JWKToPublicKey parses a single JWK into a crypto.PublicKey.
func ParsePublicKeyFromPEM ¶ added in v0.12.3
ParsePublicKeyFromPEM parses a PKIX/SPKI, certificate, or PKCS#1 RSA public key PEM.
func ParsePublicKeyFromPEMBytes ¶ added in v0.12.3
ParsePublicKeyFromPEMBytes parses a supported public key PEM block.
Types ¶
type ClaimsBuilder ¶
type ClaimsBuilder interface {
// Build returns application-specific claims to embed.
Build(ctx context.Context, userID string, base jwt.RegisteredClaims) (map[string]any, error)
}
ClaimsBuilder builds custom claims layered on top of RegisteredClaims.
type ECDSASigner ¶ added in v0.12.3
type ECDSASigner struct {
// contains filtered or unexported fields
}
ECDSASigner signs JWTs with ES256, ES384, or ES512 based on the private key curve.
func (*ECDSASigner) Algorithm ¶ added in v0.12.3
func (s *ECDSASigner) Algorithm() string
func (*ECDSASigner) KID ¶ added in v0.12.3
func (s *ECDSASigner) KID() string
func (*ECDSASigner) PublicKey ¶ added in v0.12.3
func (s *ECDSASigner) PublicKey() crypto.PublicKey
type Ed25519Signer ¶ added in v0.12.3
type Ed25519Signer struct {
// contains filtered or unexported fields
}
Ed25519Signer signs JWTs with EdDSA (Ed25519).
func NewEd25519Signer ¶ added in v0.12.3
func NewEd25519Signer(kid string) (*Ed25519Signer, error)
NewEd25519Signer generates a new Ed25519 key pair for development/testing.
func (*Ed25519Signer) Algorithm ¶ added in v0.12.3
func (s *Ed25519Signer) Algorithm() string
func (*Ed25519Signer) KID ¶ added in v0.12.3
func (s *Ed25519Signer) KID() string
func (*Ed25519Signer) PublicKey ¶ added in v0.12.3
func (s *Ed25519Signer) PublicKey() crypto.PublicKey
type GeneratedKeySource ¶
type GeneratedKeySource struct {
// contains filtered or unexported fields
}
GeneratedKeySource generates and persists RSA keys (for development only).
func NewGeneratedKeySource ¶
func NewGeneratedKeySource() (*GeneratedKeySource, error)
NewGeneratedKeySource creates a KeySource with auto-generated RSA keys.
func (*GeneratedKeySource) ActiveSigner ¶
func (g *GeneratedKeySource) ActiveSigner() Signer
func (*GeneratedKeySource) PublicKeys ¶
func (g *GeneratedKeySource) PublicKeys() map[string]crypto.PublicKey
type HeaderSigner ¶ added in v0.12.0
type HeaderSigner interface {
Signer
// SignWithHeaders signs claims and merges the provided extra JOSE header
// params into the token header (kid is still set by the signer).
SignWithHeaders(ctx context.Context, claims jwt.MapClaims, headers map[string]any) (token string, err error)
}
HeaderSigner is an extension of Signer that lets callers set extra JOSE header parameters (e.g. `typ`) on the signed token. AuthKit token minting uses it to stamp the token profile header.
type JWK ¶
type JWK struct {
Kty string `json:"kty"`
Use string `json:"use,omitempty"`
Kid string `json:"kid,omitempty"`
Alg string `json:"alg,omitempty"`
// RSA
N string `json:"n,omitempty"`
E string `json:"e,omitempty"`
// EC / OKP
Crv string `json:"crv,omitempty"`
X string `json:"x,omitempty"`
Y string `json:"y,omitempty"`
}
JWK represents a JSON Web Key (RSA, EC, or OKP).
func PublicToJWK ¶ added in v0.12.3
PublicToJWK converts a supported public key to a JWK.
type KeyRing ¶ added in v0.12.3
type KeyRing struct {
// contains filtered or unexported fields
}
KeyRing is a KeySource that exposes one active signer and a merged set of verification public keys (active + retired).
func NewKeyRing ¶ added in v0.12.3
NewKeyRing builds a KeyRing. verificationKeys are merged with the active signer's public key (when the signer implements PublicKeySigner). Retired keys remain in JWKS for rotation without being used to sign.
func (*KeyRing) ActiveSigner ¶ added in v0.12.3
type KeySource ¶
KeySource provides the active signer and public keys for JWKS.
func NewAutoKeySource ¶
NewAutoKeySource auto-discovers JWT keys from multiple sources with the following priority: 1. Environment variables (ACTIVE_KEY_ID, ACTIVE_PRIVATE_KEY_PEM, PUBLIC_KEYS) 2. Filesystem /vault/auth/keys.json 3. Auto-generated keys in .runtime/authkit/ (development fallback)
type Logger ¶ added in v0.12.3
Logger receives non-fatal key-loading warnings from jwtkit. The default is a no-op logger so libraries do not write to stdout.
type PublicKeySigner ¶ added in v0.12.3
PublicKeySigner is implemented by in-memory signers that expose their public key.
type RSASigner ¶
type RSASigner struct {
// contains filtered or unexported fields
}
Minimal in-memory RSA signer for bootstrap/dev. Production should load from KMS or DB.
func NewRSASignerFromPEM ¶
NewRSASignerFromPEM constructs an RSASigner from a PEM-encoded RSA private key.
func (*RSASigner) PrivateKey ¶
func (s *RSASigner) PrivateKey() *rsa.PrivateKey
func (*RSASigner) SignWithHeaders ¶ added in v0.12.0
func (s *RSASigner) SignWithHeaders(_ context.Context, claims jwt.MapClaims, headers map[string]any) (string, error)
SignWithHeaders implements HeaderSigner: it signs claims and merges extra JOSE header params (e.g. `typ`) into the token header. The signer's own kid is set last and cannot be overridden by the supplied headers.
type Signer ¶
type Signer interface {
// Algorithm returns the JWS algorithm (e.g., RS256, EdDSA).
Algorithm() string
// KID returns current key id.
KID() string
// Sign creates a signed JWT with provided claims.
Sign(ctx context.Context, claims jwt.MapClaims) (token string, err error)
}
Signer issues and verifies asymmetric JWTs.
type StaticKeySource ¶
StaticKeySource is a simple in-memory implementation.
func NewStaticKeySourceFromRing ¶ added in v0.12.3
func NewStaticKeySourceFromRing(active Signer, verificationKeys map[string]crypto.PublicKey) StaticKeySource
NewStaticKeySourceFromRing is a convenience alias for NewKeyRing(...).StaticKeySource().
func (StaticKeySource) ActiveSigner ¶
func (s StaticKeySource) ActiveSigner() Signer
func (StaticKeySource) PublicKeys ¶
func (s StaticKeySource) PublicKeys() map[string]crypto.PublicKey