Skip to content

Commit c608791

Browse files
authored
Merge pull request kubernetes#130875 from aramase/aramase/f/fix_email_verified_godoc
Fix godoc for `claims.email_verified` usage in claim validation rules
2 parents 2499a2c + 349e079 commit c608791

File tree

4 files changed

+63
-4
lines changed

4 files changed

+63
-4
lines changed

CHANGELOG/CHANGELOG-1.30.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1584,7 +1584,7 @@ name | architectures
15841584
([#123344](https://github.com/kubernetes/kubernetes/pull/123344), [@nilekhc](https://github.com/nilekhc))
15851585
- When configuring a JWT authenticator:
15861586

1587-
If `username.expression` used 'claims.email', then 'claims.email_verified' must have been used in `username.expression` or `extra[*].valueExpression` or `claimValidationRules[*].expression`. An example claim validation rule expression that matches the validation automatically applied when `username.claim` is set to 'email' is 'claims.?email_verified.orValue(true)'.
1587+
If `username.expression` used 'claims.email', then 'claims.email_verified' must have been used in `username.expression` or `extra[*].valueExpression` or `claimValidationRules[*].expression`. An example claim validation rule expression that matches the validation automatically applied when `username.claim` is set to 'email' is 'claims.?email_verified.orValue(true) == true'.
15881588
([#123737](https://github.com/kubernetes/kubernetes/pull/123737), [@enj](https://github.com/enj))
15891589
- `readOnly` volumes now support recursive read-only mounts for kernel versions >= 5.12."
15901590
([#123180](https://github.com/kubernetes/kubernetes/pull/123180), [@AkihiroSuda](https://github.com/AkihiroSuda))
@@ -2416,7 +2416,7 @@ name | architectures
24162416
If username.expression uses 'claims.email', then 'claims.email_verified' must be used in
24172417
username.expression or extra[*].valueExpression or claimValidationRules[*].expression.
24182418
An example claim validation rule expression that matches the validation automatically
2419-
applied when username.claim is set to 'email' is 'claims.?email_verified.orValue(true)'. ([#123737](https://github.com/kubernetes/kubernetes/pull/123737), [@enj](https://github.com/enj)) [SIG API Machinery and Auth]
2419+
applied when username.claim is set to 'email' is 'claims.?email_verified.orValue(true) == true'. ([#123737](https://github.com/kubernetes/kubernetes/pull/123737), [@enj](https://github.com/enj)) [SIG API Machinery and Auth]
24202420

24212421
### Feature
24222422

staging/src/k8s.io/apiserver/pkg/apis/apiserver/v1alpha1/types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ type ClaimMappings struct {
352352
// If username.expression uses 'claims.email', then 'claims.email_verified' must be used in
353353
// username.expression or extra[*].valueExpression or claimValidationRules[*].expression.
354354
// An example claim validation rule expression that matches the validation automatically
355-
// applied when username.claim is set to 'email' is 'claims.?email_verified.orValue(true)'.
355+
// applied when username.claim is set to 'email' is 'claims.?email_verified.orValue(true) == true'. By explicitly comparing
356+
// the value to true, we let type-checking see the result will be a boolean, and to make sure a non-boolean email_verified
357+
// claim will be caught at runtime.
356358
//
357359
// In the flag based approach, the --oidc-username-claim and --oidc-username-prefix are optional. If --oidc-username-claim is not set,
358360
// the default value is "sub". For the authentication config, there is no defaulting for claim or prefix. The claim and prefix must be set explicitly.

staging/src/k8s.io/apiserver/pkg/apis/apiserver/v1beta1/types.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ type ClaimMappings struct {
323323
// If username.expression uses 'claims.email', then 'claims.email_verified' must be used in
324324
// username.expression or extra[*].valueExpression or claimValidationRules[*].expression.
325325
// An example claim validation rule expression that matches the validation automatically
326-
// applied when username.claim is set to 'email' is 'claims.?email_verified.orValue(true)'.
326+
// applied when username.claim is set to 'email' is 'claims.?email_verified.orValue(true) == true'. By explicitly comparing
327+
// the value to true, we let type-checking see the result will be a boolean, and to make sure a non-boolean email_verified
328+
// claim will be caught at runtime.
327329
//
328330
// In the flag based approach, the --oidc-username-claim and --oidc-username-prefix are optional. If --oidc-username-claim is not set,
329331
// the default value is "sub". For the authentication config, there is no defaulting for claim or prefix. The claim and prefix must be set explicitly.

staging/src/k8s.io/apiserver/pkg/apis/apiserver/validation/validation_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,61 @@ func TestValidateAuthenticationConfiguration(t *testing.T) {
585585
},
586586
want: "",
587587
},
588+
{
589+
name: "valid authentication configuration that uses verified email via claim validation rule",
590+
in: &api.AuthenticationConfiguration{
591+
JWT: []api.JWTAuthenticator{
592+
{
593+
Issuer: api.Issuer{
594+
URL: "https://issuer-url",
595+
Audiences: []string{"audience"},
596+
},
597+
ClaimValidationRules: []api.ClaimValidationRule{
598+
{
599+
// By explicitly comparing the value to true, we let type-checking see the result will be
600+
// a boolean, and to make sure a non-boolean email_verified claim will be caught at runtime.
601+
Expression: `claims.?email_verified.orValue(true) == true`,
602+
},
603+
},
604+
// allow email claim only when email_verified is present and true
605+
ClaimMappings: api.ClaimMappings{
606+
Username: api.PrefixedClaimOrExpression{
607+
Expression: `{claims.?email: "panda"}`,
608+
},
609+
},
610+
},
611+
},
612+
},
613+
want: "",
614+
},
615+
{
616+
name: "valid authentication configuration that uses verified email via claim validation rule incorrectly",
617+
in: &api.AuthenticationConfiguration{
618+
JWT: []api.JWTAuthenticator{
619+
{
620+
Issuer: api.Issuer{
621+
URL: "https://issuer-url",
622+
Audiences: []string{"audience"},
623+
},
624+
ClaimValidationRules: []api.ClaimValidationRule{
625+
{
626+
// This expression was previously documented in the godoc for the JWT authenticator
627+
// and was incorrect. It was changed to the above expression in the previous test case.
628+
// Testing the old expression here to confirm it fails validation.
629+
Expression: `claims.?email_verified.orValue(true)`,
630+
},
631+
},
632+
// allow email claim only when email_verified is present and true
633+
ClaimMappings: api.ClaimMappings{
634+
Username: api.PrefixedClaimOrExpression{
635+
Expression: `{claims.?email: "panda"}`,
636+
},
637+
},
638+
},
639+
},
640+
},
641+
want: `[jwt[0].claimValidationRules[0].expression: Invalid value: "claims.?email_verified.orValue(true)": must evaluate to bool, jwt[0].claimMappings.username.expression: Invalid value: "{claims.?email: \"panda\"}": claims.email_verified must be used in claimMappings.username.expression or claimMappings.extra[*].valueExpression or claimValidationRules[*].expression when claims.email is used in claimMappings.username.expression]`,
642+
},
588643
{
589644
name: "valid authentication configuration",
590645
in: &api.AuthenticationConfiguration{

0 commit comments

Comments
 (0)