Remove support for setting server.host to '0' (breaking) (#87114)

This commit is contained in:
Thomas Watson 2021-01-06 13:12:01 +01:00 committed by GitHub
parent 65acd6dfc1
commit b0a66da8f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 29 additions and 60 deletions

View file

@ -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`

View file

@ -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",
]
`;

View file

@ -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();
});

View file

@ -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(

View file

@ -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' : ''}
`);

View file

@ -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',

View file

@ -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

View file

@ -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 レポート",

View file

@ -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 报告",