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

TheHive Case Connector #180138

Merged
merged 23 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9d1522e
Add thehive case connector
brijesh-elastic Apr 5, 2024
8a527cc
Merge branch 'main' into thehive_case_connector
brijesh-elastic Apr 17, 2024
b5d8164
resolve review comments
brijesh-elastic Apr 17, 2024
1c8d856
Merge branch 'main' into thehive_case_connector
brijesh-elastic Apr 19, 2024
0eeed1b
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Apr 19, 2024
4f2cc46
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Apr 19, 2024
5f96889
Add documentation and functional test
brijesh-elastic Apr 19, 2024
86c87fd
update minimumLicenseRequired to platinum
brijesh-elastic Apr 23, 2024
d6b7ae3
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Apr 23, 2024
a31e7b8
Merge branch 'main' into thehive_case_connector
brijesh-elastic May 6, 2024
f576b5f
Refactor UI and update server code to align with CaseConnector framew…
brijesh-elastic May 6, 2024
c5eee3f
Merge branch 'main' into thehive_case_connector
brijesh-elastic May 30, 2024
fa74245
Disable Recovered ActionGroup
brijesh-elastic May 30, 2024
57bb7fe
Merge branch 'main' into thehive_case_connector
brijesh-elastic Jul 15, 2024
51d4bea
Apply Translations and fix test cases
brijesh-elastic Jul 16, 2024
c9636fe
Resolve list and test issue
brijesh-elastic Jul 16, 2024
beb6a40
Resolve build failure
brijesh-elastic Jul 17, 2024
f5a5a60
hide the connector in UI for intermediate release
js-jankisalvi Jul 25, 2024
3ee54d4
Merge branch 'main' into thehive_case_connector
js-jankisalvi Jul 25, 2024
103d1a9
Merge branch 'main' into thehive_case_connector
elasticmachine Jul 26, 2024
d5c5eca
Resolve bugfix
brijesh-elastic Jul 29, 2024
c269aee
Merge branch 'main' into thehive_case_connector
elasticmachine Jul 29, 2024
a6c054e
Preserve severity, tlp and tag values in UI
brijesh-elastic Jul 30, 2024
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 @@ -88,6 +88,10 @@ a| <<swimlane-action-type,{swimlane}>>

| Create an incident in {swimlane}.

a| <<thehive-action-type,{thehive}>>

| Create cases and alerts in {thehive}.

a| <<tines-action-type,Tines>>

| Send events to a Tines Story.
Expand Down
79 changes: 79 additions & 0 deletions docs/management/connectors/action-types/thehive.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[[thehive-action-type]]
== TheHive connector and action
++++
<titleabbrev>TheHive</titleabbrev>
++++
:frontmatter-description: Add a connector that can create cases and alerts in TheHive.
:frontmatter-tags-products: [kibana]
:frontmatter-tags-content-type: [how-to]
:frontmatter-tags-user-goals: [configure]

TheHive connector uses the https://docs.strangebee.com/thehive/api-docs/[TheHive (v1) REST API] to create cases and alerts.

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

You can create connectors in *{stack-manage-app} > {connectors-ui}*
or as needed when you're creating a rule. For example:

[role="screenshot"]
image::management/connectors/images/thehive-connector.png[TheHive connector]
// NOTE: This is an autogenerated screenshot. Do not edit it directly.

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

TheHive connectors have the following configuration properties:

Name:: The name of the connector.
Organisation:: Organisation name in which user intends to create cases or alerts.
URL:: TheHive instance URL.
API Key:: TheHive API key for authentication.

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

You can test connectors for creating a case or an alert 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/thehive-params-case-test.png[TheHive case params test]
// NOTE: This is an autogenerated screenshot. Do not edit it directly.

[role="screenshot"]
image::management/connectors/images/thehive-params-alert-test.png[TheHive alert params test]
// NOTE: This is an autogenerated screenshot. Do not edit it directly.

TheHive actions have the following configuration properties.

Event Action:: Action that will be performed in thehive. Supported actions are Create Case (default) and Create Alert.
Title:: Title of the incident.
Description:: The details about the incident.
Severity:: Severity of the incident. This can be one of `LOW`, `MEDIUM`(default), `HIGH` or `CRITICAL`.
TLP:: Traffic Light Protocol designation for the incident. This can be one of `CLEAR`, `GREEN`, `AMBER`(default), `AMBER+STRICT` or `RED`.
Tags:: The keywords or tags about the incident.
Additional comments:: Additional information about the Case.
Type:: Type of the Alert.
Source:: Source of the Alert.
Source Reference:: Source reference of the Alert.

[float]
[[thehive-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.

[float]
[[configure-thehive]]
=== Configure TheHive

To generate an API Key in TheHive:

1. Log in to your TheHive instance.
2. Open profile tab and select the settings.
3. Go to *API Key*.
4. Click *Create* if no API key has been created previously; otherwise, you can view the API key by clicking on *Reveal*.
5. Copy the *API key* value to configure the connector in {kib}.
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.
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 @@ -18,6 +18,7 @@ include::action-types/servicenow-sir.asciidoc[leveloffset=+1]
include::action-types/servicenow-itom.asciidoc[leveloffset=+1]
include::action-types/swimlane.asciidoc[leveloffset=+1]
include::action-types/slack.asciidoc[leveloffset=+1]
include::action-types/thehive.asciidoc[leveloffset=+1]
include::action-types/tines.asciidoc[leveloffset=+1]
include::action-types/torq.asciidoc[leveloffset=+1]
include::action-types/webhook.asciidoc[leveloffset=+1]
Expand Down
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`, `.bedrock`, `.gemini`, `.d3security`, 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`, `.thehive`, `.tines`, `.torq`, `.xmatters`, `.gen-ai`, `.bedrock`, `.gemini`, `.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
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/common/disabled_action_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { RecoveredActionGroup } from './builtin_action_groups';

const DisabledActionGroupsByActionType: Record<string, string[]> = {
[RecoveredActionGroup.id]: ['.jira', '.resilient'],
[RecoveredActionGroup.id]: ['.jira', '.resilient', '.thehive'],
};

export const DisabledActionTypeIdsForActionGroup: Map<string, string[]> = new Map(
Expand Down
34 changes: 34 additions & 0 deletions x-pack/plugins/stack_connectors/common/thehive/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 THEHIVE_TITLE = i18n.translate(
'xpack.stackConnectors.components.thehive.connectorTypeTitle',
{
defaultMessage: 'TheHive',
}
);
export const THEHIVE_CONNECTOR_ID = '.thehive';

export enum SUB_ACTION {
PUSH_TO_SERVICE = 'pushToService',
CREATE_ALERT = 'createAlert',
}
export enum TheHiveSeverity {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember discussing it but just to be sure, are we sure that the severity and the TLP values are fixed and cannot be changed by users in TheHive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, users can't change or add new enum for severity and TLP in TheHive.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm, the TLP, PAP and Severity are static values in TheHive

LOW = 1,
MEDIUM = 2,
HIGH = 3,
CRITICAL = 4,
}
export enum TheHiveTLP {
CLEAR = 0,
GREEN = 1,
AMBER = 2,
AMBER_STRICT = 3,
RED = 4,
}
186 changes: 186 additions & 0 deletions x-pack/plugins/stack_connectors/common/thehive/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
* 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 { TheHiveSeverity, TheHiveTLP, SUB_ACTION } from './constants';

export const TheHiveConfigSchema = schema.object({
url: schema.string(),
organisation: schema.nullable(schema.string()),
});

export const TheHiveSecretsSchema = schema.object({
apiKey: schema.string(),
});

export const ExecutorSubActionPushParamsSchema = schema.object({
incident: schema.object({
title: schema.string(),
description: schema.string(),
externalId: schema.nullable(schema.string()),
severity: schema.nullable(schema.number({ defaultValue: TheHiveSeverity.MEDIUM })),
tlp: schema.nullable(schema.number({ defaultValue: TheHiveTLP.AMBER })),
tags: schema.nullable(schema.arrayOf(schema.string())),
}),
comments: schema.nullable(
schema.arrayOf(
schema.object({
comment: schema.string(),
commentId: schema.string(),
})
)
),
});

export const PushToServiceIncidentSchema = {
title: schema.string(),
description: schema.string(),
severity: schema.nullable(schema.number()),
tlp: schema.nullable(schema.number()),
tags: schema.nullable(schema.arrayOf(schema.string())),
};

export const ExecutorSubActionGetIncidentParamsSchema = schema.object({
externalId: schema.string(),
});

export const ExecutorSubActionCreateAlertParamsSchema = schema.object({
title: schema.string(),
description: schema.string(),
type: schema.string(),
source: schema.string(),
sourceRef: schema.string(),
severity: schema.nullable(schema.number({ defaultValue: TheHiveSeverity.MEDIUM })),
tlp: schema.nullable(schema.number({ defaultValue: TheHiveTLP.AMBER })),
tags: schema.nullable(schema.arrayOf(schema.string())),
});

export const ExecutorParamsSchema = schema.oneOf([
schema.object({
subAction: schema.literal(SUB_ACTION.PUSH_TO_SERVICE),
subActionParams: ExecutorSubActionPushParamsSchema,
}),
schema.object({
subAction: schema.literal(SUB_ACTION.CREATE_ALERT),
subActionParams: ExecutorSubActionCreateAlertParamsSchema,
}),
]);

export const TheHiveIncidentResponseSchema = schema.object(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that we need all the fields to be listed in the schema? Do we use them all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we don't use all of them. However, I've included them all as a precaution for future needs.

LMK your thoughts.

Copy link
Member

@cnasikas cnasikas Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure what is best tbh. Assuming TheHIve will not introduce any breaking changes in the fields I do not see any harm in keeping them. If they do then our validation will start failing. The more field we have the more the chance for this to happen. If they are documented here https://docs.strangebee.com/thehive/api-docs/#operation/Create%20case then I think it is fine to keep them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, They are documented.

{
_id: schema.string(),
_type: schema.string(),
_createdBy: schema.string(),
_updatedBy: schema.nullable(schema.string()),
_createdAt: schema.number(),
_updatedAt: schema.nullable(schema.number()),
number: schema.number(),
title: schema.string(),
description: schema.string(),
severity: schema.number(),
severityLabel: schema.string(),
startDate: schema.number(),
endDate: schema.nullable(schema.number()),
tags: schema.nullable(schema.arrayOf(schema.string())),
flag: schema.boolean(),
tlp: schema.number(),
tlpLabel: schema.string(),
pap: schema.number(),
papLabel: schema.string(),
status: schema.string(),
stage: schema.string(),
summary: schema.nullable(schema.string()),
impactStatus: schema.nullable(schema.string()),
assignee: schema.nullable(schema.string()),
customFields: schema.nullable(schema.arrayOf(schema.recordOf(schema.string(), schema.any()))),
userPermissions: schema.nullable(schema.arrayOf(schema.string())),
extraData: schema.object({}, { unknowns: 'allow' }),
newDate: schema.number(),
inProgressDate: schema.nullable(schema.number()),
closedDate: schema.nullable(schema.number()),
alertDate: schema.nullable(schema.number()),
alertNewDate: schema.nullable(schema.number()),
alertInProgressDate: schema.nullable(schema.number()),
alertImportedDate: schema.nullable(schema.number()),
timeToDetect: schema.number(),
timeToTriage: schema.nullable(schema.number()),
timeToQualify: schema.nullable(schema.number()),
timeToAcknowledge: schema.nullable(schema.number()),
timeToResolve: schema.nullable(schema.number()),
handlingDuration: schema.nullable(schema.number()),
},
{ unknowns: 'ignore' }
);

export const TheHiveUpdateIncidentResponseSchema = schema.any();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does TheHive return when you update a case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a PATCH request and it returns 204 No Content.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Do you know if schema.never() works? Not of this PR, but maybe the framework should skip the validation if the response is 204 No Content.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will check and update.


export const TheHiveAddCommentResponseSchema = schema.object(
{
_id: schema.string(),
_type: schema.string(),
createdBy: schema.string(),
createdAt: schema.number(),
updatedAt: schema.nullable(schema.number()),
updatedBy: schema.nullable(schema.string()),
message: schema.string(),
isEdited: schema.boolean(),
extraData: schema.object({}, { unknowns: 'allow' }),
},
{ unknowns: 'ignore' }
);

export const TheHiveCreateAlertResponseSchema = schema.object(
{
_id: schema.string(),
_type: schema.string(),
_createdBy: schema.string(),
_updatedBy: schema.nullable(schema.string()),
_createdAt: schema.number(),
_updatedAt: schema.nullable(schema.number()),
type: schema.string(),
source: schema.string(),
sourceRef: schema.string(),
externalLink: schema.nullable(schema.string()),
title: schema.string(),
description: schema.string(),
severity: schema.number(),
severityLabel: schema.string(),
date: schema.number(),
tags: schema.nullable(schema.arrayOf(schema.string())),
tlp: schema.number(),
tlpLabel: schema.string(),
pap: schema.number(),
papLabel: schema.string(),
follow: schema.nullable(schema.boolean()),
customFields: schema.nullable(schema.arrayOf(schema.object({}, { unknowns: 'allow' }))),
caseTemplate: schema.nullable(schema.string()),
observableCount: schema.number(),
caseId: schema.nullable(schema.string()),
status: schema.string(),
stage: schema.string(),
assignee: schema.nullable(schema.string()),
summary: schema.nullable(schema.string()),
extraData: schema.object({}, { unknowns: 'allow' }),
newDate: schema.number(),
inProgressDate: schema.nullable(schema.number()),
closedDate: schema.nullable(schema.number()),
importedDate: schema.nullable(schema.number()),
timeToDetect: schema.number(),
timeToTriage: schema.nullable(schema.number()),
timeToQualify: schema.nullable(schema.number()),
timeToAcknowledge: schema.nullable(schema.number()),
},
{ unknowns: 'ignore' }
);

export const TheHiveFailureResponseSchema = schema.object(
{
type: schema.number(),
message: schema.string(),
},
{ unknowns: 'ignore' }
);
39 changes: 39 additions & 0 deletions x-pack/plugins/stack_connectors/common/thehive/types.ts
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 { TypeOf } from '@kbn/config-schema';
import {
TheHiveConfigSchema,
TheHiveSecretsSchema,
ExecutorParamsSchema,
ExecutorSubActionPushParamsSchema,
ExecutorSubActionCreateAlertParamsSchema,
TheHiveFailureResponseSchema,
TheHiveIncidentResponseSchema,
} from './schema';

export type TheHiveConfig = TypeOf<typeof TheHiveConfigSchema>;
export type TheHiveSecrets = TypeOf<typeof TheHiveSecretsSchema>;

export type ExecutorParams = TypeOf<typeof ExecutorParamsSchema>;
export type ExecutorSubActionPushParams = TypeOf<typeof ExecutorSubActionPushParamsSchema>;
export type ExecutorSubActionCreateAlertParams = TypeOf<
typeof ExecutorSubActionCreateAlertParamsSchema
>;

export type TheHiveFailureResponse = TypeOf<typeof TheHiveFailureResponseSchema>;

export interface ExternalServiceIncidentResponse {
id: string;
title: string;
url: string;
pushedDate: string;
}

export type Incident = Omit<ExecutorSubActionPushParams['incident'], 'externalId'>;

export type GetIncidentResponse = TypeOf<typeof TheHiveIncidentResponseSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { getXmattersConnectorType } from './xmatters';
import { getD3SecurityConnectorType } from './d3security';
import { ExperimentalFeaturesService } from '../common/experimental_features_service';
import { getSentinelOneConnectorType } from './sentinelone';
import { getTheHiveConnectorType } from './thehive';
import { getCrowdStrikeConnectorType } from './crowdstrike';

export interface RegistrationServices {
Expand Down Expand Up @@ -71,6 +72,7 @@ export function registerConnectorTypes({
connectorTypeRegistry.register(getTorqConnectorType());
connectorTypeRegistry.register(getTinesConnectorType());
connectorTypeRegistry.register(getD3SecurityConnectorType());
connectorTypeRegistry.register(getTheHiveConnectorType());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @cnasikas, does the new convention to put new connectors under a feature flag apply to this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Yes, we need to follow the new intermediate release process for all new connectors.


if (ExperimentalFeaturesService.get().sentinelOneConnectorOn) {
connectorTypeRegistry.register(getSentinelOneConnectorType());
Expand Down
Loading