-
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
EMT-339: policy response schema, views and tests #65962
Changes from 3 commits
9de6691
ddedf86
6089a2e
dd9d00a
c7e9d41
440fd0d
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 | ||||
---|---|---|---|---|---|---|
|
@@ -611,47 +611,27 @@ export enum HostPolicyResponseActionStatus { | |||||
} | ||||||
|
||||||
/** | ||||||
* The details of a given action | ||||||
* Host Policy Response Applied Action | ||||||
*/ | ||||||
export interface HostPolicyResponseActionDetails { | ||||||
export interface HostPolicyResponseAppliedAction { | ||||||
name: string; | ||||||
status: HostPolicyResponseActionStatus; | ||||||
message: string; | ||||||
} | ||||||
|
||||||
/** | ||||||
* A known list of possible Endpoint actions | ||||||
*/ | ||||||
export interface HostPolicyResponseActions { | ||||||
download_model: HostPolicyResponseActionDetails; | ||||||
ingest_events_config: HostPolicyResponseActionDetails; | ||||||
workflow: HostPolicyResponseActionDetails; | ||||||
configure_elasticsearch_connection: HostPolicyResponseActionDetails; | ||||||
configure_kernel: HostPolicyResponseActionDetails; | ||||||
configure_logging: HostPolicyResponseActionDetails; | ||||||
configure_malware: HostPolicyResponseActionDetails; | ||||||
connect_kernel: HostPolicyResponseActionDetails; | ||||||
detect_file_open_events: HostPolicyResponseActionDetails; | ||||||
detect_file_write_events: HostPolicyResponseActionDetails; | ||||||
detect_image_load_events: HostPolicyResponseActionDetails; | ||||||
detect_process_events: HostPolicyResponseActionDetails; | ||||||
download_global_artifacts: HostPolicyResponseActionDetails; | ||||||
load_config: HostPolicyResponseActionDetails; | ||||||
load_malware_model: HostPolicyResponseActionDetails; | ||||||
read_elasticsearch_config: HostPolicyResponseActionDetails; | ||||||
read_events_config: HostPolicyResponseActionDetails; | ||||||
read_kernel_config: HostPolicyResponseActionDetails; | ||||||
read_logging_config: HostPolicyResponseActionDetails; | ||||||
read_malware_config: HostPolicyResponseActionDetails; | ||||||
} | ||||||
|
||||||
/** | ||||||
* policy configurations returned by the endpoint in response to a user applying a policy | ||||||
*/ | ||||||
export type HostPolicyResponseConfiguration = HostPolicyResponse['endpoint']['policy']['applied']['response']['configurations']; | ||||||
|
||||||
interface HostPolicyResponseConfigurationStatus { | ||||||
status: HostPolicyResponseActionStatus; | ||||||
concerned_actions: Array<keyof HostPolicyResponseActions>; | ||||||
concerned_actions: string[]; | ||||||
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. If you implement the suggestion above, this would then be:
Suggested change
|
||||||
} | ||||||
|
||||||
/** | ||||||
* Host Policy Response Applied Artifact | ||||||
*/ | ||||||
interface HostPolicyResponseAppliedArtifact { | ||||||
name: string; | ||||||
sha256: string; | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -674,6 +654,11 @@ export interface HostPolicyResponse { | |||||
created: number; | ||||||
kind: string; | ||||||
id: string; | ||||||
category: string; | ||||||
type: string; | ||||||
module: string; | ||||||
action: string; | ||||||
dataset: string; | ||||||
}; | ||||||
agent: { | ||||||
version: string; | ||||||
|
@@ -685,7 +670,7 @@ export interface HostPolicyResponse { | |||||
version: string; | ||||||
id: string; | ||||||
status: HostPolicyResponseActionStatus; | ||||||
actions: Partial<HostPolicyResponseActions>; | ||||||
actions: HostPolicyResponseAppliedAction[]; | ||||||
policy: { | ||||||
id: string; | ||||||
version: string; | ||||||
|
@@ -698,6 +683,16 @@ export interface HostPolicyResponse { | |||||
streaming: HostPolicyResponseConfigurationStatus; | ||||||
}; | ||||||
}; | ||||||
artifacts: { | ||||||
global: { | ||||||
version: string; | ||||||
identifiers: HostPolicyResponseAppliedArtifact[]; | ||||||
}; | ||||||
user: { | ||||||
version: string; | ||||||
identifiers: HostPolicyResponseAppliedArtifact[]; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
}; | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,16 +80,18 @@ export const hostMiddlewareFactory: ImmutableMiddlewareFactory<HostState> = core | |
version: '1.0.0', | ||
status: HostPolicyResponseActionStatus.success, | ||
id: '17d4b81d-9940-4b64-9de5-3e03ef1fb5cf', | ||
actions: { | ||
download_model: { | ||
actions: [ | ||
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. you probably added this only because @parkiino has not yet merged her change that integrates with API, correct (and to suppress ts errors)? 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. Yes just to get the test to pass. |
||
{ | ||
name: 'download_model', | ||
status: 'success', | ||
message: 'Model downloaded', | ||
}, | ||
ingest_events_config: { | ||
{ | ||
name: 'ingest_events_config', | ||
status: 'failure', | ||
message: 'No action taken', | ||
}, | ||
}, | ||
], | ||
response: { | ||
configurations: { | ||
malware: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,10 @@ import querystring from 'querystring'; | |
import { createSelector } from 'reselect'; | ||
import { | ||
Immutable, | ||
HostPolicyResponseActions, | ||
HostPolicyResponseAppliedAction, | ||
HostPolicyResponseConfiguration, | ||
HostPolicyResponseActionStatus, | ||
ImmutableArray, | ||
} from '../../../../../common/types'; | ||
import { HostState, HostIndexUIQueryParams } from '../../types'; | ||
|
||
|
@@ -62,7 +63,8 @@ export const policyResponseFailedOrWarningActionCount: ( | |
Object.entries(applied.response.configurations).map(([key, val]) => { | ||
let count = 0; | ||
for (const action of val.concerned_actions) { | ||
const actionStatus = applied.actions[action]?.status; | ||
const actionStatus = applied.actions.find(policyActions => policyActions.name === action) | ||
?.status; | ||
if ( | ||
actionStatus === HostPolicyResponseActionStatus.failure || | ||
actionStatus === HostPolicyResponseActionStatus.warning | ||
|
@@ -81,7 +83,7 @@ export const policyResponseFailedOrWarningActionCount: ( | |
*/ | ||
export const policyResponseActions: ( | ||
state: Immutable<HostState> | ||
) => undefined | Partial<HostPolicyResponseActions> = createSelector( | ||
) => undefined | ImmutableArray<HostPolicyResponseAppliedAction> = createSelector( | ||
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. Just use |
||
detailsPolicyAppliedResponse, | ||
applied => { | ||
return applied?.actions; | ||
|
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.
It would be nice if we could have a permissive list of possible actions that we could use here and everywhere else where we do
string[]
. Some like this:Then on this line (and other areas below):
Tried it quickly on my IDE and seems to work ok even with custom unknown strings: