Skip to content

Commit 4b7bbd8

Browse files
[9.2] [EDR Workflows] Fix event filter OS selector visibility and prepopulation from host events (#240791) (#241335)
# Backport This will backport the following commits from `main` to `9.2`: - [[EDR Workflows] Fix event filter OS selector visibility and prepopulation from host events (#240791)](#240791) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Konrad Szwarc","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-10-30T17:02:39Z","message":"[EDR Workflows] Fix event filter OS selector visibility and prepopulation from host events (#240791)\n\nFixes a bug where the OS selector was hidden when creating an event\nfilter from the Host Events tab, and the OS defaulted to Windows\nregardless of the actual host OS. The OS selector is now always visible\nand correctly pre-populated with the OS value extracted from the event\ndocument's `host.os.type` field.\n\n\n\nhttps://github.com/user-attachments/assets/e682a864-c2f4-49fa-9460-a6a2e9f2573f","sha":"319e53de7ed98d820a2874642b2a27ea305c0629","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Defend Workflows","backport:version","v9.1.0","v8.19.0","v9.2.0","v9.3.0"],"title":"[EDR Workflows] Fix event filter OS selector visibility and prepopulation from host events","number":240791,"url":"https://github.com/elastic/kibana/pull/240791","mergeCommit":{"message":"[EDR Workflows] Fix event filter OS selector visibility and prepopulation from host events (#240791)\n\nFixes a bug where the OS selector was hidden when creating an event\nfilter from the Host Events tab, and the OS defaulted to Windows\nregardless of the actual host OS. The OS selector is now always visible\nand correctly pre-populated with the OS value extracted from the event\ndocument's `host.os.type` field.\n\n\n\nhttps://github.com/user-attachments/assets/e682a864-c2f4-49fa-9460-a6a2e9f2573f","sha":"319e53de7ed98d820a2874642b2a27ea305c0629"}},"sourceBranch":"main","suggestedTargetBranches":["9.1","8.19","9.2"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/240791","number":240791,"mergeCommit":{"message":"[EDR Workflows] Fix event filter OS selector visibility and prepopulation from host events (#240791)\n\nFixes a bug where the OS selector was hidden when creating an event\nfilter from the Host Events tab, and the OS defaulted to Windows\nregardless of the actual host OS. The OS selector is now always visible\nand correctly pre-populated with the OS value extracted from the event\ndocument's `host.os.type` field.\n\n\n\nhttps://github.com/user-attachments/assets/e682a864-c2f4-49fa-9460-a6a2e9f2573f","sha":"319e53de7ed98d820a2874642b2a27ea305c0629"}}]}] BACKPORT--> Co-authored-by: Konrad Szwarc <[email protected]>
1 parent 83d598d commit 4b7bbd8

File tree

5 files changed

+45
-7
lines changed

5 files changed

+45
-7
lines changed

x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/test_utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const esResponseData = () => ({
133133
Ext: {
134134
variant: 'Windows Pro',
135135
},
136+
type: 'linux',
136137
name: 'Linux',
137138
family: 'Debian OS',
138139
version: '10.0',

x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/components/event_filters_flyout.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,34 @@ describe('Event filter flyout', () => {
254254
expect(renderResult.getByText('Cancel')).not.toBeNull();
255255
});
256256

257+
it('should show OS selector and trigger enrichment when rendering with event data', async () => {
258+
const searchMock = (useKibana as jest.Mock)().services.data.search.search;
259+
const eventData = ecsEventMock();
260+
261+
act(() => {
262+
render({ data: eventData });
263+
});
264+
265+
// Verify enrichment was triggered with correct parameters
266+
await waitFor(() => {
267+
expect(searchMock).toHaveBeenCalledWith({
268+
params: {
269+
index: eventData._index,
270+
body: {
271+
query: {
272+
match: {
273+
_id: eventData._id,
274+
},
275+
},
276+
},
277+
},
278+
});
279+
});
280+
281+
const osSelect = renderResult.getByTestId('eventFilters-form-os-select');
282+
expect(osSelect).toBeVisible();
283+
});
284+
257285
it('should start with "add event filter" button disabled', () => {
258286
render();
259287
const confirmButton = renderResult.getByTestId('add-exception-confirm-button');

x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/components/event_filters_flyout.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import type {
3434
import { ArtifactConfirmModal } from '../../../../components/artifact_list_page/components/artifact_confirm_modal';
3535
import { EventFiltersForm } from './form';
3636

37-
import { getInitialExceptionFromEvent } from '../utils';
37+
import { getInitialExceptionFromEvent, osTypeBasedOnAgentType } from '../utils';
3838
import { useHttp, useKibana, useToasts } from '../../../../../common/lib/kibana';
3939

4040
import { EventFiltersApiClient } from '../../service/api_client';
@@ -74,6 +74,7 @@ export const EventFiltersFlyout: React.FC<EventFiltersFlyoutProps> = memo(
7474
useEffect(() => {
7575
const enrichEvent = async () => {
7676
if (!data || !data._index) return;
77+
7778
const searchResponse = await lastValueFrom(
7879
search.search({
7980
params: {
@@ -88,16 +89,23 @@ export const EventFiltersFlyout: React.FC<EventFiltersFlyoutProps> = memo(
8889
},
8990
})
9091
);
91-
setEnrichedData({
92+
const enriched = {
9293
...data,
9394
host: {
9495
...data.host,
9596
os: {
9697
...(data?.host?.os || {}),
97-
name: [searchResponse.rawResponse.hits.hits[0]._source.host.os.name],
98+
name: [searchResponse.rawResponse.hits.hits[0]._source.host.os.type],
9899
},
99100
},
100-
});
101+
};
102+
setEnrichedData(enriched);
103+
104+
// Update the exception with the correct OS from enriched data
105+
setException((prevException) => ({
106+
...prevException,
107+
os_types: osTypeBasedOnAgentType(enriched) as Array<'windows' | 'linux' | 'macos'>,
108+
}));
101109
};
102110

103111
if (data) {
@@ -224,7 +232,7 @@ export const EventFiltersFlyout: React.FC<EventFiltersFlyoutProps> = memo(
224232

225233
<EuiFlyoutBody>
226234
<EventFiltersForm
227-
allowSelectOs={!data}
235+
allowSelectOs
228236
error={undefined}
229237
disabled={false}
230238
item={exception}

x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/components/form.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,11 @@ export const EventFiltersForm: React.FC<ArtifactFormComponentProps & { allowSele
320320
fullWidth
321321
valueOfSelected={selectedOs}
322322
onChange={handleOnOsChange}
323+
data-test-subj={getTestId('os-select')}
323324
/>
324325
</EuiFormRow>
325326
),
326-
[handleOnOsChange, selectedOs]
327+
[getTestId, handleOnOsChange, selectedOs]
327328
);
328329

329330
// comments and handler

x-pack/solutions/security/plugins/security_solution/public/management/pages/event_filters/view/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { CreateExceptionListItemSchema } from '@kbn/securitysolution-io-ts-
1010
import type { EcsSecurityExtension as Ecs } from '@kbn/securitysolution-ecs';
1111
import { ENDPOINT_EVENT_FILTERS_LIST_ID } from '../constants';
1212

13-
const osTypeBasedOnAgentType = (data?: Ecs) => {
13+
export const osTypeBasedOnAgentType = (data?: Ecs) => {
1414
if (data?.agent?.type?.includes('endpoint')) {
1515
return (data?.host?.os?.name || ['windows']).map((name) => name.toLowerCase());
1616
} else {

0 commit comments

Comments
 (0)