-
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
[alerting] Adds Action Type configuration support and whitelisting #44483
Merged
gmmorris
merged 23 commits into
elastic:master
from
gmmorris:actions/refactor-action-types
Sep 6, 2019
Merged
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6c48bc1
feat(action-types-refactor): pass kibana config to builtin action typ…
gmmorris 4113bd2
Merge branch 'master' into refactor-action-types
gmmorris c03104c
fix(webhook-whitelisting): whitelist support for webhook execution
gmmorris e46f616
fix(webhook-whitelisting): fixed missing type sig
gmmorris a12f7b9
Merge branch 'master' into actions/refactor-action-types
gmmorris ea4580f
refactor(webhook-whitelisting): removed the None option as we can use…
gmmorris f169c0a
refactor(webhook-whitelisting): unified whitelisting error message
gmmorris 4855bb0
refactor(webhook-whitelisting): curry valdiaiton to make it a little …
gmmorris cd87387
fix(webhook-whitelisting): removed unused import
gmmorris 057a6ec
fix(webhook-whitelisting): cleaned up messaging around webhook errors
gmmorris fad46ab
fix(webhook-whitelisting): fixed typing of mocks
gmmorris 7d8ed08
readme(webhook-whitelisting): added documentation of the Built-in-Act…
gmmorris a93f2f0
Merge branch 'master' into actions/refactor-action-types
gmmorris 7375745
refactor(webhook-whitelisting): extracted unsafeGet out of Result typ…
gmmorris d5baa69
refactor(webhook-whitelisting): removed usage of result in whitelisting
gmmorris ac21af9
doc(webhook-whitelisting): Updated documentation for whitelisting
gmmorris b277445
refactor(webhook-whitelisting): Whitelist Any url by specifying a * i…
gmmorris 2699dd3
doc(webhook-whitelisting): Updated documentation for actions Enabled …
gmmorris f73fb00
Merge branch 'master' into actions/refactor-action-types
gmmorris 481da21
Merge branch 'master' into actions/refactor-action-types
gmmorris 9a84b8b
refactor(webhook-whitelisting): Provide two ways of checking whitelis…
gmmorris 8a9ddc9
refactor(webhook-whitelisting): Removed whitelisting check in executo…
gmmorris 72f70b4
Merge branch 'master' into actions/refactor-action-types
gmmorris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
36 changes: 36 additions & 0 deletions
36
x-pack/legacy/plugins/actions/server/actions_config.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,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ActionsKibanaConfig, getActionsConfigurationUtilities } from './actions_config'; | ||
|
||
describe('isWhitelistedHostname', () => { | ||
test('returns true when "any" hostnames are allowed', () => { | ||
const config: ActionsKibanaConfig = { enabled: false, whitelistedHosts: 'any' }; | ||
expect( | ||
getActionsConfigurationUtilities(config).isWhitelistedHostname( | ||
'https://github.com/elastic/kibana' | ||
) | ||
).toEqual(true); | ||
}); | ||
|
||
test('returns false when the hostname in the requested uri is not in the whitelist', () => { | ||
const config: ActionsKibanaConfig = { enabled: false, whitelistedHosts: [] }; | ||
expect( | ||
getActionsConfigurationUtilities(config).isWhitelistedHostname( | ||
'https://github.com/elastic/kibana' | ||
) | ||
).toEqual(false); | ||
}); | ||
|
||
test('returns true when the hostname in the requested uri is in the whitelist', () => { | ||
const config: ActionsKibanaConfig = { enabled: false, whitelistedHosts: ['github.com'] }; | ||
expect( | ||
getActionsConfigurationUtilities(config).isWhitelistedHostname( | ||
'https://github.com/elastic/kibana' | ||
) | ||
).toEqual(true); | ||
}); | ||
}); |
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,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { fromNullable } from 'fp-ts/lib/Option'; | ||
import { URL } from 'url'; | ||
|
||
export interface ActionsKibanaConfig { | ||
enabled: boolean; | ||
whitelistedHosts: 'any' | 'none' | string[]; | ||
} | ||
|
||
export interface ActionsConfigurationUtilities { | ||
isWhitelistedHostname: (uri: string) => boolean; | ||
} | ||
|
||
export function getActionsConfigurationUtilities( | ||
config: ActionsKibanaConfig | ||
): ActionsConfigurationUtilities { | ||
return { | ||
isWhitelistedHostname(uri: string): boolean { | ||
switch (config.whitelistedHosts) { | ||
case 'none': | ||
return false; | ||
case 'any': | ||
return true; | ||
default: | ||
if (Array.isArray(config.whitelistedHosts)) { | ||
const urlHostname = new URL(uri).hostname; | ||
gmmorris marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return fromNullable( | ||
config.whitelistedHosts.find(hostname => hostname === urlHostname) | ||
).isSome(); | ||
} | ||
return false; | ||
} | ||
}, | ||
}; | ||
} |
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 think alternatives was here when the property was
string | string[]
? So, I think we can remove thealternatives()
andtry()
wrappers, just make it aJoi.array()
? Or maybe there's some joi sneakiness I don't yet understand :-)It clearly works now, so fine with shipping this way, create an issue / project card if it should be fixed later.
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, that's not needed anymore, I'll fix in a small PR next