plugin-git-manager 1.2.21 → 1.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/{434.1d19d4d6acc114f1.js → 434.b2eeaaef33aae6e0.js} +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client-v2/{434.f8836ea116648de1.js → 434.7a27051db18526c0.js} +1 -1
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +8 -8
- package/dist/locale/en-US.json +4 -3
- package/dist/locale/vi-VN.json +4 -3
- package/dist/locale/zh-CN.json +4 -3
- package/dist/server/actions/git-actions.js +21 -8
- package/dist/server/actions/gitlab-api.js +5 -8
- package/dist/server/actions/poller.js +2 -1
- package/dist/server/actions/review.js +50 -13
- package/dist/server/actions/role-permissions.js +217 -54
- package/dist/server/actions/subtree.js +4 -8
- package/dist/server/migrations/20260730000000-migrate-legacy-repository-permissions.js +94 -0
- package/dist/server/plugin.js +44 -19
- package/dist/server/repository-access.js +570 -0
- package/dist/server/services/registry-content-service.js +137 -22
- package/dist/server/utils/get-repo-account.js +5 -2
- package/dist/server/utils/gitlab-url.js +2 -0
- package/dist/server/utils/redact.js +51 -5
- package/dist/server/utils/url-security.js +109 -0
- package/package.json +1 -1
- package/src/client/components/RepositoryConfig.tsx +4 -1
- package/src/locale/en-US.json +4 -3
- package/src/locale/vi-VN.json +4 -3
- package/src/locale/zh-CN.json +4 -3
- package/src/server/__tests__/git-actions.test.ts +24 -0
- package/src/server/__tests__/plugin-url-security.test.ts +17 -0
- package/src/server/__tests__/poller.test.ts +37 -0
- package/src/server/__tests__/repository-access.test.ts +752 -0
- package/src/server/__tests__/review.test.ts +137 -0
- package/src/server/__tests__/role-permissions.test.ts +147 -0
- package/src/server/actions/git-actions.ts +33 -10
- package/src/server/actions/gitlab-api.ts +5 -8
- package/src/server/actions/poller.ts +2 -1
- package/src/server/actions/review.ts +74 -15
- package/src/server/actions/role-permissions.ts +251 -59
- package/src/server/actions/subtree.ts +4 -8
- package/src/server/migrations/20260730000000-migrate-legacy-repository-permissions.ts +81 -0
- package/src/server/plugin.ts +48 -24
- package/src/server/repository-access.ts +773 -0
- package/src/server/services/__tests__/registry-content-service.test.ts +209 -13
- package/src/server/services/registry-content-service.ts +184 -30
- package/src/server/utils/__tests__/redact.test.ts +56 -0
- package/src/server/utils/__tests__/url-security.test.ts +85 -0
- package/src/server/utils/get-repo-account.ts +22 -4
- package/src/server/utils/gitlab-url.ts +3 -0
- package/src/server/utils/redact.ts +68 -5
- package/src/server/utils/url-security.ts +95 -0
|
@@ -5,7 +5,13 @@ import { join } from 'path';
|
|
|
5
5
|
|
|
6
6
|
import type { Database } from '@nocobase/database';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
RegistryGitContentService,
|
|
10
|
+
SkillHubGitContentService,
|
|
11
|
+
type RegistryGitAccessContext,
|
|
12
|
+
} from '../registry-content-service';
|
|
13
|
+
|
|
14
|
+
const scheduledSyncAccess: RegistryGitAccessContext = { kind: 'system', reason: 'scheduled-sync' };
|
|
9
15
|
|
|
10
16
|
describe('RegistryGitContentService', () => {
|
|
11
17
|
const originalRepositoryRoot = process.env.GIT_REPOS_BASE_PATH;
|
|
@@ -54,10 +60,12 @@ describe('RegistryGitContentService', () => {
|
|
|
54
60
|
} as unknown as Database;
|
|
55
61
|
const service = new RegistryGitContentService(database);
|
|
56
62
|
|
|
57
|
-
await expect(
|
|
58
|
-
|
|
59
|
-
);
|
|
60
|
-
await expect(
|
|
63
|
+
await expect(
|
|
64
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, scheduledSyncAccess),
|
|
65
|
+
).resolves.toEqual(Buffer.from([0, 255, 128, 17]));
|
|
66
|
+
await expect(
|
|
67
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'missing.json' }, scheduledSyncAccess),
|
|
68
|
+
).rejects.toMatchObject({
|
|
61
69
|
code: 'REGISTRY_GIT_FILE_NOT_FOUND',
|
|
62
70
|
});
|
|
63
71
|
});
|
|
@@ -72,11 +80,11 @@ describe('RegistryGitContentService', () => {
|
|
|
72
80
|
} as unknown as Database;
|
|
73
81
|
const service = new RegistryGitContentService(database);
|
|
74
82
|
|
|
75
|
-
await expect(service.resolveCommit(1, 'HEAD')).rejects.toMatchObject({
|
|
83
|
+
await expect(service.resolveCommit(1, 'HEAD', scheduledSyncAccess)).rejects.toMatchObject({
|
|
76
84
|
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
77
85
|
});
|
|
78
86
|
await expect(
|
|
79
|
-
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }),
|
|
87
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, scheduledSyncAccess),
|
|
80
88
|
).rejects.toMatchObject({
|
|
81
89
|
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
82
90
|
});
|
|
@@ -88,12 +96,20 @@ describe('RegistryGitContentService', () => {
|
|
|
88
96
|
} as unknown as Database;
|
|
89
97
|
const service = new RegistryGitContentService(database);
|
|
90
98
|
|
|
91
|
-
await expect(service.resolveCommit(404, 'HEAD')).rejects.toMatchObject({
|
|
99
|
+
await expect(service.resolveCommit(404, 'HEAD', scheduledSyncAccess)).rejects.toMatchObject({
|
|
92
100
|
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
93
101
|
});
|
|
94
102
|
});
|
|
95
103
|
|
|
96
|
-
it('
|
|
104
|
+
it('waits for a killed Git process to close before returning an output-limit error', async () => {
|
|
105
|
+
// Keep Git writing after the first stdout chunk. This makes the test cover
|
|
106
|
+
// the Windows handle race: the repository must be removable immediately
|
|
107
|
+
// after `readFile()` rejects, without depending on afterEach timing.
|
|
108
|
+
writeFileSync(join(repositoryPath, 'payload.bin'), Buffer.alloc(8 * 1024 * 1024, 255));
|
|
109
|
+
execFileSync('git', ['-C', repositoryPath, 'add', 'payload.bin'], { stdio: 'ignore' });
|
|
110
|
+
execFileSync('git', ['-C', repositoryPath, 'commit', '--amend', '--no-edit'], { stdio: 'ignore' });
|
|
111
|
+
commitSha = execFileSync('git', ['-C', repositoryPath, 'rev-parse', 'HEAD'], { encoding: 'utf8' }).trim();
|
|
112
|
+
|
|
97
113
|
const database = {
|
|
98
114
|
getRepository: () => ({
|
|
99
115
|
findOne: vi.fn().mockResolvedValue({
|
|
@@ -115,9 +131,10 @@ describe('RegistryGitContentService', () => {
|
|
|
115
131
|
maxTreeOutputBytes: 1024,
|
|
116
132
|
});
|
|
117
133
|
|
|
118
|
-
await expect(
|
|
119
|
-
|
|
120
|
-
);
|
|
134
|
+
await expect(
|
|
135
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, scheduledSyncAccess),
|
|
136
|
+
).rejects.toThrow('Git file exceeds the registry source-file limit.');
|
|
137
|
+
expect(() => rmSync(repositoryRoot, { recursive: true, force: true, maxRetries: 0 })).not.toThrow();
|
|
121
138
|
});
|
|
122
139
|
|
|
123
140
|
it('rejects a Git tree that exceeds the configured entry limit', async () => {
|
|
@@ -143,7 +160,186 @@ describe('RegistryGitContentService', () => {
|
|
|
143
160
|
});
|
|
144
161
|
|
|
145
162
|
await expect(
|
|
146
|
-
service.listTree({ repositoryId: 1, commitSha, rootPath: '', recursive: true }),
|
|
163
|
+
service.listTree({ repositoryId: 1, commitSha, rootPath: '', recursive: true }, scheduledSyncAccess),
|
|
147
164
|
).rejects.toThrow('Git tree contains too many entries for registry export.');
|
|
148
165
|
});
|
|
166
|
+
|
|
167
|
+
it('requires an explicit actor instead of treating an internal call as a system sync', async () => {
|
|
168
|
+
const database = {
|
|
169
|
+
getRepository: vi.fn(),
|
|
170
|
+
} as unknown as Database;
|
|
171
|
+
const service = new RegistryGitContentService(database);
|
|
172
|
+
|
|
173
|
+
expect(service.contractVersion).toBe(2);
|
|
174
|
+
expect(service.capabilities).toEqual(
|
|
175
|
+
expect.arrayContaining(['registry-content-with-actor', 'registry-content-authorize-source']),
|
|
176
|
+
);
|
|
177
|
+
await expect(service.assertRepositoryAccess(1)).rejects.toMatchObject({
|
|
178
|
+
code: 'REGISTRY_REPOSITORY_ACCESS_DENIED',
|
|
179
|
+
});
|
|
180
|
+
expect(database.getRepository).not.toHaveBeenCalled();
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('allows a user whose Git Manager file-content scope includes the repository', async () => {
|
|
184
|
+
const acl = {
|
|
185
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
186
|
+
};
|
|
187
|
+
const database = {
|
|
188
|
+
getRepository: () => ({
|
|
189
|
+
findOne: vi.fn().mockResolvedValue({
|
|
190
|
+
get: (attribute: string) => {
|
|
191
|
+
if (attribute === 'localPath') return 'skills';
|
|
192
|
+
if (attribute === 'registryExportEnabled') return true;
|
|
193
|
+
return null;
|
|
194
|
+
},
|
|
195
|
+
}),
|
|
196
|
+
}),
|
|
197
|
+
} as unknown as Database;
|
|
198
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
199
|
+
|
|
200
|
+
await expect(service.resolveCommit(1, 'HEAD', { kind: 'user', roles: ['developer'] })).resolves.toBe(commitSha);
|
|
201
|
+
expect(acl.can).toHaveBeenCalledWith({
|
|
202
|
+
roles: ['developer'],
|
|
203
|
+
resource: 'gitManager',
|
|
204
|
+
action: 'fileContent',
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('rejects a user whose Git Manager scope excludes the requested repository', async () => {
|
|
209
|
+
const acl = {
|
|
210
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
211
|
+
};
|
|
212
|
+
const repositoryLookup = vi.fn();
|
|
213
|
+
const database = {
|
|
214
|
+
getRepository: repositoryLookup,
|
|
215
|
+
} as unknown as Database;
|
|
216
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
217
|
+
|
|
218
|
+
await expect(service.assertRepositoryAccess(2, { kind: 'user', roles: ['developer'] })).rejects.toMatchObject({
|
|
219
|
+
code: 'REGISTRY_REPOSITORY_ACCESS_DENIED',
|
|
220
|
+
});
|
|
221
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('allows root without evaluating repository scope', async () => {
|
|
225
|
+
const acl = { can: vi.fn() };
|
|
226
|
+
const database = {
|
|
227
|
+
getRepository: () => ({
|
|
228
|
+
findOne: vi.fn().mockResolvedValue({
|
|
229
|
+
get: (attribute: string) => {
|
|
230
|
+
if (attribute === 'localPath') return 'skills';
|
|
231
|
+
if (attribute === 'registryExportEnabled') return true;
|
|
232
|
+
return null;
|
|
233
|
+
},
|
|
234
|
+
}),
|
|
235
|
+
}),
|
|
236
|
+
} as unknown as Database;
|
|
237
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
238
|
+
|
|
239
|
+
await expect(service.resolveCommit(1, 'HEAD', { kind: 'user', roles: ['root'] })).resolves.toBe(commitSha);
|
|
240
|
+
expect(acl.can).not.toHaveBeenCalled();
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('allows a scheduled system sync but still requires the repository export opt-in', async () => {
|
|
244
|
+
const acl = { can: vi.fn() };
|
|
245
|
+
const database = {
|
|
246
|
+
getRepository: () => ({
|
|
247
|
+
findOne: vi.fn().mockResolvedValue({
|
|
248
|
+
get: (attribute: string) => {
|
|
249
|
+
if (attribute === 'localPath') return 'skills';
|
|
250
|
+
if (attribute === 'registryExportEnabled') return true;
|
|
251
|
+
return null;
|
|
252
|
+
},
|
|
253
|
+
}),
|
|
254
|
+
}),
|
|
255
|
+
} as unknown as Database;
|
|
256
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
257
|
+
|
|
258
|
+
await expect(service.resolveCommit(1, 'HEAD', scheduledSyncAccess)).resolves.toBe(commitSha);
|
|
259
|
+
expect(acl.can).not.toHaveBeenCalled();
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('rejects an otherwise authorized user when repository export is disabled', async () => {
|
|
263
|
+
const acl = {
|
|
264
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
265
|
+
};
|
|
266
|
+
const database = {
|
|
267
|
+
getRepository: () => ({
|
|
268
|
+
findOne: vi.fn().mockResolvedValue({
|
|
269
|
+
get: (attribute: string) => (attribute === 'registryExportEnabled' ? false : 'skills'),
|
|
270
|
+
}),
|
|
271
|
+
}),
|
|
272
|
+
} as unknown as Database;
|
|
273
|
+
const service = new RegistryGitContentService(database, undefined, acl);
|
|
274
|
+
|
|
275
|
+
await expect(service.assertRepositoryAccess(1, { kind: 'user', roles: ['developer'] })).rejects.toMatchObject({
|
|
276
|
+
code: 'REGISTRY_EXPORT_NOT_GRANTED',
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it('allows Skill Hub reads for a scoped user even when Registry export is disabled', async () => {
|
|
281
|
+
const acl = {
|
|
282
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
283
|
+
};
|
|
284
|
+
const database = {
|
|
285
|
+
getRepository: () => ({
|
|
286
|
+
findOne: vi.fn().mockResolvedValue({
|
|
287
|
+
get: (attribute: string) => {
|
|
288
|
+
if (attribute === 'localPath') return 'skills';
|
|
289
|
+
if (attribute === 'registryExportEnabled') return false;
|
|
290
|
+
return null;
|
|
291
|
+
},
|
|
292
|
+
}),
|
|
293
|
+
}),
|
|
294
|
+
} as unknown as Database;
|
|
295
|
+
const service = new SkillHubGitContentService(database, undefined, acl);
|
|
296
|
+
|
|
297
|
+
expect(service.contractVersion).toBe(2);
|
|
298
|
+
expect(service.capabilities).toContain('skill-hub-content-with-actor');
|
|
299
|
+
await expect(
|
|
300
|
+
service.readFile({ repositoryId: 1, commitSha, filePath: 'payload.bin' }, { kind: 'user', roles: ['developer'] }),
|
|
301
|
+
).resolves.toEqual(Buffer.from([0, 255, 128, 17]));
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('rejects a Skill Hub user outside repository scope before reading the database', async () => {
|
|
305
|
+
const acl = {
|
|
306
|
+
can: vi.fn().mockResolvedValue({ params: { filter: { $and: [{ id: { $in: [1] } }] } } }),
|
|
307
|
+
};
|
|
308
|
+
const repositoryLookup = vi.fn();
|
|
309
|
+
const database = {
|
|
310
|
+
getRepository: repositoryLookup,
|
|
311
|
+
} as unknown as Database;
|
|
312
|
+
const service = new SkillHubGitContentService(database, undefined, acl);
|
|
313
|
+
|
|
314
|
+
await expect(service.assertRepositoryAccess(2, { kind: 'user', roles: ['developer'] })).rejects.toMatchObject({
|
|
315
|
+
code: 'SKILL_HUB_REPOSITORY_ACCESS_DENIED',
|
|
316
|
+
});
|
|
317
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it('rejects a Skill Hub call without an actor before reading the database', async () => {
|
|
321
|
+
const repositoryLookup = vi.fn();
|
|
322
|
+
const database = {
|
|
323
|
+
getRepository: repositoryLookup,
|
|
324
|
+
} as unknown as Database;
|
|
325
|
+
const service = new SkillHubGitContentService(database);
|
|
326
|
+
|
|
327
|
+
await expect(service.assertRepositoryAccess(1)).rejects.toMatchObject({
|
|
328
|
+
code: 'SKILL_HUB_REPOSITORY_ACCESS_DENIED',
|
|
329
|
+
});
|
|
330
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
it('rejects a scheduled system actor from Skill Hub before reading the database', async () => {
|
|
334
|
+
const repositoryLookup = vi.fn();
|
|
335
|
+
const database = {
|
|
336
|
+
getRepository: repositoryLookup,
|
|
337
|
+
} as unknown as Database;
|
|
338
|
+
const service = new SkillHubGitContentService(database);
|
|
339
|
+
|
|
340
|
+
await expect(service.assertRepositoryAccess(1, scheduledSyncAccess)).rejects.toMatchObject({
|
|
341
|
+
code: 'SKILL_HUB_REPOSITORY_ACCESS_DENIED',
|
|
342
|
+
});
|
|
343
|
+
expect(repositoryLookup).not.toHaveBeenCalled();
|
|
344
|
+
});
|
|
149
345
|
});
|
|
@@ -5,6 +5,13 @@ import type { Readable } from 'stream';
|
|
|
5
5
|
import type { Database } from '@nocobase/database';
|
|
6
6
|
|
|
7
7
|
import { getGitBinaryPath, validateLocalPath, validateRef } from '../actions/git-actions';
|
|
8
|
+
import {
|
|
9
|
+
hasRepositoryAccess,
|
|
10
|
+
type RegistryGitAccessContext,
|
|
11
|
+
type RepositoryPermissionChecker,
|
|
12
|
+
} from '../repository-access';
|
|
13
|
+
|
|
14
|
+
export type { RegistryGitAccessContext } from '../repository-access';
|
|
8
15
|
|
|
9
16
|
function positiveLimit(value: string | undefined, fallback: number, maximum: number): number {
|
|
10
17
|
const parsed = Number(value);
|
|
@@ -40,8 +47,17 @@ type RepositoryModel = {
|
|
|
40
47
|
};
|
|
41
48
|
|
|
42
49
|
export const REGISTRY_EXPORT_NOT_GRANTED = 'REGISTRY_EXPORT_NOT_GRANTED';
|
|
50
|
+
export const REGISTRY_REPOSITORY_ACCESS_DENIED = 'REGISTRY_REPOSITORY_ACCESS_DENIED';
|
|
51
|
+
export const SKILL_HUB_REPOSITORY_ACCESS_DENIED = 'SKILL_HUB_REPOSITORY_ACCESS_DENIED';
|
|
43
52
|
export const REGISTRY_CONTENT_LIMIT_EXCEEDED = 'REGISTRY_CONTENT_LIMIT_EXCEEDED';
|
|
44
53
|
export const REGISTRY_GIT_FILE_NOT_FOUND = 'REGISTRY_GIT_FILE_NOT_FOUND';
|
|
54
|
+
export const REGISTRY_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
55
|
+
export const REGISTRY_GIT_CONTENT_CAPABILITIES = [
|
|
56
|
+
'registry-content-with-actor',
|
|
57
|
+
'registry-content-authorize-source',
|
|
58
|
+
] as const;
|
|
59
|
+
export const SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION = 2;
|
|
60
|
+
export const SKILL_HUB_GIT_CONTENT_CAPABILITIES = ['skill-hub-content-with-actor'] as const;
|
|
45
61
|
|
|
46
62
|
const DEFAULT_GIT_TIMEOUT_MS = 30_000;
|
|
47
63
|
const MAX_STDERR_BYTES = 64 * 1024;
|
|
@@ -55,6 +71,24 @@ export class RegistryExportNotGrantedError extends Error {
|
|
|
55
71
|
}
|
|
56
72
|
}
|
|
57
73
|
|
|
74
|
+
export class RegistryRepositoryAccessDeniedError extends Error {
|
|
75
|
+
readonly code = REGISTRY_REPOSITORY_ACCESS_DENIED;
|
|
76
|
+
|
|
77
|
+
constructor() {
|
|
78
|
+
super('The current actor is not authorized to read this repository for registry export.');
|
|
79
|
+
this.name = 'RegistryRepositoryAccessDeniedError';
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export class SkillHubRepositoryAccessDeniedError extends Error {
|
|
84
|
+
readonly code = SKILL_HUB_REPOSITORY_ACCESS_DENIED;
|
|
85
|
+
|
|
86
|
+
constructor() {
|
|
87
|
+
super('The current actor is not authorized to read this repository for Skill Hub.');
|
|
88
|
+
this.name = 'SkillHubRepositoryAccessDeniedError';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
58
92
|
export class RegistryContentLimitError extends Error {
|
|
59
93
|
readonly code = REGISTRY_CONTENT_LIMIT_EXCEEDED;
|
|
60
94
|
|
|
@@ -73,6 +107,33 @@ export class RegistryGitFileNotFoundError extends Error {
|
|
|
73
107
|
}
|
|
74
108
|
}
|
|
75
109
|
|
|
110
|
+
interface GitContentAccessPolicy {
|
|
111
|
+
contractVersion: number;
|
|
112
|
+
capabilities: readonly string[];
|
|
113
|
+
allowsSystemScheduledSync: boolean;
|
|
114
|
+
requiresRegistryExport: boolean;
|
|
115
|
+
createAccessDeniedError(): Error;
|
|
116
|
+
createRepositoryUnavailableError(): Error;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const REGISTRY_CONTENT_ACCESS_POLICY: GitContentAccessPolicy = {
|
|
120
|
+
contractVersion: REGISTRY_GIT_CONTENT_CONTRACT_VERSION,
|
|
121
|
+
capabilities: REGISTRY_GIT_CONTENT_CAPABILITIES,
|
|
122
|
+
allowsSystemScheduledSync: true,
|
|
123
|
+
requiresRegistryExport: true,
|
|
124
|
+
createAccessDeniedError: () => new RegistryRepositoryAccessDeniedError(),
|
|
125
|
+
createRepositoryUnavailableError: () => new RegistryExportNotGrantedError(),
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const SKILL_HUB_CONTENT_ACCESS_POLICY: GitContentAccessPolicy = {
|
|
129
|
+
contractVersion: SKILL_HUB_GIT_CONTENT_CONTRACT_VERSION,
|
|
130
|
+
capabilities: SKILL_HUB_GIT_CONTENT_CAPABILITIES,
|
|
131
|
+
allowsSystemScheduledSync: false,
|
|
132
|
+
requiresRegistryExport: false,
|
|
133
|
+
createAccessDeniedError: () => new SkillHubRepositoryAccessDeniedError(),
|
|
134
|
+
createRepositoryUnavailableError: () => new SkillHubRepositoryAccessDeniedError(),
|
|
135
|
+
};
|
|
136
|
+
|
|
76
137
|
function boundedPositive(value: number | undefined, fallback: number, maximum: number): number {
|
|
77
138
|
return Number.isSafeInteger(value) && Number(value) > 0 && Number(value) <= maximum ? Number(value) : fallback;
|
|
78
139
|
}
|
|
@@ -85,17 +146,17 @@ function runGitBuffer(localPath: string, args: string[], maximumBytes: number, t
|
|
|
85
146
|
let stderr = '';
|
|
86
147
|
let stderrBytes = 0;
|
|
87
148
|
let settled = false;
|
|
88
|
-
|
|
89
|
-
|
|
149
|
+
let pendingFailure: Error | undefined;
|
|
150
|
+
const stop = (error: Error) => {
|
|
151
|
+
if (settled || pendingFailure) {
|
|
90
152
|
return;
|
|
91
153
|
}
|
|
92
|
-
|
|
154
|
+
pendingFailure = error;
|
|
93
155
|
clearTimeout(timer);
|
|
94
156
|
child.kill();
|
|
95
|
-
reject(error);
|
|
96
157
|
};
|
|
97
158
|
const timer = setTimeout(() => {
|
|
98
|
-
|
|
159
|
+
stop(new RegistryContentLimitError('Git registry read exceeded its execution timeout.'));
|
|
99
160
|
}, timeoutMs);
|
|
100
161
|
|
|
101
162
|
child.stdout.on('data', (chunk: Buffer) => {
|
|
@@ -104,7 +165,7 @@ function runGitBuffer(localPath: string, args: string[], maximumBytes: number, t
|
|
|
104
165
|
}
|
|
105
166
|
outputBytes += chunk.length;
|
|
106
167
|
if (outputBytes > maximumBytes) {
|
|
107
|
-
|
|
168
|
+
stop(new RegistryContentLimitError('Git registry read exceeded its output limit.'));
|
|
108
169
|
return;
|
|
109
170
|
}
|
|
110
171
|
chunks.push(chunk);
|
|
@@ -118,13 +179,25 @@ function runGitBuffer(localPath: string, args: string[], maximumBytes: number, t
|
|
|
118
179
|
stderrBytes += bounded.length;
|
|
119
180
|
stderr += bounded.toString('utf8');
|
|
120
181
|
});
|
|
121
|
-
child.once('error', (error) =>
|
|
182
|
+
child.once('error', (error) => {
|
|
183
|
+
if (!pendingFailure) {
|
|
184
|
+
pendingFailure = error;
|
|
185
|
+
clearTimeout(timer);
|
|
186
|
+
}
|
|
187
|
+
});
|
|
122
188
|
child.once('close', (code) => {
|
|
123
189
|
if (settled) {
|
|
124
190
|
return;
|
|
125
191
|
}
|
|
126
192
|
settled = true;
|
|
127
193
|
clearTimeout(timer);
|
|
194
|
+
// `close` guarantees that the child process and both stdio streams have
|
|
195
|
+
// released their handles. In particular, Windows otherwise may still
|
|
196
|
+
// hold a temporary Git repository directory after an output-limit kill.
|
|
197
|
+
if (pendingFailure) {
|
|
198
|
+
reject(pendingFailure);
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
128
201
|
if (code !== 0) {
|
|
129
202
|
if (/does not exist in|exists on disk, but not in|path .* does not exist/i.test(stderr)) {
|
|
130
203
|
reject(new RegistryGitFileNotFoundError());
|
|
@@ -177,14 +250,31 @@ function parseTreeLine(line: string, rootPath: string): RegistryGitTreeEntry | n
|
|
|
177
250
|
};
|
|
178
251
|
}
|
|
179
252
|
|
|
180
|
-
|
|
253
|
+
class GitContentService {
|
|
254
|
+
readonly contractVersion: number;
|
|
255
|
+
readonly capabilities: readonly string[];
|
|
256
|
+
|
|
181
257
|
constructor(
|
|
182
258
|
private readonly database: Database,
|
|
183
259
|
private readonly limits: RegistryGitContentLimits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS,
|
|
184
|
-
|
|
260
|
+
private readonly acl?: RepositoryPermissionChecker,
|
|
261
|
+
private readonly accessPolicy: GitContentAccessPolicy = REGISTRY_CONTENT_ACCESS_POLICY,
|
|
262
|
+
) {
|
|
263
|
+
this.contractVersion = accessPolicy.contractVersion;
|
|
264
|
+
this.capabilities = accessPolicy.capabilities;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Validates actor access before a cross-plugin service binds or reads a
|
|
269
|
+
* repository. The concrete service policy decides whether Registry export
|
|
270
|
+
* opt-in or scheduled system access is permitted.
|
|
271
|
+
*/
|
|
272
|
+
async assertRepositoryAccess(repositoryId: string | number, access?: RegistryGitAccessContext): Promise<void> {
|
|
273
|
+
await this.findRepository(repositoryId, access);
|
|
274
|
+
}
|
|
185
275
|
|
|
186
|
-
async resolveCommit(repositoryId: string | number, ref: string): Promise<string> {
|
|
187
|
-
const repository = await this.findRepository(repositoryId);
|
|
276
|
+
async resolveCommit(repositoryId: string | number, ref: string, access?: RegistryGitAccessContext): Promise<string> {
|
|
277
|
+
const repository = await this.findRepository(repositoryId, access);
|
|
188
278
|
const localPath = validateLocalPath(repositoryValue(repository, 'localPath'));
|
|
189
279
|
if (!existsSync(localPath)) {
|
|
190
280
|
throw new Error('Repository directory does not exist. Clone the repository before reading its content.');
|
|
@@ -205,13 +295,16 @@ export class RegistryGitContentService {
|
|
|
205
295
|
return result.toLowerCase();
|
|
206
296
|
}
|
|
207
297
|
|
|
208
|
-
async listTree(
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
298
|
+
async listTree(
|
|
299
|
+
input: {
|
|
300
|
+
repositoryId: string | number;
|
|
301
|
+
commitSha: string;
|
|
302
|
+
rootPath: string;
|
|
303
|
+
recursive: boolean;
|
|
304
|
+
},
|
|
305
|
+
access?: RegistryGitAccessContext,
|
|
306
|
+
): Promise<RegistryGitTreeEntry[]> {
|
|
307
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
215
308
|
const localPath = validateLocalPath(repositoryValue(repository, 'localPath'));
|
|
216
309
|
if (!existsSync(localPath)) {
|
|
217
310
|
throw new Error('Repository directory does not exist. Clone the repository before reading its content.');
|
|
@@ -235,13 +328,16 @@ export class RegistryGitContentService {
|
|
|
235
328
|
.sort((left, right) => left.path.localeCompare(right.path));
|
|
236
329
|
}
|
|
237
330
|
|
|
238
|
-
async readFile(
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
331
|
+
async readFile(
|
|
332
|
+
input: {
|
|
333
|
+
repositoryId: string | number;
|
|
334
|
+
commitSha: string;
|
|
335
|
+
filePath: string;
|
|
336
|
+
maxBytes?: number;
|
|
337
|
+
},
|
|
338
|
+
access?: RegistryGitAccessContext,
|
|
339
|
+
): Promise<Buffer> {
|
|
340
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
245
341
|
const localPath = validateLocalPath(repositoryValue(repository, 'localPath'));
|
|
246
342
|
if (!existsSync(localPath)) {
|
|
247
343
|
throw new Error('Repository directory does not exist. Clone the repository before reading its content.');
|
|
@@ -259,8 +355,11 @@ export class RegistryGitContentService {
|
|
|
259
355
|
}
|
|
260
356
|
}
|
|
261
357
|
|
|
262
|
-
async archiveTree(
|
|
263
|
-
|
|
358
|
+
async archiveTree(
|
|
359
|
+
input: { repositoryId: string | number; commitSha: string; rootPath: string },
|
|
360
|
+
access?: RegistryGitAccessContext,
|
|
361
|
+
): Promise<Readable> {
|
|
362
|
+
const repository = await this.findRepository(input.repositoryId, access);
|
|
264
363
|
const localPath = validateLocalPath(repositoryValue(repository, 'localPath'));
|
|
265
364
|
if (!existsSync(localPath)) {
|
|
266
365
|
throw new Error('Repository directory does not exist. Clone the repository before reading its content.');
|
|
@@ -290,21 +389,56 @@ export class RegistryGitContentService {
|
|
|
290
389
|
});
|
|
291
390
|
}
|
|
292
391
|
|
|
293
|
-
private async findRepository(
|
|
392
|
+
private async findRepository(
|
|
393
|
+
repositoryId: string | number,
|
|
394
|
+
access?: RegistryGitAccessContext,
|
|
395
|
+
): Promise<RepositoryModel> {
|
|
396
|
+
await this.assertAccess(repositoryId, access);
|
|
294
397
|
const repository = await this.database.getRepository('gitRepositories').findOne({ filterByTk: repositoryId });
|
|
295
398
|
if (!repository) {
|
|
296
399
|
// Do not distinguish a missing repository from one that exists but has not
|
|
297
400
|
// granted registry export. Callers cannot use this bridge to enumerate
|
|
298
401
|
// repository IDs or infer private repository existence.
|
|
299
|
-
throw
|
|
402
|
+
throw this.accessPolicy.createRepositoryUnavailableError();
|
|
300
403
|
}
|
|
301
404
|
const repositoryModel = repository as unknown as RepositoryModel;
|
|
302
|
-
if (repositoryModel.get('registryExportEnabled') !== true) {
|
|
405
|
+
if (this.accessPolicy.requiresRegistryExport && repositoryModel.get('registryExportEnabled') !== true) {
|
|
303
406
|
throw new RegistryExportNotGrantedError();
|
|
304
407
|
}
|
|
305
408
|
return repositoryModel;
|
|
306
409
|
}
|
|
307
410
|
|
|
411
|
+
private async assertAccess(repositoryId: string | number, access?: RegistryGitAccessContext): Promise<void> {
|
|
412
|
+
if (!access) {
|
|
413
|
+
// The old call shape is intentionally retained for a stable TypeScript
|
|
414
|
+
// boundary, but treating missing identity as a system caller would let
|
|
415
|
+
// user-triggered cross-plugin calls bypass repository-scoped ACL.
|
|
416
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
417
|
+
}
|
|
418
|
+
if (access.kind === 'system') {
|
|
419
|
+
if (this.accessPolicy.allowsSystemScheduledSync && access.reason === 'scheduled-sync') {
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
423
|
+
}
|
|
424
|
+
if (
|
|
425
|
+
access.kind !== 'user' ||
|
|
426
|
+
!Array.isArray(access.roles) ||
|
|
427
|
+
!access.roles.every((role) => typeof role === 'string')
|
|
428
|
+
) {
|
|
429
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
430
|
+
}
|
|
431
|
+
const allowed = await hasRepositoryAccess({
|
|
432
|
+
acl: this.acl,
|
|
433
|
+
roles: access.roles,
|
|
434
|
+
repositoryId,
|
|
435
|
+
action: 'fileContent',
|
|
436
|
+
});
|
|
437
|
+
if (!allowed) {
|
|
438
|
+
throw this.accessPolicy.createAccessDeniedError();
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
308
442
|
private assertCommitSha(value: string): string {
|
|
309
443
|
const normalized = validateRef(value);
|
|
310
444
|
if (!/^[a-f0-9]{40,64}$/i.test(normalized)) {
|
|
@@ -313,3 +447,23 @@ export class RegistryGitContentService {
|
|
|
313
447
|
return normalized.toLowerCase();
|
|
314
448
|
}
|
|
315
449
|
}
|
|
450
|
+
|
|
451
|
+
export class RegistryGitContentService extends GitContentService {
|
|
452
|
+
constructor(
|
|
453
|
+
database: Database,
|
|
454
|
+
limits: RegistryGitContentLimits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS,
|
|
455
|
+
acl?: RepositoryPermissionChecker,
|
|
456
|
+
) {
|
|
457
|
+
super(database, limits, acl, REGISTRY_CONTENT_ACCESS_POLICY);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export class SkillHubGitContentService extends GitContentService {
|
|
462
|
+
constructor(
|
|
463
|
+
database: Database,
|
|
464
|
+
limits: RegistryGitContentLimits = DEFAULT_REGISTRY_GIT_CONTENT_LIMITS,
|
|
465
|
+
acl?: RepositoryPermissionChecker,
|
|
466
|
+
) {
|
|
467
|
+
super(database, limits, acl, SKILL_HUB_CONTENT_ACCESS_POLICY);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { isGitManagerResourceResponse, REDACTED_PAT, redactCredentialFields } from '../redact';
|
|
3
|
+
|
|
4
|
+
describe('Git Manager credential response redaction', () => {
|
|
5
|
+
it('redacts PATs recursively through nested associations and dataValues', () => {
|
|
6
|
+
const response = {
|
|
7
|
+
data: [
|
|
8
|
+
{
|
|
9
|
+
gitAccount: {
|
|
10
|
+
pat: 'top-level-secret',
|
|
11
|
+
dataValues: { pat: 'top-level-data-values-secret' },
|
|
12
|
+
},
|
|
13
|
+
dataValues: {
|
|
14
|
+
gitAccount: {
|
|
15
|
+
pat: 'nested-secret',
|
|
16
|
+
dataValues: { pat: 'nested-data-values-secret' },
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
redactCredentialFields(response);
|
|
24
|
+
|
|
25
|
+
expect(response.data[0].gitAccount.pat).toBe(REDACTED_PAT);
|
|
26
|
+
expect(response.data[0].gitAccount.dataValues.pat).toBe(REDACTED_PAT);
|
|
27
|
+
expect(response.data[0].dataValues.gitAccount.pat).toBe(REDACTED_PAT);
|
|
28
|
+
expect(response.data[0].dataValues.gitAccount.dataValues.pat).toBe(REDACTED_PAT);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('handles circular response objects without leaving a PAT exposed', () => {
|
|
32
|
+
const response: { pat: string; self?: unknown } = { pat: 'secret' };
|
|
33
|
+
response.self = response;
|
|
34
|
+
|
|
35
|
+
redactCredentialFields(response);
|
|
36
|
+
|
|
37
|
+
expect(response.pat).toBe(REDACTED_PAT);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it.each([
|
|
41
|
+
'gitManager',
|
|
42
|
+
'gitRepositories',
|
|
43
|
+
'gitReviewFlows',
|
|
44
|
+
'gitCodeReviews',
|
|
45
|
+
'gitSubtreeConfigs',
|
|
46
|
+
'gitSubtreeRuns',
|
|
47
|
+
'gitAccounts.1.repositories',
|
|
48
|
+
'gitRepositories.10.gitAccount',
|
|
49
|
+
])('recognizes nested Git Manager response route %s', (resourceName) => {
|
|
50
|
+
expect(isGitManagerResourceResponse(resourceName)).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('does not scrub unrelated resource responses', () => {
|
|
54
|
+
expect(isGitManagerResourceResponse('users')).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
});
|