Repository navigation
Improve LDAP integration - #132
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #132 +/- ##
==========================================
+ Coverage 82.44% 82.87% +0.42%
==========================================
Files 15 15
Lines 1413 1448 +35
==========================================
+ Hits 1165 1200 +35
Misses 248 248
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Set OPT_NETWORK_TIMEOUT, OPT_TIMEOUT and OPT_TIMELIMIT on the LDAP client so that a slow or unresponsive LDAP server does not block requests indefinitely. OPT_NETWORK_TIMEOUT bounds the TCP connect, OPT_TIMEOUT bounds the overall wait of synchronous calls (bind, search), and OPT_TIMELIMIT asks the server to cap its own search time. The timeout is controlled by the new AUTH_LDAP_TIMEOUT config option (default: 10 seconds).
Split AUTH_LDAP_SERVER on whitespace into individual URIs and iterate them explicitly in Python rather than passing the full string to ldap.initialize() and relying on the OpenLDAP C library's opaque internal failover logic. The new _query_single_ldap_server() helper handles one full connect/configure/bind/search/unbind cycle against a single URI and raises ldap.LDAPError on failure. query_ldap_groups() iterates over all URIs in order, returning from the first that succeeds, logging per-server errors, and returning [] after all servers are exhausted. Also: - Escape uid with ldap.filter.escape_filter_chars() before interpolating into filter strings to prevent LDAP injection. - Improve _ldap_error_description() to include both the 'desc' and 'info' fields from LDAPError (previously 'info' was silently dropped, hiding e.g. 'Connection timed out' from logs). Tests added for failover, all-servers-fail, error description format, and uid escaping.
ldap.TIMEOUT (and potentially other C-library-raised exceptions) is raised with no arguments, making str(error) return an empty string. This caused the log line to show 'Error: ' with nothing after it, giving no indication of what went wrong. Add a final fallback of type(error).__name__ so the log always contains at least the exception class name (e.g. 'TIMEOUT') instead of silence. Add two direct unit tests for _ldap_error_description: one for plain LDAPError() with no args and one for the concrete ldap.TIMEOUT subclass.
|
Bind-credential failures are retried against every server — cts/auth.py:266 Suggested fix: |
Errors that indicate a misconfiguration or a logical problem (wrong credentials, bad base DN, unsupported auth method, etc.) will reproduce identically on every replica, so retrying further servers only delays the failure. Introduce _LDAP_NON_RETRYABLE_ERRORS and catch it before the generic LDAPError handler to return early in those cases. Transient errors (SERVER_DOWN, TIMEOUT, BUSY, ...) continue to trigger failover to the next configured server as before.
|
LGTM |
…LDAP errors Both errors indicate conditions that will reproduce identically on every replica, so retrying a different server would not help. - AUTH_UNKNOWN (86): client does not recognise the authentication method, a client-side configuration issue. - CONFIDENTIALITY_REQUIRED (13): server requires a TLS-protected session; all replicas share the same policy.
Set OPT_NETWORK_TIMEOUT and OPT_TIMELIMIT on the LDAP client so that a slow or unresponsive LDAP server does not block requests indefinitely.
The timeout is controlled by the new AUTH_LDAP_TIMEOUT config option (default: 10 seconds).
The code already supports multiple configured servers. The second commit changes it so that iterating over the servers is done in the application itself, as that seems to be more reliable than letting python-ldap handle it.