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

[Backport 2.15] [Threat intel][part 3] Support for source type URL_Download and logic to activate/deactivate source #1075

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ThreatIntelS3CustomSourcePayload,
ThreatIntelSourceItem,
ThreatIntelSourcePayload,
URLDownloadSource,
} from '../../../../../types';
import { defaultIntervalUnitOptions } from '../../../../utils/constants';
import { readIocsFromFile, threatIntelSourceItemToBasePayload } from '../../utils/helpers';
Expand Down Expand Up @@ -331,6 +332,14 @@ export const ThreatIntelSourceDetails: React.FC<ThreatIntelSourceDetailsProps> =
)}
</>
)}
{type === 'URL_DOWNLOAD' && (
<EuiFormRow label="Source URL">
<EuiFieldText
readOnly={isReadOnly}
value={(sourceItem.source as URLDownloadSource).url_download?.url}
/>
</EuiFormRow>
)}
<EuiFormRow label="Types of malicious indicators">
<>
<EuiSpacer size="s" />
Expand All @@ -344,14 +353,16 @@ export const ThreatIntelSourceDetails: React.FC<ThreatIntelSourceDetailsProps> =
</EuiFormRow>
<EuiSpacer />
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
style={{ visibility: isReadOnly ? 'visible' : 'hidden' }}
onClick={() => setIsReadOnly(false)}
>
Edit
</EuiButton>
</EuiFlexItem>
{type !== 'URL_DOWNLOAD' && (
<EuiFlexItem grow={false}>
<EuiButton
style={{ visibility: isReadOnly ? 'visible' : 'hidden' }}
onClick={() => setIsReadOnly(false)}
>
Edit
</EuiButton>
</EuiFlexItem>
)}
</EuiFlexGroup>
</EuiPanel>
{!isReadOnly && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const ThreatIntelOverview: React.FC<ThreatIntelOverviewProps> = ({
initialIsOpen={threatIntelSources.length === 0 || logSources.length === 0}
>
<EuiSpacer />
<EuiFlexGroup>
<EuiFlexGroup wrap>
{threatIntelNextStepsProps.map(
({ id, title, description, footerButtonProps: { text, disabled } }) => (
<EuiFlexItem key={id}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ import { useEffect } from 'react';
import { CoreServicesContext } from '../../../../components/core_services';
import {
EuiButton,
EuiButtonIcon,
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiLoadingContent,
EuiPanel,
EuiSpacer,
EuiTabbedContent,
EuiTabbedContentTab,
EuiTitle,
EuiToolTip,
} from '@elastic/eui';
import { DescriptionGroup } from '../../../../components/Utility/DescriptionGroup';
import { IoCsTable } from '../../components/IoCsTable/IoCsTable';
Expand Down Expand Up @@ -138,8 +141,27 @@ export const ThreatIntelSource: React.FC<ThreatIntelSource> = ({
}
};

const { name, description, type, ioc_types, last_update_time, enabled } = source;
const toggleActiveState = async () => {
const updateRes = await threatIntelService.updateThreatIntelSource(source.id, {
...source,
enabled_for_scan: !source.enabled_for_scan,
});
if (updateRes.ok) {
onSourceUpdate();
}
};

const {
name,
description,
type,
ioc_types,
last_update_time,
enabled,
enabled_for_scan,
} = source;
const schedule = type === 'S3_CUSTOM' ? source.schedule : undefined;
const showActivateControls = 'enabled_for_scan' in source;

return (
<>
Expand All @@ -150,7 +172,36 @@ export const ThreatIntelSource: React.FC<ThreatIntelSource> = ({
</EuiTitle>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiFlexGroup alignItems="center">
<EuiFlexGroup alignItems="center" wrap>
{showActivateControls && (
<>
<EuiFlexItem grow={false}>
<EuiToolTip
content={
'When Active, the indicators of compromise from this source are used to scan the log data as part of the threat intel scan.'
}
>
<span>
<EuiIcon
type={'dot'}
color={enabled_for_scan ? 'success' : 'text'}
style={{ marginBottom: 4 }}
/>{' '}
{enabled_for_scan ? 'Active' : 'Inactive'}&nbsp;
<EuiIcon type={'iInCircle'} />
</span>
</EuiToolTip>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
color={enabled_for_scan ? 'danger' : 'primary'}
onClick={toggleActiveState}
>
{enabled_for_scan ? 'Deactivate' : 'Activate'}
</EuiButton>
</EuiFlexItem>
</>
)}
{type === 'S3_CUSTOM' && (
<EuiFlexItem grow={false}>
<EuiButton fill onClick={onRefresh}>
Expand All @@ -159,9 +210,9 @@ export const ThreatIntelSource: React.FC<ThreatIntelSource> = ({
</EuiFlexItem>
)}
<EuiFlexItem grow={false}>
<EuiButton color="danger" onClick={onDeleteButtonClick}>
Delete
</EuiButton>
<EuiToolTip content={'Delete'}>
<EuiButtonIcon iconType={'trash'} color="danger" onClick={onDeleteButtonClick} />
</EuiToolTip>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
Expand Down
22 changes: 21 additions & 1 deletion types/ThreatIntel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,19 @@ export interface FileUploadSource {
};
}

export interface URLDownloadSource {
url_download: {
url: string;
};
}

export interface ThreatIntelSourcePayloadBase {
name: string;
description?: string;
format: 'STIX2';
store_type: 'OS';
enabled: boolean;
enabled_for_scan: boolean;
ioc_types: ThreatIntelIocType[];
}

Expand All @@ -78,9 +85,22 @@ export interface ThreatIntelIocUploadSourcePayload extends ThreatIntelSourcePayl
source: FileUploadSource;
}

export interface ThreatIntelURLDownloadSourceInfo extends ThreatIntelSourcePayloadBase {
type: 'URL_DOWNLOAD';
schedule: {
interval: {
start_time: number;
period: number;
unit: string;
};
};
source: URLDownloadSource;
}

export type ThreatIntelSourcePayload =
| ThreatIntelS3CustomSourcePayload
| ThreatIntelIocUploadSourcePayload;
| ThreatIntelIocUploadSourcePayload
| ThreatIntelURLDownloadSourceInfo;

export interface LogSourceIocConfig {
enabled: boolean;
Expand Down
Loading