Documentation
¶
Overview ¶
Package idtoken verifies ID tokens that an external OpenID Connect provider, typically a CI system, signed: the subject tokens of the Access OIDC token exchange (POST /access/api/v1/oidc/token, research 21). Signing keys come from the provider's discovery document and JWKS, cached per provider.
Role ¶
access module, core layer: the ID token verifier. core/oidc verifies each exchange's subject token through it, and the access module's HTTP adapter builds the one Verifier the exchanges share. It is not merged into core/oidc, where the target layout puts it, because both packages declare Provider, and a merge would rename one of them (decision 0044). The package imports the standard library and go-jose.
Inputs ¶
- New: Options, the HTTP clients with and without the environment's proxy, the key cache lifetime and the clock.
- Verify: a token as the client sent it and the Provider it must agree with: the issuer URL, the expected issuer and audience, an Azure application id and whether to fetch through the proxy.
Outputs ¶
- The token's claims, once its signature, issuer, audience and validity verify.
- ErrInvalid for a token that does not verify, and ErrKeys for a provider whose keys cannot be fetched.
Invariants ¶
- Only asymmetric algorithms verify: a token signed with HS* or none is refused.
- A token naming a key not in the cache fetches the keys again at most once every 30 seconds, so forged key ids cannot make the server hammer the provider.
References ¶
- Research 21: docs/research/21-oidc-token-exchange.md.
- Decision 0019: docs/research/decisions/0019-human-authentication-tiers.md, lines 22 to 25.
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md ("Package placement and names": idtoken keeps its name and package).
- Target layout: docs/research/architecture-options/5-modular-monolith.md, lines 283 and 987, which merge it into core/oidc; decision 0044 records the difference.
- Plan: docs/implementation/plan.md#p4-identity-and-authorization and #p9d-modular-monolith-migration, epic ACC (https://github.com/weaveplatform/artifactweave/issues/940).
- https://github.com/weaveplatform/artifactweave/issues/1073
Status ¶
Implemented P4 with the OIDC token exchange (pull request 145). Moved here in P9d.
Testing ¶
idtoken_test.go: TestAccVerify, TestAccVerifyRefuses, TestAccKeyRotation, TestAccKeysUnavailable, TestAccAzureAppID, TestAccProxyChoice, TestAccBadDocuments and TestAccKeyWithoutID, each against a running idtokentest provider.
Index ¶
Constants ¶
const ( // DefaultKeyTTL is how long fetched keys are trusted before they are // fetched again. Providers rotate keys with overlap, and a key a token // names that is not cached triggers an early fetch anyway. DefaultKeyTTL = 15 * time.Minute // DefaultTimeout bounds one discovery or JWKS fetch. DefaultTimeout = 10 * time.Second )
Defaults for the zero Options fields.
Variables ¶
var ( // ErrInvalid reports a token that does not verify: malformed, signed by // no key the provider publishes, from another issuer, for another // audience, or outside its validity. ErrInvalid = errors.New("idtoken: the subject token does not verify") // ErrKeys reports a provider whose signing keys cannot be fetched, so no // token of it can be verified for now. ErrKeys = errors.New("idtoken: the provider's signing keys are unavailable") )
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// Client fetches discovery documents and keys when the provider asks for
// the default proxy, and Direct when it does not. nil means a client
// with DefaultTimeout that takes its proxy from the environment, and one
// that uses none.
Client, Direct *http.Client
KeyTTL time.Duration
// Now supplies the time; nil means time.Now.
Now func() time.Time
}
Options configures a Verifier.
type Provider ¶
type Provider struct {
// URL is the provider's issuer URL; its discovery document is at
// URL/.well-known/openid-configuration.
URL string
// Issuer is the iss a token must carry; empty means URL.
Issuer string
// Audience, when set, must be among the token's aud.
Audience string
// AppID, for Azure, asks the JWKS for an application's custom signing
// keys (the appid query parameter).
AppID string
// UseProxy fetches through the proxy from the environment.
UseProxy bool
}
Provider is what a token must agree with.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package idtokentest is a fake OpenID Connect provider for tests: it serves a discovery document and a JWKS, as GitHub Actions, GitLab and other CI systems do, and mints ID tokens signed with its current key.
|
Package idtokentest is a fake OpenID Connect provider for tests: it serves a discovery document and a JWKS, as GitHub Actions, GitLab and other CI systems do, and mints ID tokens signed with its current key. |