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

[Security Solution] Add --ssl flag to use generator and ssl with kbn and elasticsearch clients #89873

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/
/* eslint-disable no-console */
import yargs from 'yargs';
import fs from 'fs';
import { Client, ClientOptions } from '@elastic/elasticsearch';
import { ResponseError } from '@elastic/elasticsearch/lib/errors';
import { KbnClient, ToolingLog } from '@kbn/dev-utils';
import { KbnClient, ToolingLog, CA_CERT_PATH } from '@kbn/dev-utils';
import { AxiosResponse } from 'axios';
import { indexHostsAndAlerts } from '../../common/endpoint/index_data';
import { ANCESTRY_LIMIT, EndpointDocGenerator } from '../../common/endpoint/generate_data';
Expand Down Expand Up @@ -202,15 +203,41 @@ async function main() {
type: 'boolean',
default: false,
},
ssl: {
alias: 'ssl',
describe: 'Use https for elasticsearch and kbn clients',
type: 'boolean',
default: false,
},
}).argv;
let ca: Buffer;
let kbnClient: KbnClientWithApiKeySupport;
let clientOptions: ClientOptions;

const kbnClient = new KbnClientWithApiKeySupport({
log: new ToolingLog({
level: 'info',
writeTo: process.stdout,
}),
url: argv.kibana,
});
if (argv.ssl) {
ca = fs.readFileSync(CA_CERT_PATH);
const url = argv.kibana.replace('http:', 'https:');
const node = argv.node.replace('http:', 'https:');
kbnClient = new KbnClientWithApiKeySupport({
log: new ToolingLog({
level: 'info',
writeTo: process.stdout,
}),
url,
certificateAuthorities: [ca],
});
clientOptions = { node, ssl: { ca: [ca] } };
} else {
kbnClient = new KbnClientWithApiKeySupport({
log: new ToolingLog({
level: 'info',
writeTo: process.stdout,
}),
url: argv.kibana,
});
clientOptions = { node: argv.node };
}
const client = new Client(clientOptions);

try {
await doIngestSetup(kbnClient);
Expand All @@ -219,9 +246,6 @@ async function main() {
process.exit(1);
}

const clientOptions: ClientOptions = { node: argv.node };
const client = new Client(clientOptions);

if (argv.delete) {
await deleteIndices(
[argv.eventIndex, argv.metadataIndex, argv.policyIndex, argv.alertIndex],
Expand Down