Loading
Resolve a user's project access level from memberships
What does this MR do and why?
- This is an experiment behind the
resolve_project_access_from_membershipsfeature flag (per user, default off). It only changes direct access checks, where we check one user's access to a specific project. Searches and lists that decide which projects a user can see still useproject_authorizations. - Behind the flag, a user's access level on a single project is read from memberships when it isn't already cached for the request. This is the lookup behind policies and about 18 direct callers (protected branches, container registry, CI job access).
- It shares the request cache with the bulk lookup for many users, so levels preloaded for many users are still reused with no extra queries. For those, the value still comes from
project_authorizationsuntil the team lookup is switched later. - Direct calls are now also included in the
authz_*timings. - Clearing a user's cached level after a membership change also clears their cached memberships, so changes show up right away.
- Behind the flag, some specs need a few more queries. Those specs only use default roles, which
project_authorizationsstores directly, so the old count left out the extra queries a custom role needs. The new lookup gets default and custom roles from the same queries.
References
- Work item: https://gitlab.com/gitlab-org/gitlab/-/work_items/632453
- Builds on: !263758 (merged)
Screenshots or screen recordings
Not applicable, no UI changes.
How to set up and validate locally
- Enable the flag for a user:
Feature.enable(:resolve_project_access_from_memberships, user). - Add the user to a group that owns a project, then delete their
project_authorizationsrows. - In a console, run
project.team.max_member_access(user.id). It should return the new level. With the flag off it returns no access. - Visit a project page as that user and look for
authz_project_access_sourceinlog/development_json.log.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.
Edited by Ian Anderson