Documentation
¶
Overview ¶
Package oidc verifies OIDC bearer tokens and projects their already-verified claims into the engine's narrow caller identity.
Index ¶
Constants ¶
This section is empty.
Variables ¶
ErrIdentityUnavailable identifies a transient inability to obtain trusted key material from the identity provider.
var ErrInvalidConfig = errors.New("oidc: invalid configuration")
ErrInvalidConfig identifies configuration that cannot construct a validator. The wrapped error deliberately does not expose ToolHive error types.
var ErrInvalidToken = errors.New("oidc: invalid token")
ErrInvalidToken identifies a malformed, invalid, or otherwise inadmissible bearer credential.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Issuer is the exact OIDC issuer accepted in the token's iss claim.
Issuer string
// JWKSURI pins the signing-key endpoint; empty uses OIDC discovery.
JWKSURI string
// Audience is the single service audience accepted in the token's aud claim.
Audience string
// AllowAnyAudience permits an empty Audience for resource clients whose
// authorization server does not bind access tokens to an audience.
AllowAnyAudience bool
// MaxJWKSStaleness bounds cached-key use during an identity-provider outage;
// zero disables the upper bound.
MaxJWKSStaleness time.Duration
// InsecureAllowPrivateIssuer permits HTTP and private issuer/JWKS addresses.
// Deprecated: use AllowPrivateHTTPSIssuer with TrustedCAFile for a private
// HTTPS issuer. This legacy escape hatch remains for isolated tests that need
// both HTTP and private-address access.
InsecureAllowPrivateIssuer bool
// AllowPrivateHTTPSIssuer permits only the resolved private addresses of the
// JWKS host when JWKSURI is set (the issuer is then never contacted), or of
// the issuer host when JWKSURI is empty. Its internal scoped transport
// re-validates addresses on every dial, bounds keep-alives, refuses redirects,
// and retains HTTPS and TLS hostname verification.
// TrustedCAFile is required when this mode is enabled.
AllowPrivateHTTPSIssuer bool
// TrustedCAFile is the PEM CA bundle path. It is required (non-empty) when
// AllowPrivateHTTPSIssuer is enabled, and is also passed through to the
// underlying validator's own default-client CA loading for the legacy
// InsecureAllowPrivateIssuer path. This package never reads it itself: see
// TrustedCAPEM.
TrustedCAFile string
// TrustedCAPEM is the CA bundle's PEM-encoded bytes, used by
// AllowPrivateHTTPSIssuer's scoped transport to validate the issuer
// certificate. The caller is responsible for reading TrustedCAFile from
// disk; this package must not touch the host filesystem.
TrustedCAPEM []byte
// HTTPClient optionally supplies trusted roots and transport policy. Nil uses
// the validator's hardened client. When set, the caller is responsible for
// preserving equivalent redirect and private-address protections.
HTTPClient *http.Client
// OwnerIdentity selects which identity keys the returned principal. The
// zero value keys it by the token's own `iss` and `sub`; see
// OwnerIdentitySubID. Any other value is rejected with ErrInvalidConfig.
OwnerIdentity OwnerIdentity
// AcceptedClientIDs lists the OAuth clients whose access tokens are accepted.
// It is required, and only allowed, with OwnerIdentitySubID.
AcceptedClientIDs []string
}
Config is the trusted issuer, audience, and key-fetch policy for a Validator.
type KubernetesBootstrapConfig ¶ added in v0.3.0
type KubernetesBootstrapConfig struct {
DiscoveryURL string
JWKSURI string
TokenFile string
TokenSource func() ([]byte, error)
}
KubernetesBootstrapConfig supplies the fixed Kubernetes API endpoints and the broker's projected service-account token. The token's issuer claim is untrusted until the configured discovery endpoint confirms it.
TokenFile is sent as the bearer to both endpoints and is re-read for every request, so rotation is picked up. TokenSource returns that same token's contents once, to read its issuer claim: this package may not read files itself, so the caller does.
type OwnerIdentity ¶ added in v0.4.0
type OwnerIdentity string
OwnerIdentity names the token identity that keys the returned principal.
const OwnerIdentitySubID OwnerIdentity = "sub_id"
OwnerIdentitySubID keys the returned principal by the `iss` and `sub` inside the token's `sub_id` claim, an RFC 9493 `iss_sub` subject identifier, rather than by the token's own `iss` and `sub`. As preconditions it requires an RFC 9068 access token (`typ` header `at+jwt`) whose `client_id` claim is in AcceptedClientIDs, and it requires Audience with AllowAnyAudience off.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator owns token verification and its background JWKS refresh. Call Close when it is no longer needed.
func NewKubernetesValidator ¶ added in v0.3.0
func NewKubernetesValidator(ctx context.Context, cfg Config, bootstrap KubernetesBootstrapConfig) (*Validator, error)
NewKubernetesValidator derives the cluster's issuer from the projected token, confirms it through the configured discovery endpoint, and constructs a validator that fetches keys from the configured JWKS endpoint. Neither the token claim nor the discovery response selects a network destination.
cfg.Issuer and cfg.JWKSURI must be empty: both come from bootstrap. cfg.TrustedCAFile is the CA that signs the API server's certificate. The API server is reached over private addresses, so TLS verification against that CA is what authenticates it. A dedicated cfg.Audience is required: every pod in the cluster can mint tokens from this issuer, so only the audience separates the broker's callers from all of them.
The bearer is re-read per request by toolhive-core v0.0.51 or later.
func NewValidator ¶
NewValidator constructs a fail-closed OIDC validator. Issuer must be non-empty; Audience must also be non-empty unless AllowAnyAudience is explicitly enabled. Secure issuer/JWKS transport remains enabled.
func (*Validator) Ready ¶ added in v0.3.0
Ready performs a bounded, read-only check that the configured JWKS endpoint returns usable signing keys. It changes no identity-provider state and adds no credential of its own; a validator from NewKubernetesValidator sends its token file's contents to that one endpoint. Redirects are refused.
Ready checks nothing when no JWKSURI is configured (discovery mode), where the endpoint is only known to the underlying validator, and returns nil.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package scopedhttps constructs HTTPS clients confined to explicitly approved private-network endpoints.
|
Package scopedhttps constructs HTTPS clients confined to explicitly approved private-network endpoints. |