-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change all connectors to use the basic auth header instead of the `au…
…th` property of `axios` (#183162) ## Summary Fixes: #182391 ## Framework changes - Utils to construct basic header from username and password: [`fad6bde` (#183162)](fad6bde), [`b10d103` (#183162)](b10d103) - Automatically convert `auth` to basic auth header in the sub-actions framework: [`ee27353` (#183162)](ee27353) - Automatically convert `auth` to basic auth header in axios utils: [`94753a7` (#183162)](94753a7) ## Jira Commit: [`c366163` (#183162)](c366163) ## All ServiceNow connectors Commit: [`4324d93` (#183162)](4324d93) ## IBM Resilient IBM Resilient already uses the basic auth headers. PR #180561 added this functionality. The connector was manually tested when reviewing the PR. In [`7d9edab` (#183162)](7d9edab) I updated the connector to use the new util function. ## Webhook Commit: [`1a62c77` (#183162)](1a62c77) ## Cases webhook Commit: [`104f881` (#183162)](104f881) ## xMatters Commit: [`ea7be2b` (#183162)](ea7be2b) ## Connectors that do not use the `axios` `auth` property - D3Security - Email - Microsoft Teams - OpenAI - Opsgenie - PagerDuty - Sentinel One - Slack - Slack API - Swimlane - Tines - Torq ### Checklist Delete any items that are not applicable to this PR. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed ### Risk Matrix Delete this section if it is not applicable to this PR. Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release. When forming the risk matrix, consider some of the following examples and how they may potentially impact the change: | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Connectors not working correctly | Low | High | Unit test and manual testing of all connectors affected | ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: “jeramysoucy” <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
621c5bc
commit 4b7d014
Showing
22 changed files
with
361 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
x-pack/plugins/actions/server/lib/get_basic_auth_header.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { combineHeadersWithBasicAuthHeader, getBasicAuthHeader } from './get_basic_auth_header'; | ||
|
||
describe('get_basic_auth_header', () => { | ||
describe('getBasicAuthHeader', () => { | ||
it('constructs the basic auth header correctly', () => { | ||
expect(getBasicAuthHeader({ username: 'test', password: 'foo' })).toEqual({ | ||
Authorization: `Basic ${Buffer.from('test:foo').toString('base64')}`, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('combineHeadersWithBasicAuthHeader', () => { | ||
it('constructs the basic auth header correctly', () => { | ||
expect(combineHeadersWithBasicAuthHeader({ username: 'test', password: 'foo' })).toEqual({ | ||
Authorization: `Basic ${Buffer.from('test:foo').toString('base64')}`, | ||
}); | ||
}); | ||
|
||
it('adds extra headers correctly', () => { | ||
expect( | ||
combineHeadersWithBasicAuthHeader({ | ||
username: 'test', | ||
password: 'foo', | ||
headers: { 'X-token': 'foo' }, | ||
}) | ||
).toEqual({ | ||
Authorization: `Basic ${Buffer.from('test:foo').toString('base64')}`, | ||
'X-token': 'foo', | ||
}); | ||
}); | ||
|
||
it('does not overrides the auth header if provided', () => { | ||
expect( | ||
combineHeadersWithBasicAuthHeader({ | ||
username: 'test', | ||
password: 'foo', | ||
headers: { Authorization: 'Bearer my_token' }, | ||
}) | ||
).toEqual({ | ||
Authorization: 'Bearer my_token', | ||
}); | ||
}); | ||
|
||
it('returns only the headers if auth is undefined', () => { | ||
expect( | ||
combineHeadersWithBasicAuthHeader({ | ||
headers: { 'X-token': 'foo' }, | ||
}) | ||
).toEqual({ | ||
'X-token': 'foo', | ||
}); | ||
}); | ||
|
||
it('returns undefined with no arguments', () => { | ||
expect(combineHeadersWithBasicAuthHeader()).toEqual(undefined); | ||
}); | ||
|
||
it('returns undefined when headers are null', () => { | ||
expect(combineHeadersWithBasicAuthHeader({ headers: null })).toEqual(undefined); | ||
}); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
x-pack/plugins/actions/server/lib/get_basic_auth_header.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { AxiosHeaderValue } from 'axios'; | ||
|
||
interface GetBasicAuthHeaderArgs { | ||
username: string; | ||
password: string; | ||
} | ||
|
||
type CombineHeadersWithBasicAuthHeader = Partial<GetBasicAuthHeaderArgs> & { | ||
headers?: Record<string, AxiosHeaderValue> | null; | ||
}; | ||
|
||
export const getBasicAuthHeader = ({ username, password }: GetBasicAuthHeaderArgs) => { | ||
const header = `Basic ${Buffer.from(`${username}:${password}`).toString('base64')}`; | ||
|
||
return { Authorization: header }; | ||
}; | ||
|
||
export const combineHeadersWithBasicAuthHeader = ({ | ||
username, | ||
password, | ||
headers, | ||
}: CombineHeadersWithBasicAuthHeader = {}) => { | ||
return username != null && password != null | ||
? { ...getBasicAuthHeader({ username, password }), ...headers } | ||
: headers ?? undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.