Skip to content
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

Add security support for alerts and actions #41389

Merged
merged 64 commits into from
Aug 20, 2019

Conversation

mikecote
Copy link
Contributor

@mikecote mikecote commented Jul 17, 2019

This PR makes alerting and actions plugin work when security is enabled. It takes advantage of Elasticsearch API keys to run requests on behalf of a user at future times.

The PR also contains the following changes:

  • Api integration tests have been refactored to follow the x-pack/test/ui_capabilities style with different permutations. Right now it tests only for spaces & security enabled, future PRs will add spaces only and security only.
  • Executing an action will create a saved object action_task_params before scheduling a task. This saved object encrypts the API key so it can be passed from an alert to an action. (to support executing actions on behalf of the creator of the alert).
  • getServices now takes a request instead of custom parameters. This facilitates passing a real request and a fake request using API keys.
  • System ensures user can read the alert / action before running the task (code is within execute.js for actions and within getCreateTaskRunnerFunction for alerting).
  • Uses registerFeature within init to allow tests to try different permutations for a user using the savedObjectsClient within an executor (create alert but can't read dashboard. This allows us to confirm the savedObjectsClient is scoped to the user).
  • Converts alerting to use encrypted saved objects (to store API keys).
  • Capture a createdBy on the alert in future scenario we want to know who's API keys are with the saved object.
  • Fix a bug with task manager removing a task before disabling an alert. Unauthorized users were able to remove tasks by calling disable API.

Fixes: #40021
Fixes: #42959

@mikecote mikecote self-assigned this Jul 17, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-stack-services

@elasticmachine

This comment has been minimized.

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I could understand, LGTM

@elasticmachine

This comment has been minimized.

@pmuellr
Copy link
Member

pmuellr commented Aug 19, 2019

from #41389 (comment)

@kobelb
Are we at risk of leaking the secret values here if they happen to fail the validation?

@mikecote
The validators use @kbn/config-schema and from what I understand it doesn't leak data when validating. @pmuellr can you confirm that is the case?

We're fine for now, but I'm going to open an issue for config-schema because there is a case that leaks data, but shouldn't affect us now.

Generally config-schema only reports the type of the data (eg, "expecting a string but you passed a number"), but there's one case I've seen that does leak, and that's with schema.maybe(). It actually prints the object. In practice, we only use schema.maybe with strings, and so if you use a number where a string field is expected, it will print the number (eg, "expecting a string but you passed 42").

But I'd like to have a safer contract (never print values, always print types) with schema.config, so will open an issue ... actually I'm going to create a backlog card because I'll have to create a test case first ...

@elasticmachine

This comment has been minimized.

Copy link
Contributor

@bmcconaghy bmcconaghy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM.

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a bunch of comments; only critical one is the misspelled defualt string.

@elasticmachine

This comment has been minimized.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@bmcconaghy
Copy link
Contributor

Newer changes LGTM

@mikecote mikecote merged commit 5734f1c into elastic:master Aug 20, 2019
mikecote added a commit to mikecote/kibana that referenced this pull request Aug 20, 2019
* Initial work

* Cleanup add createAPIKey fn pt1

* Change getServices function to take request as parameter

* Use API key when executing alerts

* Revert task manager using encrypted saved objects

* Store fired actions within a saved object to encrypt API keys

* Fix fireActionId

* Cleanup code, fix type check error

* Add a type for getScopedSavedObjectsClient

* Fix getBasePath and spaceIdToNamespace functions

* Add safety check for API key and action

* Fix integration tests

* Fix broken jest tests

* Cleanup

* Rename generatedApiKey to apiKeyValue

* Ensure access to action record

* Cleanup

* Add unit tests

* Fix variable conflict

* Revert task manager specific code (no longer needed)

* Remove fire terminology

* Move tests to spaces and security folder

* Use ES Archiver to remove spaces (empty_kibana)

* Fix missing pieces

* Convert action tests to run per user

* Convert alerting tests to run per user

* Fix type check issue

* Fix failing test

* Add callCluster and savedObjectsClient authorization tests

* Make savedObjectsClient return 403 for authorization tests

* Cleanup

* Fix test failure

* Common function to get data from test index

* Create ObjectRemover

* Cleanup

* useApiKey now provided to functions instead of relying on condition of two strings

* Fix typo

* Make tests it(...) start with should

* Rename useApiKey to isSecurityEnabled

* Merge apiKeyId and apiKeyValue into one

* Update docs

* Use feature controls for list alert / action types API

* Remove need to add ! in TypeScript for required plugins

* Fix ESLint issue

* Include actions and alertTypeParams into AAD and genereate new API key on update

* Generate random id for API key name attribute

* Include interval in AAD

* Send pre-encoded string

* Fix ExecutorError

* Fix apiKey snapshot

* Fix 'default' typo

* De-compose apiKey

* Refresh API key when enabling / disabling an alert

* Add updatedBy

* Make unauthorized APIs return 404
mikecote added a commit that referenced this pull request Aug 20, 2019
* Initial work

* Cleanup add createAPIKey fn pt1

* Change getServices function to take request as parameter

* Use API key when executing alerts

* Revert task manager using encrypted saved objects

* Store fired actions within a saved object to encrypt API keys

* Fix fireActionId

* Cleanup code, fix type check error

* Add a type for getScopedSavedObjectsClient

* Fix getBasePath and spaceIdToNamespace functions

* Add safety check for API key and action

* Fix integration tests

* Fix broken jest tests

* Cleanup

* Rename generatedApiKey to apiKeyValue

* Ensure access to action record

* Cleanup

* Add unit tests

* Fix variable conflict

* Revert task manager specific code (no longer needed)

* Remove fire terminology

* Move tests to spaces and security folder

* Use ES Archiver to remove spaces (empty_kibana)

* Fix missing pieces

* Convert action tests to run per user

* Convert alerting tests to run per user

* Fix type check issue

* Fix failing test

* Add callCluster and savedObjectsClient authorization tests

* Make savedObjectsClient return 403 for authorization tests

* Cleanup

* Fix test failure

* Common function to get data from test index

* Create ObjectRemover

* Cleanup

* useApiKey now provided to functions instead of relying on condition of two strings

* Fix typo

* Make tests it(...) start with should

* Rename useApiKey to isSecurityEnabled

* Merge apiKeyId and apiKeyValue into one

* Update docs

* Use feature controls for list alert / action types API

* Remove need to add ! in TypeScript for required plugins

* Fix ESLint issue

* Include actions and alertTypeParams into AAD and genereate new API key on update

* Generate random id for API key name attribute

* Include interval in AAD

* Send pre-encoded string

* Fix ExecutorError

* Fix apiKey snapshot

* Fix 'default' typo

* De-compose apiKey

* Refresh API key when enabling / disabling an alert

* Add updatedBy

* Make unauthorized APIs return 404
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes review v7.4.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alerts to pass an API key to actions it fires Secured queries using Elasticsearch tokens
5 participants