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

[RAC] integrating rbac search strategy with alert flyout #107748

Merged
merged 6 commits into from
Aug 12, 2021
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
5 changes: 4 additions & 1 deletion x-pack/plugins/cases/public/components/case_view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const CaseComponent = React.memo<CaseComponentProps>(
const [initLoadingData, setInitLoadingData] = useState(true);
const init = useRef(true);
const timelineUi = useTimelineContext()?.ui;
const alertConsumers = useTimelineContext()?.alertConsumers;

const {
caseUserActions,
Expand Down Expand Up @@ -486,7 +487,9 @@ export const CaseComponent = React.memo<CaseComponentProps>(
</EuiFlexGroup>
</ContentWrapper>
</WhitePageWrapper>
{timelineUi?.renderTimelineDetailsPanel ? timelineUi.renderTimelineDetailsPanel() : null}
{timelineUi?.renderTimelineDetailsPanel
? timelineUi.renderTimelineDetailsPanel({ alertConsumers })
: null}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React, { useState } from 'react';
import { EuiMarkdownEditorUiPlugin, EuiMarkdownAstNodePosition } from '@elastic/eui';
import type { AlertConsumers } from '@kbn/rule-data-utils/target/alerts_as_data_rbac';
import { Plugin } from 'unified';
/**
* @description - manage the plugins, hooks, and ui components needed to enable timeline functionality within the cases plugin
Expand All @@ -28,6 +29,7 @@ interface TimelineProcessingPluginRendererProps {
}

export interface CasesTimelineIntegration {
alertConsumers?: AlertConsumers[];
editor_plugins: {
parsingPlugin: Plugin;
processingPluginRenderer: React.FC<
Expand All @@ -43,7 +45,11 @@ export interface CasesTimelineIntegration {
};
ui?: {
renderInvestigateInTimelineActionComponent?: (alertIds: string[]) => JSX.Element;
renderTimelineDetailsPanel?: () => JSX.Element;
renderTimelineDetailsPanel?: ({
alertConsumers,
}: {
alertConsumers?: AlertConsumers[];
}) => JSX.Element;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React, { useCallback, useRef, useState } from 'react';
import { useDispatch } from 'react-redux';
import { AlertConsumers } from '@kbn/rule-data-utils/target/alerts_as_data_rbac';

import {
getCaseDetailsUrl,
Expand All @@ -33,6 +34,7 @@ import { SpyRoute } from '../../../common/utils/route/spy_routes';
import * as timelineMarkdownPlugin from '../../../common/components/markdown_editor/plugins/timeline';
import { CaseDetailsRefreshContext } from '../../../common/components/endpoint/host_isolation/endpoint_host_isolation_cases_context';
import { getEndpointDetailsPath } from '../../../management/common/routing';
import { EntityType } from '../../../timelines/containers/details';

interface Props {
caseId: string;
Expand All @@ -53,13 +55,17 @@ export interface CaseProps extends Props {
updateCase: (newCase: Case) => void;
}

const TimelineDetailsPanel = () => {
const ALERT_CONSUMER: AlertConsumers[] = [AlertConsumers.SIEM];

const TimelineDetailsPanel = ({ alertConsumers }: { alertConsumers?: AlertConsumers[] }) => {
const { browserFields, docValueFields } = useSourcererScope(SourcererScopeName.detections);

return (
<DetailsPanel
alertConsumers={alertConsumers}
browserFields={browserFields}
docValueFields={docValueFields}
entityType={EntityType.ALERTS}
isFlyoutView
timelineId={TimelineId.casePage}
/>
Expand Down Expand Up @@ -228,6 +234,7 @@ export const CaseView = React.memo(({ caseId, subCaseId, userCanCrud }: Props) =
showAlertDetails,
subCaseId,
timelineIntegration: {
alertConsumers: ALERT_CONSUMER,
editor_plugins: {
parsingPlugin: timelineMarkdownPlugin.parser,
processingPluginRenderer: timelineMarkdownPlugin.renderer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import deepEqual from 'fast-deep-equal';
import styled from 'styled-components';

import { isEmpty } from 'lodash/fp';
import { AlertConsumers } from '@kbn/rule-data-utils/target/alerts_as_data_rbac';
import { inputsModel, inputsSelectors, State } from '../../store';
import { inputsActions } from '../../store/actions';
import { ControlColumnProps, RowRenderer, TimelineId } from '../../../../common/types/timeline';
Expand All @@ -30,6 +31,7 @@ import { useKibana } from '../../lib/kibana';
import { defaultControlColumn } from '../../../timelines/components/timeline/body/control_columns';
import { EventsViewer } from './events_viewer';
import * as i18n from './translations';
import { EntityType } from '../../../timelines/containers/details';

const EMPTY_CONTROL_COLUMNS: ControlColumnProps[] = [];
const leadingControlColumns: ControlColumnProps[] = [
Expand Down Expand Up @@ -67,6 +69,8 @@ export interface OwnProps {

type Props = OwnProps & PropsFromRedux;

const alertConsumers: AlertConsumers[] = [AlertConsumers.SIEM];

/**
* The stateful events viewer component is the highest level component that is utilized across the security_solution pages layer where
* timeline is used BESIDES the flyout. The flyout makes use of the `EventsViewer` component which is a subcomponent here
Expand Down Expand Up @@ -205,7 +209,9 @@ const StatefulEventsViewerComponent: React.FC<Props> = ({
</InspectButtonContainer>
</FullScreenContainer>
<DetailsPanel
alertConsumers={alertConsumers}
browserFields={browserFields}
entityType={EntityType.ALERTS}
docValueFields={docValueFields}
isFlyoutView
timelineId={id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import {
import React, { useState, useCallback, useMemo } from 'react';
import styled from 'styled-components';
import deepEqual from 'fast-deep-equal';
import { AlertConsumers } from '@kbn/rule-data-utils/target/alerts_as_data_rbac';
import { BrowserFields, DocValueFields } from '../../../../common/containers/source';
import { ExpandableEvent, ExpandableEventTitle } from './expandable_event';
import { useTimelineEventsDetails } from '../../../containers/details';
import { EntityType, useTimelineEventsDetails } from '../../../containers/details';
import { TimelineTabs } from '../../../../../common/types/timeline';
import { HostIsolationPanel } from '../../../../detections/components/host_isolation';
import { EndpointIsolateSuccess } from '../../../../common/components/endpoint/host_isolation';
Expand Down Expand Up @@ -49,8 +50,10 @@ const StyledEuiFlyoutBody = styled(EuiFlyoutBody)`
`;

interface EventDetailsPanelProps {
alertConsumers?: AlertConsumers[];
browserFields: BrowserFields;
docValueFields: DocValueFields[];
entityType?: EntityType;
expandedEvent: {
eventId: string;
indexName: string;
Expand All @@ -65,16 +68,20 @@ interface EventDetailsPanelProps {
}

const EventDetailsPanelComponent: React.FC<EventDetailsPanelProps> = ({
alertConsumers,
browserFields,
docValueFields,
entityType,
expandedEvent,
handleOnEventClosed,
isFlyoutView,
tabType,
timelineId,
}) => {
const [loading, detailsData] = useTimelineEventsDetails({
alertConsumers,
docValueFields,
entityType,
indexName: expandedEvent.indexName ?? '',
eventId: expandedEvent.eventId ?? '',
skip: !expandedEvent.eventId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import React, { useCallback, useMemo } from 'react';
import { useDispatch } from 'react-redux';
import { EuiFlyout, EuiFlyoutProps } from '@elastic/eui';
import { AlertConsumers } from '@kbn/rule-data-utils/target/alerts_as_data_rbac';

import { timelineActions, timelineSelectors } from '../../store/timeline';
import { timelineDefaults } from '../../store/timeline/defaults';
import { BrowserFields, DocValueFields } from '../../../common/containers/source';
Expand All @@ -16,10 +18,13 @@ import { useDeepEqualSelector } from '../../../common/hooks/use_selector';
import { EventDetailsPanel } from './event_details';
import { HostDetailsPanel } from './host_details';
import { NetworkDetailsPanel } from './network_details';
import { EntityType } from '../../containers/details';

interface DetailsPanelProps {
alertConsumers?: AlertConsumers[];
browserFields: BrowserFields;
docValueFields: DocValueFields[];
entityType?: EntityType;
handleOnPanelClosed?: () => void;
isFlyoutView?: boolean;
tabType?: TimelineTabs;
Expand All @@ -33,8 +38,10 @@ interface DetailsPanelProps {
*/
export const DetailsPanel = React.memo(
({
alertConsumers,
browserFields,
docValueFields,
entityType,
handleOnPanelClosed,
isFlyoutView,
tabType,
Expand Down Expand Up @@ -70,8 +77,10 @@ export const DetailsPanel = React.memo(
panelSize = 'm';
visiblePanel = (
<EventDetailsPanel
alertConsumers={alertConsumers}
browserFields={browserFields}
docValueFields={docValueFields}
entityType={entityType}
expandedEvent={currentTabDetail?.params}
handleOnEventClosed={closePanel}
isFlyoutView={isFlyoutView}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EuiFlyoutFooter,
EuiBadge,
} from '@elastic/eui';
import { AlertConsumers } from '@kbn/rule-data-utils/target/alerts_as_data_rbac';
import { isEmpty } from 'lodash/fp';
import React, { useEffect, useCallback } from 'react';
import styled from 'styled-components';
Expand Down Expand Up @@ -151,6 +152,8 @@ export type Props = OwnProps & PropsFromRedux;

const NO_SORTING: Sort[] = [];

const alertConsumers: AlertConsumers[] = [AlertConsumers.SIEM];

export const EqlTabContentComponent: React.FC<Props> = ({
activeTab,
columns,
Expand Down Expand Up @@ -346,6 +349,7 @@ export const EqlTabContentComponent: React.FC<Props> = ({
<VerticalRule />
<ScrollableFlexItem grow={1}>
<DetailsPanel
alertConsumers={alertConsumers}
browserFields={browserFields}
docValueFields={docValueFields}
tabType={TimelineTabs.eql}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
EuiPanel,
EuiHorizontalRule,
} from '@elastic/eui';
import { AlertConsumers } from '@kbn/rule-data-utils/target/alerts_as_data_rbac';

import React, { Fragment, useCallback, useMemo, useState } from 'react';
import { useDispatch } from 'react-redux';
import styled from 'styled-components';
Expand Down Expand Up @@ -64,6 +66,8 @@ const Username = styled(EuiText)`
font-weight: bold;
`;

const alertConsumers: AlertConsumers[] = [AlertConsumers.SIEM];

interface UsernameWithAvatar {
username: string;
}
Expand Down Expand Up @@ -170,6 +174,7 @@ const NotesTabContentComponent: React.FC<NotesTabContentProps> = ({ timelineId }
() =>
expandedDetail[TimelineTabs.notes]?.panelView ? (
<DetailsPanel
alertConsumers={alertConsumers}
browserFields={browserFields}
docValueFields={docValueFields}
handleOnPanelClosed={handleOnPanelClosed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { EuiFlexGroup, EuiFlexItem, EuiFlyoutBody, EuiFlyoutFooter } from '@elastic/eui';
import { AlertConsumers } from '@kbn/rule-data-utils/target/alerts_as_data_rbac';
import { isEmpty } from 'lodash/fp';
import React, { useMemo, useCallback } from 'react';
import styled from 'styled-components';
Expand Down Expand Up @@ -88,6 +89,8 @@ const VerticalRule = styled.div`

VerticalRule.displayName = 'VerticalRule';

const alertConsumers: AlertConsumers[] = [AlertConsumers.SIEM];

interface OwnProps {
renderCellValue: (props: CellValueElementProps) => React.ReactNode;
rowRenderers: RowRenderer[];
Expand Down Expand Up @@ -266,6 +269,7 @@ export const PinnedTabContentComponent: React.FC<Props> = ({
<VerticalRule />
<ScrollableFlexItem grow={1}>
<DetailsPanel
alertConsumers={alertConsumers}
browserFields={browserFields}
docValueFields={docValueFields}
handleOnPanelClosed={handleOnPanelClosed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
EuiFlyoutFooter,
EuiBadge,
} from '@elastic/eui';
import { AlertConsumers } from '@kbn/rule-data-utils/target/alerts_as_data_rbac';
import { isEmpty } from 'lodash/fp';
import React, { useState, useMemo, useEffect, useCallback } from 'react';
import styled from 'styled-components';
Expand Down Expand Up @@ -135,6 +136,8 @@ const EventsCountBadge = styled(EuiBadge)`
margin-left: ${({ theme }) => theme.eui.paddingSizes.s};
`;

const alertConsumers: AlertConsumers[] = [AlertConsumers.SIEM];

const isTimerangeSame = (prevProps: Props, nextProps: Props) =>
prevProps.end === nextProps.end &&
prevProps.start === nextProps.start &&
Expand Down Expand Up @@ -414,6 +417,7 @@ export const QueryTabContentComponent: React.FC<Props> = ({
<VerticalRule />
<ScrollableFlexItem grow={1}>
<DetailsPanel
alertConsumers={alertConsumers}
browserFields={browserFields}
docValueFields={docValueFields}
handleOnPanelClosed={handleOnPanelClosed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isEmpty, noop } from 'lodash/fp';
import { useCallback, useEffect, useRef, useState } from 'react';
import deepEqual from 'fast-deep-equal';
import { Subscription } from 'rxjs';
import { AlertConsumers } from '@kbn/rule-data-utils/target/alerts_as_data_rbac';

import { inputsModel } from '../../../common/store';
import { useKibana } from '../../../common/lib/kibana';
Expand All @@ -23,18 +24,28 @@ import { isCompleteResponse, isErrorResponse } from '../../../../../../../src/pl
import { useAppToasts } from '../../../common/hooks/use_app_toasts';
import * as i18n from './translations';

export enum EntityType {
ALERTS = 'alerts',
EVENTS = 'events',
}
export interface EventsArgs {
detailsData: TimelineEventsDetailsItem[] | null;
}

export interface UseTimelineEventsDetailsProps {
alertConsumers?: AlertConsumers[];
entityType?: EntityType;
docValueFields: DocValueFields[];
indexName: string;
eventId: string;
skip: boolean;
}

const EMPTY_ARRAY: AlertConsumers[] = [];

export const useTimelineEventsDetails = ({
alertConsumers = EMPTY_ARRAY,
entityType = EntityType.EVENTS,
docValueFields,
indexName,
eventId,
Expand Down Expand Up @@ -104,7 +115,9 @@ export const useTimelineEventsDetails = ({
setTimelineDetailsRequest((prevRequest) => {
const myRequest = {
...(prevRequest ?? {}),
alertConsumers,
docValueFields,
entityType,
indexName,
eventId,
factoryQueryType: TimelineEventsQueries.details,
Expand All @@ -114,7 +127,7 @@ export const useTimelineEventsDetails = ({
}
return prevRequest;
});
}, [docValueFields, eventId, indexName]);
}, [alertConsumers, docValueFields, entityType, eventId, indexName]);

useEffect(() => {
timelineDetailsSearch(timelineDetailsRequest);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/timelines/common/utils/field_formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const getDataFromSourceHits = (
category?: string,
path?: string
): TimelineEventsDetailsItem[] =>
Object.keys(sources).reduce<TimelineEventsDetailsItem[]>((accumulator, source) => {
Object.keys(sources ?? {}).reduce<TimelineEventsDetailsItem[]>((accumulator, source) => {
const item: EventSource = get(source, sources);
if (Array.isArray(item) || isString(item) || isNumber(item)) {
const field = path ? `${path}.${source}` : source;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export const timelineEventsDetails: TimelineFactory<TimelineEventsQueries.detail
const inspect = {
dsl: [inspectStringifyObject(buildTimelineDetailsQuery(indexName, eventId, docValueFields))],
};

if (response.isRunning) {
return {
...response,
Expand Down