-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Security Solution][Detection Engine] Fix enrichment tests for Entity Store V2 on MKI #271093
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
Open
abhishekbhatia1710
wants to merge
24
commits into
elastic:main
Choose a base branch
from
abhishekbhatia1710:ea-fix-detection-enrichment-v2-mki
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
18dfcbc
[Security Solution][Detection Engine] Fix enrichment tests for Entity…
abhishekbhatia1710 a71016a
Merge branch 'main' into ea-fix-detection-enrichment-v2-mki
abhishekbhatia1710 860818d
Remove V1 fallback from enrichment setup — always use Entity Store V2
abhishekbhatia1710 3c231d6
Merge branch 'main' into ea-fix-detection-enrichment-v2-mki
abhishekbhatia1710 182b19c
Fix: restore log service used in teardown
abhishekbhatia1710 fe5d1ef
[EA] Fix V2 enrichment setup: skip when disabled, fix user EUID mismatch
abhishekbhatia1710 f58c084
Merge branch 'main' into ea-fix-detection-enrichment-v2-mki
abhishekbhatia1710 e8b1ad7
Remove entityAnalyticsEntityStoreV2 disable flag from configs and mig…
abhishekbhatia1710 b956234
Merge branch 'main' into ea-fix-detection-enrichment-v2-mki
abhishekbhatia1710 813cb3c
Address reviewer comments: fix teardown status check, clarify EUID co…
abhishekbhatia1710 2ea6c02
Merge branch 'main' into ea-fix-detection-enrichment-v2-mki
abhishekbhatia1710 5f07216
Remove em-dash from comments
abhishekbhatia1710 1ae5fe0
cleanup
abhishekbhatia1710 d3b66c3
Fix: add entity.id to user entities, re-enable V2 on all envs, remove…
abhishekbhatia1710 fcdc46e
Remove recent anomalies search filter changes that belong to PR 271851
abhishekbhatia1710 296a781
Fix user entity.id to use @unknown namespace suffix
abhishekbhatia1710 7530a01
Fix threshold tests: use name-based host EUIDs since threshold alerts…
abhishekbhatia1710 9bd6b87
Fix indicator match user entity EUID: use local-namespace for auditbe…
abhishekbhatia1710 26db922
Fix custom_query user EUID, migrate ML enrichment tests to V2, fix ra…
abhishekbhatia1710 7fa1c3c
Merge branch 'main' into ea-fix-detection-enrichment-v2-mki
abhishekbhatia1710 e68ad19
Fix type errors: add host to UserEntityConfig, remove unused host ID …
abhishekbhatia1710 8e834e9
Skip enrichment tests when V2 unavailable, fix ready check race condi…
abhishekbhatia1710 9ba4921
Fix entity store V2 enrichment setup: broaden skip conditions and fix…
abhishekbhatia1710 7863061
Merge branch 'main' into ea-fix-detection-enrichment-v2-mki
abhishekbhatia1710 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
112 changes: 112 additions & 0 deletions
112
...ctions_response/detection_engine/rule_execution_logic/entity_store_v2_enrichment_setup.ts
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import type { FtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
|
||
| const PUBLIC_API_HEADERS: ReadonlyArray<[string, string]> = [ | ||
| ['kbn-xsrf', 'true'], | ||
| ['x-elastic-internal-origin', 'Kibana'], | ||
| ['elastic-api-version', '2023-10-31'], | ||
| ]; | ||
|
|
||
| const withHeaders = <T extends { set: (key: string, value: string) => T }>(req: T): T => | ||
| PUBLIC_API_HEADERS.reduce((acc, [k, v]) => acc.set(k, v), req); | ||
|
|
||
| export interface HostEntityConfig { | ||
| host: Record<string, unknown>; | ||
| entity?: Record<string, unknown>; | ||
| asset?: Record<string, unknown>; | ||
| } | ||
|
|
||
| export interface UserEntityConfig { | ||
| user: Record<string, unknown>; | ||
| entity?: Record<string, unknown>; | ||
| asset?: Record<string, unknown>; | ||
| } | ||
|
|
||
| export interface EnrichmentSetupConfig { | ||
| hosts?: HostEntityConfig[]; | ||
| users?: UserEntityConfig[]; | ||
| } | ||
|
|
||
| /** | ||
| * Installs Entity Store V2 engines and seeds entities for alert enrichment tests. | ||
| * | ||
| * Inspired by the approach started in https://github.com/elastic/kibana/pull/270939 | ||
| * by @denar50. | ||
| */ | ||
| export const EntityStoreV2EnrichmentSetup = (getService: FtrProviderContext['getService']) => { | ||
| const supertest = getService('supertest'); | ||
| const retry = getService('retry'); | ||
| const log = getService('log'); | ||
|
|
||
| const setup = async (enrichmentConfig: EnrichmentSetupConfig): Promise<void> => { | ||
| const entityTypes: string[] = []; | ||
| if (enrichmentConfig.hosts?.length) entityTypes.push('host'); | ||
| if (enrichmentConfig.users?.length) entityTypes.push('user'); | ||
|
|
||
| if (entityTypes.length === 0) return; | ||
|
|
||
| const installRes = await withHeaders(supertest.post('/api/security/entity_store/install')).send( | ||
| { entityTypes } | ||
| ); | ||
|
|
||
| if (installRes.status !== 200 && installRes.status !== 201) { | ||
| throw new Error( | ||
| `Entity Store V2 install failed (status ${installRes.status}): ${JSON.stringify( | ||
| installRes.body | ||
| )}` | ||
| ); | ||
| } | ||
|
|
||
| await retry.waitForWithTimeout('Entity Store V2 to be ready', 60_000, async () => { | ||
| const res = await withHeaders(supertest.get('/api/security/entity_store/status')); | ||
| if (res.body.status === 'error') { | ||
| throw new Error(`Entity Store V2 install errored: ${JSON.stringify(res.body)}`); | ||
| } | ||
| return res.body.status === 'running' || res.body.status === 'stopped'; | ||
| }); | ||
|
|
||
| for (const hostConfig of enrichmentConfig.hosts ?? []) { | ||
| const createRes = await withHeaders( | ||
| supertest.post('/api/security/entity_store/entities/host') | ||
| ).send(hostConfig); | ||
| if (createRes.status !== 200) { | ||
| throw new Error( | ||
| `Create host entity failed (status ${createRes.status}): ${JSON.stringify( | ||
| createRes.body | ||
| )}` | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| for (const userConfig of enrichmentConfig.users ?? []) { | ||
| const createRes = await withHeaders( | ||
| supertest.post('/api/security/entity_store/entities/user') | ||
| ).send(userConfig); | ||
| if (createRes.status !== 200) { | ||
| throw new Error( | ||
| `Create user entity failed (status ${createRes.status}): ${JSON.stringify( | ||
| createRes.body | ||
| )}` | ||
| ); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| const teardown = async (): Promise<void> => { | ||
| try { | ||
| await withHeaders(supertest.post('/api/security/entity_store/uninstall')).send({ | ||
|
abhishekbhatia1710 marked this conversation as resolved.
Outdated
|
||
| entityTypes: ['user', 'host', 'service'], | ||
| }); | ||
| } catch (err) { | ||
| log.debug(`Entity Store V2 uninstall skipped: ${err instanceof Error ? err.message : err}`); | ||
| } | ||
| }; | ||
|
|
||
| return { setup, teardown }; | ||
| }; | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.