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

[7.10] [Security Solution][Detections] Immediately refresh exceptions when new list is created after rule creation (#81014) #81245

Merged
merged 1 commit into from
Oct 21, 2020
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 @@ -23,7 +23,7 @@ export type ReturnExceptionListAndItems = [
* Hook for using to get an ExceptionList and it's ExceptionListItems
*
* @param http Kibana http service
* @param lists array of ExceptionIdentifiers for all lists to fetch
* @param lists array of ExceptionListIdentifiers for all lists to fetch
* @param onError error callback
* @param onSuccess callback when all lists fetched successfully
* @param filterOptions optional - filter by fields or tags
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/lists/public/exceptions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface UseExceptionListSuccess {

export interface UseExceptionListProps {
http: HttpStart;
lists: ExceptionIdentifiers[];
lists: ExceptionListIdentifiers[];
onError?: (arg: string[]) => void;
filterOptions: FilterExceptionsOptions[];
pagination?: Pagination;
Expand All @@ -60,7 +60,7 @@ export interface UseExceptionListProps {
onSuccess?: (arg: UseExceptionListSuccess) => void;
}

export interface ExceptionIdentifiers {
export interface ExceptionListIdentifiers {
id: string;
listId: string;
namespaceType: NamespaceType;
Expand Down Expand Up @@ -91,7 +91,7 @@ export interface ApiCallMemoProps {
}

export interface ApiCallFindListsItemsMemoProps {
lists: ExceptionIdentifiers[];
lists: ExceptionListIdentifiers[];
filterOptions: FilterExceptionsOptions[];
pagination: Partial<Pagination>;
showDetectionsListsOnly: boolean;
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/lists/public/exceptions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import { NamespaceType } from '../../common/schemas';

import { ExceptionIdentifiers } from './types';
import { ExceptionListIdentifiers } from './types';

export const getIdsAndNamespaces = ({
lists,
showDetection,
showEndpoint,
}: {
lists: ExceptionIdentifiers[];
lists: ExceptionListIdentifiers[];
showDetection: boolean;
showEndpoint: boolean;
}): { ids: string[]; namespaces: NamespaceType[] } =>
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lists/public/shared_exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export {
} from './exceptions/api';
export {
ExceptionList,
ExceptionIdentifiers,
ExceptionListIdentifiers,
Pagination,
UseExceptionListSuccess,
} from './exceptions/types';
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ interface Props {
kqlMode: KqlMode;
onChangeItemsPerPage: OnChangeItemsPerPage;
query: Query;
onRuleChange?: () => void;
start: string;
sort: Sort;
toggleColumn: (column: ColumnHeaderOptions) => void;
Expand Down Expand Up @@ -131,6 +132,7 @@ const EventsViewerComponent: React.FC<Props> = ({
kqlMode,
onChangeItemsPerPage,
query,
onRuleChange,
start,
sort,
toggleColumn,
Expand Down Expand Up @@ -286,6 +288,7 @@ const EventsViewerComponent: React.FC<Props> = ({
docValueFields={docValueFields}
id={id}
isEventViewer={true}
onRuleChange={onRuleChange}
refetch={refetch}
sort={sort}
toggleColumn={toggleColumn}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface OwnProps {
start: string;
headerFilterGroup?: React.ReactNode;
pageFilters?: Filter[];
onRuleChange?: () => void;
utilityBar?: (refetch: inputsModel.Refetch, totalCount: number) => React.ReactNode;
}

Expand All @@ -64,6 +65,7 @@ const StatefulEventsViewerComponent: React.FC<Props> = ({
kqlMode,
pageFilters,
query,
onRuleChange,
removeColumn,
start,
scopeId,
Expand Down Expand Up @@ -153,6 +155,7 @@ const StatefulEventsViewerComponent: React.FC<Props> = ({
kqlMode={kqlMode}
onChangeItemsPerPage={onChangeItemsPerPage}
query={query}
onRuleChange={onRuleChange}
start={start}
sort={sort}
toggleColumn={toggleColumn}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ExceptionListItemIdentifiers, Filter } from '../types';
import { allExceptionItemsReducer, State, ViewerModalName } from './reducer';
import {
useExceptionList,
ExceptionIdentifiers,
ExceptionListIdentifiers,
ExceptionListTypeEnum,
ExceptionListItemSchema,
UseExceptionListSuccess,
Expand Down Expand Up @@ -54,7 +54,7 @@ interface ExceptionsViewerProps {
ruleId: string;
ruleName: string;
ruleIndices: string[];
exceptionListsMeta: ExceptionIdentifiers[];
exceptionListsMeta: ExceptionListIdentifiers[];
availableListTypes: ExceptionListTypeEnum[];
commentsAccordionId: string;
onRuleChange?: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import {
ExceptionListType,
ExceptionListItemSchema,
ExceptionIdentifiers,
ExceptionListIdentifiers,
Pagination,
} from '../../../../../public/lists_plugin_deps';

Expand All @@ -36,7 +36,7 @@ export interface State {
export type Action =
| {
type: 'setExceptions';
lists: ExceptionIdentifiers[];
lists: ExceptionListIdentifiers[];
exceptions: ExceptionListItemSchema[];
pagination: Pagination;
}
Expand All @@ -48,7 +48,7 @@ export type Action =
| { type: 'updateModalOpen'; modalName: ViewerModalName }
| {
type: 'updateExceptionToEdit';
lists: ExceptionIdentifiers[];
lists: ExceptionListIdentifiers[];
exception: ExceptionListItemSchema;
}
| { type: 'updateLoadingItemIds'; items: ExceptionListItemIdentifiers[] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface OwnProps {
hasIndexWrite: boolean;
from: string;
loading: boolean;
onRuleChange?: () => void;
showBuildingBlockAlerts: boolean;
onShowBuildingBlockAlertsChanged: (showBuildingBlockAlerts: boolean) => void;
to: string;
Expand All @@ -75,6 +76,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
isSelectAllChecked,
loading,
loadingEventIds,
onRuleChange,
selectedEventIds,
setEventsDeleted,
setEventsLoading,
Expand Down Expand Up @@ -330,6 +332,7 @@ export const AlertsTableComponent: React.FC<AlertsTableComponentProps> = ({
end={to}
headerFilterGroup={headerFilterGroup}
id={timelineId}
onRuleChange={onRuleChange}
scopeId={SourcererScopeName.detections}
start={from}
utilityBar={utilityBarCallback}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { FILTER_OPEN, FILTER_CLOSED, FILTER_IN_PROGRESS } from '../alerts_filter
import { updateAlertStatusAction } from '../actions';
import { SetEventsDeletedProps, SetEventsLoadingProps } from '../types';
import { Ecs } from '../../../../../common/ecs';
import { AddExceptionModal as AddExceptionModalComponent } from '../../../../common/components/exceptions/add_exception_modal';
import { AddExceptionModal } from '../../../../common/components/exceptions/add_exception_modal';
import * as i18nCommon from '../../../../common/translations';
import * as i18n from '../translations';
import {
Expand All @@ -45,13 +45,15 @@ interface AlertContextMenuProps {
disabled: boolean;
ecsRowData: Ecs;
refetch: inputsModel.Refetch;
onRuleChange?: () => void;
timelineId: string;
}

const AlertContextMenuComponent: React.FC<AlertContextMenuProps> = ({
disabled,
ecsRowData,
refetch,
onRuleChange,
timelineId,
}) => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -376,7 +378,7 @@ const AlertContextMenuComponent: React.FC<AlertContextMenuProps> = ({
</EventsTdContent>
</EventsTd>
{exceptionModalType != null && ruleId != null && ecsRowData != null && (
<AddExceptionModalComponent
<AddExceptionModal
ruleName={ruleName}
ruleId={ruleId}
ruleIndices={ruleIndices}
Expand All @@ -385,6 +387,7 @@ const AlertContextMenuComponent: React.FC<AlertContextMenuProps> = ({
onCancel={onAddExceptionCancel}
onConfirm={onAddExceptionConfirm}
alertStatus={alertStatus}
onRuleChange={onRuleChange}
/>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import { ExceptionsViewer } from '../../../../../common/components/exceptions/vi
import { DEFAULT_INDEX_PATTERN } from '../../../../../../common/constants';
import { useFullScreen } from '../../../../../common/containers/use_full_screen';
import { Display } from '../../../../../hosts/pages/display';
import { ExceptionListTypeEnum, ExceptionIdentifiers } from '../../../../../shared_imports';
import { ExceptionListTypeEnum, ExceptionListIdentifiers } from '../../../../../shared_imports';
import { isMlRule } from '../../../../../../common/machine_learning/helpers';
import { isThresholdRule } from '../../../../../../common/detection_engine/utils';
import { useRuleAsync } from '../../../../containers/detection_engine/rules/use_rule_async';
Expand Down Expand Up @@ -354,12 +354,12 @@ export const RuleDetailsPageComponent: FC<PropsFromRedux> = ({
const { indicesExist, indexPattern } = useSourcererScope(SourcererScopeName.detections);

const exceptionLists = useMemo((): {
lists: ExceptionIdentifiers[];
lists: ExceptionListIdentifiers[];
allowedExceptionListTypes: ExceptionListTypeEnum[];
} => {
if (rule != null && rule.exceptions_list != null) {
return rule.exceptions_list.reduce<{
lists: ExceptionIdentifiers[];
lists: ExceptionListIdentifiers[];
allowedExceptionListTypes: ExceptionListTypeEnum[];
}>(
(acc, { id, list_id: listId, namespace_type: namespaceType, type }) => {
Expand Down Expand Up @@ -542,6 +542,7 @@ export const RuleDetailsPageComponent: FC<PropsFromRedux> = ({
loading={loading}
showBuildingBlockAlerts={showBuildingBlockAlerts}
onShowBuildingBlockAlertsChanged={onShowBuildingBlockAlertsChangedCallback}
onRuleChange={refreshRule}
to={to}
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/security_solution/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export {
updateExceptionListItem,
fetchExceptionListById,
addExceptionList,
ExceptionIdentifiers,
ExceptionListIdentifiers,
ExceptionList,
Pagination,
UseExceptionListSuccess,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ interface Props {
onRowSelected: OnRowSelected;
onUnPinEvent: OnUnPinEvent;
refetch: inputsModel.Refetch;
onRuleChange?: () => void;
selectedEventIds: Readonly<Record<string, TimelineNonEcsData[]>>;
showCheckboxes: boolean;
showNotes: boolean;
Expand Down Expand Up @@ -88,6 +89,7 @@ export const EventColumnView = React.memo<Props>(
onRowSelected,
onUnPinEvent,
refetch,
onRuleChange,
selectedEventIds,
showCheckboxes,
showNotes,
Expand Down Expand Up @@ -157,6 +159,7 @@ export const EventColumnView = React.memo<Props>(
timelineId={timelineId}
disabled={eventType !== 'signal'}
refetch={refetch}
onRuleChange={onRuleChange}
/>,
],
[
Expand All @@ -171,6 +174,7 @@ export const EventColumnView = React.memo<Props>(
isEventPinned,
isEventViewer,
refetch,
onRuleChange,
showNotes,
status,
timelineId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface Props {
onUnPinEvent: OnUnPinEvent;
pinnedEventIds: Readonly<Record<string, boolean>>;
refetch: inputsModel.Refetch;
onRuleChange?: () => void;
rowRenderers: RowRenderer[];
selectedEventIds: Readonly<Record<string, TimelineNonEcsData[]>>;
showCheckboxes: boolean;
Expand Down Expand Up @@ -77,6 +78,7 @@ const EventsComponent: React.FC<Props> = ({
onUnPinEvent,
pinnedEventIds,
refetch,
onRuleChange,
rowRenderers,
selectedEventIds,
showCheckboxes,
Expand Down Expand Up @@ -108,6 +110,7 @@ const EventsComponent: React.FC<Props> = ({
onUpdateColumns={onUpdateColumns}
refetch={refetch}
rowRenderers={rowRenderers}
onRuleChange={onRuleChange}
selectedEventIds={selectedEventIds}
showCheckboxes={showCheckboxes}
timelineId={id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface Props {
onUpdateColumns: OnUpdateColumns;
isEventPinned: boolean;
refetch: inputsModel.Refetch;
onRuleChange?: () => void;
rowRenderers: RowRenderer[];
selectedEventIds: Readonly<Record<string, TimelineNonEcsData[]>>;
showCheckboxes: boolean;
Expand Down Expand Up @@ -129,6 +130,7 @@ const StatefulEventComponent: React.FC<Props> = ({
onUnPinEvent,
onUpdateColumns,
refetch,
onRuleChange,
rowRenderers,
selectedEventIds,
showCheckboxes,
Expand Down Expand Up @@ -208,6 +210,7 @@ const StatefulEventComponent: React.FC<Props> = ({
onRowSelected={onRowSelected}
onUnPinEvent={onUnPinEvent}
refetch={refetch}
onRuleChange={onRuleChange}
selectedEventIds={selectedEventIds}
showCheckboxes={showCheckboxes}
showNotes={!!showNotes[event._id]}
Expand Down Expand Up @@ -296,6 +299,7 @@ const StatefulEventComponent: React.FC<Props> = ({
onUnPinEvent,
onUpdateColumns,
refetch,
onRuleChange,
rowRenderers,
selectedEventIds,
showCheckboxes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export interface BodyProps {
onUnPinEvent: OnUnPinEvent;
pinnedEventIds: Readonly<Record<string, boolean>>;
refetch: inputsModel.Refetch;
onRuleChange?: () => void;
rowRenderers: RowRenderer[];
selectedEventIds: Readonly<Record<string, TimelineNonEcsData[]>>;
show: boolean;
Expand Down Expand Up @@ -101,6 +102,7 @@ export const Body = React.memo<BodyProps>(
pinnedEventIds,
rowRenderers,
refetch,
onRuleChange,
selectedEventIds,
show,
showCheckboxes,
Expand Down Expand Up @@ -186,6 +188,7 @@ export const Body = React.memo<BodyProps>(
pinnedEventIds={pinnedEventIds}
refetch={refetch}
rowRenderers={rowRenderers}
onRuleChange={onRuleChange}
selectedEventIds={selectedEventIds}
showCheckboxes={showCheckboxes}
toggleColumn={toggleColumn}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface OwnProps {
sort: Sort;
toggleColumn: (column: ColumnHeaderOptions) => void;
refetch: inputsModel.Refetch;
onRuleChange?: () => void;
}

type StatefulBodyComponentProps = OwnProps & PropsFromRedux;
Expand Down Expand Up @@ -73,6 +74,7 @@ const StatefulBodyComponent = React.memo<StatefulBodyComponentProps>(
selectedEventIds,
setSelected,
clearSelected,
onRuleChange,
show,
showCheckboxes,
graphEventId,
Expand Down Expand Up @@ -211,6 +213,7 @@ const StatefulBodyComponent = React.memo<StatefulBodyComponentProps>(
onUpdateColumns={onUpdateColumns}
pinnedEventIds={pinnedEventIds}
refetch={refetch}
onRuleChange={onRuleChange}
rowRenderers={enabledRowRenderers}
selectedEventIds={selectedEventIds}
show={id === TimelineId.active ? show : true}
Expand Down