@@ -41,7 +41,7 @@ import (
41
41
)
42
42
43
43
// ValidateAuthenticationConfiguration validates a given AuthenticationConfiguration.
44
- func ValidateAuthenticationConfiguration (c * api.AuthenticationConfiguration ) field.ErrorList {
44
+ func ValidateAuthenticationConfiguration (c * api.AuthenticationConfiguration , disallowedIssuers [] string ) field.ErrorList {
45
45
root := field .NewPath ("jwt" )
46
46
var allErrs field.ErrorList
47
47
@@ -69,7 +69,7 @@ func ValidateAuthenticationConfiguration(c *api.AuthenticationConfiguration) fie
69
69
// check and add validation for duplicate issuers.
70
70
for i , a := range c .JWT {
71
71
fldPath := root .Index (i )
72
- _ , errs := validateJWTAuthenticator (a , fldPath , utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthenticationConfiguration ))
72
+ _ , errs := validateJWTAuthenticator (a , fldPath , sets . New ( disallowedIssuers ... ), utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthenticationConfiguration ))
73
73
allErrs = append (allErrs , errs ... )
74
74
}
75
75
@@ -79,41 +79,41 @@ func ValidateAuthenticationConfiguration(c *api.AuthenticationConfiguration) fie
79
79
// CompileAndValidateJWTAuthenticator validates a given JWTAuthenticator and returns a CELMapper with the compiled
80
80
// CEL expressions for claim mappings and validation rules.
81
81
// This is exported for use in oidc package.
82
- func CompileAndValidateJWTAuthenticator (authenticator api.JWTAuthenticator ) (authenticationcel.CELMapper , field.ErrorList ) {
83
- return validateJWTAuthenticator (authenticator , nil , utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthenticationConfiguration ))
82
+ func CompileAndValidateJWTAuthenticator (authenticator api.JWTAuthenticator , disallowedIssuers [] string ) (authenticationcel.CELMapper , field.ErrorList ) {
83
+ return validateJWTAuthenticator (authenticator , nil , sets . New ( disallowedIssuers ... ), utilfeature .DefaultFeatureGate .Enabled (features .StructuredAuthenticationConfiguration ))
84
84
}
85
85
86
- func validateJWTAuthenticator (authenticator api.JWTAuthenticator , fldPath * field.Path , structuredAuthnFeatureEnabled bool ) (authenticationcel.CELMapper , field.ErrorList ) {
86
+ func validateJWTAuthenticator (authenticator api.JWTAuthenticator , fldPath * field.Path , disallowedIssuers sets. Set [ string ], structuredAuthnFeatureEnabled bool ) (authenticationcel.CELMapper , field.ErrorList ) {
87
87
var allErrs field.ErrorList
88
88
89
89
compiler := authenticationcel .NewCompiler (environment .MustBaseEnvSet (environment .DefaultCompatibilityVersion ()))
90
90
mapper := & authenticationcel.CELMapper {}
91
91
92
- allErrs = append (allErrs , validateIssuer (authenticator .Issuer , fldPath .Child ("issuer" ))... )
92
+ allErrs = append (allErrs , validateIssuer (authenticator .Issuer , disallowedIssuers , fldPath .Child ("issuer" ))... )
93
93
allErrs = append (allErrs , validateClaimValidationRules (compiler , mapper , authenticator .ClaimValidationRules , fldPath .Child ("claimValidationRules" ), structuredAuthnFeatureEnabled )... )
94
94
allErrs = append (allErrs , validateClaimMappings (compiler , mapper , authenticator .ClaimMappings , fldPath .Child ("claimMappings" ), structuredAuthnFeatureEnabled )... )
95
95
allErrs = append (allErrs , validateUserValidationRules (compiler , mapper , authenticator .UserValidationRules , fldPath .Child ("userValidationRules" ), structuredAuthnFeatureEnabled )... )
96
96
97
97
return * mapper , allErrs
98
98
}
99
99
100
- func validateIssuer (issuer api.Issuer , fldPath * field.Path ) field.ErrorList {
100
+ func validateIssuer (issuer api.Issuer , disallowedIssuers sets. Set [ string ], fldPath * field.Path ) field.ErrorList {
101
101
var allErrs field.ErrorList
102
102
103
- allErrs = append (allErrs , validateIssuerURL (issuer .URL , fldPath .Child ("url" ))... )
103
+ allErrs = append (allErrs , validateIssuerURL (issuer .URL , disallowedIssuers , fldPath .Child ("url" ))... )
104
104
allErrs = append (allErrs , validateIssuerDiscoveryURL (issuer .URL , issuer .DiscoveryURL , fldPath .Child ("discoveryURL" ))... )
105
105
allErrs = append (allErrs , validateAudiences (issuer .Audiences , issuer .AudienceMatchPolicy , fldPath .Child ("audiences" ), fldPath .Child ("audienceMatchPolicy" ))... )
106
106
allErrs = append (allErrs , validateCertificateAuthority (issuer .CertificateAuthority , fldPath .Child ("certificateAuthority" ))... )
107
107
108
108
return allErrs
109
109
}
110
110
111
- func validateIssuerURL (issuerURL string , fldPath * field.Path ) field.ErrorList {
111
+ func validateIssuerURL (issuerURL string , disallowedIssuers sets. Set [ string ], fldPath * field.Path ) field.ErrorList {
112
112
if len (issuerURL ) == 0 {
113
113
return field.ErrorList {field .Required (fldPath , "URL is required" )}
114
114
}
115
115
116
- return validateURL (issuerURL , fldPath )
116
+ return validateURL (issuerURL , disallowedIssuers , fldPath )
117
117
}
118
118
119
119
func validateIssuerDiscoveryURL (issuerURL , issuerDiscoveryURL string , fldPath * field.Path ) field.ErrorList {
@@ -127,13 +127,18 @@ func validateIssuerDiscoveryURL(issuerURL, issuerDiscoveryURL string, fldPath *f
127
127
allErrs = append (allErrs , field .Invalid (fldPath , issuerDiscoveryURL , "discoveryURL must be different from URL" ))
128
128
}
129
129
130
- allErrs = append (allErrs , validateURL (issuerDiscoveryURL , fldPath )... )
130
+ // issuerDiscoveryURL is not an issuer URL and does not need to validated against any set of disallowed issuers
131
+ allErrs = append (allErrs , validateURL (issuerDiscoveryURL , nil , fldPath )... )
131
132
return allErrs
132
133
}
133
134
134
- func validateURL (issuerURL string , fldPath * field.Path ) field.ErrorList {
135
+ func validateURL (issuerURL string , disallowedIssuers sets. Set [ string ], fldPath * field.Path ) field.ErrorList {
135
136
var allErrs field.ErrorList
136
137
138
+ if disallowedIssuers .Has (issuerURL ) {
139
+ allErrs = append (allErrs , field .Invalid (fldPath , issuerURL , fmt .Sprintf ("URL must not overlap with disallowed issuers: %s" , sets .List (disallowedIssuers ))))
140
+ }
141
+
137
142
u , err := url .Parse (issuerURL )
138
143
if err != nil {
139
144
allErrs = append (allErrs , field .Invalid (fldPath , issuerURL , err .Error ()))
0 commit comments