Skip to content

Commit 2bab2cc

Browse files
[SIEM][Detection Engine] critical blocker, fixes ordering issue that causes rules to not run the first time
## Summary Fixes ordering issue that @mikecote found for us with rules where we need to first update the rule before trying to enable it so there aren't issues with API keys. These types of errors should no longer be seen: ``` {"type":"log","@timestamp":"2020-01-11T09:06:25-07:00","tags":["error","plugins","siem"],"pid":61190,"message":"Error from signal rule name: \"Windows Execution via Connection Manager\", id: \"0624c880-8e64-4c7c-90b4-226b77311ac4\", rule_id: \"f2728299-167a-489c-913c-2e0955ac3c40\" message: [security_exception] missing authentication credentials for REST request [/auditbeat-*%2Cendgame-*%2Cfilebeat-*%2Cpacketbeat-*%2Cwinlogbeat-*/_search?allow_no_indices=true&size=100&ignore_unavailable=true], with { header={ WWW-Authenticate={ 0=\"Bearer realm=\\\"security\\\"\" & 1=\"ApiKey\" & 2=\"Basic realm=\\\"security\\\" charset=\\\"UTF-8\\\"\" } } }"} ``` Testing: ```ts ./hard_reset.sh ``` Then load the pre-packaged rules and enable them all at once. Ensure you don't see any errors such as the ones above. ### Checklist Use ~~strikethroughs~~ to remove checklist items you don't feel are applicable to this PR. ~~- [ ] This was checked for cross-browser compatibility, [including a check against IE11](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility)~~ ~~- [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)~~ ~~- [ ] [Documentation](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#writing-documentation) was added for features that require explanation or tutorials~~ - [x] [Unit or functional tests](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#cross-browser-compatibility) were updated or added to match the most common scenarios ~~- [ ] This was checked for [keyboard-only and screenreader accessibility](https://developer.mozilla.org/en-US/docs/Learn/Tools_and_testing/Cross_browser_testing/Accessibility#Accessibility_testing_checklist)~~ ### For maintainers ~~- [ ] This was checked for breaking API changes and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)~~ - [x] This includes a feature addition or change that requires a release note and was [labeled appropriately](https://github.com/elastic/kibana/blob/master/CONTRIBUTING.md#release-notes-process)
1 parent fe037bb commit 2bab2cc

File tree

1 file changed

+20
-13
lines changed
  • x-pack/legacy/plugins/siem/server/lib/detection_engine/rules

1 file changed

+20
-13
lines changed

x-pack/legacy/plugins/siem/server/lib/detection_engine/rules/update_rules.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
import { defaults, pickBy, isEmpty } from 'lodash/fp';
8+
import { PartialAlert } from '../../../../../alerting/server/types';
89
import { readRules } from './read_rules';
910
import { UpdateRuleParams, IRuleSavedAttributesSavedObjectAttributes } from './types';
1011
import { addTags } from './add_tags';
@@ -108,7 +109,7 @@ export const updateRules = async ({
108109
type,
109110
references,
110111
version,
111-
}: UpdateRuleParams) => {
112+
}: UpdateRuleParams): Promise<PartialAlert | null> => {
112113
const rule = await readRules({ alertsClient, ruleId, id });
113114
if (rule == null) {
114115
return null;
@@ -169,6 +170,18 @@ export const updateRules = async ({
169170
}
170171
);
171172

173+
const update = await alertsClient.update({
174+
id: rule.id,
175+
data: {
176+
tags: addTags(tags ?? rule.tags, rule.params.ruleId, immutable ?? rule.params.immutable),
177+
name: calculateName({ updatedName: name, originalName: rule.name }),
178+
schedule: {
179+
interval: calculateInterval(interval, rule.schedule.interval),
180+
},
181+
actions: rule.actions,
182+
params: nextParams,
183+
},
184+
});
172185
if (rule.enabled && enabled === false) {
173186
await alertsClient.disable({ id: rule.id });
174187
} else if (!rule.enabled && enabled === true) {
@@ -194,16 +207,10 @@ export const updateRules = async ({
194207
} else {
195208
// enabled is null or undefined and we do not touch the rule
196209
}
197-
return alertsClient.update({
198-
id: rule.id,
199-
data: {
200-
tags: addTags(tags ?? rule.tags, rule.params.ruleId, immutable ?? rule.params.immutable),
201-
name: calculateName({ updatedName: name, originalName: rule.name }),
202-
schedule: {
203-
interval: calculateInterval(interval, rule.schedule.interval),
204-
},
205-
actions: rule.actions,
206-
params: nextParams,
207-
},
208-
});
210+
211+
if (enabled != null) {
212+
return { ...update, enabled };
213+
} else {
214+
return update;
215+
}
209216
};

0 commit comments

Comments
 (0)