@@ -2,6 +2,7 @@ package validation
2
2
3
3
import (
4
4
"fmt"
5
+ "strings"
5
6
6
7
"gopkg.in/ldap.v2"
7
8
@@ -111,7 +112,8 @@ func ValidateRFC2307Config(config *api.RFC2307Config) ValidationResults {
111
112
validationResults .AddErrors (field .Required (field .NewPath ("groupMembershipAttributes" ), "" ))
112
113
}
113
114
114
- validationResults .Append (ValidateLDAPQuery (config .AllUsersQuery , field .NewPath ("usersQuery" )))
115
+ isUserDNQuery := strings .TrimSpace (strings .ToLower (config .UserUIDAttribute )) == "dn"
116
+ validationResults .Append (validateLDAPQuery (config .AllUsersQuery , field .NewPath ("usersQuery" ), isUserDNQuery ))
115
117
if len (config .UserUIDAttribute ) == 0 {
116
118
validationResults .AddErrors (field .Required (field .NewPath ("userUIDAttribute" ), "" ))
117
119
}
@@ -147,7 +149,8 @@ func ValidateAugmentedActiveDirectoryConfig(config *api.AugmentedActiveDirectory
147
149
validationResults .AddErrors (field .Required (field .NewPath ("groupMembershipAttributes" ), "" ))
148
150
}
149
151
150
- validationResults .Append (ValidateLDAPQuery (config .AllGroupsQuery , field .NewPath ("groupsQuery" )))
152
+ isGroupDNQuery := strings .TrimSpace (strings .ToLower (config .GroupUIDAttribute )) == "dn"
153
+ validationResults .Append (validateLDAPQuery (config .AllGroupsQuery , field .NewPath ("groupsQuery" ), isGroupDNQuery ))
151
154
if len (config .GroupUIDAttribute ) == 0 {
152
155
validationResults .AddErrors (field .Required (field .NewPath ("groupUIDAttribute" ), "" ))
153
156
}
@@ -159,6 +162,9 @@ func ValidateAugmentedActiveDirectoryConfig(config *api.AugmentedActiveDirectory
159
162
}
160
163
161
164
func ValidateLDAPQuery (query api.LDAPQuery , fldPath * field.Path ) ValidationResults {
165
+ return validateLDAPQuery (query , fldPath , false )
166
+ }
167
+ func validateLDAPQuery (query api.LDAPQuery , fldPath * field.Path , isDNOnly bool ) ValidationResults {
162
168
validationResults := ValidationResults {}
163
169
164
170
if _ , err := ldap .ParseDN (query .BaseDN ); err != nil {
@@ -185,6 +191,13 @@ func ValidateLDAPQuery(query api.LDAPQuery, fldPath *field.Path) ValidationResul
185
191
"timeout must be equal to or greater than zero" ))
186
192
}
187
193
194
+ if isDNOnly {
195
+ if len (query .Filter ) != 0 {
196
+ validationResults .AddErrors (field .Invalid (fldPath .Child ("filter" ), query .Filter , `cannot specify a filter when using "dn" as the UID attribute` ))
197
+ }
198
+ return validationResults
199
+ }
200
+
188
201
if _ , err := ldap .CompileFilter (query .Filter ); err != nil {
189
202
validationResults .AddErrors (field .Invalid (fldPath .Child ("filter" ), query .Filter ,
190
203
fmt .Sprintf ("invalid query filter: %v" , err )))
0 commit comments