Skip to content

Commit 5c2ab34

Browse files
mw-dingzfy0701
authored andcommitted
[Code] Add a security flag for git certificate check (#35445)
1 parent fc534e5 commit 5c2ab34

File tree

12 files changed

+32
-13
lines changed

12 files changed

+32
-13
lines changed

x-pack/plugins/code/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export const code = (kibana: any) =>
6464
gitProtocolWhitelist: Joi.array()
6565
.items(Joi.string())
6666
.default(['https', 'git', 'ssh']),
67+
enableGitCertCheck: Joi.boolean().default(true),
6768
}).default(),
6869
maxWorkspace: Joi.number().default(5), // max workspace folder for each language server
6970
disableIndexScheduler: Joi.boolean().default(true), // Temp option to disable index scheduler.

x-pack/plugins/code/server/__tests__/repository_service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('repository service test', () => {
2929
after(() => {
3030
return rimraf.sync(baseDir);
3131
});
32-
const service = new RepositoryService(repoDir, credsDir, log);
32+
const service = new RepositoryService(repoDir, credsDir, log, false /* enableGitCertCheck */);
3333

3434
it('can not clone a repo by ssh without a key', async () => {
3535
const repo = RepositoryUtils.buildRepository(

x-pack/plugins/code/server/queue/clone_worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export class CloneWorker extends AbstractGitWorker {
5858
const repoService = this.repoServiceFactory.newInstance(
5959
this.serverOptions.repoPath,
6060
this.serverOptions.credsPath,
61-
this.log
61+
this.log,
62+
this.serverOptions.security.enableGitCertCheck
6263
);
6364
const repo = RepositoryUtils.buildRepository(url);
6465
return await repoService.clone(repo, (progress: number, cloneProgress?: CloneProgress) => {

x-pack/plugins/code/server/queue/delete_worker.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ test('Execute delete job.', async () => {
6666
esQueue as Esqueue,
6767
log,
6868
esClient as EsClient,
69-
{} as ServerOptions,
69+
{
70+
security: {
71+
enableGitCertCheck: false,
72+
},
73+
} as ServerOptions,
7074
(cancellationService as any) as CancellationSerivce,
7175
(lspService as any) as LspService,
7276
(repoServiceFactory as any) as RepositoryServiceFactory

x-pack/plugins/code/server/queue/delete_worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ export class DeleteWorker extends AbstractWorker {
4747
const repoService = this.repoServiceFactory.newInstance(
4848
this.serverOptions.repoPath,
4949
this.serverOptions.credsPath,
50-
this.log
50+
this.log,
51+
this.serverOptions.security.enableGitCertCheck
5152
);
5253
const deleteRepoPromise = this.deletePromiseWrapper(repoService.remove(uri), 'git data', uri);
5354

x-pack/plugins/code/server/queue/update_worker.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ test('Execute update job', async () => {
4141
esQueue as Esqueue,
4242
log,
4343
esClient as EsClient,
44-
{} as ServerOptions,
44+
{
45+
security: {
46+
enableGitCertCheck: false,
47+
},
48+
} as ServerOptions,
4549
(repoServiceFactory as any) as RepositoryServiceFactory
4650
);
4751

x-pack/plugins/code/server/queue/update_worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export class UpdateWorker extends AbstractGitWorker {
3131
const repoService = this.repoServiceFactory.newInstance(
3232
this.serverOptions.repoPath,
3333
this.serverOptions.credsPath,
34-
this.log
34+
this.log,
35+
this.serverOptions.security.enableGitCertCheck
3536
);
3637
return await repoService.update(repo);
3738
}

x-pack/plugins/code/server/repository_service.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ export class RepositoryService {
2828
constructor(
2929
private readonly repoVolPath: string,
3030
private readonly credsPath: string,
31-
private log: Logger
31+
private readonly log: Logger,
32+
private readonly enableGitCertCheck: boolean
3233
) {}
3334

34-
private isProd = process.env.NODE_ENV === 'production';
35-
3635
public async clone(repo: Repository, handler?: CloneProgressHandler): Promise<CloneWorkerResult> {
3736
if (!repo) {
3837
throw new Error(`Invalid repository.`);
@@ -108,7 +107,7 @@ export class RepositoryService {
108107
credentials: this.credentialFunc(key),
109108
};
110109
// Ignore cert check on testing environment.
111-
if (!this.isProd) {
110+
if (!this.enableGitCertCheck) {
112111
cbs.certificateCheck = () => {
113112
// Ignore cert check failures.
114113
return 0;
@@ -205,7 +204,7 @@ export class RepositoryService {
205204
credentials: this.credentialFunc(keyFile),
206205
};
207206
// Ignore cert check on testing environment.
208-
if (!this.isProd) {
207+
if (!this.enableGitCertCheck) {
209208
cbs.certificateCheck = () => {
210209
// Ignore cert check failures.
211210
return 0;

x-pack/plugins/code/server/repository_service_factory.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ import { Logger } from './log';
88
import { RepositoryService } from './repository_service';
99

1010
export class RepositoryServiceFactory {
11-
public newInstance(repoPath: string, credsPath: string, log: Logger): RepositoryService {
12-
return new RepositoryService(repoPath, credsPath, log);
11+
public newInstance(
12+
repoPath: string,
13+
credsPath: string,
14+
log: Logger,
15+
enableGitCertCheck: boolean
16+
): RepositoryService {
17+
return new RepositoryService(repoPath, credsPath, log, enableGitCertCheck);
1318
}
1419
}

x-pack/plugins/code/server/server_options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface SecurityOptions {
1919
installNodeDependency: boolean;
2020
gitHostWhitelist: string[];
2121
gitProtocolWhitelist: string[];
22+
enableGitCertCheck: boolean;
2223
}
2324

2425
export class ServerOptions {

0 commit comments

Comments
 (0)