-
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] Classify EQL verification and ML job missing errors as user errors #180094
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee129f7
Classify EQL verification errors as user errors
marshallmain efa33eb
Classify ML job missing errors as user error
marshallmain c0ece99
Add API integration tests verifying that errors are classified correctly
marshallmain 10cd847
Merge branch 'main' into classify-user-errors
marshallmain a67a9a9
PR feedback: runtime check before typecasting
marshallmain ccb747a
Merge branch 'main' into classify-user-errors
marshallmain 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,6 +64,7 @@ describe('ml_executor', () => { | |
errors: [], | ||
createdItems: [], | ||
}); | ||
jobsSummaryMock.mockResolvedValue([]); | ||
}); | ||
|
||
it('should throw an error if ML plugin was not available', async () => { | ||
|
@@ -131,4 +132,26 @@ describe('ml_executor', () => { | |
); | ||
expect(response.warningMessages.length).toEqual(1); | ||
}); | ||
|
||
it('should report job missing errors as user errors', async () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ML test suite is skipped, but this test works locally if you unskip the suite |
||
(findMlSignals as jest.Mock).mockRejectedValue({ | ||
message: 'my_test_job_name missing', | ||
}); | ||
|
||
const result = await mlExecutor({ | ||
completeRule: mlCompleteRule, | ||
tuple, | ||
ml: mlMock, | ||
services: alertServices, | ||
ruleExecutionLogger, | ||
listClient, | ||
bulkCreate: jest.fn(), | ||
wrapHits: jest.fn(), | ||
exceptionFilter: undefined, | ||
unprocessedExceptions: [], | ||
}); | ||
expect(result.userError).toEqual(true); | ||
expect(result.success).toEqual(false); | ||
expect(result.errors).toEqual(['my_test_job_name missing']); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
* 2.0. | ||
*/ | ||
|
||
/* eslint require-atomic-updates: ["error", { "allowProperties": true }] */ | ||
|
||
import type { KibanaRequest } from '@kbn/core/server'; | ||
import type { ExceptionListItemSchema } from '@kbn/securitysolution-io-ts-list-types'; | ||
import type { | ||
|
@@ -30,6 +32,7 @@ import { | |
import type { SetupPlugins } from '../../../../plugin'; | ||
import { withSecuritySpan } from '../../../../utils/with_security_span'; | ||
import type { IRuleExecutionLogForExecutors } from '../../rule_monitoring'; | ||
import type { AnomalyResults } from '../../../machine_learning'; | ||
|
||
export const mlExecutor = async ({ | ||
completeRule, | ||
|
@@ -93,19 +96,29 @@ export const mlExecutor = async ({ | |
result.warning = true; | ||
} | ||
|
||
const anomalyResults = await findMlSignals({ | ||
ml, | ||
// Using fake KibanaRequest as it is needed to satisfy the ML Services API, but can be empty as it is | ||
// currently unused by the mlAnomalySearch function. | ||
request: {} as unknown as KibanaRequest, | ||
savedObjectsClient: services.savedObjectsClient, | ||
jobIds: ruleParams.machineLearningJobId, | ||
anomalyThreshold: ruleParams.anomalyThreshold, | ||
from: tuple.from.toISOString(), | ||
to: tuple.to.toISOString(), | ||
maxSignals: tuple.maxSignals, | ||
exceptionFilter, | ||
}); | ||
let anomalyResults: AnomalyResults; | ||
try { | ||
anomalyResults = await findMlSignals({ | ||
ml, | ||
// Using fake KibanaRequest as it is needed to satisfy the ML Services API, but can be empty as it is | ||
// currently unused by the mlAnomalySearch function. | ||
request: {} as unknown as KibanaRequest, | ||
savedObjectsClient: services.savedObjectsClient, | ||
jobIds: ruleParams.machineLearningJobId, | ||
anomalyThreshold: ruleParams.anomalyThreshold, | ||
from: tuple.from.toISOString(), | ||
to: tuple.to.toISOString(), | ||
maxSignals: tuple.maxSignals, | ||
exceptionFilter, | ||
}); | ||
} catch (error) { | ||
if ((error.message as string).endsWith('missing')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same as above regarding the error type. |
||
result.userError = true; | ||
} | ||
result.errors.push(error.message); | ||
result.success = false; | ||
return result; | ||
} | ||
|
||
if ( | ||
anomalyResults.hits.total && | ||
|
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
Oops, something went wrong.
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.
JS allow to throw anything. Generally speaking
message
can beundefined
in rare cases. Since it's an error handler I'd recommend to add more robust check here like