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

Added support for anonymous LDAP server authentication #2170

Closed
Closed
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
12 changes: 10 additions & 2 deletions redash/authentication/ldap_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from flask_login import current_user, login_required, login_user, logout_user

try:
from ldap3 import Server, Connection, SIMPLE
from ldap3 import Server, Connection, SIMPLE, ANONYMOUS
except ImportError:
if settings.LDAP_LOGIN_ENABLED:
logger.error("The ldap3 library was not found. This is required to use LDAP authentication (see requirements.txt).")
Expand Down Expand Up @@ -51,7 +51,15 @@ def login(org_slug=None):

def auth_ldap_user(username, password):
server = Server(settings.LDAP_HOST_URL)
conn = Connection(server, settings.LDAP_BIND_DN, password=settings.LDAP_BIND_DN_PASSWORD, authentication=SIMPLE, auto_bind=True)

if settings.LDAP_HOST_AUTH == SIMPLE:
conn = Connection(server, settings.LDAP_BIND_DN, password=settings.LDAP_BIND_DN_PASSWORD,
authentication=SIMPLE, auto_bind=True)
elif settings.LDAP_HOST_AUTH == ANONYMOUS:
conn = Connection(server, authentication=ANONYMOUS, auto_bind=True)
else:
logger.error("The ldap3 authentication type " + settings.LDAP_HOST_AUTH + " is not valid.")
return None

conn.search(settings.LDAP_SEARCH_DN, settings.LDAP_SEARCH_TEMPLATE % {"username": username}, attributes=[settings.LDAP_DISPLAY_NAME_KEY, settings.LDAP_EMAIL_KEY])

Expand Down
2 changes: 2 additions & 0 deletions redash/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ def all_settings():
LDAP_LOGIN_ENABLED = parse_boolean(os.environ.get('REDASH_LDAP_LOGIN_ENABLED', 'false'))
# The LDAP directory address (ex. ldap://10.0.10.1:389)
LDAP_HOST_URL = os.environ.get('REDASH_LDAP_URL', None)
# The LDAP authentication type (ex. SIMPLE, ANONYMOUS)
LDAP_HOST_AUTH = os.environ.get('REDASH_LDAP_AUTH', 'SIMPLE')
# The DN & password used to connect to LDAP to determine the identity of the user being authenticated. For AD this should be "org\\user".
LDAP_BIND_DN = os.environ.get('REDASH_LDAP_BIND_DN', None)
LDAP_BIND_DN_PASSWORD = os.environ.get('REDASH_LDAP_BIND_DN_PASSWORD', '')
Expand Down
4 changes: 2 additions & 2 deletions redash/templates/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

{% if show_ldap_login %}
<div class="row">
<a href="/ldap_auth/login">LDAP/SSO Login</a>
<a href="/ldap/login">LDAP/SSO Login</a>
</div>

<div class="login-or">
Expand Down Expand Up @@ -71,7 +71,7 @@
Log In
</button>
</form>

{% if not hide_forgot_password %}
<hr>
<a href="{{ url_for("redash.forgot_password", org_slug=org_slug) }}">I forgot my password</a>
Expand Down