Skip to content

Commit 41b11cd

Browse files
authored
fix(gitlab): scale group discovery and permission-aware search (#10138)
* fix(gitlab): scale group discovery and permission-aware search * fix(gitlab): validate combined permission uploads before saving * fix(gitlab): clarify byte limits and use browser file fixtures
1 parent 7e7a0c8 commit 41b11cd

27 files changed

Lines changed: 893 additions & 189 deletions

‎apps/docs/content/docs/search/gitlab.mdx‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,17 @@ Sim checks returned content against these restrictions independently of the quer
4545

4646
## Add a group
4747

48-
Choose **Group** in the source's **Scope** field and enter the numeric group ID or full group path. Enable **Include subgroups** only if descendant projects should be included. Sim supports groups with at most 1,000 projects visible to the source token; larger groups need narrower sources. Projects shared from outside the group are excluded.
48+
Choose **Group** in the source's **Scope** field and enter the numeric group ID or full group path. Enable **Include subgroups** only if descendant projects should be included. Sim supports up to **50,000 projects** visible to the source token, subject to the CSV limits below and a 16 MiB limit for saved project IDs and paths. Projects shared from outside the group are excluded.
49+
50+
Discovery reads 100 projects per page and must finish within five minutes. GitLab's configured offset and rate limits still apply; choose narrower groups if the instance cannot return the complete listing within these limits. Sim also handles listings without total-count headers, which GitLab can omit above 10,000 results.
4951

5052
The same permission strategies apply. Group membership alone never grants access to every project: administrator mode checks each project's current permissions, and non-admin mode requires a CSV grant for each project and reader. The source token must be able to read every project you want to search.
5153

5254
In CSV mode, each successful upload rediscovers the group's projects and replaces all grants atomically. Newly discovered projects become searchable only for users explicitly listed in the uploaded CSV. Updating and saving source settings also refreshes discovery. A failed discovery or stale revision preserves the previous configuration and grants. If a group configured by path is renamed, save the new path and an updated project-permissions CSV together in source settings. Numeric group IDs remain valid across renames.
5355

54-
Search visits project pages within a bounded request budget. Continuation cursors cover remaining projects and results; targeting a project narrows the request. Renamed or moved projects are blocked until a successful refresh; projects outside the configured group remain excluded. Group setup uses the existing project search APIs, so it does not require group-wide advanced search.
56+
In CSV mode, search uses GitLab's group search API and checks each result against the saved projects and reader grants. Group code search requires Advanced Search or Exact Code Search; group wiki search requires Advanced Search. Unsupported scopes fall back to project search. A configured branch/tag, date filters, or administrator-token mode also use project search where needed. Each request visits a bounded number of pages; continuation cursors cover the remainder. Targeting a project narrows the request.
57+
58+
Group search stops at 10,000 candidates per content type to respect GitLab's Advanced Search window. Sim marks this as partial and asks you to narrow the query or target a project. This candidate limit applies before permission filtering. Renamed or moved projects are blocked until a successful refresh; projects outside the configured group remain excluded. See GitLab's [search capabilities and pagination limits](https://docs.gitlab.com/api/search/).
5559

5660
To expand an existing deployment, create a **separate group source** after the application deployment finishes. Keep the working project source and its CI variables unchanged while validating the group. Give the group job its new `SIM_SOURCE_ID`, then pause the old source after confirming the wider setup. Regular knowledge-base ingestion remains project-scoped.
5761

@@ -78,7 +82,7 @@ engineering/platform,456
7882
Use the full namespace path even if **Project** contains a numeric ID. Include inherited members explicitly. A grant without an email mapping grants nothing; rows for other projects cannot expand this source.
7983

8084
- Each file has exactly two columns in the shown order and at least one data row. Template headers or headerless data are accepted.
81-
- Use UTF-8 CSV, at most 4 MiB and 100,000 data rows per file. The full request must fit 10 MiB.
85+
- Use UTF-8 CSV, at most **8 MiB and 500,000 data rows per file**. The complete JSON upload, including escaped CSV content, must fit **10 MiB**. These are independent limits; split large deployments into narrower sources when either is reached.
8286
- Identical rows are deduplicated. Conflicting user-ID/email mappings and malformed rows are rejected.
8387

8488
In this example, Alice can search `engineering/platform` because the files link GitLab user `123` to both that project and `alice@example.com`. Sim checks that Alice is a current organization member and that her verified Sim email uniquely matches the grant. It checks again when she opens a result. GitLab receives the request under the source's read-only service account; Alice does not sign in to GitLab or authorize Sim individually.
@@ -120,6 +124,8 @@ The export includes active, unlocked human members with Reporter access or highe
120124

121125
Requests run serially, paced at 60 per minute by default. Set `--requests-per-minute` to change this export-job ceiling; it does not configure live Search traffic. Each run reads each project's identity and membership pages, plus one profile request per distinct candidate reader. Group exports also read the group identity and project listing. The request ceiling applies across the entire export. API errors, hidden emails, identity conflicts, inconsistent pagination totals (when GitLab provides them), and oversized exports stop the job without publishing either file. Run exports after bulk membership updates finish; paginated API reads are not a point-in-time snapshot.
122126

127+
Large exports can take hours. For example, 50,000 projects require at least 100,000 project and membership requests, before listing and profile requests: over 27 hours at the default ceiling. Set the CI job timeout and schedule accordingly, or use smaller groups. Agree any higher request rate with your GitLab administrator. CSV files are written incrementally and published only when the complete export succeeds.
128+
123129
## Access checks
124130

125131
The source token retrieves content. Administrator mode proves the reader's current GitLab identity from verified Sim email, then checks project/group membership and policy during the request. Unsupported restrictions fail closed.
@@ -169,6 +175,10 @@ sync_gitlab_permissions:
169175
'{expectedRevision: $rev, permissions: {provider: "gitlab",
170176
userMapping: {filename: "users.csv", content: $users},
171177
projectPermissions: {filename: "project-permissions.csv", content: $grants}}}' > "$export_root/update.json"
178+
if [ "$(wc -c < "$export_root/update.json")" -gt 10485760 ]; then
179+
echo "Permission upload exceeds 10 MiB; use a narrower source." >&2
180+
exit 1
181+
fi
172182
curl --fail --silent --show-error --request PUT -H "$auth" \
173183
-H 'Content-Type: application/json' --data-binary "@$export_root/update.json" "$url"
174184
```

‎apps/docs/openapi-v2-resources.json‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10233,7 +10233,7 @@
1023310233
"put": {
1023410234
"operationId": "replaceSearchSourcePermissions",
1023510235
"summary": "Replace Search source permissions",
10236-
"description": "Replace the complete permission grants for one Search source. Requires organization Admin access. Supply the current revision and the grants for the configured provider. A stale revision returns 409. GitLab CSV mode accepts both files together, up to 4 MiB and 100,000 data rows each. Workspace API keys return `403`; use a personal API key or scoped OAuth token.\n\nOAuth scope: `api:write`.",
10236+
"description": "Replace the complete permission grants for one Search source. Requires organization Admin access. Supply the current revision and the grants for the configured provider. A stale revision returns 409. GitLab CSV mode accepts both files together, up to 8 MiB and 500,000 data rows each, within a 10 MiB limit for the complete JSON-encoded request. Workspace API keys return `403`; use a personal API key or scoped OAuth token.\n\nOAuth scope: `api:write`.",
1023710237
"x-sim-operation": "knowledge.search.source_permissions.replace",
1023810238
"x-oauth-scope": "api:write",
1023910239
"tags": ["Organizations"],
@@ -24566,8 +24566,7 @@
2456624566
"content": {
2456724567
"type": "string",
2456824568
"minLength": 1,
24569-
"maxLength": 4194304,
24570-
"description": "UTF-8 CSV contents, up to 4 MiB. Both files travel in one request body limited to 10 MiB after JSON encoding."
24569+
"description": "UTF-8 CSV contents, up to 8 MiB. Both files travel in one request body limited to 10 MiB after JSON encoding."
2457124570
}
2457224571
},
2457324572
"required": ["filename", "content"],
@@ -24586,8 +24585,7 @@
2458624585
"content": {
2458724586
"type": "string",
2458824587
"minLength": 1,
24589-
"maxLength": 4194304,
24590-
"description": "UTF-8 CSV contents, up to 4 MiB. Both files travel in one request body limited to 10 MiB after JSON encoding."
24588+
"description": "UTF-8 CSV contents, up to 8 MiB. Both files travel in one request body limited to 10 MiB after JSON encoding."
2459124589
}
2459224590
},
2459324591
"required": ["filename", "content"],

0 commit comments

Comments
 (0)