-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Security solution][Endpoint] Add Host Isolation related data to the endpoint generator and test data loader #100727
Changes from all commits
d19aeae
4d9c717
0d4e75d
4d45c0a
fd57e28
0ffdafe
9e8bd54
d48ae6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,21 @@ export interface EndpointAction { | |
}; | ||
} | ||
|
||
export interface EndpointActionResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this already exist anywhere else? @ashokaditya maybe in your PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might exist in Ash's draft. Does not exist anywhere else yet, since we don't really know what the success structure looks like (or even failure when it comes from the endpoint). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I was wondering that as well. Feels like the Agent should know what an error/success looks like since they are the ones writing this to es. (just by looking at the schema, I thought that if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agent knows about the fields it writes. It does not know about the fields Endpoint writes (and vice versa). AFAIK it treats the response given via endpoint as a total unparsed black box, wraps it with its own fields, and then passes to fleet server (where maybe more fields are written? no? who knows?). that |
||
'@timestamp': string; | ||
/** The id of the action for which this response is associated with */ | ||
action_id: string; | ||
/** The agent id that sent this action response */ | ||
agent_id: string; | ||
started_at: string; | ||
completed_at: string; | ||
error: string; | ||
action_data: { | ||
command: ISOLATION_ACTIONS; | ||
comment?: string; | ||
}; | ||
} | ||
|
||
export type HostIsolationRequestBody = TypeOf<typeof HostIsolationRequestSchema.body>; | ||
|
||
export interface HostIsolationResponse { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
future improvement:
Math.random() < 0.2 ? !isIsolated : isIsolated
perhaps