Repository navigation
Conversation
…ted inefficiencies
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #22009 +/- ##
==========================================
- Coverage 93.22% 93.20% -0.03%
==========================================
Files 1024 1024
Lines 59153 59265 +112
Branches 331 331
==========================================
+ Hits 55148 55236 +88
- Misses 4005 4029 +24
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
BeryJu
left a comment
There was a problem hiding this comment.
@ryanpesek I like the general idea of this and the optimisation for checking policybindings on multiple objects, however I'd much prefer that optimisation to be more re-usable for other things such as listing applications or RAC endpoints. Now rewriting this optimisation to be usable for that will take a bit longer so I'll keep this open and up-to-date as a temporary bug fix
Details
PR #13947 introduced this filter in
SCIMProvider.get_object_qs(User):This iterates every user in the database and instantiates PolicyEngine once per user. get_object_qs(User) is called once per page-sync task (one per sync_page_size users), once per signal-driven sync, and once during _sync_cleanup. With N users and N/page_size pages, that's O(N²/page_size) PolicyEngine evaluations per full sync per provider; each evaluation runs a recursive group-membership CTE plus the static-binding aggregation. On a instance with thousands of users and multiple SCIM providers, this produced:
The fix:
Replace the Python loop with a SQL-level translation of PolicyEngine.compute_static_bindings:
hierarchy, matching PolicyEngine's user.all_groups(). Negated bindings become ~Q(...). The application's policy_engine_mode is honored. Zero PolicyEngine instantiations.
PolicyEngine. For MODE_ALL, pre-filter candidates via the static-binding SQL filter first (a static-failing user can never pass MODE_ALL overall). For MODE_ANY, still iterate every user since a static-failing user might pass via policy.
Checklist
ak test authentik/)make lint-fix)If an API change has been made
make gen)If changes to the frontend have been made
make web)If applicable
make docs)