Skip to content

Commit

Permalink
Remove support for setting server.host to '0' (breaking) (#87114)
Browse files Browse the repository at this point in the history
  • Loading branch information
watson authored Jan 6, 2021
1 parent 65acd6d commit b0a66da
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 60 deletions.
2 changes: 1 addition & 1 deletion docs/setup/docker.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
9 changes: 9 additions & 0 deletions src/core/server/http/__snapshots__/http_config.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 9 additions & 10 deletions src/core/server/http/http_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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', () => {
Expand Down Expand Up @@ -304,17 +303,17 @@ describe('with compression', () => {

test('throws if invalid referrer whitelist', () => {
const httpSchema = config.schema;
const invalidHostnames = {
const nonEmptyArray = {
compression: {
referrerWhitelist: [invalidHostname],
referrerWhitelist: invalidHostnames,
},
};
const emptyArray = {
compression: {
referrerWhitelist: [],
},
};
expect(() => httpSchema.validate(invalidHostnames)).toThrowErrorMatchingSnapshot();
expect(() => httpSchema.validate(nonEmptyArray)).toThrowErrorMatchingSnapshot();
expect(() => httpSchema.validate(emptyArray)).toThrowErrorMatchingSnapshot();
});

Expand Down
13 changes: 6 additions & 7 deletions src/core/server/http/http_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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:/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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' : ''}
`);
Expand Down
22 changes: 0 additions & 22 deletions x-pack/plugins/reporting/server/config/create_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
20 changes: 3 additions & 17 deletions x-pack/plugins/reporting/server/config/create_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 レポート",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 报告",
Expand Down

0 comments on commit b0a66da

Please sign in to comment.