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

[SIEM][Detections] Allow synchronous rule actions to be updated via PATCH #67914

Merged
merged 4 commits into from
Jun 2, 2020

Conversation

rylnd
Copy link
Contributor

@rylnd rylnd commented Jun 1, 2020

Summary

Fixes #67815.

Notes

  • I added regression tests to the patchRules function. Testing this at higher levels isn't currently possible due to the way that we generate rule responses: the actions that exist on the rule SO itself (i.e. synchronous actions executed during rule execution) are not part of the rule output and are masked in those situations by the separate ruleActions SO (which is used for asynchronous actions). However, we always create a separate ruleActions SO for these synchronous actions even though it is never used, which is what made this bug so confusing: everything in the UI and API tell you that the actions have been updated, which is partially true: one version of the actions has been updated, but it's not the version that's actually used.

As a visualization:

  • Rule with synchronous Actions:
    • what's executed: rule.actions
    • what's displayed: ruleActions
  • Rule with asynchronous Actions:
    • what's executed: ruleActions
    • what's displayed: ruleActions

This PR updates things so that both rule.actions and ruleActions are updated together, but it does not address the above disparity. I'm happy to create an issue to discuss removing rule.actions or other potential solutions to the above.

Checklist

For maintainers

rylnd added 2 commits June 1, 2020 17:12
This method was typed to accept actions, but it was not doing anything
with them. This was mainly a "bug by omission" so I'm simply adding
unit tests for regression purposes.
Now that patchRules uses this field, we simply need to pass it.
@rylnd rylnd added Team:SIEM v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.8.0 v7.7.2 labels Jun 1, 2020
@rylnd rylnd self-assigned this Jun 1, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@rylnd rylnd marked this pull request as ready for review June 1, 2020 22:52
@rylnd rylnd requested review from a team as code owners June 1, 2020 22:52
@rylnd rylnd requested a review from spong June 2, 2020 00:32
Copy link
Member

@spong spong left a comment

Choose a reason for hiding this comment

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

Checked out and verified fix locally as follows:

  • Created new rule with synchronous slack action (and default action message)
  • Created ./rules/patches/update_action.json patch with updated action message
  • Used CLI scripts to update action: ./patch_rule.sh ./rules/patches/update_action.json
  • Verified UI/API returned action with updated message
  • Verified in subsequent executions that the action fired with the updated message

Many thanks for the sleuthing and detailed description in both the issue and fix @rylnd! And thanks also to Mercwri over on the community forums for finding this one, appreciate the time! 🙂

LGTM! 👍 I'd say this fix is low-impact enough to make it into 7.8, and 7.7.2 as well. As for the disparity between synch and asynch actions, let's open an issue for tracking, and continue our discussion from earlier today with the team to see what we can do to improve this area of the codebase.

@rylnd
Copy link
Contributor Author

rylnd commented Jun 2, 2020

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@spong spong added the v7.9.0 label Jun 2, 2020
@rylnd rylnd merged commit 332a92d into elastic:master Jun 2, 2020
@rylnd rylnd deleted the patch_actions_bugfix branch June 2, 2020 16:57
rylnd added a commit to rylnd/kibana that referenced this pull request Jun 2, 2020
…ATCH (elastic#67914)

* Update synchronous actions in patchRules

This method was typed to accept actions, but it was not doing anything
with them. This was mainly a "bug by omission" so I'm simply adding
unit tests for regression purposes.

* Allow synchronous actions to be patched either individually or in bulk

Now that patchRules uses this field, we simply need to pass it.

Co-authored-by: Garrett Spong <spong@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/siem/server/lib/detection_engine/rules/patch_rules.ts
rylnd added a commit that referenced this pull request Jun 2, 2020
…ATCH (#67914) (#67990)

* Update synchronous actions in patchRules

This method was typed to accept actions, but it was not doing anything
with them. This was mainly a "bug by omission" so I'm simply adding
unit tests for regression purposes.

* Allow synchronous actions to be patched either individually or in bulk

Now that patchRules uses this field, we simply need to pass it.

Co-authored-by: Garrett Spong <spong@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/siem/server/lib/detection_engine/rules/patch_rules.ts
rylnd added a commit that referenced this pull request Jun 2, 2020
…ATCH (#67914) (#67988)

* Update synchronous actions in patchRules

This method was typed to accept actions, but it was not doing anything
with them. This was mainly a "bug by omission" so I'm simply adding
unit tests for regression purposes.

* Allow synchronous actions to be patched either individually or in bulk

Now that patchRules uses this field, we simply need to pass it.

Co-authored-by: Garrett Spong <spong@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Garrett Spong <spong@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
rylnd added a commit to rylnd/kibana that referenced this pull request Jun 9, 2020
…ATCH (elastic#67914)

* Update synchronous actions in patchRules

This method was typed to accept actions, but it was not doing anything
with them. This was mainly a "bug by omission" so I'm simply adding
unit tests for regression purposes.

* Allow synchronous actions to be patched either individually or in bulk

Now that patchRules uses this field, we simply need to pass it.

Co-authored-by: Garrett Spong <spong@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/siem/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts
#	x-pack/plugins/siem/server/lib/detection_engine/routes/rules/patch_rules_route.ts
#	x-pack/plugins/siem/server/lib/detection_engine/rules/patch_rules.test.ts
#	x-pack/plugins/siem/server/lib/detection_engine/rules/patch_rules.ts
rylnd added a commit that referenced this pull request Jun 9, 2020
… via PATCH (#67914) (#68684)

* [SIEM][Detections] Allow synchronous rule actions to be updated via PATCH (#67914)

* Update synchronous actions in patchRules

This method was typed to accept actions, but it was not doing anything
with them. This was mainly a "bug by omission" so I'm simply adding
unit tests for regression purposes.

* Allow synchronous actions to be patched either individually or in bulk

Now that patchRules uses this field, we simply need to pass it.

Co-authored-by: Garrett Spong <spong@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	x-pack/plugins/siem/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts
#	x-pack/plugins/siem/server/lib/detection_engine/routes/rules/patch_rules_route.ts
#	x-pack/plugins/siem/server/lib/detection_engine/rules/patch_rules.test.ts
#	x-pack/plugins/siem/server/lib/detection_engine/rules/patch_rules.ts

* Update tests for backport

This API changed since 7.7, so we can't just backport our uses of it
(e.g. the tests).
@MindyRS MindyRS added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Sep 23, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:SIEM v7.7.2 v7.8.0 v7.9.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[SIEM][Detections] PATCHing a rule does not update synchronous actions
5 participants