From ddc9e029709150e9f65d223ed7e7bc16a9d76568 Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Fri, 28 Jan 2022 11:28:43 +0100 Subject: [PATCH 1/8] Functional test runner creates system_indices_superuser --- .../functional_test_runner.ts | 2 +- .../elasticsearch_without_system_indices.ts | 40 ++++++++++++++ test/common/services/index.ts | 2 + test/common/services/security/security.ts | 2 + .../services/security/system_indices_user.ts | 52 +++++++++++++++++++ 5 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 test/common/services/elasticsearch_without_system_indices.ts create mode 100644 test/common/services/security/system_indices_user.ts diff --git a/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts b/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts index ea55a2672d670..345bf727e4a6b 100644 --- a/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts +++ b/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts @@ -63,7 +63,7 @@ export class FunctionalTestRunner { // validate es version if (providers.hasService('es')) { - const es = (await providers.getService('es')) as unknown as EsClient; + const es = (await providers.getService('esWithoutSystemIndices')) as unknown as EsClient; let esInfo; try { esInfo = await es.info(); diff --git a/test/common/services/elasticsearch_without_system_indices.ts b/test/common/services/elasticsearch_without_system_indices.ts new file mode 100644 index 0000000000000..10ded46df3a58 --- /dev/null +++ b/test/common/services/elasticsearch_without_system_indices.ts @@ -0,0 +1,40 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { format as formatUrl } from 'url'; +import fs from 'fs'; +import { Client, HttpConnection } from '@elastic/elasticsearch'; +import { CA_CERT_PATH } from '@kbn/dev-utils'; + +import { FtrProviderContext } from '../ftr_provider_context'; + +/* + registers Kibana-specific @elastic/elasticsearch client instance. + */ +export function ElasticsearchWithoutSystemIndicesProvider({ + getService, +}: FtrProviderContext): Client { + const config = getService('config'); + + if (process.env.TEST_CLOUD) { + return new Client({ + nodes: [formatUrl(config.get('servers.elasticsearch'))], + requestTimeout: config.get('timeouts.esRequestTimeout'), + Connection: HttpConnection, + }); + } else { + return new Client({ + tls: { + ca: fs.readFileSync(CA_CERT_PATH, 'utf-8'), + }, + nodes: [formatUrl(config.get('servers.elasticsearch'))], + requestTimeout: config.get('timeouts.esRequestTimeout'), + Connection: HttpConnection, + }); + } +} diff --git a/test/common/services/index.ts b/test/common/services/index.ts index 91d17ce1bb3e8..da9b6953598cb 100644 --- a/test/common/services/index.ts +++ b/test/common/services/index.ts @@ -8,6 +8,7 @@ import { DeploymentService } from './deployment'; import { ElasticsearchProvider } from './elasticsearch'; +import { ElasticsearchWithoutSystemIndicesProvider } from './elasticsearch_without_system_indices'; import { EsArchiverProvider } from './es_archiver'; import { KibanaServerProvider } from './kibana_server'; import { RetryService } from './retry'; @@ -21,6 +22,7 @@ import { BSearchProvider } from './bsearch'; export const services = { deployment: DeploymentService, es: ElasticsearchProvider, + esWithoutSystemIndices: ElasticsearchWithoutSystemIndicesProvider, esArchiver: EsArchiverProvider, kibanaServer: KibanaServerProvider, retry: RetryService, diff --git a/test/common/services/security/security.ts b/test/common/services/security/security.ts index b8fea0a0c59b2..a182f225f2388 100644 --- a/test/common/services/security/security.ts +++ b/test/common/services/security/security.ts @@ -11,6 +11,7 @@ import { User } from './user'; import { RoleMappings } from './role_mappings'; import { FtrProviderContext } from '../../ftr_provider_context'; import { createTestUserService, TestUserSupertestProvider, TestUser } from './test_user'; +import { createSystemIndicesUser } from './system_indices_user'; export class SecurityService { constructor( @@ -28,6 +29,7 @@ export async function SecurityServiceProvider(ctx: FtrProviderContext) { const role = new Role(log, kibanaServer); const user = new User(log, kibanaServer); + await createSystemIndicesUser(ctx); const testUser = await createTestUserService(ctx, role, user); const testUserSupertest = TestUserSupertestProvider(ctx); const roleMappings = new RoleMappings(log, kibanaServer); diff --git a/test/common/services/security/system_indices_user.ts b/test/common/services/security/system_indices_user.ts new file mode 100644 index 0000000000000..46b4e0263a4ca --- /dev/null +++ b/test/common/services/security/system_indices_user.ts @@ -0,0 +1,52 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import { systemIndicesSuperuser } from '@kbn/test'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +const SYSTEM_INDICES_SUPERUSER_ROLE = 'system_indices_superuser'; + +export async function createSystemIndicesUser(ctx: FtrProviderContext) { + const log = ctx.getService('log'); + const config = ctx.getService('config'); + const es = ctx.getService('esWithoutSystemIndices'); + + const enabled = !config + .get('esTestCluster.serverArgs') + .some((arg: string) => arg === 'xpack.security.enabled=false'); + + if (enabled) { + log.debug('===============creating system indices role and user==============='); + + await es.security.putRole({ + name: SYSTEM_INDICES_SUPERUSER_ROLE, + cluster: ['all'], + indices: [ + { + names: ['*'], + privileges: ['all'], + allow_restricted_indices: true, + }, + ], + applications: [ + { + application: '*', + privileges: ['*'], + resources: ['*'], + }, + ], + run_as: ['*'], + }); + + await es.security.putUser({ + username: systemIndicesSuperuser.username, + password: systemIndicesSuperuser.password, + roles: [SYSTEM_INDICES_SUPERUSER_ROLE], + }); + } +} From 6ebe1ecd3ac679eebbe12554737d4f37410010ff Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Fri, 28 Jan 2022 12:51:48 +0100 Subject: [PATCH 2/8] Make esWithoutSystemIndices service available in spaces_api_integration tests --- x-pack/test/spaces_api_integration/common/config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/test/spaces_api_integration/common/config.ts b/x-pack/test/spaces_api_integration/common/config.ts index 5d135cd05605c..c175855ad7aee 100644 --- a/x-pack/test/spaces_api_integration/common/config.ts +++ b/x-pack/test/spaces_api_integration/common/config.ts @@ -33,6 +33,7 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions) servers: config.xpack.api.get('servers'), services: { es: config.kibana.api.get('services.es'), + esWithoutSystemIndices: config.kibana.api.get('services.esWithoutSystemIndices'), esSupertestWithoutAuth: config.xpack.api.get('services.esSupertestWithoutAuth'), supertest: config.kibana.api.get('services.supertest'), supertestWithoutAuth: config.xpack.api.get('services.supertestWithoutAuth'), From d0f5ac5df0a61d05f4d9737d30b5096977affe48 Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Tue, 1 Feb 2022 10:29:34 +0100 Subject: [PATCH 3/8] Adjust default users tests for cloud env --- x-pack/test/functional/apps/security/users.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/test/functional/apps/security/users.ts b/x-pack/test/functional/apps/security/users.ts index 634c7ace52735..d7201eae98bdb 100644 --- a/x-pack/test/functional/apps/security/users.ts +++ b/x-pack/test/functional/apps/security/users.ts @@ -44,7 +44,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { // In Cloud default users are defined in file realm, such users aren't exposed through the Users API. if (isCloudEnvironment()) { - expect(Object.keys(users)).to.eql(['test_user']); + expect(users).to.not.have.property('elastic'); + expect(users).to.not.have.property('kibana_system'); + expect(users).to.not.have.property('kibana'); } else { expect(users.elastic.roles).to.eql(['superuser']); expect(users.elastic.reserved).to.be(true); From 4bbc130a6fbed58c8a5d635046a3b13b0b863e2a Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 2 Feb 2022 11:51:09 -0700 Subject: [PATCH 4/8] use independent client in ftr for version check, share creation logic --- .../kbn-test/src/es/es_client_for_testing.ts | 55 +++++++++++++++ packages/kbn-test/src/es/index.ts | 2 + .../functional_test_runner.ts | 51 ++++++++------ packages/kbn-test/src/index.ts | 15 ++++- test/common/services/elasticsearch.ts | 29 ++------ .../elasticsearch_without_system_indices.ts | 40 ----------- test/common/services/index.ts | 2 - .../services/security/system_indices_user.ts | 67 ++++++++++--------- .../apm/ftr_e2e/cypress/plugins/index.ts | 16 ++--- .../common/services/cluster_client.ts | 27 ++------ 10 files changed, 149 insertions(+), 155 deletions(-) create mode 100644 packages/kbn-test/src/es/es_client_for_testing.ts delete mode 100644 test/common/services/elasticsearch_without_system_indices.ts diff --git a/packages/kbn-test/src/es/es_client_for_testing.ts b/packages/kbn-test/src/es/es_client_for_testing.ts new file mode 100644 index 0000000000000..6469bec52cf76 --- /dev/null +++ b/packages/kbn-test/src/es/es_client_for_testing.ts @@ -0,0 +1,55 @@ +/* + * 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 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import * as Url from 'url'; +import * as Fs from 'fs'; + +import { CA_CERT_PATH } from '@kbn/dev-utils'; +import { Client as EsClient, ClientOptions, HttpConnection } from '@elastic/elasticsearch'; +import type { Config } from '../functional_test_runner'; + +/** options for creating es instances used in functional testing scenarios */ +export interface EsClientForTestingOptions extends Omit { + /** url of es instance */ + esUrl: string; + /** overwrite the auth embedded in the url to use a different user in this client instance */ + authOverride?: { username: string; password: string }; +} + +export function createEsClientForFtrConfig( + config: Config, + overrides?: Omit +) { + const esUrl = Url.format(config.get('servers.elasticsearch')); + return createEsClientForTesting({ + esUrl, + requestTimeout: config.get('timeouts.esRequestTimeout'), + ...overrides, + }); +} + +export function createEsClientForTesting(options: EsClientForTestingOptions) { + const { esUrl, authOverride, ...otherOptions } = options; + + const url = options.authOverride + ? Url.format({ + ...Url.parse(options.esUrl), + auth: `${options.authOverride.username}:${options.authOverride.password}`, + }) + : options.esUrl; + + return new EsClient({ + Connection: HttpConnection, + tls: process.env.TEST_CLOUD ? undefined : { ca: Fs.readFileSync(CA_CERT_PATH) }, + + ...otherOptions, + + // force nodes config + nodes: [url], + }); +} diff --git a/packages/kbn-test/src/es/index.ts b/packages/kbn-test/src/es/index.ts index 0c19a6b903742..c823adaab101f 100644 --- a/packages/kbn-test/src/es/index.ts +++ b/packages/kbn-test/src/es/index.ts @@ -10,3 +10,5 @@ export { createTestEsCluster } from './test_es_cluster'; export type { CreateTestEsClusterOptions, EsTestCluster, ICluster } from './test_es_cluster'; export { esTestConfig } from './es_test_config'; export { convertToKibanaClient } from './client_to_kibana_client'; +export { createEsClientForTesting, createEsClientForFtrConfig } from './es_client_for_testing'; +export type { EsClientForTestingOptions } from './es_client_for_testing'; diff --git a/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts b/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts index 345bf727e4a6b..5b4b41a456f1d 100644 --- a/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts +++ b/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts @@ -6,7 +6,6 @@ * Side Public License, v 1. */ -import type { Client as EsClient } from '@elastic/elasticsearch'; import { ToolingLog } from '@kbn/dev-utils'; import { Suite, Test } from './fake_mocha_types'; @@ -24,6 +23,7 @@ import { SuiteTracker, EsVersion, } from './lib'; +import { createEsClientForFtrConfig } from '../es'; export class FunctionalTestRunner { public readonly lifecycle = new Lifecycle(); @@ -61,27 +61,7 @@ export class FunctionalTestRunner { ...readProviderSpec('PageObject', config.get('pageObjects')), ]); - // validate es version - if (providers.hasService('es')) { - const es = (await providers.getService('esWithoutSystemIndices')) as unknown as EsClient; - let esInfo; - try { - esInfo = await es.info(); - } catch (error) { - throw new Error( - `attempted to use the "es" service to fetch Elasticsearch version info but the request failed: ${error.stack}` - ); - } - - if (!this.esVersion.eql(esInfo.version.number)) { - throw new Error( - `ES reports a version number "${ - esInfo.version.number - }" which doesn't match supplied es version "${this.esVersion.toString()}"` - ); - } - } - + await this.validateEsVersion(config); await providers.loadAll(); const customTestRunner = config.get('testRunner'); @@ -100,6 +80,33 @@ export class FunctionalTestRunner { }); } + private async validateEsVersion(config: Config) { + const es = createEsClientForFtrConfig(config); + + let esInfo; + try { + esInfo = await es.info(); + } catch (error) { + throw new Error( + `attempted to use the "es" service to fetch Elasticsearch version info but the request failed: ${error.stack}` + ); + } finally { + try { + await es.close(); + } catch { + // noop + } + } + + if (!this.esVersion.eql(esInfo.version.number)) { + throw new Error( + `ES reports a version number "${ + esInfo.version.number + }" which doesn't match supplied es version "${this.esVersion.toString()}"` + ); + } + } + async getTestStats() { return await this._run(async (config, coreProviders) => { if (config.get('testRunner')) { diff --git a/packages/kbn-test/src/index.ts b/packages/kbn-test/src/index.ts index a3772665b8891..4f9edf350b3d6 100644 --- a/packages/kbn-test/src/index.ts +++ b/packages/kbn-test/src/index.ts @@ -25,8 +25,19 @@ export { runTests, startServers } from './functional_tests/tasks'; // @internal export { KIBANA_ROOT } from './functional_tests/lib/paths'; -export type { CreateTestEsClusterOptions, EsTestCluster, ICluster } from './es'; -export { esTestConfig, createTestEsCluster, convertToKibanaClient } from './es'; +export type { + CreateTestEsClusterOptions, + EsTestCluster, + ICluster, + EsClientForTestingOptions, +} from './es'; +export { + esTestConfig, + createTestEsCluster, + convertToKibanaClient, + createEsClientForTesting, + createEsClientForFtrConfig, +} from './es'; export { kbnTestConfig, diff --git a/test/common/services/elasticsearch.ts b/test/common/services/elasticsearch.ts index baa4050ee10f7..2f19bfe9105d0 100644 --- a/test/common/services/elasticsearch.ts +++ b/test/common/services/elasticsearch.ts @@ -6,12 +6,9 @@ * Side Public License, v 1. */ -import { format as formatUrl } from 'url'; -import fs from 'fs'; -import { Client, HttpConnection } from '@elastic/elasticsearch'; -import { CA_CERT_PATH } from '@kbn/dev-utils'; +import { Client } from '@elastic/elasticsearch'; -import { systemIndicesSuperuser } from '@kbn/test'; +import { systemIndicesSuperuser, createEsClientForFtrConfig } from '@kbn/test'; import { FtrProviderContext } from '../ftr_provider_context'; /* @@ -20,26 +17,8 @@ import { FtrProviderContext } from '../ftr_provider_context'; export function ElasticsearchProvider({ getService }: FtrProviderContext): Client { const config = getService('config'); - const esUrl = formatUrl({ - ...config.get('servers.elasticsearch'), + return createEsClientForFtrConfig(config, { // Use system indices user so tests can write to system indices - auth: `${systemIndicesSuperuser.username}:${systemIndicesSuperuser.password}`, + authOverride: systemIndicesSuperuser, }); - - if (process.env.TEST_CLOUD) { - return new Client({ - nodes: [esUrl], - requestTimeout: config.get('timeouts.esRequestTimeout'), - Connection: HttpConnection, - }); - } else { - return new Client({ - tls: { - ca: fs.readFileSync(CA_CERT_PATH, 'utf-8'), - }, - nodes: [esUrl], - requestTimeout: config.get('timeouts.esRequestTimeout'), - Connection: HttpConnection, - }); - } } diff --git a/test/common/services/elasticsearch_without_system_indices.ts b/test/common/services/elasticsearch_without_system_indices.ts deleted file mode 100644 index 10ded46df3a58..0000000000000 --- a/test/common/services/elasticsearch_without_system_indices.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 and the Server Side Public License, v 1; you may not use this file except - * in compliance with, at your election, the Elastic License 2.0 or the Server - * Side Public License, v 1. - */ - -import { format as formatUrl } from 'url'; -import fs from 'fs'; -import { Client, HttpConnection } from '@elastic/elasticsearch'; -import { CA_CERT_PATH } from '@kbn/dev-utils'; - -import { FtrProviderContext } from '../ftr_provider_context'; - -/* - registers Kibana-specific @elastic/elasticsearch client instance. - */ -export function ElasticsearchWithoutSystemIndicesProvider({ - getService, -}: FtrProviderContext): Client { - const config = getService('config'); - - if (process.env.TEST_CLOUD) { - return new Client({ - nodes: [formatUrl(config.get('servers.elasticsearch'))], - requestTimeout: config.get('timeouts.esRequestTimeout'), - Connection: HttpConnection, - }); - } else { - return new Client({ - tls: { - ca: fs.readFileSync(CA_CERT_PATH, 'utf-8'), - }, - nodes: [formatUrl(config.get('servers.elasticsearch'))], - requestTimeout: config.get('timeouts.esRequestTimeout'), - Connection: HttpConnection, - }); - } -} diff --git a/test/common/services/index.ts b/test/common/services/index.ts index da9b6953598cb..91d17ce1bb3e8 100644 --- a/test/common/services/index.ts +++ b/test/common/services/index.ts @@ -8,7 +8,6 @@ import { DeploymentService } from './deployment'; import { ElasticsearchProvider } from './elasticsearch'; -import { ElasticsearchWithoutSystemIndicesProvider } from './elasticsearch_without_system_indices'; import { EsArchiverProvider } from './es_archiver'; import { KibanaServerProvider } from './kibana_server'; import { RetryService } from './retry'; @@ -22,7 +21,6 @@ import { BSearchProvider } from './bsearch'; export const services = { deployment: DeploymentService, es: ElasticsearchProvider, - esWithoutSystemIndices: ElasticsearchWithoutSystemIndicesProvider, esArchiver: EsArchiverProvider, kibanaServer: KibanaServerProvider, retry: RetryService, diff --git a/test/common/services/security/system_indices_user.ts b/test/common/services/security/system_indices_user.ts index 46b4e0263a4ca..c1ab6b1e0abfa 100644 --- a/test/common/services/security/system_indices_user.ts +++ b/test/common/services/security/system_indices_user.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { systemIndicesSuperuser } from '@kbn/test'; +import { systemIndicesSuperuser, createEsClientForFtrConfig } from '@kbn/test'; import { FtrProviderContext } from '../../ftr_provider_context'; const SYSTEM_INDICES_SUPERUSER_ROLE = 'system_indices_superuser'; @@ -14,39 +14,46 @@ const SYSTEM_INDICES_SUPERUSER_ROLE = 'system_indices_superuser'; export async function createSystemIndicesUser(ctx: FtrProviderContext) { const log = ctx.getService('log'); const config = ctx.getService('config'); - const es = ctx.getService('esWithoutSystemIndices'); const enabled = !config .get('esTestCluster.serverArgs') .some((arg: string) => arg === 'xpack.security.enabled=false'); - if (enabled) { - log.debug('===============creating system indices role and user==============='); - - await es.security.putRole({ - name: SYSTEM_INDICES_SUPERUSER_ROLE, - cluster: ['all'], - indices: [ - { - names: ['*'], - privileges: ['all'], - allow_restricted_indices: true, - }, - ], - applications: [ - { - application: '*', - privileges: ['*'], - resources: ['*'], - }, - ], - run_as: ['*'], - }); - - await es.security.putUser({ - username: systemIndicesSuperuser.username, - password: systemIndicesSuperuser.password, - roles: [SYSTEM_INDICES_SUPERUSER_ROLE], - }); + if (!enabled) { + return; } + + const es = createEsClientForFtrConfig(config); + + log.debug('===============creating system indices role and user==============='); + + await es.security.putRole({ + name: SYSTEM_INDICES_SUPERUSER_ROLE, + refresh: 'wait_for', + cluster: ['all'], + indices: [ + { + names: ['*'], + privileges: ['all'], + allow_restricted_indices: true, + }, + ], + applications: [ + { + application: '*', + privileges: ['*'], + resources: ['*'], + }, + ], + run_as: ['*'], + }); + + await es.security.putUser({ + username: systemIndicesSuperuser.username, + refresh: 'wait_for', + password: systemIndicesSuperuser.password, + roles: [SYSTEM_INDICES_SUPERUSER_ROLE], + }); + + await es.close(); } diff --git a/x-pack/plugins/apm/ftr_e2e/cypress/plugins/index.ts b/x-pack/plugins/apm/ftr_e2e/cypress/plugins/index.ts index 90cf964691274..3235b257ae67e 100644 --- a/x-pack/plugins/apm/ftr_e2e/cypress/plugins/index.ts +++ b/x-pack/plugins/apm/ftr_e2e/cypress/plugins/index.ts @@ -4,10 +4,8 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import Fs from 'fs'; -import { Client, HttpConnection } from '@elastic/elasticsearch'; import { apm, createLogger, LogLevel } from '@elastic/apm-synthtrace'; -import { CA_CERT_PATH } from '@kbn/dev-utils'; +import { createEsClientForTesting } from '@kbn/test'; // *********************************************************** // This example plugins/index.ts can be used to load plugins @@ -29,15 +27,9 @@ const plugin: Cypress.PluginConfig = (on, config) => { // `on` is used to hook into various events Cypress emits // `config` is the resolved Cypress config - const node = config.env.ES_NODE; - const requestTimeout = config.env.ES_REQUEST_TIMEOUT; - const isCloud = config.env.TEST_CLOUD; - - const client = new Client({ - node, - requestTimeout, - Connection: HttpConnection, - ...(isCloud ? { tls: { ca: Fs.readFileSync(CA_CERT_PATH, 'utf-8') } } : {}), + const client = createEsClientForTesting({ + esUrl: config.env.ES_NODE, + requestTimeout: config.env.ES_REQUEST_TIMEOUT, }); const synthtraceEsClient = new apm.ApmSynthtraceEsClient( diff --git a/x-pack/test/rule_registry/common/services/cluster_client.ts b/x-pack/test/rule_registry/common/services/cluster_client.ts index 198919e2317fa..25c6228a7b529 100644 --- a/x-pack/test/rule_registry/common/services/cluster_client.ts +++ b/x-pack/test/rule_registry/common/services/cluster_client.ts @@ -5,10 +5,8 @@ * 2.0. */ -import { format as formatUrl } from 'url'; -import fs from 'fs'; -import { Client, HttpConnection, Transport } from '@elastic/elasticsearch'; -import { CA_CERT_PATH } from '@kbn/dev-utils'; +import { Client, Transport } from '@elastic/elasticsearch'; +import { createEsClientForFtrConfig } from '@kbn/test'; import type { TransportRequestParams, TransportRequestOptions, @@ -35,22 +33,7 @@ export function clusterClientProvider({ getService }: FtrProviderContext): Clien } } - if (process.env.TEST_CLOUD) { - return new Client({ - nodes: [formatUrl(config.get('servers.elasticsearch'))], - requestTimeout: config.get('timeouts.esRequestTimeout'), - Transport: KibanaTransport, - Connection: HttpConnection, - }); - } else { - return new Client({ - tls: { - ca: fs.readFileSync(CA_CERT_PATH, 'utf-8'), - }, - nodes: [formatUrl(config.get('servers.elasticsearch'))], - requestTimeout: config.get('timeouts.esRequestTimeout'), - Transport: KibanaTransport, - Connection: HttpConnection, - }); - } + return createEsClientForFtrConfig(config, { + Transport: KibanaTransport, + }); } From f743fc3d3cf54141be65bd8a7c4c7e51fce80ca5 Mon Sep 17 00:00:00 2001 From: spalger Date: Wed, 2 Feb 2022 13:11:39 -0700 Subject: [PATCH 5/8] maintain the alternate TEST_CLOUD detection logic for cypress tests --- packages/kbn-test/src/es/es_client_for_testing.ts | 10 ++++++++-- x-pack/plugins/apm/ftr_e2e/cypress/plugins/index.ts | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/kbn-test/src/es/es_client_for_testing.ts b/packages/kbn-test/src/es/es_client_for_testing.ts index 6469bec52cf76..084cb8d77eac5 100644 --- a/packages/kbn-test/src/es/es_client_for_testing.ts +++ b/packages/kbn-test/src/es/es_client_for_testing.ts @@ -19,6 +19,12 @@ export interface EsClientForTestingOptions extends Omit { const client = createEsClientForTesting({ esUrl: config.env.ES_NODE, requestTimeout: config.env.ES_REQUEST_TIMEOUT, + isCloud: !!config.env.TEST_CLOUD, }); const synthtraceEsClient = new apm.ApmSynthtraceEsClient( From 9ff30dcf54ee893a2d33a7d7342cc7401c8585bb Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Thu, 3 Feb 2022 12:40:25 +0100 Subject: [PATCH 6/8] Remove esSupertestWithoutAuth from spaces test config --- x-pack/test/spaces_api_integration/common/config.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/test/spaces_api_integration/common/config.ts b/x-pack/test/spaces_api_integration/common/config.ts index c175855ad7aee..c3315ae1007ec 100644 --- a/x-pack/test/spaces_api_integration/common/config.ts +++ b/x-pack/test/spaces_api_integration/common/config.ts @@ -34,7 +34,6 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions) services: { es: config.kibana.api.get('services.es'), esWithoutSystemIndices: config.kibana.api.get('services.esWithoutSystemIndices'), - esSupertestWithoutAuth: config.xpack.api.get('services.esSupertestWithoutAuth'), supertest: config.kibana.api.get('services.supertest'), supertestWithoutAuth: config.xpack.api.get('services.supertestWithoutAuth'), retry: config.xpack.api.get('services.retry'), From 9dcb689cdcf5e9a11a7f862d6c8fa4c9de309f06 Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Thu, 3 Feb 2022 12:42:24 +0100 Subject: [PATCH 7/8] Fix esSupertestWithoutAuth removal from config --- x-pack/test/spaces_api_integration/common/config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/spaces_api_integration/common/config.ts b/x-pack/test/spaces_api_integration/common/config.ts index c3315ae1007ec..5d135cd05605c 100644 --- a/x-pack/test/spaces_api_integration/common/config.ts +++ b/x-pack/test/spaces_api_integration/common/config.ts @@ -33,7 +33,7 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions) servers: config.xpack.api.get('servers'), services: { es: config.kibana.api.get('services.es'), - esWithoutSystemIndices: config.kibana.api.get('services.esWithoutSystemIndices'), + esSupertestWithoutAuth: config.xpack.api.get('services.esSupertestWithoutAuth'), supertest: config.kibana.api.get('services.supertest'), supertestWithoutAuth: config.xpack.api.get('services.supertestWithoutAuth'), retry: config.xpack.api.get('services.retry'), From 94a551273cb0df020194d2cddfc607c661aa8183 Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Thu, 3 Feb 2022 14:23:45 +0100 Subject: [PATCH 8/8] Re-add es service check before validating version --- .../src/functional_test_runner/functional_test_runner.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts b/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts index 5b4b41a456f1d..19a2a6d774a5a 100644 --- a/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts +++ b/packages/kbn-test/src/functional_test_runner/functional_test_runner.ts @@ -61,7 +61,9 @@ export class FunctionalTestRunner { ...readProviderSpec('PageObject', config.get('pageObjects')), ]); - await this.validateEsVersion(config); + if (providers.hasService('es')) { + await this.validateEsVersion(config); + } await providers.loadAll(); const customTestRunner = config.get('testRunner');