Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

rene-dekker
Copy link
Member

@rene-dekker rene-dekker commented Dec 2, 2023

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.

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)
Copy link
Contributor

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

// Validate LDAP fields.
bindDN := secret.Data[render.BindDNSecretField]
bindPW := secret.Data[render.BindPWSecretField]
if len(bindDN) > 0 && len(bindPW) > 0 {
Copy link
Contributor

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?

Copy link
Member Author

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.

}[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)
Copy link
Contributor

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"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants