Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/docs/content/docs/search/gitlab.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ Sim checks returned content against these restrictions independently of the quer

## Add a group

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 discovers up to 1,000 projects visible to the source token. Projects shared from outside the group are excluded.
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.

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.

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.
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.

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.

Expand Down
7 changes: 6 additions & 1 deletion apps/sim/connectors/gitlab/permission-config/capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { OutboundRoutingError } from '@/lib/core/network/routing'
import { OrchestrationError } from '@/lib/core/orchestration/types'
import type { ConnectorPermissionConfigCapability } from '@/lib/knowledge/connectors/permission-config'
import { writeConnectorPermissions } from '@/lib/knowledge/connectors/permission-store'
import { gitLabGroupMatchesConfig } from '@/connectors/gitlab/group'
import { prepareGitLabPermissionChange } from '@/connectors/gitlab/permission-config/prepare'
import {
gitLabPermissionData,
Expand Down Expand Up @@ -47,7 +48,11 @@ export const gitLabPermissionConfig: ConnectorPermissionConfigCapability = {
)
}
)
if (discovered.host !== stored.host || discovered.group.id !== stored.group.id)
if (
discovered.host !== stored.host ||
discovered.group.id !== stored.group.id ||
!gitLabGroupMatchesConfig(discovered, source.sourceConfig)
)
throw new OrchestrationError(
'validation',
'The GitLab group identity changed. Update the connection before replacing permissions.'
Expand Down
78 changes: 69 additions & 9 deletions apps/sim/lib/knowledge/__integration__/gitlab-group.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ import {
readSearchSourcePermissions,
replaceSearchSourcePermissions,
} from '@/lib/knowledge/application/source-permissions'
import { readConnectorPermissionGrants } from '@/lib/knowledge/connectors/permission-store'
import {
loadConnectorPermissionSnapshot,
readConnectorPermissionGrants,
} from '@/lib/knowledge/connectors/permission-store'
import { readLiveDocument, searchLiveKnowledge } from '@/lib/sim-search/live/application'
import { decodeLiveReference } from '@/lib/sim-search/live/reference'
import { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry'
Expand Down Expand Up @@ -68,15 +71,15 @@ describe('GitLab group Search permission boundary', () => {
group: 'team',
contentTypes: 'issues',
}
const permissions = (revoke = false) => ({
const permissions = (revoke = false, namespace = 'team') => ({
provider: 'gitlab' as const,
userMapping: {
filename: 'users.csv',
content: `user_id,email\n1,${ids.aliceId}@fixture.test\n2,${ids.bobId}@fixture.test`,
},
projectPermissions: {
filename: 'permissions.csv',
content: `project_path,user_id\nteam/a,${revoke ? 2 : 1}\nteam/b,2${added ? '\nteam/c,1' : ''}`,
content: `project_path,user_id\n${namespace}/a,${revoke ? 2 : 1}\n${namespace}/b,2${added ? `\n${namespace}/c,1` : ''}`,
},
})
const server = createServer((request, response) => {
Expand All @@ -92,16 +95,19 @@ describe('GitLab group Search permission boundary', () => {
)
return reply(401, {})
if (providerState === 'revoked') return reply(401, {})
const namespace = providerState === 'renamed' ? 'renamed-team' : 'team'
if (path === '/api/v4/user') return reply(200, { id: 50, state: 'active', locked: false })
if (path === '/api/v4/groups/team' && providerState === 'renamed')
return reply(301, {}, { location: '/api/v4/groups/7' })
if (path === '/api/v4/groups/team' || path === '/api/v4/groups/7')
return reply(200, { id: 7, full_path: providerState === 'renamed' ? 'renamed-team' : 'team' })
return reply(200, { id: 7, full_path: namespace })
if (path === '/api/v4/groups/7/projects') {
if (url.searchParams.get('with_shared') !== 'false') return reply(400, {})
const projects = [
{ id: 11, path_with_namespace: 'team/a' },
{ id: 12, path_with_namespace: 'team/b' },
{ id: 11, path_with_namespace: `${namespace}/a` },
{ id: 12, path_with_namespace: `${namespace}/b` },
]
if (added) projects.push({ id: 13, path_with_namespace: 'team/c' })
if (added) projects.push({ id: 13, path_with_namespace: `${namespace}/c` })
const page = url.searchParams.get('page') ?? '1'
if (page === '1')
return reply(200, projects.slice(0, 1), {
Expand All @@ -118,7 +124,13 @@ describe('GitLab group Search permission boundary', () => {
if (!match) return reply(404, {})
const id = Number(match[1])
const projectPath =
id === 11 ? (moved ? 'outside/a' : 'team/a') : id === 12 ? 'team/b' : 'team/c'
id === 11
? moved
? 'outside/a'
: `${namespace}/a`
: id === 12
? `${namespace}/b`
: `${namespace}/c`
const issue = (iid: number) => ({
project_id: id,
iid,
Expand Down Expand Up @@ -247,7 +259,7 @@ describe('GitLab group Search permission boundary', () => {
boundary:
'Application use cases, real PostgreSQL and HTTP GitLab API fixture; TLS/SSRF transport substituted',
checks,
passed: checks.length === 8,
passed: checks.length === 10,
},
null,
2
Expand Down Expand Up @@ -538,4 +550,52 @@ describe('GitLab group Search permission boundary', () => {
).rejects.toMatchObject({ code: 'forbidden' })
checks.push('Organization administration boundary')
})

it.each(['team', '7'])(
'refreshes renamed groups only when saved scope %s still matches',
async (group) => {
const { connector } = await createKnowledgeConnector.execute({
principal: principal(ids.aliceId),
input: {
knowledgeBaseId: ids.knowledgeBaseId,
assertedOrganizationId: ids.organizationId,
connectorType: 'gitlab',
accessMode: 'admin',
apiKey: token,
sourceConfig: { ...config, group },
permissionConfig: { ...permissions(), mode: 'csv' },
syncIntervalMinutes: 60,
},
})
const before = await loadConnectorPermissionSnapshot(connector.id)
providerState = 'renamed'
try {
const refresh = replaceSearchSourcePermissions.execute({
principal: principal(ids.aliceId),
input: {
organizationId: ids.organizationId,
sourceId: connector.id,
expectedRevision: 1,
permissions: permissions(false, 'renamed-team'),
},
})
if (group === 'team') {
await expect(refresh).rejects.toMatchObject({ code: 'validation' })
expect(await loadConnectorPermissionSnapshot(connector.id)).toEqual(before)
providerState = 'healthy'
} else {
expect(await refresh).toEqual({ revision: 2 })
}
const results = (await search(ids.aliceId, '11', undefined, 20, connector.id)).results
expect(results.length).toBeGreaterThan(0)
const first = results[0]
if (!first) throw new Error('Missing allowed fixture result')
expect((await read(ids.aliceId, first.documentId)).chunks.length).toBeGreaterThan(0)
expect((await search(ids.bobId, '11', undefined, 20, connector.id)).results).toEqual([])
checks.push(`Renamed group refresh preserves permissions for configured scope ${group}`)
} finally {
providerState = 'healthy'
}
}
)
})
Loading