Disable Product check in @elastic/elasticsearch-js (#107642)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Alejandro Fernández Haro 2021-08-05 20:55:41 +01:00 committed by GitHub
parent 125a22c233
commit 74107a1fbd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 56 additions and 5 deletions

View file

@ -97,7 +97,7 @@
"@elastic/apm-rum-react": "^1.2.11",
"@elastic/charts": "33.1.0",
"@elastic/datemath": "link:bazel-bin/packages/elastic-datemath",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.13",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@^8.0.0-canary.14",
"@elastic/ems-client": "7.14.0",
"@elastic/eui": "36.1.0",
"@elastic/filesaver": "1.1.2",

View file

@ -11,6 +11,23 @@ const chalk = require('chalk');
const { log: defaultLog } = require('./log');
/**
* Hack to skip the Product Check performed by the Elasticsearch-js client.
* We noticed a couple of bugs that may need to be fixed before taking full
* advantage of this feature.
*
* The bugs are detailed in this issue: https://github.com/elastic/kibana/issues/105557
*
* The hack is copied from the test/utils in the elasticsearch-js repo
* (https://github.com/elastic/elasticsearch-js/blob/master/test/utils/index.js#L45-L56)
*/
function skipProductCheck(client) {
const tSymbol = Object.getOwnPropertySymbols(client.transport || client).filter(
(symbol) => symbol.description === 'product check'
)[0];
(client.transport || client)[tSymbol] = 2;
}
exports.NativeRealm = class NativeRealm {
constructor({ elasticPassword, port, log = defaultLog, ssl = false, caCert }) {
this._client = new Client({
@ -22,6 +39,8 @@ exports.NativeRealm = class NativeRealm {
}
: undefined,
});
// TODO: @elastic/es-clients I had to disable the product check here because the client is getting 404 while ES is initializing, but the requests here auto retry them.
skipProductCheck(this._client);
this._elasticPassword = elasticPassword;
this._log = log;
}

View file

@ -50,6 +50,12 @@ export const configureClient = (
const client = new Client({ ...clientOptions, Transport: KibanaTransport });
addLogging(client, logger.get('query', type));
// ------------------------------------------------------------------------ //
// Hack to disable the "Product check" while the bugs in //
// https://github.com/elastic/kibana/issues/105557 are handled. //
skipProductCheck(client);
// ------------------------------------------------------------------------ //
return client;
};
@ -112,3 +118,21 @@ const addLogging = (client: Client, logger: Logger) => {
}
});
};
/**
* Hack to skip the Product Check performed by the Elasticsearch-js client.
* We noticed a couple of bugs that may need to be fixed before taking full
* advantage of this feature.
*
* The bugs are detailed in this issue: https://github.com/elastic/kibana/issues/105557
*
* The hack is copied from the test/utils in the elasticsearch-js repo
* (https://github.com/elastic/elasticsearch-js/blob/master/test/utils/index.js#L45-L56)
*/
function skipProductCheck(client: Client) {
const tSymbol = Object.getOwnPropertySymbols(client.transport || client).filter(
(symbol) => symbol.description === 'product check'
)[0];
// @ts-expect-error `tSymbol` is missing in the index signature of Transport
(client.transport || client)[tSymbol] = 2;
}

View file

@ -29,6 +29,14 @@ var IGNORE_WARNINGS = [
file: '/node_modules/supertest/node_modules/superagent/lib/node/index.js',
line: 418,
},
{
// TODO: @elastic/es-clients - The new client will attempt a Product check and it will `process.emitWarning`
// that the security features are blocking such check.
// Such emit is causing Node.js to crash unless we explicitly catch it.
// We need to discard that warning
message:
'The client is unable to verify that the server is Elasticsearch due to security privileges on the server side. Some functionality may not be compatible if the server is running an unsupported product.',
},
];
if (process.noProcessWarnings !== true) {

View file

@ -1433,10 +1433,10 @@
dependencies:
"@elastic/ecs-helpers" "^1.1.0"
"@elastic/elasticsearch@npm:@elastic/elasticsearch-canary@^8.0.0-canary.13":
version "8.0.0-canary.13"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch-canary/-/elasticsearch-canary-8.0.0-canary.13.tgz#bb5c71440411703364701eabae7960c8899d2012"
integrity sha512-QbwwpOqnarG469fIJw9VL+PTs4WLHl5M6OsEZA3IqQOlMfjtXEMdC0dRQoVz8UCcDW1rp+r87QPDkMneCFxFKg==
"@elastic/elasticsearch@npm:@elastic/elasticsearch-canary@^8.0.0-canary.14":
version "8.0.0-canary.14"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch-canary/-/elasticsearch-canary-8.0.0-canary.14.tgz#36f0dedc5e02c43a2fd1ceb86e273e29c603f1fb"
integrity sha512-ZwyjT16581grvJLgsbkT9tzy49g5E2qYQ05mS41Db98Kqe0sYZsm25eHGuV7U9DqJo5LuV0TTTs3rhsaqL5Mhw==
dependencies:
debug "^4.3.1"
hpagent "^0.1.1"