diff --git a/docs/setup/docker.asciidoc b/docs/setup/docker.asciidoc index 0dee112d15e864..5d79a81e0aa91b 100644 --- a/docs/setup/docker.asciidoc +++ b/docs/setup/docker.asciidoc @@ -129,7 +129,7 @@ images: [horizontal] `server.name`:: `kibana` -`server.host`:: `"0"` +`server.host`:: `"0.0.0.0"` `elasticsearch.hosts`:: `http://elasticsearch:9200` `monitoring.ui.container.elasticsearch.enabled`:: `true` diff --git a/src/core/server/http/__snapshots__/http_config.test.ts.snap b/src/core/server/http/__snapshots__/http_config.test.ts.snap index 9b667f888771e1..4545396c27b5e9 100644 --- a/src/core/server/http/__snapshots__/http_config.test.ts.snap +++ b/src/core/server/http/__snapshots__/http_config.test.ts.snap @@ -24,6 +24,12 @@ Object { } `; +exports[`accepts valid hostnames 5`] = ` +Object { + "host": "0.0.0.0", +} +`; + exports[`basePath throws if appends a slash 1`] = `"[basePath]: must start with a slash, don't end with one"`; exports[`basePath throws if is an empty string 1`] = `"[basePath]: must start with a slash, don't end with one"`; @@ -105,6 +111,8 @@ Object { exports[`throws if invalid hostname 1`] = `"[host]: value must be a valid hostname (see RFC 1123)."`; +exports[`throws if invalid hostname 2`] = `"[host]: value 0 is not a valid hostname (use \\"0.0.0.0\\" to bind to all interfaces)"`; + exports[`with TLS throws if TLS is enabled but \`redirectHttpFromPort\` is equal to \`port\` 1`] = `"Kibana does not accept http traffic to [port] when ssl is enabled (only https is allowed), so [ssl.redirectHttpFromPort] cannot be configured to the same value. Both are [1234]."`; exports[`with compression accepts valid referrer whitelist 1`] = ` @@ -113,6 +121,7 @@ Array [ "8.8.8.8", "::1", "localhost", + "0.0.0.0", ] `; diff --git a/src/core/server/http/http_config.test.ts b/src/core/server/http/http_config.test.ts index b71763e8a2e14a..b1b2ba5b295a75 100644 --- a/src/core/server/http/http_config.test.ts +++ b/src/core/server/http/http_config.test.ts @@ -22,8 +22,8 @@ import { config, HttpConfig } from './http_config'; import { CspConfig } from '../csp'; import { ExternalUrlConfig } from '../external_url'; -const validHostnames = ['www.example.com', '8.8.8.8', '::1', 'localhost']; -const invalidHostname = 'asdf$%^'; +const validHostnames = ['www.example.com', '8.8.8.8', '::1', 'localhost', '0.0.0.0']; +const invalidHostnames = ['asdf$%^', '0']; jest.mock('os', () => { const original = jest.requireActual('os'); @@ -48,11 +48,10 @@ test('accepts valid hostnames', () => { }); test('throws if invalid hostname', () => { - const httpSchema = config.schema; - const obj = { - host: invalidHostname, - }; - expect(() => httpSchema.validate(obj)).toThrowErrorMatchingSnapshot(); + for (const host of invalidHostnames) { + const httpSchema = config.schema; + expect(() => httpSchema.validate({ host })).toThrowErrorMatchingSnapshot(); + } }); describe('requestId', () => { @@ -304,9 +303,9 @@ describe('with compression', () => { test('throws if invalid referrer whitelist', () => { const httpSchema = config.schema; - const invalidHostnames = { + const nonEmptyArray = { compression: { - referrerWhitelist: [invalidHostname], + referrerWhitelist: invalidHostnames, }, }; const emptyArray = { @@ -314,7 +313,7 @@ describe('with compression', () => { referrerWhitelist: [], }, }; - expect(() => httpSchema.validate(invalidHostnames)).toThrowErrorMatchingSnapshot(); + expect(() => httpSchema.validate(nonEmptyArray)).toThrowErrorMatchingSnapshot(); expect(() => httpSchema.validate(emptyArray)).toThrowErrorMatchingSnapshot(); }); diff --git a/src/core/server/http/http_config.ts b/src/core/server/http/http_config.ts index 61a9b5f04b23f8..aa4db6f88d3387 100644 --- a/src/core/server/http/http_config.ts +++ b/src/core/server/http/http_config.ts @@ -73,6 +73,11 @@ export const config = { host: schema.string({ defaultValue: 'localhost', hostname: true, + validate(value) { + if (value === '0') { + return 'value 0 is not a valid hostname (use "0.0.0.0" to bind to all interfaces)'; + } + }, }), maxPayload: schema.byteSize({ defaultValue: '1048576b', @@ -195,13 +200,7 @@ export class HttpConfig { rawExternalUrlConfig: ExternalUrlConfig ) { this.autoListen = rawHttpConfig.autoListen; - // TODO: Consider dropping support for '0' in v8.0.0. This value is passed - // to hapi, which validates it. Prior to hapi v20, '0' was considered a - // valid host, however the validation logic internally in hapi was - // re-written for v20 and hapi no longer considers '0' a valid host. For - // details, see: - // https://github.com/elastic/kibana/issues/86716#issuecomment-749623781 - this.host = rawHttpConfig.host === '0' ? '0.0.0.0' : rawHttpConfig.host; + this.host = rawHttpConfig.host; this.port = rawHttpConfig.port; this.cors = rawHttpConfig.cors; this.customResponseHeaders = Object.entries(rawHttpConfig.customResponseHeaders ?? {}).reduce( diff --git a/src/dev/build/tasks/os_packages/docker_generator/templates/kibana_yml.template.ts b/src/dev/build/tasks/os_packages/docker_generator/templates/kibana_yml.template.ts index 240ec6f4e9326a..a849c6bf4992d1 100644 --- a/src/dev/build/tasks/os_packages/docker_generator/templates/kibana_yml.template.ts +++ b/src/dev/build/tasks/os_packages/docker_generator/templates/kibana_yml.template.ts @@ -29,7 +29,7 @@ function generator({ imageFlavor }: TemplateContext) { # Default Kibana configuration for docker target server.name: kibana - server.host: "0" + server.host: "0.0.0.0" elasticsearch.hosts: [ "http://elasticsearch:9200" ] ${!imageFlavor ? 'monitoring.ui.container.elasticsearch.enabled: true' : ''} `); diff --git a/x-pack/plugins/reporting/server/config/create_config.test.ts b/x-pack/plugins/reporting/server/config/create_config.test.ts index 154a05742d747a..9e533d97585213 100644 --- a/x-pack/plugins/reporting/server/config/create_config.test.ts +++ b/x-pack/plugins/reporting/server/config/create_config.test.ts @@ -117,28 +117,6 @@ describe('Reporting server createConfig$', () => { expect((mockLogger.warn as any).mock.calls.length).toBe(0); }); - it('show warning when kibanaServer.hostName === "0"', async () => { - mockInitContext = makeMockInitContext({ - encryptionKey: 'aaaaaaaaaaaaabbbbbbbbbbbbaaaaaaaaa', - kibanaServer: { hostname: '0' }, - }); - const mockConfig$: any = mockInitContext.config.create(); - const result = await createConfig$(mockCoreSetup, mockConfig$, mockLogger).toPromise(); - - expect(result.kibanaServer).toMatchInlineSnapshot(` - Object { - "hostname": "0.0.0.0", - "port": 5601, - "protocol": "http", - } - `); - expect((mockLogger.warn as any).mock.calls.length).toBe(1); - expect((mockLogger.warn as any).mock.calls[0]).toMatchObject([ - `Found 'server.host: \"0\"' in Kibana configuration. This is incompatible with Reporting. To enable Reporting to work, 'xpack.reporting.kibanaServer.hostname: 0.0.0.0' is being automatically ` + - `to the configuration. You can change the setting to 'server.host: 0.0.0.0' or add 'xpack.reporting.kibanaServer.hostname: 0.0.0.0' in kibana.yml to prevent this message.`, - ]); - }); - it('uses user-provided disableSandbox: false', async () => { mockInitContext = makeMockInitContext({ encryptionKey: '888888888888888888888888888888888', diff --git a/x-pack/plugins/reporting/server/config/create_config.ts b/x-pack/plugins/reporting/server/config/create_config.ts index 2e07478c1663c8..1f3d00540e81c3 100644 --- a/x-pack/plugins/reporting/server/config/create_config.ts +++ b/x-pack/plugins/reporting/server/config/create_config.ts @@ -42,26 +42,12 @@ export function createConfig$( } const { kibanaServer: reportingServer } = config; const serverInfo = core.http.getServerInfo(); - // kibanaServer.hostname, default to server.host, don't allow "0" - let kibanaServerHostname = reportingServer.hostname + // kibanaServer.hostname, default to server.host + const kibanaServerHostname = reportingServer.hostname ? reportingServer.hostname : serverInfo.hostname; - if (kibanaServerHostname === '0') { - logger.warn( - i18n.translate('xpack.reporting.serverConfig.invalidServerHostname', { - defaultMessage: - `Found 'server.host: "0"' in Kibana configuration. This is incompatible with Reporting. ` + - `To enable Reporting to work, '{configKey}: 0.0.0.0' is being automatically to the configuration. ` + - `You can change the setting to 'server.host: 0.0.0.0' or add '{configKey}: 0.0.0.0' in kibana.yml to prevent this message.`, - values: { configKey: 'xpack.reporting.kibanaServer.hostname' }, - }) - ); - kibanaServerHostname = '0.0.0.0'; - } // kibanaServer.port, default to server.port - const kibanaServerPort = reportingServer.port - ? reportingServer.port - : serverInfo.port; // prettier-ignore + const kibanaServerPort = reportingServer.port ? reportingServer.port : serverInfo.port; // kibanaServer.protocol, default to server.protocol const kibanaServerProtocol = reportingServer.protocol ? reportingServer.protocol diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 0411c2448bbfc1..c340914b1d39c2 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -15270,7 +15270,6 @@ "xpack.reporting.screenCapturePanelContent.optimizeForPrintingLabel": "印刷用に最適化", "xpack.reporting.serverConfig.autoSet.sandboxDisabled": "Chromiumサンドボックスは保護が強化されていますが、{osName} OSではサポートされていません。自動的に'{configKey}: true'を設定しています。", "xpack.reporting.serverConfig.autoSet.sandboxEnabled": "Chromiumサンドボックスは保護が強化され、{osName} OSでサポートされています。自動的にChromiumサンドボックスを有効にしています。", - "xpack.reporting.serverConfig.invalidServerHostname": "Kibana構成で「server.host:\"0\"」が見つかりました。これはReportingと互換性がありません。レポートが動作するように、「{configKey}:0.0.0.0」が自動的に構成になります。設定を「server.host:0.0.0.0」に変更するか、kibana.ymlに「{configKey}:0.0.0.0'」を追加して、このメッセージが表示されないようにすることができます。", "xpack.reporting.serverConfig.osDetected": "OSは'{osName}'で実行しています", "xpack.reporting.serverConfig.randomEncryptionKey": "xpack.reporting.encryptionKeyのランダムキーを生成しています。再起動時にセッションが無効にならないようにするには、kibana.ymlでxpack.reporting.encryptionKeyを設定してください。", "xpack.reporting.shareContextMenu.csvReportsButtonLabel": "CSV レポート", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index b045fadfea6808..5739440c20435d 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -15287,7 +15287,6 @@ "xpack.reporting.screenCapturePanelContent.optimizeForPrintingLabel": "打印优化", "xpack.reporting.serverConfig.autoSet.sandboxDisabled": "Chromium 沙盒提供附加保护层,但不受 {osName} OS 支持。自动设置“{configKey}: true”。", "xpack.reporting.serverConfig.autoSet.sandboxEnabled": "Chromium 沙盒提供附加保护层,受 {osName} OS 支持。自动启用 Chromium 沙盒。", - "xpack.reporting.serverConfig.invalidServerHostname": "在 Kibana 配置中找到“server.host:\"0\"”。其不与 Reporting 兼容。要使 Reporting 运行,“{configKey}:0.0.0.0”将自动添加到配置中。可以将该设置更改为“server.host:0.0.0.0”或在 kibana.yml 中添加“{configKey}:0.0.0.0”,以阻止此消息。", "xpack.reporting.serverConfig.osDetected": "正在以下 OS 上运行:“{osName}”", "xpack.reporting.serverConfig.randomEncryptionKey": "正在为 xpack.reporting.encryptionKey 生成随机密钥。要防止会话在重新启动时失效,请在 kibana.yml 中设置 xpack.reporting.encryptionKey", "xpack.reporting.shareContextMenu.csvReportsButtonLabel": "CSV 报告",