Skip to content

Commit

Permalink
Elasticsearch: don't use url authentication for new client (#81564)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
rudolf and kibanamachine authored Oct 26, 2020
1 parent 7508321 commit 3f91254
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 43 deletions.
36 changes: 3 additions & 33 deletions src/core/server/elasticsearch/client/client_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,28 +216,14 @@ describe('parseClientOptions', () => {
);
});

it('adds auth to the nodes if both `username` and `password` are set', () => {
let options = parseClientOptions(
it('does not add auth to the nodes', () => {
const options = parseClientOptions(
createConfig({
username: 'user',
hosts: ['http://node-A:9200'],
}),
false
);
expect(options.nodes).toMatchInlineSnapshot(`
Array [
Object {
"url": "http://node-a:9200/",
},
]
`);

options = parseClientOptions(
createConfig({
password: 'pass',
hosts: ['http://node-A:9200'],
}),
false
true
);
expect(options.nodes).toMatchInlineSnapshot(`
Array [
Expand All @@ -246,22 +232,6 @@ describe('parseClientOptions', () => {
},
]
`);

options = parseClientOptions(
createConfig({
username: 'user',
password: 'pass',
hosts: ['http://node-A:9200'],
}),
false
);
expect(options.nodes).toMatchInlineSnapshot(`
Array [
Object {
"url": "http://user:pass@node-a:9200/",
},
]
`);
});
});
describe('when `scoped` is true', () => {
Expand Down
12 changes: 2 additions & 10 deletions src/core/server/elasticsearch/client/client_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function parseClientOptions(
};
}

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

if (config.ssl) {
clientOptions.ssl = generateSslConfig(
Expand Down Expand Up @@ -140,18 +140,10 @@ const generateSslConfig = (
return ssl;
};

const convertHost = (
host: string,
needAuth: boolean,
{ username, password }: ElasticsearchClientConfig
): NodeOptions => {
const convertHost = (host: string): NodeOptions => {
const url = new URL(host);
const isHTTPS = url.protocol === 'https:';
url.port = url.port || (isHTTPS ? '443' : '80');
if (needAuth && username && password) {
url.username = username;
url.password = password;
}

return {
url,
Expand Down

0 comments on commit 3f91254

Please sign in to comment.