Skip to content

Commit 139de99

Browse files
authored
feat: add FailedRefetchDuration to RemoteJWKS (#9265)
Add support for failed_refetch_duration Signed-off-by: jukie <10012479+jukie@users.noreply.github.com>
1 parent 008c980 commit 139de99

17 files changed

Lines changed: 98 additions & 10 deletions

File tree

api/v1alpha1/jwt_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@ type RemoteJWKS struct {
115115
// +kubebuilder:default="300s"
116116
// +optional
117117
CacheDuration *gwapiv1.Duration `json:"cacheDuration,omitempty"`
118+
119+
// FailedRefetchDuration is the duration Envoy waits before re-fetching the JWKS
120+
// after a failed fetch.
121+
// This does not control retries within a single fetch attempt (see BackendSettings.Retry),
122+
// only the interval between fetch attempts after a failure.
123+
// If not specified, Envoy's default of 1 second is used.
124+
//
125+
// +optional
126+
FailedRefetchDuration *gwapiv1.Duration `json:"failedRefetchDuration,omitempty"`
118127
}
119128

120129
// LocalJWKSType defines the types of values for Local JWKS.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/gateway-crds-helm/templates/generated/gateway.envoyproxy.io_securitypolicies.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5369,6 +5369,15 @@ spec:
53695369
in GEP-2257, a strict subset of the syntax parsed by Golang time.ParseDuration.
53705370
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
53715371
type: string
5372+
failedRefetchDuration:
5373+
description: |-
5374+
FailedRefetchDuration is the duration Envoy waits before re-fetching the JWKS
5375+
after a failed fetch.
5376+
This does not control retries within a single fetch attempt (see BackendSettings.Retry),
5377+
only the interval between fetch attempts after a failure.
5378+
If not specified, Envoy's default of 1 second is used.
5379+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
5380+
type: string
53725381
uri:
53735382
description: |-
53745383
URI is the HTTPS URI to fetch the JWKS. Envoy's system trust bundle is used to validate the server certificate.

charts/gateway-helm/charts/crds/crds/generated/gateway.envoyproxy.io_securitypolicies.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5368,6 +5368,15 @@ spec:
53685368
in GEP-2257, a strict subset of the syntax parsed by Golang time.ParseDuration.
53695369
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
53705370
type: string
5371+
failedRefetchDuration:
5372+
description: |-
5373+
FailedRefetchDuration is the duration Envoy waits before re-fetching the JWKS
5374+
after a failed fetch.
5375+
This does not control retries within a single fetch attempt (see BackendSettings.Retry),
5376+
only the interval between fetch attempts after a failure.
5377+
If not specified, Envoy's default of 1 second is used.
5378+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
5379+
type: string
53715380
uri:
53725381
description: |-
53735382
URI is the HTTPS URI to fetch the JWKS. Envoy's system trust bundle is used to validate the server certificate.

internal/gatewayapi/securitypolicy.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,11 +1479,12 @@ func (t *Translator) buildRemoteJWKS(
14791479
gtwCtx *GatewayContext,
14801480
) (*ir.RemoteJWKS, error) {
14811481
var (
1482-
protocol ir.AppProtocol
1483-
rd *ir.RouteDestination
1484-
traffic *ir.TrafficFeatures
1485-
err error
1486-
cacheDuration *metav1.Duration
1482+
protocol ir.AppProtocol
1483+
rd *ir.RouteDestination
1484+
traffic *ir.TrafficFeatures
1485+
err error
1486+
cacheDuration *metav1.Duration
1487+
failedRefetchDuration *metav1.Duration
14871488
)
14881489

14891490
u, err := url.Parse(remoteJWKS.URI)
@@ -1518,11 +1519,20 @@ func (t *Translator) buildRemoteJWKS(
15181519
cacheDuration = ir.MetaV1DurationPtr(d)
15191520
}
15201521

1522+
if remoteJWKS.FailedRefetchDuration != nil {
1523+
d, err := time.ParseDuration(string(*remoteJWKS.FailedRefetchDuration))
1524+
if err != nil {
1525+
return nil, err
1526+
}
1527+
failedRefetchDuration = ir.MetaV1DurationPtr(d)
1528+
}
1529+
15211530
return &ir.RemoteJWKS{
1522-
Destination: rd,
1523-
Traffic: traffic,
1524-
URI: remoteJWKS.URI,
1525-
CacheDuration: cacheDuration,
1531+
Destination: rd,
1532+
Traffic: traffic,
1533+
URI: remoteJWKS.URI,
1534+
CacheDuration: cacheDuration,
1535+
FailedRefetchDuration: failedRefetchDuration,
15261536
}, nil
15271537
}
15281538

internal/gatewayapi/testdata/securitypolicy-with-jwt-backendsettings.in.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ securityPolicies:
114114
consecutiveLocalOriginFailures: 5
115115
splitExternalLocalOriginErrors: false
116116
uri: https://foo.bar.com/jwt/public-key/jwks.json
117+
failedRefetchDuration: 30s
117118
claimToHeaders:
118119
- header: claim-header
119120
claim: claim

internal/gatewayapi/testdata/securitypolicy-with-jwt-backendsettings.out.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ securityPolicies:
176176
requestTimeout: 5s
177177
tcp:
178178
connectTimeout: 15s
179+
failedRefetchDuration: 30s
179180
uri: https://foo.bar.com/jwt/public-key/jwks.json
180181
targetRef:
181182
group: gateway.networking.k8s.io
@@ -284,6 +285,7 @@ xdsIR:
284285
issuer: https://foo.bar.com
285286
name: foobar
286287
remoteJWKS:
288+
failedRefetchDuration: 30s
287289
traffic:
288290
backendConnection:
289291
bufferLimit: 100000000

internal/ir/xds.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,10 @@ type RemoteJWKS struct {
12631263

12641264
// Duration after which the cached JWKS should be expired. If not specified, default cache duration is 5 minutes.
12651265
CacheDuration *metav1.Duration `json:"cacheDuration,omitempty"`
1266+
1267+
// FailedRefetchDuration is the interval Envoy waits before re-fetching the JWKS after a
1268+
// failed fetch. If not specified, Envoy's default of 1 second is used.
1269+
FailedRefetchDuration *metav1.Duration `json:"failedRefetchDuration,omitempty"`
12661270
}
12671271

12681272
// OIDC defines the schema for authenticating HTTP requests using

internal/ir/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/xds/translator/jwt.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ func buildJWTAuthn(irListener *ir.HTTPListener, jwtAuthn *jwtauthnv3.JwtAuthenti
182182
if jwks.CacheDuration != nil {
183183
remote.RemoteJwks.CacheDuration = durationpb.New(jwks.CacheDuration.Duration)
184184
}
185+
if jwks.FailedRefetchDuration != nil {
186+
remote.RemoteJwks.AsyncFetch.FailedRefetchDuration = durationpb.New(jwks.FailedRefetchDuration.Duration)
187+
}
185188
// Set the retry policy if it exists.
186189
if jwks.Traffic != nil && jwks.Traffic.Retry != nil {
187190
var rp *corev3.RetryPolicy

0 commit comments

Comments
 (0)