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

authlib: Avoid following LDAP referrals #1408

Merged
merged 1 commit into from
Dec 9, 2024
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
4 changes: 2 additions & 2 deletions nipap/nipap.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ db_path = /etc/nipap/local_auth.db ; path to SQLite database used
#
#basedn = ou=Users,dc=example,dc=com ; base DN
#uri = ldaps://ldap.example.com ; LDAP server URI
#tls = False ; initiate TLS, use ldap://
#tls = false ; initiate TLS, use ldap://
#
# LDAP style
#binddn_fmt = uid={},ou=Users,dc=example,dc=com
Expand Down Expand Up @@ -209,4 +209,4 @@ secret_key = {{WWW_SECRET_KEY}}
# Specify OTLP HTTP endpoint. Used to send traces to OpenTelemetry Collector but also used when proxying traces to OpenTelemetry-Collector from nipap-cli
# otlp_http_endpoint=http://opentelemetry-collector:4318/v1/traces
# Set sampler. Valid values are always_on, always_off, parentbased_always_on, parentbased_always_off, traceidratio and parentbased_traceidratio. Default is parentbased_always_on.
# otel_traces_sampler = always_on
# otel_traces_sampler = always_on
7 changes: 6 additions & 1 deletion nipap/nipap/authlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ def __init__(self, name, username, password, authoritative_source, auth_options=
self._logger.error('Unable to load Python ldap module, please verify it is installed')
raise AuthError('Unable to authenticate')

# Avoid following referrals for now, as NIPAP doesn't support
# initializing a separate connection for them anyway.
ldap.set_option(ldap.OPT_REFERRALS, ldap.OPT_OFF)

self._logger.debug('LDAP URI: ' + self._ldap_uri)
self._ldap_conn = ldap.initialize(self._ldap_uri)

Expand Down Expand Up @@ -578,7 +582,8 @@ def authenticate(self):
self.readonly = True

except ldap.LDAPError as exc:
raise AuthError(exc)
self._logger.error("Got LDAP error: %s", exc)
raise AuthError("LDAP server returned an error")
except KeyError:
raise AuthError('LDAP attribute missing')
except IndexError:
Expand Down
Loading