-
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
[Security Solution][Legacy Actions] - Update legacy action migration to account for more edge cases #130511
[Security Solution][Legacy Actions] - Update legacy action migration to account for more edge cases #130511
Conversation
…s_migration_logic
…s_migration_logic
…ro/kibana into updating_actions_migration_logic
…s_migration_logic
…s_migration_logic
Pinging @elastic/security-solution (Team: SecuritySolution) |
@elasticmachine merge upstream |
.../plugins/security_solution/server/lib/detection_engine/routes/__mocks__/request_responses.ts
Outdated
Show resolved
Hide resolved
…ons_migration_logic
…ro/kibana into updating_actions_migration_logic
…s_migration_logic
jest.resetAllMocks(); | ||
}); | ||
|
||
test('it does no cleanup or migration if no legacy reminants found', async () => { |
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.
Small typo here (remnants)
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.
Tested locally, it worked fine and as expected. No sidecar objects after enabling the rules in the branch!
The code LGTM -- this implementation is of some really high quality. The tests look awesome, thank you for adding them and for putting so much effort into this fix.
Suggestion: it would be great to put the table from the PR description somewhere close to the legacyMigrate
implementation, or to some dev docs. It really helps with understanding what this migration is all about.
@@ -588,4 +651,415 @@ describe('utils', () => { | |||
]); | |||
}); | |||
}); | |||
|
|||
describe('#legacyMigrate', () => { |
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.
Tests are awesome here, clean and easy to understand. Thank you @yctercero for working on them, appreciate a lot!
// If the legacy notification rule type ("siem.notification") exist, | ||
// migration and cleanup are needed | ||
if (siemNotificationsExist) { | ||
await rulesClient.delete({ id: siemNotification.data[0].id }); | ||
} | ||
// If legacy notification sidecar ("siem-detection-engine-rule-actions") | ||
// exist, migration and cleanup are needed | ||
if (legacyRuleNotificationSOsExist) { | ||
// Delete the legacy sidecar SO | ||
await savedObjectsClient.delete( | ||
legacyRuleActionsSavedObjectType, | ||
legacyRuleActionsSO.saved_objects[0].id | ||
); | ||
|
||
// If "siem-detection-engine-rule-actions" notes that `ruleThrottle` is | ||
// "no_actions" or "rule", rule has no actions or rule is set to run | ||
// action on every rule run. In these cases, sidecar deletion is the only | ||
// cleanup needed and updates to the "throttle" and "notifyWhen". "siem.notification" are | ||
// not created for these action types | ||
if ( | ||
legacyRuleActionsSO.saved_objects[0].attributes.ruleThrottle === 'no_actions' || | ||
legacyRuleActionsSO.saved_objects[0].attributes.ruleThrottle === 'rule' | ||
) { | ||
return rule; | ||
} | ||
|
||
// Use "legacyRuleActionsSO" instead of "siemNotification" as "siemNotification" is not created | ||
// until a rule is run and added to task manager. That means that if by chance a user has a rule | ||
// with actions which they have yet to enable, the actions would be lost. Instead, | ||
// "legacyRuleActionsSO" is created on rule creation (pre 7.15) and we can rely on it to be there |
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 really appreciate all the comments here!
...test/detection_engine_api_integration/security_and_spaces/tests/legacy_actions_migrations.ts
Show resolved
Hide resolved
it('migrates legacy actions for rule with no actions', async () => { | ||
const soId = '9095ee90-b075-11ec-bb3f-1f063f8e06cf'; | ||
const ruleId = '2297be91-894c-4831-830f-b424a0ec84f0'; | ||
const legacySidecarId = '926668d0-b075-11ec-bb3f-1f063f8e06cf'; | ||
|
||
// check for legacy sidecar action | ||
const sidecarActionSO = await getLegacyActionSOById(es, legacySidecarId); | ||
expect(sidecarActionSO.hits.hits.length).to.eql(1); | ||
|
||
// check for legacy notification SO | ||
// should not have been created for a rule with no actions | ||
const legacyNotificationSO = await getLegacyActionNotificationSOById(es, soId); | ||
expect(legacyNotificationSO.hits.hits.length).to.eql(0); |
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.
These tests are awesome too!
💚 Build SucceededMetrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @yctercero |
⚪ Backport skippedThe pull request was not backported as there were no branches to backport to. If this is a mistake, please apply the desired version labels or run the backport tool manually. Manual backportTo create the backport manually run:
Questions ?Please refer to the Backport tool documentation |
…to account for more edge cases (elastic#130511) ## Summary Updates the legacy actions migration code to account for edge cases we had not initially caught. Thanks to testing from some teammates, they reported seeing the following behavior: - Rules created pre 7.16 with no actions still create the legacy action sidecar (but not a `siem.notifications` legacy actions alert) which upon migration to 7.16+ was not being deleted - Rules created pre 7.16 with actions that run on every rule run create the legacy action sidecar(but not a `siem.notifications` legacy actions alert) which upon migration to 7.16+ was not being deleted - Rules created pre 7.16 with actions that were never enabled until 8.x did not have a `siem.notifications` legacy actions alert type created Because the legacy migration code relied on checking if a corresponding `siem.notifications` SO existed to kick off the necessary cleanup/migration, the above edge cases were not being caught.
Summary
Updates the legacy actions migration code to account for edge cases we had not initially caught. Thanks to testing from some teammates, they reported seeing the following behavior:
siem.notifications
legacy actions alert) which upon migration to 7.16+ was not being deletedsiem.notifications
legacy actions alert) which upon migration to 7.16+ was not being deletedsiem.notifications
legacy actions alert type createdBecause the legacy migration code relied on checking if a corresponding
siem.notifications
SO existed to kick off the necessary cleanup/migration, the above edge cases were not being caught.Working to migrate the legacy actions can definitely scramble your head a bit so I'll try to break it down below and made sure to add plenty of tests (e2e, unit) to check the logic.
siem.notifications
SO created-
siem-detection-engine-rule-actions
SO created- Empty actions array on rule params
siem-detection-engine-rule-actions
DELETED-
throttle
isnull
-
notifyWhen
isonActiveAlert
-
actions
is[]
siem.notifications
SO created-
siem-detection-engine-rule-actions
SO created- action lives on rule params
siem-detection-engine-rule-actions
DELETED- actions continue to live on rule params
-
throttle
isnull
-
notifyWhen
isonActiveAlert
siem.notifications
SO created-
siem-detection-engine-rule-actions
SO created- actions array on rule params empty
iem-detection-engine-rule-actions
DELETED-
siem.notifications
DELETED- actions moved to live on rule params
-
throttle
is1h
-
notifyWhen
isonThrottleInterval
siem.notifications
SO created-
siem-detection-engine-rule-actions
SO created- actions array on rule params empty
siem-detection-engine-rule-actions
DELETED-
siem.notifications
DELETED- actions moved to live on rule params
-
throttle
is1d
-
notifyWhen
isonThrottleInterval
siem.notifications
SO created-
siem-detection-engine-rule-actions
SO created- actions array on rule params empty
siem-detection-engine-rule-actions
DELETED-
siem.notifications
DELETED- actions moved to live on rule params
-
throttle
is7d
-
notifyWhen
isonThrottleInterval
Testing
Useful scripts:
Followup Needed
Checklist
For maintainers