Skip to content

Commit 7c2c3e4

Browse files
committed
If JwksURI is not set, SNI should not be set
1 parent 72063bd commit 7c2c3e4

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

pkg/apis/configuration/validation/policy.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ func validateJWT(jwt *v1.JWTAuth, fieldPath *field.Path) field.ErrorList {
202202
return allErrs
203203
}
204204

205+
if jwt.JwksURI == "" {
206+
// If JwksURI is not set, then none of the SNI fields should be set.
207+
if jwt.SNIEnabled {
208+
return append(allErrs, field.Forbidden(fieldPath.Child("sniEnabled"), "sniEnabled can only be set when JwksURI is set"))
209+
}
210+
211+
if jwt.SNIName != "" {
212+
return append(allErrs, field.Forbidden(fieldPath.Child("sniName"), "sniName can only be set when JwksURI is set"))
213+
}
214+
}
215+
205216
// Verify a case when using JWKS
206217
if jwt.JwksURI != "" {
207218
allErrs = append(allErrs, validateURL(jwt.JwksURI, fieldPath.Child("JwksURI"))...)

pkg/apis/configuration/validation/policy_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,31 @@ func TestValidateJWT_FailsOnInvalidInput(t *testing.T) {
994994
},
995995
msg: "SNI server name passed, SNI not passed",
996996
},
997+
{
998+
jwt: &v1.JWTAuth{
999+
Realm: "My Product API",
1000+
Token: "$cookie_auth_token",
1001+
SNIEnabled: true,
1002+
},
1003+
msg: "Jwks URI not set, but SNI is enabled",
1004+
},
1005+
{
1006+
jwt: &v1.JWTAuth{
1007+
Realm: "My Product API",
1008+
Token: "$cookie_auth_token",
1009+
SNIName: "https://idp.com",
1010+
},
1011+
msg: "Jwks URI not set, but SNIName is set",
1012+
},
1013+
{
1014+
jwt: &v1.JWTAuth{
1015+
Realm: "My Product API",
1016+
Token: "$cookie_auth_token",
1017+
SNIName: "https://idp.com",
1018+
SNIEnabled: true,
1019+
},
1020+
msg: "Jwks URI not set, but SNIName is set and SNI is enabled",
1021+
},
9971022
}
9981023
for _, test := range tests {
9991024
test := test

0 commit comments

Comments
 (0)