-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[server/rewriteBasePath] Support rewriting basePath requests #16724
Conversation
6768f58
to
1f8ae3a
Compare
💚 Build Succeeded |
1f8ae3a
to
3c07d08
Compare
💚 Build Succeeded |
config/kibana.yml
Outdated
# Specifies whether Kibana should rewrite requests that are prefixed with | ||
# `server.basePath` or require that they are rewritten by your reverse proxy. | ||
# This setting was effectively always `false` before Kibana 6.3 and will | ||
# default to `true` starting in Kibana 7.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: full stop after Kibana 7.0
?
docs/setup/settings.asciidoc
Outdated
the URLs generated by Kibana, your proxy is expected to remove the basePath value before forwarding requests | ||
to Kibana. This setting cannot end in a slash (`/`). | ||
`server.basePath:`:: Enables you to specify a path to mount Kibana at if you are running behind a proxy. Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath from requests it receives, and to prevent a deprecation warning at startup. This setting cannot end in a slash (`/`). | ||
`server.rewriteBasePath:`:: *Default: false* Specifies whether Kibana should rewrite requests that are prefixed with `server.basePath` or require that they are rewritten by your reverse proxy. This setting was effectively always `false` before Kibana 6.3 and will default to `true` starting in Kibana 7.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: full stop after Kibana 7.0
?
src/server/config/schema.js
Outdated
@@ -53,6 +53,11 @@ export default () => Joi.object({ | |||
autoListen: Joi.boolean().default(true), | |||
defaultRoute: Joi.string().default('/app/kibana').regex(/^\//, `start with a slash`), | |||
basePath: Joi.string().default('').allow('').regex(/(^$|^\/.*[^\/]$)/, `start with a slash, don't end with one`), | |||
rewriteBasePath: Joi.boolean().when('basePath', { | |||
is: Joi.valid(''), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can it be just is: ''
?
@@ -25,6 +25,18 @@ const savedObjectsIndexCheckTimeout = (settings, log) => { | |||
} | |||
}; | |||
|
|||
const rewriteBasePath = (settings, log) => { | |||
if (_.has(settings, 'server.basePath') && !_.has(settings, 'server.rewriteBasePath')) { | |||
log( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: is there any magic step (apart from defining deprecated keys in config obviously) I should make to see this warning? I don't see any deprecation warnings defined in this file for some reason :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha, yeah code lgtm
@@ -0,0 +1,188 @@ | |||
import { Server } from 'hapi'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: not sure what is our convention here, but shouldn't this test file have the same name as the file it tests?
|
||
describe('no base path', () => { | ||
it('/bar => 404', async () => { | ||
const server = createServer({ basePath: '', rewriteBasePath: false }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: maybe move const server = createServer({ basePath: '', rewriteBasePath: false });
to beforeEach
(for this suite and suites below)?
expect(resp.payload).to.be('resp:/'); | ||
}); | ||
|
||
it('/bar/ => 404', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: wrong description
expect(resp.payload).to.be('resp:/'); | ||
}); | ||
|
||
it('/bar/foo => 404', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: wrong description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
log( | ||
'Setting server.basePath without server.rewriteBasePath is deprecated until Kibana 7.0, ' + | ||
'when the default behavior of server.basePath will change and Kibana will start expecting ' + | ||
'that all requests start with the server.basePath rather expecting you to rewrite the ' + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, rather than expecting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also maybe a nit, I found it hard to follow this sentence. Would it be easier to read if it said,
You should set server.basePath along with server.rewriteBasePath. From Kibana 7.0 onward, server.rewriteBasePath defaults to true, even if not set; Kibana will start expecting that all requests start with the server.basePath rather than expecting you to rewrite the requests in your reverse proxy. Explicitly set server.rewriteBasePath to false to preserve the current behavior and silence this warning.
I would 👍 as it is, leaving it up to you, of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @archanid, I like your phasing in certain parts a lot more. I'll merge the two.
the URLs generated by Kibana, your proxy is expected to remove the basePath value before forwarding requests | ||
to Kibana. This setting cannot end in a slash (`/`). | ||
`server.basePath:`:: Enables you to specify a path to mount Kibana at if you are running behind a proxy. Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath from requests it receives, and to prevent a deprecation warning at startup. This setting cannot end in a slash (`/`). | ||
`server.rewriteBasePath:`:: *Default: false* Specifies whether Kibana should rewrite requests that are prefixed with `server.basePath` or require that they are rewritten by your reverse proxy. This setting was effectively always `false` before Kibana 6.3 and will default to `true` starting in Kibana 7.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++
@@ -22,12 +22,14 @@ export default class ClusterManager { | |||
this.basePathProxy = new BasePathProxy(this, settings); | |||
|
|||
optimizerArgv.push( | |||
`--server.basePath=${this.basePathProxy.basePath}` | |||
`--server.basePath=${this.basePathProxy.basePath}`, | |||
'--server.rewriteBasePath=true', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for trailing commas
const { error } = validate({ server: { rewriteBasePath: 'foo' } }); | ||
expect(error).to.have.property('details'); | ||
expect(error.details[0]).to.have.property('path', 'server.rewriteBasePath'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should there be a test case rejecting everything but strings for basePath
?
src/server/config/schema.js
Outdated
rewriteBasePath: Joi.boolean().when('basePath', { | ||
is: '', | ||
then: Joi.default(false).valid(false), | ||
otherwise: Joi.default(false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: trailing comma?
💚 Build Succeeded |
Looks like you have two LGTMs, so I'm leaving mine off--I haven't run the code yet. But code LGTM! |
💚 Build Succeeded |
…#16724) * [server/rewriteBasePath] add option to enable basePath rewriting * [server/rewriteBasePath/docs] end sentences with periods * [server/rewriteBasePath] simplify Joi schema a smidge * [server/rewriteBasePath] rename test file to match source * [server/rewriteBasePath] initialize server in before/after hooks * [server/rewriteBasePath] rephrase deprecation warning * [server/config/schema] verify that non-strings are not accepted for basePath * [server/config/schema] toss a trailing comma in there
…#16814) * [server/rewriteBasePath] add option to enable basePath rewriting * [server/rewriteBasePath/docs] end sentences with periods * [server/rewriteBasePath] simplify Joi schema a smidge * [server/rewriteBasePath] rename test file to match source * [server/rewriteBasePath] initialize server in before/after hooks * [server/rewriteBasePath] rephrase deprecation warning * [server/config/schema] verify that non-strings are not accepted for basePath * [server/config/schema] toss a trailing comma in there
6.3/6.x: ae0358a |
kibana/elastic#16724 added a basepath rewrite to the kibana server, and any route that doesn't go through hapi needs to deal with it explicitly
Fixes #9522
For some reason
server.basePath
expects the proxy sending the request to rewrite the request and strip thebasePath
. Unfortunately, users constantly encounter this expectation with surprise and many waste a good amount of time wondering why Kibana isn't responding properly.The new
server.rewriteBasePath
setting enables request rewriting in the Kibana server so that Kibana will respond as expected when it receives requests starting with theserver.baseRoute
. For BWCserver.rewriteBasePath
isfalse
by default, and settingserver.basePath
without settingserver.rewriteBasePath
will cause a deprecation warning to be logged.In 7.0
server.rewriteBasePath
will default totrue
and the deprecation warning will go away (a PR will follow this one to enable this behavior for 7.0).Release Note: Adds support for rewriting the
server.basePath
within in the Kibana server so you no longer need to rewrite urls in your reverse proxy. To control this behavior in Kibana 6.3+ addserver.rewriteBasePath: true|false
to your Kibana config file. If you are usingserver.basePath
and don't enable or disable theserver.rewriteBasePath
setting in your config file then a deprecation warning will be logged at startup because this setting will default totrue
in Kibana 7.0.