From cc10fc02f6346889b500df43595cacbdc483c86d Mon Sep 17 00:00:00 2001 From: Jonathan Budzenski Date: Mon, 17 Sep 2018 09:54:05 -0500 Subject: [PATCH] [es] set default port based on protocol (#21564) * [es] set default port based on protocol * explicit https/http check * url parses port as string * breaking changes docs * remove 9200 fallback --- docs/migration/migrate_7_0.asciidoc | 7 ++++++ .../lib/__tests__/parse_config.js | 23 +++++++++++++++++++ .../elasticsearch/lib/parse_config.js | 5 +++- 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/migration/migrate_7_0.asciidoc b/docs/migration/migrate_7_0.asciidoc index dbaf8ac7e8db..6df5f37f4dc8 100644 --- a/docs/migration/migrate_7_0.asciidoc +++ b/docs/migration/migrate_7_0.asciidoc @@ -65,3 +65,10 @@ considered unique based on its persistent UUID, which is written to the path.dat *Details:* Any timezone can now be specified by canonical id. *Impact:* The logging.useUTC flag will have to be replaced with a timezone id. If set to true the id is `UTC`. + +[float] +=== kibana.yml setting `elasticsearch.url` sets port based on protocol +*Details:* In prior versions of Kibana, if no port was specified in `elasticsearch.url` a default of 9200 was chosen. +The port is now protocol dependent: https ports will use 443, and http ports will use 80. + +*Impact:* If your `elasticsearch.url` was dependent on an unspecified port set to 9200, `:9200` will have to be appended to the url. diff --git a/src/core_plugins/elasticsearch/lib/__tests__/parse_config.js b/src/core_plugins/elasticsearch/lib/__tests__/parse_config.js index 7c79c4887b88..386f36f88777 100644 --- a/src/core_plugins/elasticsearch/lib/__tests__/parse_config.js +++ b/src/core_plugins/elasticsearch/lib/__tests__/parse_config.js @@ -123,6 +123,29 @@ describe('plugins/elasticsearch', function () { const config = parseConfig(serverConfig, { ignoreCertAndKey: true }); expect(config.ssl.passphrase).to.be(undefined); }); + + describe('port', () => { + it('uses the specified port', () => { + const config1 = parseConfig(serverConfig); + expect(config1.host.port).to.be('9200'); + + serverConfig.url = 'https://localhost:555'; + const config2 = parseConfig(serverConfig); + expect(config2.host.port).to.be('555'); + }); + + it('uses port 80 if http and no specified port', () => { + serverConfig.url = 'http://localhost'; + const config2 = parseConfig(serverConfig); + expect(config2.host.port).to.be('80'); + }); + + it ('uses port 443 if https and no specified port', () => { + serverConfig.url = 'https://localhost'; + const config2 = parseConfig(serverConfig); + expect(config2.host.port).to.be('443'); + }); + }); }); }); }); diff --git a/src/core_plugins/elasticsearch/lib/parse_config.js b/src/core_plugins/elasticsearch/lib/parse_config.js index cf792eea86cf..251033179c42 100644 --- a/src/core_plugins/elasticsearch/lib/parse_config.js +++ b/src/core_plugins/elasticsearch/lib/parse_config.js @@ -35,9 +35,12 @@ export function parseConfig(serverConfig = {}, { ignoreCertAndKey = false } = {} }; const uri = url.parse(serverConfig.url); + const httpsURI = uri.protocol === 'https:'; + const httpURI = uri.protocol === 'http:'; + const protocolPort = httpsURI && '443' || httpURI && '80'; config.host = { host: uri.hostname, - port: uri.port, + port: uri.port || protocolPort, protocol: uri.protocol, path: uri.pathname, query: uri.query,