Skip to content

feat(ldap): Slim user synchronization mechanics - #29

Open
josegomezr wants to merge 4 commits into
suse-2025.12from
ldap_jit_auth
Open

josegomezr wants to merge 4 commits into
suse-2025.12from
ldap_jit_auth

Conversation

@josegomezr

Copy link
Copy Markdown

No description provided.

@josegomezr
josegomezr requested a review from a team April 22, 2026 23:22

@tacerus tacerus left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The search generator is a nice idea, but does it bring any functional benefit over using the existing functions? I am wondering as the changes to the core code are quite large ..

Comment thread lifecycle/ak Outdated
Comment thread authentik/sources/ldap/sync/base.py Outdated
@josegomezr

Copy link
Copy Markdown
Author

The search generator is a nice idea, but does it bring any functional benefit over using the existing functions? I am wondering as the changes to the core code are quite large ..

At first removes divergent uses of the ldap library (Base synchronizer implements pagination by hand, but membership paginator uses paged search) so all of them use the same mechanism (generator with paged search).

On the other hand, I'm still need to work on extra methods on the base synchronizer, the ldap task decorates a lot of things outside of the synchronizer that are easily computable there. Like the user_filters based on the provider user distinguished name, or extending the base search scope with the user/group filter, etc.

What I can do for a more easy change management experience is to isolate the changes to another object and add it to the inheritance chain.

There I can overwrite the implementations (and duplicate them potentially) but will make diffs against the upstream file much easier to manage

@josegomezr
josegomezr force-pushed the ldap_jit_auth branch 5 times, most recently from 9b57001 to 64afb41 Compare April 27, 2026 21:21
@josegomezr

Copy link
Copy Markdown
Author

Went back and forth a bit more on the JIT sync tasks.

TL;DR:

  1. JIT won't schedule an LDAP Sync on in the background by default, unless ldap.jit.enable_schedules is set to true. As means to have another toggle to control the long running task.
  • The full sync also has a mutex to avoid concurrent syncs
  1. The tasks now respect the delete_not_found_objects instead of always deleting
  2. Actors have dedicated queue names

@josegomezr
josegomezr force-pushed the ldap_jit_auth branch 3 times, most recently from 778b725 to a3bf541 Compare May 11, 2026 20:57
Comment on lines +26 to +30
from authentik.suse.ldap.tasks import (
ldap_jit_sync_existing_users, # noqa: F401
ldap_trigger_jit_sync, # noqa: F401
ldap_trigger_jit_sync_direct, # noqa: F401
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these for?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A forced side effect so they're available in dramatiq's task discovery mechanism

@tacerus

tacerus commented May 12, 2026

Copy link
Copy Markdown
Member

Not sure if I'm missing something from the last discussion, but I'm still conflicted about the benefit of the large amount of JIT logic, as every user logging in again exponentially increases the amount of users to cover in the full/clenaup sync, leading back to the original issue in the long run.
Did we not say the timestamp based sync would be sufficient as it also covers "new" users as part of the delta?

@josegomezr

Copy link
Copy Markdown
Author

Did we not say the timestamp based sync would be sufficient as it also covers "new" users as part of the delta?

the JIT part is for manual operations (to force sync a single user rather than going for a full directory scan), it's available for us via the terminal but not in use in the server hot paths.

I can remove authentik.suse.tasks.ldap_jit_sync_existing_users if that's required, but ldap_trigger_jit_sync is definitely useful for individual cases.

The Timestamp+delta handling will follow in a bit, I couldn't retro fit it easily yesterday on #35, I'll bring it here.

feat(suse,ldap): Group/User/Membership synchronizer classes expose the `since=` parameter. It accepts a datetime and expands the `search_filter` with `(modifyTimestamp>={since})` to narrow down the LDAP results.

feat(suse,ldap): Group/User/Membership synchronizer exposes a `sync_single_record` exposing the logic of processing a single entry.

feat(suse,ldap): Group/User/Membership synchronizer exposes a `get_iterator` method returning an unconditional generator (even if sync is disabled) respecting the base dn restrictions + since

feat(suse,ldap): Align all ldap search operations to use extended search instead of manual cookie fetching

feat(ldap): Disable sync task schedule on save, avoid spamming the LDAP task on changes to the source.
…riants

Minimize changes in the upstream files by decorating the python class
inheritance chain.
@josegomezr josegomezr changed the title feat(ldap): JIT user synchronization mechanics feat(ldap): Slim user synchronization mechanics May 25, 2026
Slim sync downloads DN pages into the cache, and each page is live
queried in the background.

Optimizes cache storage at the expense of increasing LDAP traffic by
querying single entries many many many times.
@tacerus
tacerus changed the base branch from suse-main to suse-2025.12 June 9, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants