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 user_format_string to allow use with AD #3067

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

TomGoedeme
Copy link

Description

We encountered issues with LDAP login integration using our Active Directory (AD) when binding with the user_attr format. This update introduces a new user_format property in the LDAP configuration. This property accepts a Python format string, which defaults to the previous configuration but allows for custom user string formats.

config example:

  ldap:
    dn: OU=BASE,DC=foo,DC=local
    group_attr: memberOf
    red_group: "CN=Some Security Group Name,OU=Security Groups,OU=BASE,DC=foo,DC=local"
    server: ldaps://dc-prod04.foo.local:636
    user_attr: userPrincipalName
    user_format: "{user}"

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Current testing is broken on Caldera(see #3013). But this is being used in production.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Comment on lines 60 to +62
user_string = '%s=%s,%s' % (user_attr, username, dn)
user_format_string = self._ldap_config.get("user_format") or "{user_attr}={user},{dn}"
user_string = user_format_string.format(user_attr=user_attr, user=username, dn=dn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
user_string = '%s=%s,%s' % (user_attr, username, dn)
user_format_string = self._ldap_config.get("user_format") or "{user_attr}={user},{dn}"
user_string = user_format_string.format(user_attr=user_attr, user=username, dn=dn)
user_format_string = self._ldap_config.get("user_format") or "{user_attr}={user},{dn}"
try:
user_string = user_format_string.format(user_attr=user_attr, user=username, dn=dn)
except KeyError:
user_string = '%s=%s,%s' % (user_attr, username, dn)

In case users provide a user_format value in their LDAP config that doesn't contain the required parameters, we should default to the previous format.

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.

3 participants