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 more configurations for ldap integration #1145

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs_website/docs/configurations/infra_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ for LDAP authentication:
- `LDAP_SEARCH` (**required**) LDAP search base (ex. `ou=people,dc=example,dc=com`)
- `LDAP_FILTER` (optional) LDAP filter condition (ex. `(departmentNumber=01000)`)
- `LDAP_UID_FIELD` (optional) Field that matches the username when searching for the account to bind to (defaults to `uid`)
- `LDAP_EMAIL_FIELD`: (optional) Field that matches the user email (default to `mail`)
- `LDAP_LASTNAME_FIELD`: (optional) Field that matches the user surname (default to `sn`)
- `LDAP_FIRSTNAME_FIELD`: (optional) Field that matches the user given name (default to `givenName`)
- `LDAP_FULLNAME_FIELD`: (optional) Field that matches the user full/common name (default to `cn`)

- Login flow:
1) Initialized connection for the _bind user_.
2) Searching the _login user_ using the _bind user_ in LDAP dictionary based on `LDAP_SEARCH` and `LDAP_FILTER`.
Expand Down
4 changes: 4 additions & 0 deletions querybook/config/querybook_default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ OAUTH_USER_PROFILE: ~
LDAP_CONN: ~
LDAP_USER_DN: uid={},dc=example,dc=com
LDAP_UID_FIELD: uid
LDAP_EMAIL_FIELD: mail
LDAP_LASTNAME_FIELD: sn
LDAP_FIRSTNAME_FIELD: givenName
LDAP_FULLNAME_FIELD: cn

# --------------- Result Store ---------------
RESULT_STORE_TYPE: db
Expand Down
15 changes: 10 additions & 5 deletions querybook/server/app/auth/ldap_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ class LDAPAuthErrors:

@dataclass
class LDAPUserInfo:
LDAP_ATTRS = ["cn", "givenName", "mail", "sn"]
LDAP_ATTRS = [
QuerybookSettings.LDAP_FULLNAME_FIELD, # default: cn
QuerybookSettings.LDAP_FIRSTNAME_FIELD, # default: givenName
QuerybookSettings.LDAP_EMAIL_FIELD, # default: mail
QuerybookSettings.LDAP_LASTNAME_FIELD, # default: sn
]

cn: Optional[str] = None
dn: Optional[str] = None
Expand Down Expand Up @@ -91,11 +96,11 @@ def _parse_user_info(ldap_user_info: Tuple[str, Dict]) -> LDAPUserInfo:
try:
user_info = ldap_user_info[1]
return LDAPUserInfo(
cn=_parse_value(user_info["cn"]),
cn=_parse_value(user_info[QuerybookSettings.LDAP_FULLNAME_FIELD]),
dn=ldap_user_info[0],
email=_parse_value(user_info["mail"]),
first_name=_parse_value(user_info["givenName"]),
last_name=_parse_value(user_info["sn"]),
email=_parse_value(user_info[QuerybookSettings.LDAP_EMAIL_FIELD]),
first_name=_parse_value(user_info[QuerybookSettings.LDAP_FIRSTNAME_FIELD]),
last_name=_parse_value(user_info[QuerybookSettings.LDAP_LASTNAME_FIELD]),
)

except (IndexError, NameError):
Expand Down
4 changes: 4 additions & 0 deletions querybook/server/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class QuerybookSettings(object):
LDAP_SEARCH = get_env_config("LDAP_SEARCH")
LDAP_FILTER = get_env_config("LDAP_FILTER")
LDAP_UID_FIELD = get_env_config("LDAP_UID_FIELD")
LDAP_EMAIL_FIELD = get_env_config("LDAP_EMAIL_FIELD")
LDAP_LASTNAME_FIELD = get_env_config("LDAP_LASTNAME_FIELD")
LDAP_FIRSTNAME_FIELD = get_env_config("LDAP_FIRSTNAME_FIELD")
LDAP_FULLNAME_FIELD = get_env_config("LDAP_FULLNAME_FIELD")
# Configuration validation
if LDAP_CONN is not None:
if LDAP_USE_BIND_USER:
Expand Down