Skip to content

Commit 276ba9f

Browse files
authored
feat: add cacheDuration for remoteJWKS in SecurityPolicy (#6641)
* feat: add cacheDuration support for remoteJWKS in SecurityPolicy Signed-off-by: sachin maurya <[email protected]> * address issues for failing ci Signed-off-by: sachin maurya <[email protected]>
1 parent 218cca9 commit 276ba9f

30 files changed

+103
-12
lines changed

api/v1alpha1/jwt_types.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
package v1alpha1
77

8-
import gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
8+
import (
9+
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
10+
)
911

1012
// JWT defines the configuration for JSON Web Token (JWT) authentication.
1113
type JWT struct {
@@ -108,6 +110,11 @@ type RemoteJWKS struct {
108110
// +kubebuilder:validation:MinLength=1
109111
// +kubebuilder:validation:MaxLength=253
110112
URI string `json:"uri"`
113+
// Duration after which the cached JWKS should be expired. If not specified, default cache duration is 5 minutes.
114+
115+
// +kubebuilder:default="300s"
116+
// +optional
117+
CacheDuration *gwapiv1.Duration `json:"cacheDuration,omitempty"`
111118
}
112119

113120
// 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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,6 +3761,13 @@ spec:
37613761
type: object
37623762
type: object
37633763
type: object
3764+
cacheDuration:
3765+
default: 300s
3766+
description: |-
3767+
Duration is a string value representing a duration in time. The format is as specified
3768+
in GEP-2257, a strict subset of the syntax parsed by Golang time.ParseDuration.
3769+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
3770+
type: string
37643771
uri:
37653772
description: |-
37663773
URI is the HTTPS URI to fetch the JWKS. Envoy's system trust bundle is used to validate the server certificate.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3760,6 +3760,13 @@ spec:
37603760
type: object
37613761
type: object
37623762
type: object
3763+
cacheDuration:
3764+
default: 300s
3765+
description: |-
3766+
Duration is a string value representing a duration in time. The format is as specified
3767+
in GEP-2257, a strict subset of the syntax parsed by Golang time.ParseDuration.
3768+
pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$
3769+
type: string
37633770
uri:
37643771
description: |-
37653772
URI is the HTTPS URI to fetch the JWKS. Envoy's system trust bundle is used to validate the server certificate.

examples/kubernetes/jwt/jwt.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ spec:
1212
- name: example
1313
remoteJWKS:
1414
uri: https://raw.githubusercontent.com/envoyproxy/gateway/main/examples/kubernetes/jwt/jwks.json
15+
cacheDuration: 60s
1516
---
1617
apiVersion: gateway.networking.k8s.io/v1
1718
kind: HTTPRoute

internal/cmd/egctl/testdata/translate/in/jwt-single-route-single-match-to-xds.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ spec:
8484
- name: example
8585
remoteJWKS:
8686
uri: https://raw.githubusercontent.com/envoyproxy/gateway/main/examples/kubernetes/jwt/jwks.json
87+
cacheDuration: 300s
8788
---
8889
apiVersion: gateway.networking.k8s.io/v1
8990
kind: HTTPRoute

internal/gatewayapi/resource/testdata/all-resources.out.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ securityPolicies:
383383
providers:
384384
- name: example
385385
remoteJWKS:
386+
cacheDuration: 300s
386387
uri: https://raw.githubusercontent.com/envoyproxy/gateway/main/examples/kubernetes/jwt/jwks.json
387388
targetRef:
388389
group: gateway.networking.k8s.io

internal/gatewayapi/securitypolicy.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,10 +1007,11 @@ func (t *Translator) buildRemoteJWKS(
10071007
envoyProxy *egv1a1.EnvoyProxy,
10081008
) (*ir.RemoteJWKS, error) {
10091009
var (
1010-
protocol ir.AppProtocol
1011-
rd *ir.RouteDestination
1012-
traffic *ir.TrafficFeatures
1013-
err error
1010+
protocol ir.AppProtocol
1011+
rd *ir.RouteDestination
1012+
traffic *ir.TrafficFeatures
1013+
err error
1014+
cacheDuration *metav1.Duration
10141015
)
10151016

10161017
u, err := url.Parse(remoteJWKS.URI)
@@ -1037,10 +1038,19 @@ func (t *Translator) buildRemoteJWKS(
10371038
}
10381039
}
10391040

1041+
if remoteJWKS.CacheDuration != nil {
1042+
d, err := time.ParseDuration(string(*remoteJWKS.CacheDuration))
1043+
if err != nil {
1044+
return nil, err
1045+
}
1046+
cacheDuration = ir.MetaV1DurationPtr(d)
1047+
}
1048+
10401049
return &ir.RemoteJWKS{
1041-
Destination: rd,
1042-
Traffic: traffic,
1043-
URI: remoteJWKS.URI,
1050+
Destination: rd,
1051+
Traffic: traffic,
1052+
URI: remoteJWKS.URI,
1053+
CacheDuration: cacheDuration,
10441054
}, nil
10451055
}
10461056

internal/ir/xds.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,9 @@ type RemoteJWKS struct {
10771077
// URI is the HTTPS URI to fetch the JWKS. Envoy's system trust bundle is used to validate the server certificate.
10781078
// If a custom trust bundle is needed, it can be specified in a BackendTLSConfig resource and target the BackendRefs.
10791079
URI string `json:"uri"`
1080+
1081+
// Duration after which the cached JWKS should be expired. If not specified, default cache duration is 5 minutes.
1082+
CacheDuration *metav1.Duration `json:"cacheDuration,omitempty"`
10801083
}
10811084

10821085
// 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.

0 commit comments

Comments
 (0)