Repository navigation
fix: bound the per-key fetch gates in UpstreamCredentials - #65
Merged
Merged
Conversation
cachedFetch created a fetch mutex for every cache key but pruneLocked only dropped the ones whose key was also in the token cache. A token exchange that *fails* never reaches the token cache, so its gate was never pruned — and under token-exchange the key is (issuer, subject), an identifier the gateway does not choose. A caller with no grant on the upstream fails on every request, so the map grew with the caller population and never shrank. Give each gate a waiter count and drop it when the last caller leaves, so the map is bounded by the fetches in flight rather than by the callers ever seen. pruneLocked no longer touches it, which removes the coupling that caused the bug. TestTokenCachePruning asserted the old contract — that pruning bounds the gate map — so it moves to covering the token cache alone. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
blakebauman
added a commit
that referenced
this pull request
Aug 14, 2026
Covers #65, #66 and #68. Filed under "Unreleased" rather than a dated version: entries here are written as part of a release and land in the release commit, so a dated heading on main before the tag is the exact drift the release runbook warns about. It becomes the version heading when these ship. Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
blakebauman
added a commit
that referenced
this pull request
Aug 14, 2026
Dates the changelog entry for the three caller-derived credential fixes (#65, #66, #68) and bumps the chart: appVersion to v1.12.1, which is what a default helm install deploys, and the chart's own version to 0.2.2, since a published OCI tag is immutable. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
cachedFetchcreated a fetch mutex for every cache key, butpruneLockedonly dropped the ones whose key was also present in the token cache:A token exchange that fails never reaches the token cache, so its gate was never pruned. Under
token-exchangethe key is(issuer, subject)— an identifier the gateway does not choose — and a caller with no grant on that upstream fails on every request. So the map grew with the caller population and never shrank, which is exactly what the bounded-cache rule inCLAUDE.mdexists to prevent:How
Each gate now carries a waiter count (guarded by the existing
UpstreamCredentials.mu) and is deleted when the last caller leaves, so the map is bounded by the fetches in flight rather than the callers ever seen. Lock ordering matches the existing cache write — gate, thenc.mu— so the two cannot deadlock.pruneLockedno longer touches the gate map at all, which removes the coupling that caused the bug. Single-flighting is unchanged:TestTokenExchangeSingleFlightstill passes.Tests
TestFetchGatesDoNotLeakdrives 500 principals whose exchange is rejected and asserts zero surviving gates. On the previous code that map holds all 500 — which is the steady state for callers who have not connected the upstream.TestTokenCachePruningasserted the old contract (that pruning bounds the gate map), so it now covers the token cache alone.Not changed
auth/jwks.go:32has the identical pattern, but its keys are JWKS URIs from the issuer config — identifiers the gateway does choose, bounded by the config document. Not a leak, so left alone.Gate
gofmt,go mod tidy -diff,go vet,go build,go test -race ./..., andgolangci-lint run(0 issues) all pass locally.🤖 Generated with Claude Code