-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Fixes Modification of ML Rules #60662
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
28d02fa
Fixe updating of ML rules
rylnd c018814
Add a regression test for updating ML Rules
rylnd 7ee9da4
Allow ML Rules to be patched
rylnd 19c9e1a
Allow ML rule params to be imported when overwriting
rylnd a2a0d0c
Add a basic regression test for creating a rule with ML params
rylnd 9341e06
Prevent users from changing an existing Rule's type
rylnd 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
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
50 changes: 50 additions & 0 deletions
50
x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/create_rules.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,50 @@ | ||
/* | ||
* 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 { alertsClientMock } from '../../../../../../../plugins/alerting/server/mocks'; | ||
import { actionsClientMock } from '../../../../../../../plugins/actions/server/mocks'; | ||
import { getMlResult } from '../routes/__mocks__/request_responses'; | ||
import { createRules } from './create_rules'; | ||
|
||
describe('createRules', () => { | ||
let actionsClient: ReturnType<typeof actionsClientMock.create>; | ||
let alertsClient: ReturnType<typeof alertsClientMock.create>; | ||
|
||
beforeEach(() => { | ||
actionsClient = actionsClientMock.create(); | ||
alertsClient = alertsClientMock.create(); | ||
}); | ||
|
||
it('calls the alertsClient with ML params', async () => { | ||
const params = { | ||
...getMlResult().params, | ||
anomalyThreshold: 55, | ||
machineLearningJobId: 'new_job_id', | ||
}; | ||
|
||
await createRules({ | ||
alertsClient, | ||
actionsClient, | ||
...params, | ||
ruleId: 'new-rule-id', | ||
enabled: true, | ||
interval: '', | ||
name: '', | ||
tags: [], | ||
}); | ||
|
||
expect(alertsClient.create).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
params: expect.objectContaining({ | ||
anomalyThreshold: 55, | ||
machineLearningJobId: 'new_job_id', | ||
}), | ||
}), | ||
}) | ||
); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/patch_rules.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,51 @@ | ||
/* | ||
* 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 { savedObjectsClientMock } from '../../../../../../../../src/core/server/mocks'; | ||
import { alertsClientMock } from '../../../../../../../plugins/alerting/server/mocks'; | ||
import { actionsClientMock } from '../../../../../../../plugins/actions/server/mocks'; | ||
import { getMlResult } from '../routes/__mocks__/request_responses'; | ||
import { patchRules } from './patch_rules'; | ||
|
||
describe('patchRules', () => { | ||
let actionsClient: ReturnType<typeof actionsClientMock.create>; | ||
let alertsClient: ReturnType<typeof alertsClientMock.create>; | ||
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>; | ||
|
||
beforeEach(() => { | ||
actionsClient = actionsClientMock.create(); | ||
alertsClient = alertsClientMock.create(); | ||
savedObjectsClient = savedObjectsClientMock.create(); | ||
}); | ||
|
||
it('calls the alertsClient with ML params', async () => { | ||
alertsClient.get.mockResolvedValue(getMlResult()); | ||
const params = { | ||
...getMlResult().params, | ||
anomalyThreshold: 55, | ||
machineLearningJobId: 'new_job_id', | ||
}; | ||
|
||
await patchRules({ | ||
alertsClient, | ||
actionsClient, | ||
savedObjectsClient, | ||
id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd', | ||
...params, | ||
}); | ||
|
||
expect(alertsClient.update).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
params: expect.objectContaining({ | ||
anomalyThreshold: 55, | ||
machineLearningJobId: 'new_job_id', | ||
}), | ||
}), | ||
}) | ||
); | ||
}); | ||
}); |
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
56 changes: 56 additions & 0 deletions
56
x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/update_rules.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,56 @@ | ||
/* | ||
* 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 { savedObjectsClientMock } from '../../../../../../../../src/core/server/mocks'; | ||
import { alertsClientMock } from '../../../../../../../plugins/alerting/server/mocks'; | ||
import { actionsClientMock } from '../../../../../../../plugins/actions/server/mocks'; | ||
import { getMlResult } from '../routes/__mocks__/request_responses'; | ||
import { updateRules } from './update_rules'; | ||
|
||
describe('updateRules', () => { | ||
let actionsClient: ReturnType<typeof actionsClientMock.create>; | ||
let alertsClient: ReturnType<typeof alertsClientMock.create>; | ||
let savedObjectsClient: ReturnType<typeof savedObjectsClientMock.create>; | ||
|
||
beforeEach(() => { | ||
actionsClient = actionsClientMock.create(); | ||
alertsClient = alertsClientMock.create(); | ||
savedObjectsClient = savedObjectsClientMock.create(); | ||
}); | ||
|
||
it('calls the alertsClient with ML params', async () => { | ||
alertsClient.get.mockResolvedValue(getMlResult()); | ||
|
||
const params = { | ||
...getMlResult().params, | ||
anomalyThreshold: 55, | ||
machineLearningJobId: 'new_job_id', | ||
}; | ||
|
||
await updateRules({ | ||
alertsClient, | ||
actionsClient, | ||
savedObjectsClient, | ||
id: '04128c15-0d1b-4716-a4c5-46997ac7f3bd', | ||
...params, | ||
enabled: true, | ||
interval: '', | ||
name: '', | ||
tags: [], | ||
}); | ||
|
||
expect(alertsClient.update).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
data: expect.objectContaining({ | ||
params: expect.objectContaining({ | ||
anomalyThreshold: 55, | ||
machineLearningJobId: 'new_job_id', | ||
}), | ||
}), | ||
}) | ||
); | ||
}); | ||
}); |
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
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.
@FrankHassanabad I noticed that
lists
is absent from this logic branch, meaning that we wouldn't be able to, on import, overwrite a rule's lists. Happy to add that here if you want.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 you can here if you want or we can do another PR for it. But yes, it is missing here.
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.
Thank you for finding it.