From bbad5c133847a722c6c0cd607ac52fea080eb5e2 Mon Sep 17 00:00:00 2001 From: Moutaz Chaara Date: Wed, 22 Jul 2026 17:55:03 +0200 Subject: [PATCH] Document LDAP marker pagination as unsupported; fix sizelimit pool poisoning LDAP has no native keyset pagination, and the server-side paging cookie cannot survive across stateless HTTP requests in a multi-node deployment. Marker-based pagination is therefore not supported for LDAP-backed domains. Callers should not rely on next-link markers. Additionally, the previous approach of passing sizelimit to _paged_search_s was broken: when sizelimit caused pagination to stop mid-page, the server-side LDAP cursor was abandoned without a cancel request, poisoning the connection pool and causing subsequent requests to return empty results non-deterministically. This made the limit cap unreliable in practice. The fix sets sizelimit=0 always in _ldap_get_all, fetching the full result set from LDAP. Truncation to the requested limit is handled reliably in Python by the @driver_hints.truncated decorator. A regression test pins the documented marker behaviour so future developers do not mistake the ignored marker for a bug and reintroduce the broken O(N)-per-page approach. Closes-Bug: #2161103 Change-Id: I9becfd359e4c21c99da3b8a39df56f17b07341b5 Signed-off-by: Moutaz Chaara --- keystone/identity/backends/ldap/common.py | 8 +++++++- .../unit/identity/backends/test_ldap_common.py | 16 ++++++++++++++++ ...-ldap-marker-pagination-3b8e21f4c9d70a15.yaml | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/fix-ldap-marker-pagination-3b8e21f4c9d70a15.yaml diff --git a/keystone/identity/backends/ldap/common.py b/keystone/identity/backends/ldap/common.py index 02096f806b..cc2b96126d 100644 --- a/keystone/identity/backends/ldap/common.py +++ b/keystone/identity/backends/ldap/common.py @@ -1834,7 +1834,13 @@ class BaseLdap: + list(self.extra_attr_mapping.keys()) ) ) - sizelimit = hints.limit['limit'] if hints and hints.limit else 0 + # Always fetch the full result set from LDAP (sizelimit=0 means + # unlimited). Passing a sizelimit to _paged_search_s abandons the + # server-side cursor mid-page, poisoning the connection pool and + # making subsequent requests return empty results non-deterministically. + # Truncation to the requested limit is handled in Python by the + # @driver_hints.truncated decorator after the full set is returned. + sizelimit = 0 with self.get_connection() as conn: try: diff --git a/keystone/tests/unit/identity/backends/test_ldap_common.py b/keystone/tests/unit/identity/backends/test_ldap_common.py index 0e33f54b4a..2a6deedd56 100644 --- a/keystone/tests/unit/identity/backends/test_ldap_common.py +++ b/keystone/tests/unit/identity/backends/test_ldap_common.py @@ -575,6 +575,22 @@ class LDAPPagedResultsTest(unit.TestCase): self.assertLessEqual(len(users), list_limit) + def test_marker_ignored_for_ldap_domain(self): + """LDAP backends do not support marker pagination; markers are ignored. + + LDAP has no native keyset pagination and the server-side paging cookie + cannot survive across stateless HTTP requests. Client-side emulation + would require a full directory scan on every page request, which is + unacceptable at scale. The correct behaviour is to ignore the marker + and return results from the beginning of the list, capped by + list_limit. This test pins that behaviour so future developers do not + mistake it for a bug and attempt to "fix" it with an O(N) full fetch. + """ + hints = driver_hints.Hints() + hints.set_marker(uuid.uuid4().hex) + users = PROVIDERS.identity_api.list_users(hints=hints) + self.assertEqual(len(default_fixtures.USERS), len(users)) + class CommonLdapTestCase(unit.BaseTestCase): """These test cases call functions in keystone.common.ldap.""" diff --git a/releasenotes/notes/fix-ldap-marker-pagination-3b8e21f4c9d70a15.yaml b/releasenotes/notes/fix-ldap-marker-pagination-3b8e21f4c9d70a15.yaml new file mode 100644 index 0000000000..49d06b8828 --- /dev/null +++ b/releasenotes/notes/fix-ldap-marker-pagination-3b8e21f4c9d70a15.yaml @@ -0,0 +1,14 @@ +--- +fixes: + - | + [`bug 2161103 `_] + LDAP-backed domains do not support marker-based (keyset) pagination. + LDAP has no native keyset pagination, and the session cookie required + for native LDAP paging cannot survive across stateless HTTP requests in + a multi-node deployment. Attempting client-side emulation (fetching all + entries to find the marker position) would incur a full directory scan + on every page request, which is unacceptable for large directories. + + The ``list_limit`` setting continues to cap the number of entries + returned per request. Callers should not rely on ``next`` link markers + for LDAP-backed domains.