-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Configurable headers for all elasticsearch requests #7996
Conversation
8e3a3e3
to
78b178d
Compare
Please add a section in |
How do you feel about combining Such a configuration setting would take an array of strings or objects. I think it would make it a tad more obvious to the person making the configuration what's going on, particularly if they would've otherwise inadvertently defined the same header in both settings at different points in time. |
They are really two different things though: one is the name of headers that should be proxied through from the clieny, the other is essentially hardcoded header names and values and is not exposed to the client at all.
|
Alright. I think then we should make it clear in the inline config
|
78b178d
to
906feb5
Compare
@ycombinator Good call. I updated the kibana.yml as well as docs. |
@@ -65,6 +65,10 @@ | |||
# headers, set this value to [] (an empty list). | |||
# elasticsearch.requestHeadersWhitelist: [ authorization ] | |||
|
|||
# Header names and values that are sent to Elasticsearch. Any custom headers cannot be | |||
# overwritten by client-side headers, regardless of requestHeadersWhitelist configuration. |
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: change requestHeadersWhitelist
to elasticsearch.requestHeadersWhitelist
for consistency.
906feb5
to
e076ed0
Compare
@ycombinator Updated |
import { isObject } from 'lodash'; | ||
|
||
export default function setHeaders(originalHeaders, newHeaders) { | ||
if (!isObject(originalHeaders)) { |
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.
Consider using isPlainObject
as it is a stricter check than isObject
.
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.
I considered that, but spread should work just fine with any enumerable object, so I couldn't think of a reason to only allow plain objects.
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.
I was thinking more that you probably don't want either of these to be arrays or functions, for example, right? I know they could be and the spread operator would work fine but, from a validation perspective for what this function does, you only want headers to be plain objects, right?
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.
I agree with @ycombinator here. If the intention is to verify that the arguments are compatible with the spread operator then so be it, but if the intention is to make sure that setHeaders()
is being used as intended, a more strict check is probably appropriate.
Someone sending an instance of RegExp
, or an array, is probably a mistake that would not be caught by these helpful checks.
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.
I'm sold.
Left a couple of comments in the code. Functionality LGTM, though: With only
|
can we see if this gets merged in time to backporting to the upcoming 4.x release as well? |
@kimchy The backporting is likely to take longer than the remaining time to get this merged, but that's the goal. |
const host = { | ||
host: uri.hostname, | ||
port: uri.port, | ||
protocol: uri.protocol.replace(':', ''), |
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.
replacing the ":" isn't necessary, and protocol will be null if the parsed uri is just //localhost
or something... just a thought
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.
Is the unnecessary :
a tested feature of the elasticsearch client?
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.
Yeah, https://github.com/elastic/elasticsearch-js/blob/master/test/unit/specs/host.js#L118-L119. Docs should be updated with that fact
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.
Awesome.
A new server-side configuration, elasticsearch.customHeaders, allows people to configure any number of custom headers that will get sent along to all requests to Elasticsearch that are made via the proxy or exposed client. This allows for advanced architectures that do things such as dynamic routing based on install-specific headers.
e076ed0
to
d00d177
Compare
@spalger @ycombinator All outstanding feedback should be addressed now. |
LGTM |
LGTM |
--------- **Commit 1:** Configurable headers for all elasticsearch requests A new server-side configuration, elasticsearch.customHeaders, allows people to configure any number of custom headers that will get sent along to all requests to Elasticsearch that are made via the proxy or exposed client. This allows for advanced architectures that do things such as dynamic routing based on install-specific headers. * Original sha: d00d177 * Authored by Court Ewing <court@epixa.com> on 2016-08-13T16:46:54Z
[backport] PR #7996 to 4.x - Configurable headers for all elasticsearch requests
Configurable headers for all elasticsearch requests Former-commit-id: bca4732
A new server-side configuration, elasticsearch.customHeaders, allows
people to configure any number of custom headers that will get sent
along to all requests to Elasticsearch that are made via the proxy or
exposed client.
This allows for advanced architectures that do things such as dynamic
routing based on install-specific headers.
Closes #7964