Skip to content

Commit 29aafc9

Browse files
rudolfkibanamachine
andcommitted
Elasticsearch: don't use url authentication for new client (#81564)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 26ff502 commit 29aafc9

2 files changed

Lines changed: 5 additions & 43 deletions

File tree

src/core/server/elasticsearch/client/client_config.test.ts

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -216,28 +216,14 @@ describe('parseClientOptions', () => {
216216
);
217217
});
218218

219-
it('adds auth to the nodes if both `username` and `password` are set', () => {
220-
let options = parseClientOptions(
219+
it('does not add auth to the nodes', () => {
220+
const options = parseClientOptions(
221221
createConfig({
222222
username: 'user',
223-
hosts: ['http://node-A:9200'],
224-
}),
225-
false
226-
);
227-
expect(options.nodes).toMatchInlineSnapshot(`
228-
Array [
229-
Object {
230-
"url": "http://node-a:9200/",
231-
},
232-
]
233-
`);
234-
235-
options = parseClientOptions(
236-
createConfig({
237223
password: 'pass',
238224
hosts: ['http://node-A:9200'],
239225
}),
240-
false
226+
true
241227
);
242228
expect(options.nodes).toMatchInlineSnapshot(`
243229
Array [
@@ -246,22 +232,6 @@ describe('parseClientOptions', () => {
246232
},
247233
]
248234
`);
249-
250-
options = parseClientOptions(
251-
createConfig({
252-
username: 'user',
253-
password: 'pass',
254-
hosts: ['http://node-A:9200'],
255-
}),
256-
false
257-
);
258-
expect(options.nodes).toMatchInlineSnapshot(`
259-
Array [
260-
Object {
261-
"url": "http://user:pass@node-a:9200/",
262-
},
263-
]
264-
`);
265235
});
266236
});
267237
describe('when `scoped` is true', () => {

src/core/server/elasticsearch/client/client_config.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export function parseClientOptions(
9393
};
9494
}
9595

96-
clientOptions.nodes = config.hosts.map((host) => convertHost(host, !scoped, config));
96+
clientOptions.nodes = config.hosts.map((host) => convertHost(host));
9797

9898
if (config.ssl) {
9999
clientOptions.ssl = generateSslConfig(
@@ -140,18 +140,10 @@ const generateSslConfig = (
140140
return ssl;
141141
};
142142

143-
const convertHost = (
144-
host: string,
145-
needAuth: boolean,
146-
{ username, password }: ElasticsearchClientConfig
147-
): NodeOptions => {
143+
const convertHost = (host: string): NodeOptions => {
148144
const url = new URL(host);
149145
const isHTTPS = url.protocol === 'https:';
150146
url.port = url.port || (isHTTPS ? '443' : '80');
151-
if (needAuth && username && password) {
152-
url.username = username;
153-
url.password = password;
154-
}
155147

156148
return {
157149
url,

0 commit comments

Comments
 (0)