Skip to content

[Security Solution] Disable legacy rules on upgrade to 8.x#121442

Merged
madirey merged 13 commits intoelastic:mainfrom
madirey:disable-legacy-rule
Jan 10, 2022
Merged

[Security Solution] Disable legacy rules on upgrade to 8.x#121442
madirey merged 13 commits intoelastic:mainfrom
madirey:disable-legacy-rule

Conversation

@madirey
Copy link
Copy Markdown
Contributor

@madirey madirey commented Dec 16, 2021

Summary

This PR modifies the alerting migration for Detection Engine rules to disable each rule on upgrade to 8.x. This ensures that legacy rules will no longer fire, in the case that the customer failed to disable the rules manually before upgrading. The rules will need to be re-enabled once the upgrade is complete, which is in line with current customer guidance.

@jmikell821 Can we verify that our documentation reflects the steps above? They should no longer need to disable their rules before upgrading, but they will need to go back in and re-enable all their rules post-upgrade (from pre-8.0 to 8.x). cc: @marshallmain

@MadameSheema Should we add upgrade tests to cover this? cc: @rylnd

There is a related issue where dupes can occur after upgrading ... I'll create a separate issue for that.

For maintainers

@madirey madirey changed the title [Security Solution] Disable legacy rule and notify user to upgrade [Security Solution] Disable legacy rules on upgrade to 8.x Dec 21, 2021
@madirey madirey added needs_docs Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Alerts Security Detection Alerts Area Team Team:Detections and Resp Security Detection Response Team labels Dec 21, 2021
@madirey madirey marked this pull request as ready for review December 21, 2021 19:18
@madirey madirey requested review from a team as code owners December 21, 2021 19:18
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Copy Markdown
Contributor

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

@madirey
Copy link
Copy Markdown
Contributor Author

madirey commented Jan 4, 2022

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

expected head sha didn’t match current head ref.

attributes: {
...doc.attributes,
alertTypeId: ruleTypeMappings[ruleType],
enabled: false,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@elastic/kibana-alerting-services is this sufficient for disabling a rule during migration. Or because the task still exists, the rule runs regardless?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As of 8.1, we have this logic in place to skip running rules when they are disabled: #119239

That hasn't been backported to 8.0 though, so maybe it needs to be to support this PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Even if we backported the above-mentioned PR, I'm wondering if 2 tasks will run when the rule does get enabled. Since we're just setting enabled to false here but the scheduled task still exists, a new task document will get created when the rule gets enabled and then both tasks will run

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As part of this PR, we also delete the code that registered the old rule type so the old task still exists but it doesn't get picked up by task manager to actually execute since it can't find the executor logic.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Gotcha! Verified that this all works as expected. It will just leave an API key that is never invalidated. Is that a big deal @mikecote ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

From a platform perspective, it is ok, it will not cause any harm leaving API keys behind. If folks in the security solution are ok with this caveat, we should be ok.

@madirey
Copy link
Copy Markdown
Contributor Author

madirey commented Jan 6, 2022

@elasticmachine merge upstream

@kibanamachine
Copy link
Copy Markdown
Contributor

merge conflict between base and head

Copy link
Copy Markdown
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

Can we update the unit tests for x-pack/plugins/alerting/server/saved_objects/migrations.ts to test for this migration? We also have alerting migration functional tests but it sounds like there might already be security solutions functional tests to cover this?

@madirey
Copy link
Copy Markdown
Contributor Author

madirey commented Jan 10, 2022

@ymao1 Added tests!

Copy link
Copy Markdown
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for adding the tests.

@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled in files

id before after diff
securitySolution 67 66 -1

ESLint disabled line counts

id before after diff
securitySolution 453 452 -1

Total ESLint disabled count

id before after diff
securitySolution 520 518 -2

History

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

@madirey madirey added the auto-backport Deprecated - use backport:version if exact versions are needed label Jan 10, 2022
@madirey madirey merged commit 1ddb647 into elastic:main Jan 10, 2022
@madirey madirey deleted the disable-legacy-rule branch January 10, 2022 18:57
@kibanamachine
Copy link
Copy Markdown
Contributor

💔 All backports failed

Status Branch Result
8.0 Backport failed because of merge conflicts

How to fix

Re-run the backport manually:

node scripts/backport --pr 121442

Questions ?

Please refer to the Backport tool documentation

madirey added a commit to madirey/kibana that referenced this pull request Jan 11, 2022
…21442)

* Disable legacy rule and notify user to upgrade

* Ensure rules are disabled on upgrade

* Fix dupe detection on upgrade

* Revert "Fix dupe detection on upgrade"

This reverts commit 021ec0f.

* Add legacy notification

* Add tests for 8.0 security_solution rule migration

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 1ddb647)

# Conflicts:
#	x-pack/plugins/alerting/server/saved_objects/migrations.ts
#	x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts
#	x-pack/plugins/security_solution/server/plugin.ts
@madirey
Copy link
Copy Markdown
Contributor Author

madirey commented Jan 11, 2022

@mikecote @ymao1 @marshallmain The behavior I'm observing is that the rule continues to run after upgrading even though it's disabled during the migration (but it's running the new code...). Does that make sense based on the current functionality? If so, then can we expect users won't need to go manually enable the rule after upgrading?

UPDATE: Please disregard, this is working as expected!

@ymao1
Copy link
Copy Markdown
Contributor

ymao1 commented Jan 11, 2022

That would not be what I expect (and also not what I observed when I tried running it locally).

Both the alerting rule & the scheduled task with the legacy task type should exist after the migration. The first time task manager claims the task, it should mark it as unrecognized because the task type is no longer registered and therefore no longer recognized by task manager. This should prevent this task from being claimed in the future.

A new scheduled task with the new task task type should not be created until the rule is enabled by the user.

madirey added a commit that referenced this pull request Jan 11, 2022
…1442) (#122695)

* [Security Solution] Disable legacy rules on upgrade to 8.x (#121442)

* Disable legacy rule and notify user to upgrade

* Ensure rules are disabled on upgrade

* Fix dupe detection on upgrade

* Revert "Fix dupe detection on upgrade"

This reverts commit 021ec0f.

* Add legacy notification

* Add tests for 8.0 security_solution rule migration

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 1ddb647)

# Conflicts:
#	x-pack/plugins/alerting/server/saved_objects/migrations.ts
#	x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts
#	x-pack/plugins/security_solution/server/plugin.ts

* RawRule should be RawAlert in 8.0
@madirey madirey self-assigned this Jan 11, 2022
@madirey
Copy link
Copy Markdown
Contributor Author

madirey commented Jan 12, 2022

@ymao1 Thanks, I'm not sure what I was seeing, but I'm not seeing it now. I think this is working as expected. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Deprecated - use backport:version if exact versions are needed needs_docs release_note:deprecation Team:Detection Alerts Security Detection Alerts Area Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.0.0 v8.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants