Skip to content

Commit a44d5a6

Browse files
[Security Solution][Detections] -Fixes rule edit flow bug with max_signals (#92748) (#93157)
### Summary Fixes a bug where max_signals was being reverted to it's default value when the rule was edited via the UI. Co-authored-by: Yara Tercero <yctercero@users.noreply.github.com>
1 parent f2123b3 commit a44d5a6

6 files changed

Lines changed: 46 additions & 5 deletions

File tree

x-pack/plugins/security_solution/cypress/integration/detection_rules/custom_query_rule.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ import {
108108
} from '../../tasks/create_new_rule';
109109
import { saveEditedRule, waitForKibana } from '../../tasks/edit_rule';
110110
import { loginAndWaitForPageWithoutDateRange } from '../../tasks/login';
111+
import { activatesRule } from '../../tasks/rule_details';
111112

112113
import { DETECTIONS_URL } from '../../urls/navigation';
113114

@@ -308,6 +309,21 @@ describe('Custom detection rules deletion and edition', () => {
308309
reload();
309310
});
310311

312+
it('Only modifies rule active status on enable/disable', () => {
313+
activatesRule();
314+
315+
cy.intercept('GET', `/api/detection_engine/rules?id=`).as('fetchRuleDetails');
316+
317+
goToRuleDetails();
318+
319+
cy.wait('@fetchRuleDetails').then(({ response }) => {
320+
cy.wrap(response!.statusCode).should('eql', 200);
321+
322+
cy.wrap(response!.body.max_signals).should('eql', existingRule.maxSignals);
323+
cy.wrap(response!.body.enabled).should('eql', false);
324+
});
325+
});
326+
311327
it('Allows a rule to be edited', () => {
312328
editFirstRule();
313329
waitForKibana();
@@ -347,8 +363,17 @@ describe('Custom detection rules deletion and edition', () => {
347363
goToAboutStepTab();
348364
cy.get(TAGS_CLEAR_BUTTON).click({ force: true });
349365
fillAboutRule(editedRule);
366+
367+
cy.intercept('GET', '/api/detection_engine/rules?id').as('getRule');
368+
350369
saveEditedRule();
351370

371+
cy.wait('@getRule').then(({ response }) => {
372+
cy.wrap(response!.statusCode).should('eql', 200);
373+
// ensure that editing rule does not modify max_signals
374+
cy.wrap(response!.body.max_signals).should('eql', existingRule.maxSignals);
375+
});
376+
352377
cy.get(RULE_NAME_HEADER).should('have.text', `${editedRule.name}`);
353378
cy.get(ABOUT_RULE_DESCRIPTION).should('have.text', editedRule.description);
354379
cy.get(ABOUT_DETAILS).within(() => {

x-pack/plugins/security_solution/cypress/objects/rule.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface CustomRule {
5454
runsEvery: Interval;
5555
lookBack: Interval;
5656
timeline: CompleteTimeline;
57+
maxSignals: number;
5758
}
5859

5960
export interface ThresholdRule extends CustomRule {
@@ -174,6 +175,7 @@ export const newRule: CustomRule = {
174175
runsEvery,
175176
lookBack,
176177
timeline,
178+
maxSignals: 100,
177179
};
178180

179181
export const existingRule: CustomRule = {
@@ -192,6 +194,9 @@ export const existingRule: CustomRule = {
192194
runsEvery,
193195
lookBack,
194196
timeline,
197+
// Please do not change, or if you do, needs
198+
// to be any number other than default value
199+
maxSignals: 500,
195200
};
196201

197202
export const newOverrideRule: OverrideRule = {
@@ -213,6 +218,7 @@ export const newOverrideRule: OverrideRule = {
213218
runsEvery,
214219
lookBack,
215220
timeline,
221+
maxSignals: 100,
216222
};
217223

218224
export const newThresholdRule: ThresholdRule = {
@@ -232,6 +238,7 @@ export const newThresholdRule: ThresholdRule = {
232238
runsEvery,
233239
lookBack,
234240
timeline,
241+
maxSignals: 100,
235242
};
236243

237244
export const machineLearningRule: MachineLearningRule = {
@@ -265,6 +272,7 @@ export const eqlRule: CustomRule = {
265272
runsEvery,
266273
lookBack,
267274
timeline,
275+
maxSignals: 100,
268276
};
269277

270278
export const eqlSequenceRule: CustomRule = {
@@ -285,6 +293,7 @@ export const eqlSequenceRule: CustomRule = {
285293
runsEvery,
286294
lookBack,
287295
timeline,
296+
maxSignals: 100,
288297
};
289298

290299
export const newThreatIndicatorRule: ThreatIndicatorRule = {
@@ -304,6 +313,7 @@ export const newThreatIndicatorRule: ThreatIndicatorRule = {
304313
indicatorMapping: 'agent.id',
305314
indicatorIndexField: 'agent.threat',
306315
timeline,
316+
maxSignals: 100,
307317
};
308318

309319
export const severitiesOverride = ['Low', 'Medium', 'High', 'Critical'];

x-pack/plugins/security_solution/cypress/tasks/api_calls/rules.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export const createCustomRuleActivated = (rule: CustomRule, ruleId = '1') =>
8585
language: 'kuery',
8686
enabled: true,
8787
tags: ['rule1'],
88+
max_signals: 500,
8889
},
8990
headers: { 'kbn-xsrf': 'cypress-creds' },
9091
failOnStatusCode: false,

x-pack/plugins/security_solution/cypress/tasks/rule_details.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ export const activatesRule = () => {
3434
});
3535
};
3636

37-
export const deactivatesRule = () => {
38-
cy.get(RULE_SWITCH).should('be.visible');
39-
cy.get(RULE_SWITCH).click();
40-
};
41-
4237
export const addsException = (exception: Exception) => {
4338
cy.get(LOADING_SPINNER).should('exist');
4439
cy.get(LOADING_SPINNER).should('not.exist');

x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/edit/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ const EditRulePageComponent: FC = () => {
251251
rule
252252
),
253253
...(ruleId ? { id: ruleId } : {}),
254+
...(rule != null ? { max_signals: rule.max_signals } : {}),
254255
});
255256
}
256257
}, [
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "Query With Max Signals",
3+
"description": "Simplest query with max signals set to something other than default",
4+
"risk_score": 1,
5+
"severity": "high",
6+
"type": "query",
7+
"query": "user.name: root or user.name: admin",
8+
"max_signals": 500
9+
}

0 commit comments

Comments
 (0)