goSet.JWKS over keyfunc v3Date: 2026-11-19
Accepted (issue #399, release train 0.12.0). Amends ADR 0034 §4 and §5.
The 0.12.0 dependency refresh brings every module to latest stable,
majors included (planning ADR 0079). MicahParks/keyfunc moved from v2 to
v3, and v3 is a rewrite:
NewGiven, NewGivenRSA, NewGivenCustom,
GivenKeyOptions) is gone. ADR 0034 §4 used it to merge RFC 9964 AKP
(ML-DSA) keys into a JWKS. jwkset, which v3 parses with, cannot read AKP
keys.jwkset HTTP client. That client
re-reads only the JWK Set it parses, so an AKP key captured at the first
load would never be refreshed. A rotated ML-DSA key would stay frozen
until restart.*keyfunc.JWKS was part of this module’s exported API, in
goSetSstp.VerifyConfig.JWKS, goSet.Parse and the services layer.
Sister repos compile against it, so any keyfunc major is a cross-repo
break.1. The exported type is family-owned. pkg/goSet exports JWKS,
VerificationKey{Key, Alg}, NewJwksFromKeys, NewJwksWithAKP, AKPKeys,
FetchJwks with JwksOptions, and ErrKIDNotFound. No keyfunc or jwkset
type appears in the exported API, so a later keyfunc major is a change inside
pkg/goSet only. Close replaces EndBackground; it is nil-safe,
idempotent, and does nothing on a static set.
2. A JWKS has two parts, built together from the same bytes.
VerificationKey map. It holds the AKP keys, parsed
by pkg/goSet/mldsa, and every key built in memory.MemoryStorage behind a
keyfunc v3 Keyfunc.A refresh builds both parts from one fetched document and swaps them under one lock, so an AKP key rotates exactly like an RSA key. This replaces ADR 0034 §4’s “given keys merged back in on every refresh”.
3. goSet owns the fetch loop, not jwkset. FetchJwks requires a
successful first fetch, then runs a ticker at RefreshInterval (default 1h).
It also refreshes when a token names a kid the set does not hold, at most
once per RefreshRateLimit (default 5m; authSupport uses 1s for issue
#115). The rules:
kid never triggers a refresh.OnRefreshError (by default a WARN log).Owning the loop is what lets decision 2 hold. It also gives the refresher a
stable stack frame, goSet.(*jwksRemote).loop, which the GH #290 leak tests
count.
4. Alg pinning at the key is kept (ADR 0034 §5).
Alg differs from the token’s alg header is refused.alg.Alg is not pinned. Only test fixtures
build one.5. One bad JWK is skipped, not fatal. Each non-AKP key is parsed separately and an unusable one is logged and skipped. jwkset’s whole-set parse would cost a receiver every key because of one bad entry.
6. The not-found error keeps the v2 phrase. ErrKIDNotFound reads
“goSet: the given key ID was not found in the JWKS”, and a lookup wraps it
with the kid (: "rsa-2"). The text is not byte-identical to v2’s, so match
with errors.Is. The classifiers that match the substring “key ID” still
work.
Close, which makes
the GH #290 leak accounting exact.pkg/goSet/jwks_loader.go (about 200 lines), and this project maintains it.*keyfunc.JWKS becomes *goSet.JWKS;keyfunc.NewGiven* becomes goSet.NewJwksFromKeys with
goSet.VerificationKey;keyfunc.Get becomes goSet.FetchJwks;AKPGivenKeys becomes AKPKeys;EndBackground becomes Close.RefreshTimeout (default 60s). Fetches are serialized, so other
unknown-kid lookups on the same set wait for an in-flight fetch.
Known-kid lookups never wait. Under v2 the refresh was queued to the
background loop. The rate limit keeps a burst of unknown kids to one
fetch.