Skip to content

Commit

Permalink
[ResponseOps] Granular Connector RBAC - adding back UIs for testing c…
Browse files Browse the repository at this point in the history
…onnectors in stack management (elastic#204804)

Part of elastic#180908

## Summary

As part of the changes for EDR Connector Execution for Testing, this PRs
updates the SentinelOne and Crowdstrike params UIs to limit to a single
sub-action.

SentinelOne:
<img width="861" alt="Screenshot 2024-12-18 at 11 16 49 AM"
src="https://github.com/user-attachments/assets/1a839d21-7ba7-4c4e-b3e9-8772725fad63"
/>

Crowdstrike:
<img width="855" alt="Screenshot 2024-12-18 at 11 17 01 AM"
src="https://github.com/user-attachments/assets/b6c17964-8c49-4b5a-b1c7-bb4c6bb89621"
/>

### Checklist

Check the PR satisfies following conditions.

- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### To test

1. In Stack Management create SentinelOne and Crowdstrike connectors
(They don't need to work, you can use fake values for the url and token)
2. Test the new connectors. Verify that you only see one action type and
that it can't be changed and that the params are correctly sent in the
request.

(cherry picked from commit 99f5e32)
  • Loading branch information
doakalexi committed Jan 6, 2025
1 parent 596e017 commit d02cc27
Show file tree
Hide file tree
Showing 10 changed files with 267 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ export function getConnectorType(): ConnectorTypeModel<
return { errors };
},
actionConnectorFields: lazy(() => import('./crowdstrike_connector')),
actionParamsFields: lazy(() => import('./crowdstrike_params_empty')),
// TODO: Enable once we add support for automated response actions
// actionParamsFields: lazy(() => import('./crowdstrike_params')),
actionParamsFields: lazy(() => import('./crowdstrike_params')),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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 React from 'react';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { SUB_ACTION } from '../../../common/crowdstrike/constants';
import type { CrowdstrikeActionParams } from '../../../common/crowdstrike/types';
import CrowdstrikeParamsFields from './crowdstrike_params';

const actionParams = {
subAction: SUB_ACTION.GET_AGENT_DETAILS,
subActionParams: {
ids: ['test'],
},
} as unknown as CrowdstrikeActionParams;

describe('CrowdstrikeParamsFields renders', () => {
test('all params fields are rendered', () => {
const wrapper = mountWithIntl(
<CrowdstrikeParamsFields
actionParams={actionParams}
errors={{ body: [] }}
editAction={jest.fn()}
index={0}
messageVariables={[]}
/>
);
expect(wrapper.find('[data-test-subj="actionTypeSelect"]').length > 0).toBeTruthy();
expect(wrapper.find('[data-test-subj="actionTypeSelect"]').first().prop('readOnly')).toEqual(
true
);
expect(wrapper.find('[data-test-subj="agentIdSelect"]').length > 0).toBeTruthy();
});
});
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 React, { useMemo, useCallback, useState, useEffect } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiSuperSelect, EuiComboBox } from '@elastic/eui';
import { ActionParamsProps } from '@kbn/triggers-actions-ui-plugin/public';
import { SUB_ACTION } from '../../../common/crowdstrike/constants';
import type { CrowdstrikeActionParams } from '../../../common/crowdstrike/types';
import * as i18n from './translations';

const actionTypeOptions = [
{
value: SUB_ACTION.GET_AGENT_DETAILS,
inputDisplay: i18n.GET_AGENT_DETAILS_ACTION_LABEL,
},
];

const CrowdstrikeParamsFields: React.FunctionComponent<
ActionParamsProps<CrowdstrikeActionParams>
> = ({ actionParams, editAction, index, errors }) => {
const [subActionValue] = useState<string | undefined>(SUB_ACTION.GET_AGENT_DETAILS);

const { ids } = useMemo(
() =>
actionParams.subActionParams ??
({
ids: [],
} as unknown as CrowdstrikeActionParams['subActionParams']),
[actionParams.subActionParams]
);

const labelOptions = useMemo(() => (ids ? ids.map((label: string) => ({ label })) : []), [ids]);

const editSubActionParams = useCallback(
(value: any) => {
return editAction(
'subActionParams',
{
ids: value,
},
index
);
},
[editAction, index]
);

useEffect(() => {
if (!actionParams.subAction) {
editAction('subAction', SUB_ACTION.GET_AGENT_DETAILS, index);
}
if (!actionParams.subActionParams) {
editAction(
'subActionParams',
{
ids: [],
},
index
);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [actionParams]);

return (
<EuiFlexGroup direction="column">
<EuiFlexItem>
<EuiFormRow fullWidth label={i18n.ACTION_TYPE_LABEL}>
<EuiSuperSelect
fullWidth
options={actionTypeOptions}
valueOfSelected={subActionValue}
readOnly={true}
data-test-subj="actionTypeSelect"
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem>
<EuiFormRow
fullWidth
label={i18n.AGENT_IDS_LABEL}
error={errors['subActionParams.ids'] as string[]}
>
<EuiComboBox
noSuggestions
fullWidth
selectedOptions={labelOptions}
onCreateOption={(searchValue: string) => {
const newOptions = [...labelOptions, { label: searchValue }];
editSubActionParams(newOptions.map((newOption) => newOption.label));
}}
onChange={(selectedOptions: Array<{ label: string }>) => {
editSubActionParams(selectedOptions.map((selectedOption) => selectedOption.label));
}}
onBlur={() => {
if (!ids) {
editSubActionParams([]);
}
}}
isClearable={true}
data-test-subj="agentIdSelect"
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
);
};

// eslint-disable-next-line import/no-default-export
export { CrowdstrikeParamsFields as default };

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,24 @@ export const INVALID_ACTION = i18n.translate(
defaultMessage: 'Invalid action name.',
}
);

export const ACTION_TYPE_LABEL = i18n.translate(
'xpack.stackConnectors.security.crowdstrike.params.actionTypeFieldLabel',
{
defaultMessage: 'Action type',
}
);

export const GET_AGENT_DETAILS_ACTION_LABEL = i18n.translate(
'xpack.stackConnectors.security.crowdstrike.params.getAgentDetailsActionLabel',
{
defaultMessage: 'Get agent details',
}
);

export const AGENT_IDS_LABEL = i18n.translate(
'xpack.stackConnectors.security.crowdstrike.params.agentIdsLabel',
{
defaultMessage: 'Agent IDs',
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ export function getConnectorType(): ConnectorTypeModel<
return { errors };
},
actionConnectorFields: lazy(() => import('./sentinelone_connector')),
actionParamsFields: lazy(() => import('./sentinelone_params_empty')),
actionParamsFields: lazy(() => import('./sentinelone_params')),
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 React from 'react';
import { mountWithIntl } from '@kbn/test-jest-helpers';
import { SUB_ACTION } from '../../../common/sentinelone/constants';
import type { SentinelOneActionParams } from '../../../common/sentinelone/types';
import SentinelOneParamsFields from './sentinelone_params';

const actionParams = {
subAction: SUB_ACTION.GET_AGENTS,
subActionParams: {},
} as unknown as SentinelOneActionParams;

describe('SentinelOneParamsFields renders', () => {
test('all params fields are rendered', () => {
const wrapper = mountWithIntl(
<SentinelOneParamsFields
actionParams={actionParams}
errors={{ body: [] }}
editAction={jest.fn()}
index={0}
messageVariables={[]}
/>
);
expect(wrapper.find('[data-test-subj="actionTypeSelect"]').length > 0).toBeTruthy();
expect(wrapper.find('[data-test-subj="actionTypeSelect"]').first().prop('readOnly')).toEqual(
true
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 React, { useState, useEffect } from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiSuperSelect } from '@elastic/eui';
import { ActionParamsProps } from '@kbn/triggers-actions-ui-plugin/public';
import { SUB_ACTION } from '../../../common/sentinelone/constants';
import type { SentinelOneActionParams } from '../../../common/sentinelone/types';
import * as i18n from './translations';

const actionTypeOptions = [
{
value: SUB_ACTION.GET_AGENTS,
inputDisplay: i18n.GET_AGENT_ACTION_LABEL,
},
];

const SentinelOneParamsFields: React.FunctionComponent<
ActionParamsProps<SentinelOneActionParams>
> = ({ editAction, index }) => {
const [subAction] = useState<string | undefined>(SUB_ACTION.GET_AGENTS);

useEffect(() => {
editAction('subActionParams', {}, index);
editAction('subAction', subAction, index);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<EuiFlexGroup direction="column">
<EuiFlexItem>
<EuiFormRow fullWidth label={i18n.ACTION_TYPE_LABEL}>
<EuiSuperSelect
fullWidth
options={actionTypeOptions}
valueOfSelected={subAction}
readOnly={true}
data-test-subj="actionTypeSelect"
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
);
};

// eslint-disable-next-line import/no-default-export
export { SentinelOneParamsFields as default };

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ export const RELEASE_AGENT_ACTION_LABEL = i18n.translate(
}
);

export const GET_AGENT_ACTION_LABEL = i18n.translate(
'xpack.stackConnectors.security.sentinelone.params.getAgentActionLabel',
{
defaultMessage: 'Get agent details',
}
);

export const AGENTS_FIELD_LABEL = i18n.translate(
'xpack.stackConnectors.security.sentinelone.params.agentsFieldLabel',
{
Expand All @@ -90,7 +97,7 @@ export const AGENTS_FIELD_PLACEHOLDER = i18n.translate(
export const ACTION_TYPE_LABEL = i18n.translate(
'xpack.stackConnectors.security.sentinelone.params.actionTypeFieldLabel',
{
defaultMessage: 'Action Type',
defaultMessage: 'Action type',
}
);

Expand Down

0 comments on commit d02cc27

Please sign in to comment.