9
9
"strings"
10
10
"unicode"
11
11
12
+ validation2 "github.com/nginx/kubernetes-ingress/internal/validation"
12
13
v1 "github.com/nginx/kubernetes-ingress/pkg/apis/configuration/v1"
13
14
"k8s.io/apimachinery/pkg/util/validation"
14
15
"k8s.io/apimachinery/pkg/util/validation/field"
@@ -198,6 +199,16 @@ func validateJWT(jwt *v1.JWTAuth, fieldPath *field.Path) field.ErrorList {
198
199
if jwt .KeyCache != "" {
199
200
allErrs = append (allErrs , field .Forbidden (fieldPath .Child ("keyCache" ), "key cache must not be used when using Secret" ))
200
201
}
202
+
203
+ // If JwksURI is not set, then none of the SNI fields should be set.
204
+ if jwt .SNIEnabled {
205
+ return append (allErrs , field .Forbidden (fieldPath .Child ("sniEnabled" ), "sniEnabled can only be set when JwksURI is set" ))
206
+ }
207
+
208
+ if jwt .SNIName != "" {
209
+ return append (allErrs , field .Forbidden (fieldPath .Child ("sniName" ), "sniName can only be set when JwksURI is set" ))
210
+ }
211
+
201
212
return allErrs
202
213
}
203
214
@@ -213,7 +224,22 @@ func validateJWT(jwt *v1.JWTAuth, fieldPath *field.Path) field.ErrorList {
213
224
if jwt .KeyCache == "" {
214
225
allErrs = append (allErrs , field .Required (fieldPath .Child ("keyCache" ), "key cache must be set, example value: 1h" ))
215
226
}
216
- return allErrs
227
+
228
+ // if SNI server name is provided, but SNI is not enabled, return an error
229
+ if jwt .SNIName != "" && ! jwt .SNIEnabled {
230
+ allErrs = append (allErrs , field .Forbidden (fieldPath .Child ("sniServerName" ), "sniServerName can only be set when sniEnabled is true" ))
231
+ }
232
+
233
+ // if SNI is enabled and SNI server name is provided, make sure it's a valid URI
234
+ if jwt .SNIEnabled && jwt .SNIName != "" {
235
+ err := validation2 .ValidateURI (jwt .SNIName ,
236
+ validation2 .WithAllowedSchemes ("https" ),
237
+ validation2 .WithUserAllowed (false ),
238
+ validation2 .WithDefaultScheme ("https" ))
239
+ if err != nil {
240
+ allErrs = append (allErrs , field .Invalid (fieldPath .Child ("sniServerName" ), jwt .SNIName , "sniServerName is not a valid URI" ))
241
+ }
242
+ }
217
243
}
218
244
return allErrs
219
245
}
0 commit comments