Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git cert ignore #35445

Merged
merged 1 commit into from
Apr 23, 2019
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
1 change: 1 addition & 0 deletions x-pack/plugins/code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const code = (kibana: any) =>
gitProtocolWhitelist: Joi.array()
.items(Joi.string())
.default(['https', 'git', 'ssh']),
enableGitCertCheck: Joi.boolean().default(true),
}).default(),
maxWorkspace: Joi.number().default(5), // max workspace folder for each language server
disableIndexScheduler: Joi.boolean().default(true), // Temp option to disable index scheduler.
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/code/server/__tests__/repository_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('repository service test', () => {
after(() => {
return rimraf.sync(baseDir);
});
const service = new RepositoryService(repoDir, credsDir, log);
const service = new RepositoryService(repoDir, credsDir, log, false /* enableGitCertCheck */);

it('can not clone a repo by ssh without a key', async () => {
const repo = RepositoryUtils.buildRepository(
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/code/server/queue/clone_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export class CloneWorker extends AbstractGitWorker {
const repoService = this.repoServiceFactory.newInstance(
this.serverOptions.repoPath,
this.serverOptions.credsPath,
this.log
this.log,
this.serverOptions.security.enableGitCertCheck
);
const repo = RepositoryUtils.buildRepository(url);
return await repoService.clone(repo, (progress: number, cloneProgress?: CloneProgress) => {
Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/code/server/queue/delete_worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ test('Execute delete job.', async () => {
esQueue as Esqueue,
log,
esClient as EsClient,
{} as ServerOptions,
{
security: {
enableGitCertCheck: false,
},
} as ServerOptions,
(cancellationService as any) as CancellationSerivce,
(lspService as any) as LspService,
(repoServiceFactory as any) as RepositoryServiceFactory
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/code/server/queue/delete_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export class DeleteWorker extends AbstractWorker {
const repoService = this.repoServiceFactory.newInstance(
this.serverOptions.repoPath,
this.serverOptions.credsPath,
this.log
this.log,
this.serverOptions.security.enableGitCertCheck
);
const deleteRepoPromise = this.deletePromiseWrapper(repoService.remove(uri), 'git data', uri);

Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/code/server/queue/update_worker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ test('Execute update job', async () => {
esQueue as Esqueue,
log,
esClient as EsClient,
{} as ServerOptions,
{
security: {
enableGitCertCheck: false,
},
} as ServerOptions,
(repoServiceFactory as any) as RepositoryServiceFactory
);

Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/code/server/queue/update_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export class UpdateWorker extends AbstractGitWorker {
const repoService = this.repoServiceFactory.newInstance(
this.serverOptions.repoPath,
this.serverOptions.credsPath,
this.log
this.log,
this.serverOptions.security.enableGitCertCheck
);
return await repoService.update(repo);
}
Expand Down
9 changes: 4 additions & 5 deletions x-pack/plugins/code/server/repository_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ export class RepositoryService {
constructor(
private readonly repoVolPath: string,
private readonly credsPath: string,
private log: Logger
private readonly log: Logger,
private readonly enableGitCertCheck: boolean
) {}

private isProd = process.env.NODE_ENV === 'production';

public async clone(repo: Repository, handler?: CloneProgressHandler): Promise<CloneWorkerResult> {
if (!repo) {
throw new Error(`Invalid repository.`);
Expand Down Expand Up @@ -108,7 +107,7 @@ export class RepositoryService {
credentials: this.credentialFunc(key),
};
// Ignore cert check on testing environment.
if (!this.isProd) {
if (!this.enableGitCertCheck) {
cbs.certificateCheck = () => {
// Ignore cert check failures.
return 0;
Expand Down Expand Up @@ -205,7 +204,7 @@ export class RepositoryService {
credentials: this.credentialFunc(keyFile),
};
// Ignore cert check on testing environment.
if (!this.isProd) {
if (!this.enableGitCertCheck) {
cbs.certificateCheck = () => {
// Ignore cert check failures.
return 0;
Expand Down
9 changes: 7 additions & 2 deletions x-pack/plugins/code/server/repository_service_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { Logger } from './log';
import { RepositoryService } from './repository_service';

export class RepositoryServiceFactory {
public newInstance(repoPath: string, credsPath: string, log: Logger): RepositoryService {
return new RepositoryService(repoPath, credsPath, log);
public newInstance(
repoPath: string,
credsPath: string,
log: Logger,
enableGitCertCheck: boolean
): RepositoryService {
return new RepositoryService(repoPath, credsPath, log, enableGitCertCheck);
}
}
1 change: 1 addition & 0 deletions x-pack/plugins/code/server/server_options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface SecurityOptions {
installNodeDependency: boolean;
gitHostWhitelist: string[];
gitProtocolWhitelist: string[];
enableGitCertCheck: boolean;
}

export class ServerOptions {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/code/server/test_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const TEST_OPTIONS = {
enableMavenImport: true,
enableGradleImport: true,
installNodeDependency: true,
enableGitCertCheck: false,
},
repos: [],
maxWorkspace: 5, // max workspace folder for each language server
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/functional/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export default async function ({ readConfigFile }) {
'--xpack.xpack_main.telemetry.enabled=false',
'--xpack.maps.showMapsInspectorAdapter=true',
'--xpack.security.encryptionKey="wuGNaIhoMpk5sO4UBxgr3NyW1sFcLgIf"', // server restarts should not invalidate active sessions
'--xpack.code.security.enableGitCertCheck=false' // Disable git certificate check
],
},
uiSettings: {
Expand Down