Fix search group and project auth for subgroups
What does this MR do and why?
Related to #477814 (closed) #480232 (closed)
Fix a bug with project search discovered in https://gitlab.com/gitlab-com/enablement-sub-department/section-enable-request-for-help/-/issues/107 . While working on it, I found the same bug in group search.
This MR changes how traversal_ids
are determined for users for group, group, and project search. The approach moved away from database queries to using a TrieNode for determining permissions in the traversal_ids
hierarchy.
Global search
Authorized groups are sent into a TrieNode first to remove duplicates and reduce the traversal_ids list in the ES query. We've seen for our own IDs on GitLab.com, that we have access to top level group gitlab-org
and also sub groups within gitlab-org
. This optimization was added in a second commit
Group search
traversal_ids
are returned in the following order:
- all namespaces searched are checked and allowed if user is a
- direct member of namespace
- direct member of an ancestor of namespace
- any descendent namespaces that user has access to are also allowed
Project search
- all projects searched have their parent namespaces checked and allowed if user is a
- direct member of the project's parent namespace
- direct member of an ancestor of project's parent namespace
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
N/A
How to set up and validate locally
- enable elasticsearch for gdk
- enable
search_query_authorization_refactor
feature flag - setup a user
- setup a top level private group -
Group A
withProject A
- setup a group the top level -
Group A-B
withProject A-B
- setup a group under the sub group -
Group A-B-C
with projectProject A-B-C
- give user direct access to
Group A-B
(i tested with access through a shared group) - perform a global search for
"gdk.test:3000/group-"
or"localhost:3000/group-"
depending on if you use gdk.test or localhost - verify results only come back from
Project A-B
andProject A-B-C
- perform a group search under
Group A-B
- verify results only come back from
Project A-B
andProject A-B-C
- perform a group search under
Group A-B-C
- verify results only come back from
Project A-B-C
- perform a project search under
Project A-B
- verify results only come back from
Project A-B
- perform a project search under
Project A-B-C
- verify results only come back from
Project A-B-C