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_memberships feature 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 use project_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_authorizations until 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_authorizations stores 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

Screenshots or screen recordings

Not applicable, no UI changes.

How to set up and validate locally

  1. Enable the flag for a user: Feature.enable(:resolve_project_access_from_memberships, user).
  2. Add the user to a group that owns a project, then delete their project_authorizations rows.
  3. 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.
  4. Visit a project page as that user and look for authz_project_access_source in log/development_json.log.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Edited by Ian Anderson

Merge request reports

Loading
Loading