[TT-16245] Configurable Gateway-default JWKS cache timeout - #7690
Conversation
|
API Changes --- prev.txt 2026-02-04 14:46:55.029053076 +0000
+++ current.txt 2026-02-04 14:46:44.330030913 +0000
@@ -6690,6 +6690,9 @@
Streaming StreamingConfig `json:"streaming"`
Labs LabsConfig `json:"labs"`
+
+ // JWKS holds the configuration for Tyk JWKS functionalities
+ JWKS JWKSConfig `json:"jwks"`
}
Config is the configuration object used by Tyk to set up various parameters.
@@ -7004,6 +7007,17 @@
type IPsHandleStrategy string
+type JWKSCacheConfig struct {
+ // Timeout defines how long the JWKS will be kept in the cache before forcing a refresh from the JWKS endpoint.
+ // Default is 240 seconds (4 minutes). Set to 0 to use the default value.
+ Timeout int64 `json:"timeout"`
+}
+
+type JWKSConfig struct {
+ // Cache hodls configuration for JWKS caching
+ Cache JWKSCacheConfig `json:"cache"`
+}
+
type LabsConfig map[string]interface{}
LabsConfig include config for streaming
@@ -9277,7 +9291,6 @@
GatewayFireSystemEvent declared as global variable, set during gw start
var GetJWK = getJWK
-var JWKCaches = sync.Map{}
var LoopHostRE = regexp.MustCompile("tyk://([^/]+)")
var NonAlphaNumRE = regexp.MustCompile("[^A-Za-z0-9]+")
var TykErrors = make(map[string]config.TykError) |
|
This pull request introduces a configurable timeout for the gateway-default JSON Web Key Set (JWKS) cache, allowing operators to set a custom duration via the The more significant change in this PR is a substantial architectural refactoring of the JWKS caching mechanism. The implementation moves away from using global, package-level variables for caching and centralizes this state within the Files Changed AnalysisThe changes are spread across configuration, core gateway logic, authentication middlewares, and their corresponding tests.
Architecture & Impact Assessment
graph TD
subgraph "Before: Global State"
G_MW_JWT["JWT Middleware"] --> G_JWKCaches["Global JWKCaches (sync.Map)"]
G_MW_OAuth["External OAuth Middleware"] --> G_OAuthCache["Global externalOAuthJWKCache"]
end
subgraph "After: Instance-based State"
subgraph GatewayInstance["Gateway Instance"]
direction LR
apiJWKCaches["apiJWKCaches (sync.Map)"]
jwkCache["jwkCache"]
end
MW_JWT["JWT Middleware"] --> |accesses k.Gw.apiJWKCaches| GatewayInstance
MW_OAuth["External OAuth Middleware"] --> |accesses k.Gw.jwkCache| GatewayInstance
end
Scope Discovery & Context ExpansionThe scope of this PR extends significantly beyond adding a simple configuration option. The refactoring of state management from global to instance-based is a foundational architectural change that positively impacts the entire lifecycle of requests involving JWT validation.
This move away from global variables represents a significant improvement in the gateway's robustness, making its internal state management more predictable, testable, and easier to reason about. Metadata
Powered by Visor from Probelabs Last updated: 2026-02-04T14:51:12.165Z | Triggered by: pr_updated | Commit: f85bdde 💡 TIP: You can chat with Visor using |
Security Issues (2)
Architecture Issues (1)
✅ Performance Check PassedNo performance issues found – changes LGTM. Quality Issues (3)
Powered by Visor from Probelabs Last updated: 2026-02-04T14:51:15.674Z | Triggered by: pr_updated | Commit: f85bdde 💡 TIP: You can chat with Visor using |
e5a9fb5 to
0db45b2
Compare
f51a2c0 to
8bdf12d
Compare
8bdf12d to
f85bdde
Compare
|



Description
Related Issue
Motivation and Context
How This Has Been Tested
Screenshots (if appropriate)
Types of changes
Checklist
Ticket Details
TT-16245
Generated at: 2026-02-04 14:46:02