-
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
[Entity Analytics][Risk Engine] Risk Scoring Task #163216
Merged
Merged
Conversation
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
rylnd
force-pushed
the
risk_engine_task
branch
3 times, most recently
from
August 10, 2023 00:46
989cc64
to
9107a52
Compare
* Adds the basic registration/start code paths, although we still need to `start()` the task from our management route * Adds some of the task state, although I'm not entirely sure what we want/need there. * Still need to pull most of the execution parameters from our new Saved Object.
Rather than creating the transforms/indices on behalf of the internal kibana user, we now do so on behalf of the user who initially set up/enabled the risk engine. If we have need for the internal user in the future, we can add that as a separate dependency. This also refactors some of the setup so that we instantiate the data client when it is requested from the request context. We do not currently have a need to create a data client outside of the context of a user request.
After a previous refactor we were no longer using the `user` argument to a lot of these methods, and the `savedObjectsClient` and `namespace` args were being passed around a bunch because they came from `init`. Since we don't currently have a need to instantiate the client/resources outside of the current space, both the namespace and the soClient are now part of the client's constructor. I left the namespace as an argument to a few calls from routes; this should be identical to the property internal to the client, and I don't quite know what it would mean/whether it would work if they were different. The SO client, for example, is coded for the current namespace.
Most queries that use 'now' cannot be cached by elasticsearch. Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/shard-request-cache.html
* Adds helper methods for converting data from configuration * Adds retrieval of SO config and inputs index data to both dataclient and riskScoreService.
This includes the alerts index for the current space.
…-ref HEAD~1..HEAD --fix'
We added attributes to the SO, here.
I do not like the way this is structure, but right now I'm just trying to execute the task so that I can TDD this. However, local ES/Kibana errors are preventing me from running FTRs locally, so I guess I'll wait for CI tonight.
All our tests invoke this with ssl: true, but in the case where we're trying to run tests against e.g. localhost this override prevents us from being able to use a non-SSL connection.
This all works, now, but the code is super confusing and I hate it. Will be refactoring once integration tests are written.
What are the odds that we rely on behavior, there? Let's find out!
* Renames a test file because it was identical to the production filename and driving me crazy * Moves some shared logic into utils: SO management, invoking Risk Engine routes, etc. * Excercises most of the functionality of the task via tests. I'll probably come up with some more here but I think this will be enough to confidently refactor the task code
* Remove console statements * lint improperly spaced comments :(
One (or more) of these tests would occasinally fail when the first batch of 5 scores caused `waitForRiskScores` to return prematurely (before the second batch of 5 scores was available in ES). By specifying a scoreCount, we can address that race condition. Closes elastic#162736.
I couldn't find a permutation of `removeIfExists` that actually worked, but now that this is under test I'll take another pass later.
So that I can run `--grep "Risk Engine"` to run all these.
We were previously using this to retrieve the username, but that functionality no longer exists.
* Remove unused dependencies * Better error messages
* Adds `interval` to SO configuration * Adds `namespace` to task state so that a per-space task can be executed (theoretically) * Updates tests
This way the UI/API can convey it to the user.
If an error is raised during enablement (either updating the SO or starting the task), we will undo enablement by disabling the engine.
rylnd
force-pushed
the
risk_engine_task
branch
from
August 23, 2023 04:31
7250a06
to
7cf14b9
Compare
nkhristinin
approved these changes
Aug 23, 2023
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.
Thanks for addressing the comments, LGTM!
This required threading through a `namespace` parameter for a few rule helpers, but I made it optional so it should be a minimal change.
We do not need to return a schedule here until we have need to override the default interval. When the risk engine is enabled, the task is scheduled with the interval configured in the saved object.
Rather than defining the SO extensions ourselves, we instead build a fake kibana request for the particular namespace we're in, and use the request-based helpers to build a scoped SO client from that request. In this way, we're not coupled to the extensions implementation, and additionally we have the encryption and spaces extensions defined/enabled for us. We need to disable the security extension, however, because there is not a kibana system user that would be able to access these Saved Objects, normally.
Conflicts: src/core/server/integration_tests/saved_objects/migrations/group2/check_registered_types.test.ts
Now that we're actually enabling the task when we enable the risk engine, we need this flag enabled, or else we'll get an error because the task wasn't registered on kibana startup.
We can navigate directly to the entity analytics management page; we don't need to visit alerts for these tests.
azasypkin
reviewed
Aug 24, 2023
x-pack/plugins/security_solution/server/lib/risk_engine/tasks/helpers.ts
Outdated
Show resolved
Hide resolved
I didn't quite understand what these SSL changes were doing, and although they seem to be unused I'm just not going to touch them for now. This was committed in the course of running some things locally against a non-SSL kibana, but that time has passed. Additionally, this reverts the disabling of observability in integration tests. While this was useful for developing locally, it's not something that should be in main.
Conflicts: x-pack/test/detection_engine_api_integration/utils/create_rule.ts x-pack/test/detection_engine_api_integration/utils/wait_for_rule_status.ts
* Rescheduling is inherent to the fact that define an `interval` for our schedule; no need to test that explicitly * Also removes tests around failure conditions; the entire task run is wrapped in a try/catch such that we don't need to do that ourselves.
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
History
To update your PR or re-run it, just comment with: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
8.11 candidate
backport:skip
This commit does not require backporting
Feature:Entity Analytics
Security Solution Entity Analytics features
release_note:skip
Skip the PR/issue when compiling release notes
Team:Detection Engine
Security Solution Detection Engine Area
Team: SecuritySolution
Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc.
Theme: entity_analytics
v8.11.0
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.
What this PR does
risk_engine:risk_scoring
, responsible for invoking thecalculateAndPersistRiskScores
API defined in the risk scoring service.risk-engine-configuration
Saved Objectrisk-engine-configuration
SO to include more configuration fieldsSettings -> Entity Risk Score
pageHow to Review
riskScoringPersistence
andriskScoringRoutesEnabled
Settings -> Entity Risk Score
page, and enable the task by togglingEntity risk scoring
toOn
GET risk-score.risk-score-default/_search
default
with the name of your current space, as necessary.Risk Matrix
Delete this section if it is not applicable to this PR.
Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.
When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:
For maintainers