-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validation to ldap secret to catch misconfigurations #3031
Conversation
pkg/controller/utils/auth.go
Outdated
bindPW := secret.Data[render.BindPWSecretField] | ||
if len(bindDN) > 0 && len(bindPW) > 0 { | ||
if _, err := ldap.ParseDN(string(bindDN)); err != nil { | ||
return nil, fmt.Errorf("secret %s/%s: should have be a valid LDAP DN", common.OperatorNamespace(), secretName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wording seems a little off here should have be a
pkg/controller/utils/auth.go
Outdated
// Validate LDAP fields. | ||
bindDN := secret.Data[render.BindDNSecretField] | ||
bindPW := secret.Data[render.BindPWSecretField] | ||
if len(bindDN) > 0 && len(bindPW) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it valid to have one and not the other? If not, should that be validated too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are both part of the requiredFields
variable, which the loop above checks are all present. So at this point we know that if this is an ldap secret, both of these are present.
pkg/controller/utils/auth.go
Outdated
}[s] | ||
})) | ||
if err := json.Unmarshal(data, &map[string]any{}); err != nil { | ||
return nil, fmt.Errorf("secret %s/%s should have properly escaped data for bindDN and bindPW", common.OperatorNamespace(), secretName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, would the error message be better worded stating just that it's not escaped "Fields bindDN and bindPW in secret %s/%s are not properly escaped"?
ev-4161 ci-1331
The secret for LDAP is mounted into the dex pod via ENV and there, Dex is using os.epandenv to insert it into a json config. This means that certain characters need extra escaping. Currently, the user does not see an error in the TigeraStatus when Dex fails to start. This PR adds that validation by performing similar operations.