Skip to content

Commit

Permalink
Disable Product check in @elastic/elasticsearch-js (#107642)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
afharo and kibanamachine authored Aug 5, 2021
1 parent 125a22c commit 74107a1
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
19 changes: 19 additions & 0 deletions packages/kbn-es/src/utils/native_realm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions src/core/server/elasticsearch/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions src/setup_node_env/exit_on_warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 74107a1

Please sign in to comment.