Skip to content
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

D3 Security Sub Actions Connector #158569

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f676315
Add d3 connector
d3-naiji Nov 9, 2022
9dd38a3
d3_connector_paramsChange
d3-naiji Nov 9, 2022
671e764
D3NewConnectorType
d3-naiji Nov 9, 2022
432b9a7
newParamsBody
d3-naiji Nov 11, 2022
00c12cd
Removed extra console log and revised codes
d3-naiji Nov 14, 2022
a101013
readme_update
d3-naiji Nov 15, 2022
7df0081
Updated unit test
d3-naiji Nov 15, 2022
9c995a5
Fix Syntax errors after merge new file structure
d3-naiji May 11, 2023
ca0a818
Merge branch 'main' into new-connector-type-d3-security-v2
d3-naiji May 11, 2023
1bc4a20
Merge branch 'main' into new-connector-type-d3-security-v2
d3-bensong May 18, 2023
d4b5ef0
fix(new-connector-type-d3-security-v2): fix bugs
d3-bensong May 19, 2023
482e7f1
Merge branch 'main' into new-connector-type-d3-security-v2
stephmilovic May 26, 2023
85c7d62
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine May 26, 2023
6967536
Merge branch 'main' into new-connector-type-d3-security-v2
d3-bensong May 26, 2023
5ed4467
cleanup
stephmilovic May 26, 2023
bf873de
linting
stephmilovic May 26, 2023
3c0bf43
fix merge
stephmilovic May 26, 2023
14b4053
fix test and translaiton
stephmilovic May 26, 2023
375f9ca
fix lint issue
stephmilovic May 26, 2023
a7b6ebf
fix
stephmilovic May 26, 2023
7055370
added docs
stephmilovic May 26, 2023
b2d2dbf
fix docs
stephmilovic May 26, 2023
9e8288a
Fix test
stephmilovic May 26, 2023
750b69e
fix test
stephmilovic May 26, 2023
0484761
fix(new-connector-type-d3-security-v2): fix build issues
d3-bensong May 29, 2023
487e01a
Merge branch 'elastic:main' into new-connector-type-d3-security-v2
d3-bensong May 29, 2023
c795da8
fix(new-connector-type-d3-security-v2): fix lint error
d3-bensong May 29, 2023
3f998f9
fix(new-connector-type-d3-security-v2): fix i18n issues
d3-bensong May 29, 2023
05ff285
Merge branch 'main' into new-connector-type-d3-security-v2
d3-bensong May 29, 2023
9885d3f
merge in d3
stephmilovic May 30, 2023
273df5f
Merge branch 'main' into new-connector-type-d3-security-v2
d3-bensong May 30, 2023
0bfec84
fix(new-connector-type-d3-security-v2): fix lint error
d3-bensong May 30, 2023
0ff1815
Merge branch 'main' into new-connector-type-d3-security-v2
d3-bensong May 31, 2023
0fb616d
Merge remote-tracking branch 'd3/new-connector-type-d3-security-v2' i…
stephmilovic May 31, 2023
9694289
Merge branch 'main' into new-connector-type-d3-security-v2
d3-bensong May 31, 2023
c3b678b
implement subactions
stephmilovic May 31, 2023
6d52d79
fix schema
stephmilovic May 31, 2023
baf9d2c
add tests
stephmilovic May 31, 2023
6d261ff
add api tests
stephmilovic May 31, 2023
d0a9587
fix small mistakes
stephmilovic Jun 1, 2023
11091e1
Merge remote-tracking branch 'd3/new-connector-type-d3-security-v2' i…
stephmilovic Jun 1, 2023
40848f4
Merge branch 'main' into new-connector-type-d3-security-v2
stephmilovic Jun 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/management/action-types.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ a| <<gen-ai-action-type,Generative AI>>

| Send a request to OpenAI.

a| <<d3security-action-type,D3 Security>>

| Send a request to D3 Security.

|===

[NOTE]
Expand Down
91 changes: 91 additions & 0 deletions docs/management/connectors/action-types/d3security.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
[[d3security-action-type]]
== D3 Security connector and action
++++
<titleabbrev>D3 Security</titleabbrev>
++++

The D3 Security connector uses https://github.com/axios/axios[axios] to send a POST request to a D3 Security endpoint. The connector uses the <<execute-connector-api,run connector API>> to send the request. You can use the connector for rule actions.

[float]
[[d3security-connector-prerequisites]]
=== Prerequisites

To use a D3 Security connector, you must first configure a webhook key in your D3 SOAR environment. To generate an API URL and a token in D3 Security:
1. Log in to your D3 SOAR environment.
2. Navigate to Configuration.
3. Navigate to Integration > Search for “Kibana”. Click “Fetch Event”.
4. Select the "Enable Webhook" checkbox.
5. Click Set up Webhook Keys.
6. Under Event Ingestion, Click +. Select the site for the webhook integration, then click Generate.
7. Copy the Request URL and Request Header Value to configure the Kibana connector

[float]
[[define-d3security-ui]]
=== Create connectors in {kib}

You can create connectors in *{stack-manage-app} > {connectors-ui}*. For example:

[role="screenshot"]
image::management/connectors/images/d3security-connector.png[D3 Security connector]

[float]
[[d3security-connector-configuration]]
==== Connector configuration

D3 Security connectors have the following configuration properties:

Name:: The name of the connector.
URL:: The D3 Security API request URL.
Token:: The D3 Security token

[float]
[[preconfigured-d3security-configuration]]
=== Create preconfigured connectors

If you are running {kib} on-prem, you can define connectors by
adding `xpack.actions.preconfigured` settings to your `kibana.yml` file.
For example:

[source,text]
--
xpack.actions.preconfigured:
my-d3security:
name: preconfigured-d3security-connector-type
actionTypeId: .d3security
config:
url: https://testurl.com/elasticsearch/VSOC/api/Data/Kibana/Security%20Operations/CreateEvents
secrets:
token: superlongtoken
--

Config defines information for the connector type.

`url`:: A URL string that corresponds to the *D3 Security API URL*.

Secrets defines sensitive information for the connector type.

`token`:: A string that corresponds to *D3 Security API Token*.

[float]
[[d3security-action-configuration]]
=== Test connectors

You can test connectors with the <<execute-connector-api,run connector API>> or
as you're creating or editing the connector in {kib}. For example:

[role="screenshot"]
image::management/connectors/images/d3security-params-test.png[D3 Security params test]

The D3 Security actions have the following configuration properties.

Body:: A typeless payload sent to the D3 Security API URL. For example:
+
[source,text]
--
this can be any type, it is not validated
--
[float]
[[d3security-connector-networking-configuration]]
=== Connector networking configuration

Use the <<action-settings, Action configuration settings>> to customize connector networking configurations, such as proxies, certificates, or TLS settings. You can set configurations that apply to all your connectors or use `xpack.actions.customHostSettings` to set per-host configurations.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/management/connectors/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ include::action-types/webhook.asciidoc[leveloffset=+1]
include::action-types/cases-webhook.asciidoc[leveloffset=+1]
include::action-types/xmatters.asciidoc[leveloffset=+1]
include::action-types/gen-ai.asciidoc[leveloffset=+1]
include::action-types/d3security.asciidoc[leveloffset=+1]
include::pre-configured-connectors.asciidoc[leveloffset=+1]
2 changes: 1 addition & 1 deletion docs/settings/alert-action-settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ WARNING: This feature is available in {kib} 7.17.4 and 8.3.0 onwards but is not
A boolean value indicating that a footer with a relevant link should be added to emails sent as alerting actions. Default: true.

`xpack.actions.enabledActionTypes` {ess-icon}::
A list of action types that are enabled. It defaults to `[*]`, enabling all types. The names for built-in {kib} action types are prefixed with a `.` and include: `.email`, `.index`, `.jira`, `.opsgenie`, `.pagerduty`, `.resilient`, `.server-log`, `.servicenow`, .`servicenow-itom`, `.servicenow-sir`, `.slack`, `.swimlane`, `.teams`, `.tines`, `.torq`, `.xmatters`, `.gen-ai`, and `.webhook`. An empty list `[]` will disable all action types.
A list of action types that are enabled. It defaults to `[*]`, enabling all types. The names for built-in {kib} action types are prefixed with a `.` and include: `.email`, `.index`, `.jira`, `.opsgenie`, `.pagerduty`, `.resilient`, `.server-log`, `.servicenow`, .`servicenow-itom`, `.servicenow-sir`, `.slack`, `.swimlane`, `.teams`, `.tines`, `.torq`, `.xmatters`, `.gen-ai`, `.d3security`, and `.webhook`. An empty list `[]` will disable all action types.
+
Disabled action types will not appear as an option when creating new connectors, but existing connectors and actions of that type will remain in {kib} and will not function.

Expand Down
26 changes: 26 additions & 0 deletions x-pack/plugins/stack_connectors/common/d3security/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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 { i18n } from '@kbn/i18n';

export const D3_SECURITY_TITLE = i18n.translate(
'xpack.stackConnectors.components.d3Security.connectorTypeTitle',
{
defaultMessage: 'D3 Security',
}
);
export const D3_SECURITY_CONNECTOR_ID = '.d3security';
export enum SUB_ACTION {
RUN = 'run',
TEST = 'test',
}
export enum D3SecuritySeverity {
EMPTY = '',
HIGH = 'high',
MEDIUM = 'medium',
LOW = 'low',
}
30 changes: 30 additions & 0 deletions x-pack/plugins/stack_connectors/common/d3security/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 { schema } from '@kbn/config-schema';
import { D3SecuritySeverity } from './constants';

// Connector schema
export const D3SecurityConfigSchema = schema.object({
url: schema.string(),
});

export const D3SecuritySecretsSchema = schema.object({ token: schema.string() });

// Run action schema
export const D3SecurityRunActionParamsSchema = schema.object({
body: schema.maybe(schema.string()),
severity: schema.maybe(schema.string({ defaultValue: D3SecuritySeverity.EMPTY })),
eventType: schema.maybe(schema.string({ defaultValue: '' })),
});

export const D3SecurityRunActionResponseSchema = schema.object(
{
refid: schema.string(),
},
{ unknowns: 'ignore' }
);
19 changes: 19 additions & 0 deletions x-pack/plugins/stack_connectors/common/d3security/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 { TypeOf } from '@kbn/config-schema';
import {
D3SecurityConfigSchema,
D3SecuritySecretsSchema,
D3SecurityRunActionParamsSchema,
D3SecurityRunActionResponseSchema,
} from './schema';

export type D3SecurityConfig = TypeOf<typeof D3SecurityConfigSchema>;
export type D3SecuritySecrets = TypeOf<typeof D3SecuritySecretsSchema>;
export type D3SecurityRunActionParams = TypeOf<typeof D3SecurityRunActionParamsSchema>;
export type D3SecurityRunActionResponse = TypeOf<typeof D3SecurityRunActionResponseSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* 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 D3SecurityConnectorFields from './connector';
import { ConnectorFormTestProvider } from '../lib/test_utils';
import { act, render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

jest.mock('@kbn/triggers-actions-ui-plugin/public/common/lib/kibana');

describe('D3ActionConnectorFields renders', () => {
test('D3Security connector fields are rendered', () => {
const actionConnector = {
actionTypeId: '.d3security',
name: 'd3security',
config: {
url: 'https://test.com',
},
secrets: {
Token: 'token',
},
isDeprecated: false,
};

const wrapper = mountWithIntl(
<ConnectorFormTestProvider connector={actionConnector}>
<D3SecurityConnectorFields
readOnly={false}
isEdit={false}
registerPreSubmitValidator={() => {}}
/>
</ConnectorFormTestProvider>
);

expect(wrapper.find('[data-test-subj="config.url-input"]').length > 0).toBeTruthy();
expect(wrapper.find('[data-test-subj="secrets.token-input"]').length > 0).toBeTruthy();
});

describe('Validation', () => {
const onSubmit = jest.fn();

beforeEach(() => {
jest.clearAllMocks();
});

const tests: Array<[string, string]> = [
['config.url-input', 'not-valid'],
['secrets.token-input', ''],
];

it('connector validation succeeds when connector config is valid', async () => {
const actionConnector = {
actionTypeId: '.d3security',
name: 'd3security',
config: {
url: 'https://test.com',
},
secrets: {
token: 'token',
},
isDeprecated: false,
};

const { getByTestId } = render(
<ConnectorFormTestProvider connector={actionConnector} onSubmit={onSubmit}>
<D3SecurityConnectorFields
readOnly={false}
isEdit={false}
registerPreSubmitValidator={() => {}}
/>
</ConnectorFormTestProvider>
);

await act(async () => {
userEvent.click(getByTestId('form-test-provide-submit'));
});

waitFor(() => {
expect(onSubmit).toBeCalledWith({
data: {
actionTypeId: '.d3security',
name: 'd3security',
config: {
url: 'https://test.com',
},
secrets: {
token: 'token',
},
isDeprecated: false,
},
isValid: true,
});
});
});

it.each(tests)('validates correctly %p', async (field, value) => {
const actionConnector = {
actionTypeId: '.d3security',
name: 'd3security',
config: {
url: 'https://test.com',
},
secrets: {
token: 'token',
},
isDeprecated: false,
};

const res = render(
<ConnectorFormTestProvider connector={actionConnector} onSubmit={onSubmit}>
<D3SecurityConnectorFields
readOnly={false}
isEdit={false}
registerPreSubmitValidator={() => {}}
/>
</ConnectorFormTestProvider>
);

await act(async () => {
await userEvent.type(res.getByTestId(field), `{selectall}{backspace}${value}`, {
delay: 10,
});
});

await act(async () => {
userEvent.click(res.getByTestId('form-test-provide-submit'));
});

expect(onSubmit).toHaveBeenCalledWith({ data: {}, isValid: false });
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 { ActionConnectorFieldsProps } from '@kbn/triggers-actions-ui-plugin/public';
import {
ConfigFieldSchema,
SimpleConnectorForm,
SecretsFieldSchema,
} from '@kbn/triggers-actions-ui-plugin/public';
import * as i18n from './translations';

const configFormSchema: ConfigFieldSchema[] = [
{ id: 'url', label: i18n.D3_URL_LABEL, isUrlField: true },
];

const secretsFormSchema: SecretsFieldSchema[] = [
{ id: 'token', label: i18n.D3_TOKEN_LABEL, isPasswordField: true },
];

const D3SecurityConnectorFields: React.FC<ActionConnectorFieldsProps> = ({ readOnly, isEdit }) => {
return (
<>
<SimpleConnectorForm
isEdit={isEdit}
readOnly={readOnly}
configFormSchema={configFormSchema}
secretsFormSchema={secretsFormSchema}
/>
</>
);
};

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