-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Security Solution][Endpoint] Endpoint generator and data loader supp…
…ort for Host Isolation (#100813) Re-introduces the changes from #100727 which was backed out due to a bug. Changes included: * Generate random isolation values for endpoint metadata * Generator for Fleet Actions * Added creation of actions to the index test data loader Plus: * Fix generator `randomBoolean()` to ensure it works with seeded random numbers * Update resolver snapshots due to additional call to randomizer
- Loading branch information
1 parent
fc3814d
commit db8ff04
Showing
7 changed files
with
197 additions
and
51 deletions.
There are no files selected for viewing
This file contains 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
62 changes: 62 additions & 0 deletions
62
x-pack/plugins/security_solution/common/endpoint/data_generators/fleet_action_generator.ts
This file contains 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,62 @@ | ||
/* | ||
* 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 { DeepPartial } from 'utility-types'; | ||
import { merge } from 'lodash'; | ||
import { BaseDataGenerator } from './base_data_generator'; | ||
import { EndpointAction, EndpointActionResponse, ISOLATION_ACTIONS } from '../types'; | ||
|
||
const ISOLATION_COMMANDS: ISOLATION_ACTIONS[] = ['isolate', 'unisolate']; | ||
|
||
export class FleetActionGenerator extends BaseDataGenerator { | ||
/** Generate an Action */ | ||
generate(overrides: DeepPartial<EndpointAction> = {}): EndpointAction { | ||
const timeStamp = new Date(this.randomPastDate()); | ||
|
||
return merge( | ||
{ | ||
action_id: this.randomUUID(), | ||
'@timestamp': timeStamp.toISOString(), | ||
expiration: this.randomFutureDate(timeStamp), | ||
type: 'INPUT_ACTION', | ||
input_type: 'endpoint', | ||
agents: [this.randomUUID()], | ||
user_id: 'elastic', | ||
data: { | ||
command: this.randomIsolateCommand(), | ||
comment: this.randomString(15), | ||
}, | ||
}, | ||
overrides | ||
); | ||
} | ||
|
||
/** Generates an action response */ | ||
generateResponse(overrides: DeepPartial<EndpointActionResponse> = {}): EndpointActionResponse { | ||
const timeStamp = new Date(); | ||
|
||
return merge( | ||
{ | ||
action_data: { | ||
command: this.randomIsolateCommand(), | ||
comment: '', | ||
}, | ||
action_id: this.randomUUID(), | ||
agent_id: this.randomUUID(), | ||
started_at: this.randomPastDate(), | ||
completed_at: timeStamp.toISOString(), | ||
error: 'some error happen', | ||
'@timestamp': timeStamp.toISOString(), | ||
}, | ||
overrides | ||
); | ||
} | ||
|
||
protected randomIsolateCommand() { | ||
return this.randomChoice(ISOLATION_COMMANDS); | ||
} | ||
} |
This file contains 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 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 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 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.