@@ -38,14 +38,13 @@ import (
38
38
authenticationcel "k8s.io/apiserver/pkg/authentication/cel"
39
39
authorizationcel "k8s.io/apiserver/pkg/authorization/cel"
40
40
"k8s.io/apiserver/pkg/cel"
41
- "k8s.io/apiserver/pkg/cel/environment"
42
41
"k8s.io/apiserver/pkg/features"
43
42
utilfeature "k8s.io/apiserver/pkg/util/feature"
44
43
"k8s.io/client-go/util/cert"
45
44
)
46
45
47
46
// ValidateAuthenticationConfiguration validates a given AuthenticationConfiguration.
48
- func ValidateAuthenticationConfiguration (c * api.AuthenticationConfiguration , disallowedIssuers []string ) field.ErrorList {
47
+ func ValidateAuthenticationConfiguration (compiler authenticationcel. Compiler , c * api.AuthenticationConfiguration , disallowedIssuers []string ) field.ErrorList {
49
48
root := field .NewPath ("jwt" )
50
49
var allErrs field.ErrorList
51
50
@@ -62,7 +61,7 @@ func ValidateAuthenticationConfiguration(c *api.AuthenticationConfiguration, dis
62
61
seenDiscoveryURLs := sets .New [string ]()
63
62
for i , a := range c .JWT {
64
63
fldPath := root .Index (i )
65
- _ , errs := validateJWTAuthenticator (a , fldPath , sets .New (disallowedIssuers ... ), utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthenticationConfiguration ))
64
+ _ , errs := validateJWTAuthenticator (compiler , a , fldPath , sets .New (disallowedIssuers ... ), utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthenticationConfiguration ))
66
65
allErrs = append (allErrs , errs ... )
67
66
68
67
if seenIssuers .Has (a .Issuer .URL ) {
@@ -93,15 +92,13 @@ func ValidateAuthenticationConfiguration(c *api.AuthenticationConfiguration, dis
93
92
// CompileAndValidateJWTAuthenticator validates a given JWTAuthenticator and returns a CELMapper with the compiled
94
93
// CEL expressions for claim mappings and validation rules.
95
94
// This is exported for use in oidc package.
96
- func CompileAndValidateJWTAuthenticator (authenticator api.JWTAuthenticator , disallowedIssuers []string ) (authenticationcel.CELMapper , field.ErrorList ) {
97
- return validateJWTAuthenticator (authenticator , nil , sets .New (disallowedIssuers ... ), utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthenticationConfiguration ))
95
+ func CompileAndValidateJWTAuthenticator (compiler authenticationcel. Compiler , authenticator api.JWTAuthenticator , disallowedIssuers []string ) (authenticationcel.CELMapper , field.ErrorList ) {
96
+ return validateJWTAuthenticator (compiler , authenticator , nil , sets .New (disallowedIssuers ... ), utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthenticationConfiguration ))
98
97
}
99
98
100
- func validateJWTAuthenticator (authenticator api.JWTAuthenticator , fldPath * field.Path , disallowedIssuers sets.Set [string ], structuredAuthnFeatureEnabled bool ) (authenticationcel.CELMapper , field.ErrorList ) {
99
+ func validateJWTAuthenticator (compiler authenticationcel. Compiler , authenticator api.JWTAuthenticator , fldPath * field.Path , disallowedIssuers sets.Set [string ], structuredAuthnFeatureEnabled bool ) (authenticationcel.CELMapper , field.ErrorList ) {
101
100
var allErrs field.ErrorList
102
101
103
- // strictCost is set to true which enables the strict cost for CEL validation.
104
- compiler := authenticationcel .NewCompiler (environment .MustBaseEnvSet (environment .DefaultCompatibilityVersion (), true ))
105
102
state := & validationState {}
106
103
107
104
allErrs = append (allErrs , validateIssuer (authenticator .Issuer , disallowedIssuers , fldPath .Child ("issuer" ), structuredAuthnFeatureEnabled )... )
@@ -616,7 +613,7 @@ func compileUserCELExpression(compiler authenticationcel.Compiler, expression au
616
613
}
617
614
618
615
// ValidateAuthorizationConfiguration validates a given AuthorizationConfiguration.
619
- func ValidateAuthorizationConfiguration (fldPath * field.Path , c * api.AuthorizationConfiguration , knownTypes sets.String , repeatableTypes sets.String ) field.ErrorList {
616
+ func ValidateAuthorizationConfiguration (compiler authorizationcel. Compiler , fldPath * field.Path , c * api.AuthorizationConfiguration , knownTypes sets.Set [ string ] , repeatableTypes sets.Set [ string ] ) field.ErrorList {
620
617
allErrs := field.ErrorList {}
621
618
622
619
if len (c .Authorizers ) == 0 {
@@ -633,7 +630,7 @@ func ValidateAuthorizationConfiguration(fldPath *field.Path, c *api.Authorizatio
633
630
continue
634
631
}
635
632
if ! knownTypes .Has (aType ) {
636
- allErrs = append (allErrs , field .NotSupported (fldPath .Child ("type" ), aType , knownTypes .List ()))
633
+ allErrs = append (allErrs , field .NotSupported (fldPath .Child ("type" ), aType , sets .List (knownTypes )))
637
634
continue
638
635
}
639
636
if seenAuthorizerTypes .Has (aType ) && ! repeatableTypes .Has (aType ) {
@@ -657,7 +654,7 @@ func ValidateAuthorizationConfiguration(fldPath *field.Path, c *api.Authorizatio
657
654
allErrs = append (allErrs , field .Required (fldPath .Child ("webhook" ), "required when type=Webhook" ))
658
655
continue
659
656
}
660
- allErrs = append (allErrs , ValidateWebhookConfiguration (fldPath , a .Webhook )... )
657
+ allErrs = append (allErrs , ValidateWebhookConfiguration (compiler , fldPath , a .Webhook )... )
661
658
default :
662
659
if a .Webhook != nil {
663
660
allErrs = append (allErrs , field .Invalid (fldPath .Child ("webhook" ), "non-null" , "may only be specified when type=Webhook" ))
@@ -668,7 +665,7 @@ func ValidateAuthorizationConfiguration(fldPath *field.Path, c *api.Authorizatio
668
665
return allErrs
669
666
}
670
667
671
- func ValidateWebhookConfiguration (fldPath * field.Path , c * api.WebhookConfiguration ) field.ErrorList {
668
+ func ValidateWebhookConfiguration (compiler authorizationcel. Compiler , fldPath * field.Path , c * api.WebhookConfiguration ) field.ErrorList {
672
669
allErrs := field.ErrorList {}
673
670
674
671
if c .Timeout .Duration == 0 {
@@ -740,19 +737,19 @@ func ValidateWebhookConfiguration(fldPath *field.Path, c *api.WebhookConfigurati
740
737
allErrs = append (allErrs , field .NotSupported (fldPath .Child ("connectionInfo" , "type" ), c .ConnectionInfo , []string {api .AuthorizationWebhookConnectionInfoTypeInCluster , api .AuthorizationWebhookConnectionInfoTypeKubeConfigFile }))
741
738
}
742
739
743
- _ , errs := compileMatchConditions (c .MatchConditions , fldPath , utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthorizationConfiguration ))
740
+ _ , errs := compileMatchConditions (compiler , c .MatchConditions , fldPath , utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthorizationConfiguration ))
744
741
allErrs = append (allErrs , errs ... )
745
742
746
743
return allErrs
747
744
}
748
745
749
746
// ValidateAndCompileMatchConditions validates a given webhook's matchConditions.
750
747
// This is exported for use in authz package.
751
- func ValidateAndCompileMatchConditions (matchConditions []api.WebhookMatchCondition ) (* authorizationcel.CELMatcher , field.ErrorList ) {
752
- return compileMatchConditions (matchConditions , nil , utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthorizationConfiguration ))
748
+ func ValidateAndCompileMatchConditions (compiler authorizationcel. Compiler , matchConditions []api.WebhookMatchCondition ) (* authorizationcel.CELMatcher , field.ErrorList ) {
749
+ return compileMatchConditions (compiler , matchConditions , nil , utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthorizationConfiguration ))
753
750
}
754
751
755
- func compileMatchConditions (matchConditions []api.WebhookMatchCondition , fldPath * field.Path , structuredAuthzFeatureEnabled bool ) (* authorizationcel.CELMatcher , field.ErrorList ) {
752
+ func compileMatchConditions (compiler authorizationcel. Compiler , matchConditions []api.WebhookMatchCondition , fldPath * field.Path , structuredAuthzFeatureEnabled bool ) (* authorizationcel.CELMatcher , field.ErrorList ) {
756
753
var allErrs field.ErrorList
757
754
// should fail when match conditions are used without feature enabled
758
755
if len (matchConditions ) > 0 && ! structuredAuthzFeatureEnabled {
@@ -763,8 +760,6 @@ func compileMatchConditions(matchConditions []api.WebhookMatchCondition, fldPath
763
760
return nil , allErrs
764
761
}
765
762
766
- // strictCost is set to true which enables the strict cost for CEL validation.
767
- compiler := authorizationcel .NewCompiler (environment .MustBaseEnvSet (environment .DefaultCompatibilityVersion (), true ))
768
763
seenExpressions := sets .NewString ()
769
764
var compilationResults []authorizationcel.CompilationResult
770
765
var usesFieldSelector , usesLabelSelector bool
0 commit comments