kibana/x-pack/test/osquery_cypress/runner.ts
Paul Tavares 8613b0f17d
[Security Solution][Endpoint] several refactors of CLI tooling and associated common services (#169987)
## Summary

PR makes a series of refactors to CLI scripts and common services used
in CLI scripts and CI, including:

- Standard interface for interacting with Host VMs that abstracts away
the need to know what VM manager was used to start that VM
- Reduce/eliminate the need to have conditional code when interacting
directly with a VM (ex. executing bash commands, stop/kill/delete VM,
etc)
- Removed use of `endpoint_agent_runner` (CLI script) private
implementation methods from Cypress and replace them with calls to
common services
- Removed duplicate code from `endpoint_agent_runner` CLI script and
replace it with calls to common services
- Enhanced the `run_sentinelone_host.js` script so that it also ensures
that the SentinenlOne fleet integration/policy (agentless policy) has at
least one VM host running
    - The VM ensures that the data from S1 is pulled into ES
- FYI: once changes for SentinelOne are merged and the Connector
available, script will also be updated to create an SentinelOne
connector instance under `"Stack Management > Connectors"`
- Added support for `WITH_FLEET_SERVER` to the Cypress config. When set
to `true`, fleet server will be automatically started and connected to
the stack
- Cypress parallel runner will now start fleet if this variable is true,
right after setting up the stack
2023-11-13 15:10:55 -05:00

66 lines
2.6 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import Url from 'url';
import { verifyDockerInstalled, maybeCreateDockerNetwork } from '@kbn/es';
import { createToolingLogger } from '@kbn/security-solution-plugin/common/endpoint/data_loaders/utils';
import { prefixedOutputLogger } from '@kbn/security-solution-plugin/scripts/endpoint/common/utils';
import { FtrProviderContext } from './ftr_provider_context';
import { AgentManager } from './agent';
import { FleetManager } from './fleet_server';
import { createAgentPolicy } from './utils';
async function setupFleetAgent({ getService }: FtrProviderContext) {
// Un-comment line below to set tooling log levels to verbose. Useful when debugging
// createToolingLogger.defaultLogLevel = 'verbose';
// const log = getService('log');
const config = getService('config');
const kbnClient = getService('kibanaServer');
const log = prefixedOutputLogger('cy.OSQuery', createToolingLogger());
await verifyDockerInstalled(log);
await maybeCreateDockerNetwork(log);
await new FleetManager(kbnClient, log, config.get('servers.fleetserver.port')).setup();
const policyEnrollmentKey = await createAgentPolicy(kbnClient, log, `Default policy`);
const policyEnrollmentKeyTwo = await createAgentPolicy(kbnClient, log, `Osquery policy`);
const port = config.get('servers.fleetserver.port');
await new AgentManager(policyEnrollmentKey, port, log, kbnClient).setup();
await new AgentManager(policyEnrollmentKeyTwo, port, log, kbnClient).setup();
}
export async function startOsqueryCypress(context: FtrProviderContext) {
const config = context.getService('config');
await setupFleetAgent(context);
return {
FORCE_COLOR: '1',
baseUrl: Url.format({
protocol: config.get('servers.kibana.protocol'),
hostname: config.get('servers.kibana.hostname'),
port: config.get('servers.kibana.port'),
}),
protocol: config.get('servers.kibana.protocol'),
hostname: config.get('servers.kibana.hostname'),
configport: config.get('servers.kibana.port'),
ELASTICSEARCH_URL: Url.format(config.get('servers.elasticsearch')),
ELASTICSEARCH_USERNAME: config.get('servers.kibana.username'),
ELASTICSEARCH_PASSWORD: config.get('servers.kibana.password'),
KIBANA_URL: Url.format({
protocol: config.get('servers.kibana.protocol'),
hostname: config.get('servers.kibana.hostname'),
port: config.get('servers.kibana.port'),
}),
};
}