-
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] Handle negative lookback in rule upgrade flyout #204317
base: main
Are you sure you want to change the base?
[Security Solution] Handle negative lookback in rule upgrade flyout #204317
Conversation
3254df1
to
a8dacbc
Compare
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
Pinging @elastic/security-detection-rule-management (Team:Detection Rule Management) |
@maximpn when I follow your instructions and attempt to open the upgrade flyout for the modified rule, I receive the following error, which looks to have been thrown by The above error occurred in ErrorBoundary:
|
a8dacbc
to
1a0d56f
Compare
Hi @rylnd, are you sure you pulled the latest PR changes? I double checked and it works for me locally as described in the PR description. Could you try removing the branch and pull the latest changes? |
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.
@maximpn I tested this and verified that it works as described. However, I'm not sure that this is the best solution for users. There are two main issues with the implementation:
- By disallowing negative lookback values, it forces the user to change the rule's logic on upgrade
- The upstream rule will continue to conflict, necessitate resolution, and (again) have its in-situ schedule changed on each subsequent release/upgrade workflow.
If I'm understanding correctly, these rules cannot be edited/upgraded without (significantly) changing their schedule. I would like to discuss this with both rule authors and the rest of the DE team to get their thoughts before approving this.
I appreciate the move toward consistency here, and the addressing of some of the UI/form bugs, but I really think we should strive to preserve the existing values, if possible. Can we not simply use a form component that allows negative values?
'xpack.securitySolution.detectionEngine.rules.upgradeRules.ruleSchedule.lookbackInconsistencyWarning', | ||
{ | ||
defaultMessage: | ||
'There is an inconsistency in rule schedule configuration. Rule may run with gaps. Default value "{defaultValue}" is suggested for upgrade.', |
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.
We might want some additional articles here for legibility:
'There is an inconsistency in rule schedule configuration. Rule may run with gaps. Default value "{defaultValue}" is suggested for upgrade.', | |
'There is an inconsistency in rule schedule configuration, and the rule may run with gaps. The default value "{defaultValue}" is suggested.', |
'xpack.securitySolution.detectionEngine.ruleDetails.lookbackInconsistencyWarning', | ||
{ | ||
defaultMessage: | ||
'There is an inconsistency in rule schedule configuration. Rule may run with gaps. Please edit the rule to resolve it.', |
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.
Again, I'd make this one sentence to make the relationship clearer between the two statements:
'There is an inconsistency in rule schedule configuration. Rule may run with gaps. Please edit the rule to resolve it.', | |
'There is an inconsistency in rule schedule configuration, and the rule may run with gaps. Please edit the rule to resolve this.', |
@@ -577,7 +577,7 @@ export const getCatchupTuples = ({ | |||
*/ | |||
export const calculateFromValue = (interval: string, lookback: string) => { | |||
const parsedInterval = parseInterval(interval) ?? moment.duration(0); | |||
const parsedFrom = parseInterval(lookback) ?? moment.duration(0); | |||
const parsedFrom = parseInterval(lookback) ?? moment.duration(1, 'm'); |
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.
Should this be more closely tied to DEFAULT_RULE_EXECUTION_LOOKBACK
? It seems like we're adding this default in two places instead of just one.
@rylnd thanks for your review 🙏 Generally speaking the problem won't be solved by allowing editing negative look-back. Rule can also have
It's possible but requires some amount of work justification to users.
Sure. Let's discuss it. |
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.
@maximpn I agree with:
- @rylnd's points from [Security Solution] Handle negative lookback in rule upgrade flyout #204317 (review)
- @xcrzx's points from [Security Solution] Negative lookback is not handled properly during upgrade #204714 (comment)
Whatever comes or can possibly come from prebuilt rules or rules CRUD API (as long as the rule is valid and can be created/updated/installed) should not be reset to any default values by the rule upgrade workflow, and should stay as is, unless the user explicitly changes it. UI elements should not reset / change the values on their own.
I'm blocking this PR until an agreement is reached in #204714.
We should have a single PR that resolves both #202715 and #204714.
9f7223f
to
5ebec94
Compare
09b35af
to
e63a9e5
Compare
e63a9e5
to
85aa6da
Compare
b4bf2a1
to
95bbf57
Compare
💔 Build Failed
Failed CI StepsMetrics [docs]Module Count
Async chunks
History
cc @maximpn |
Resolves: #202715
Summary
This PR makes inconsistent/wrong rule's look-back duration prominent for a user. It falls back to a default 1 minute value in rule upgrade workflow.
Details
Negative/wrong
lookback
problemThere is a difference between rule schedule value in a saved object and value represented to users
interval
,from
andto
fields representing rule schedule.interval
shows how often a rule runs in task runner.from
andto
stored in date math format likenow-10m
represent a date time range used to fetch source events. Task manager strives to run rules exactly everyinterval
but it's not always possible due to multiple reasons like system load and various delays. To avoid any gaps to appearfrom
point in time usually stands earlier than current time minusinterval
, for exampleinterval
is10 minutes
andfrom
isnow-12m
meaning rule will analyze events starting from 12 minutes old.to
represents the latest point in time source events will be analyzed.interval
andlookback
. Whereinterval
is the same as above andlookback
and a time duration before current time minusinterval
. For exampleinterval
is10 minutes
and lookback is2 minutes
it means a rule will analyzing events starting with 12 minutes old until the current moment in time.Literally
interval
,from
andto
mean a rule runs everyinterval
and analyzes events starting fromfrom
untilto
. Technicallyfrom
andto
may not have any correlation withinterval
, for example a rule may analyze one year old events. While it's reasonable for manual rule runs and gap remediation the same approach doesn't work well for usual rule schedule. Transformation betweeninterval
/from
/to
andinterval
/lookback
works only whento
is equal the current moment in time i.e.now
.Rule management APIs allow to set any
from
andto
values resulting in inconsistent rule schedule. Transformedinterval
/lookback
value won't represent real time interval used to fetch source events for analysis. On top of that negativelookback
value may puzzle users on the meaning of the negative sign.Prebuilt rules with
interval
/from
/to
resulting in negativelookback
Some prebuilt rules have such
interval
,from
andto
field values thatnegativelookback
is expected, for exampleMultiple Okta Sessions Detected for a Single User
. It runs every60 minutes
but hasfrom
field set tonow-30m
andto
equalsnow
. In the end we havelookback
equalsto
-from
-interval
=30 minutes
-60 minutes
=-30 minutes
.Our UI doesn't handle negative
lookback
values. It simply discards a negative sign and substitutes the rest for editing. In the case above30 minutes
will be suggested for editing. Saving the form will result in changingfrom
tonow-90m
Changes in this PR
This PR mitigates rule schedule inconsistencies caused by
to
fields not using the current point in time i.e.now
. The following was done_perform
rule upgrade API endpoint was changed to use default 1 minute look back in case provided look back interval can't be parsed. Parsing error happens for negativelookback
. Previously it resulted in settinglookback
to0s
upon rule upgrade.to
isn't equalnow
.to
isn't equalnow
.from
value whento
isn't equalnow
. Transformed values are incorrect in that case since transformation functionality assumesto
is equalnow
.to
isn't equalnow
.Screenshots
Screen.Recording.2024-12-16.at.15.20.56.mov
How to test?
prebuiltRulesCustomizationEnabled
feature flag is enabledserver.restrictInternalApis: false
tokibana.dev.yaml
security_detection_engine
Fleet packageSuspicious File Creation via Kworker
rule by running a query belowSuspicious File Creation via Kworker
rule