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

[Security Solution] Switches remaining rule types to use new Rule Preview API #116374

Merged
merged 35 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
70e0bdb
switches old preview to new api
dplumlee Oct 26, 2021
5ef4af0
fixes types
dplumlee Oct 27, 2021
1965bb8
updates eql and query rule type previews
dplumlee Nov 4, 2021
6e28d0f
fixes types
dplumlee Nov 8, 2021
963ed0d
fixes types
dplumlee Nov 8, 2021
0798046
adds query to preview
dplumlee Nov 9, 2021
dac95eb
fixes text errors
dplumlee Nov 9, 2021
e435c5d
updates react tests
dplumlee Nov 11, 2021
889c057
adds integration tests
dplumlee Nov 11, 2021
929cd9e
ready for es update
dplumlee Nov 15, 2021
f15835c
updates jest tests
dplumlee Nov 15, 2021
c4de39e
updates cypress tests
dplumlee Nov 16, 2021
ec6d047
updates basename for backing indices
dplumlee Nov 22, 2021
fc4bcde
fixes query obj nesting
dplumlee Nov 23, 2021
9b12937
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Nov 29, 2021
9fab7d2
fixes histogram query
dplumlee Nov 29, 2021
5ec0fcb
fix rule interval logic
dplumlee Nov 29, 2021
28416b2
fixes some tests
dplumlee Nov 30, 2021
4f286f5
fixes rests of tests
dplumlee Nov 30, 2021
cb7ef5f
addresses some comments
dplumlee Nov 30, 2021
566e42c
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 1, 2021
e1e4094
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 2, 2021
e71b2e1
addresses comments
dplumlee Dec 2, 2021
af31a21
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 2, 2021
33f97ec
removes comment
dplumlee Dec 2, 2021
5aaf91f
fixes lookback time
dplumlee Dec 3, 2021
4145e8a
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 3, 2021
5b25b3f
fixes timeframe reset bug
dplumlee Dec 3, 2021
9b3b2f3
addresses comments
dplumlee Dec 6, 2021
a4e2aff
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 6, 2021
75fd94c
adds ml rule preview and fixes refresh error
dplumlee Dec 6, 2021
a60e3c7
updates jest tests for ML previews
dplumlee Dec 7, 2021
5f62ed2
updates rule data client mock
dplumlee Dec 7, 2021
1505e01
Merge remote-tracking branch 'upstream/main' into update-rule-type-pr…
dplumlee Dec 7, 2021
0fa27da
fixes 404 error
dplumlee Dec 7, 2021
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
1 change: 0 additions & 1 deletion x-pack/plugins/rule_registry/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ export const config: PluginConfigDescriptor = {
export type RuleRegistryPluginConfig = TypeOf<typeof config.schema>;

export const INDEX_PREFIX = '.alerts' as const;
export const INDEX_PREFIX_FOR_BACKING_INDICES = '.internal.alerts' as const;
Copy link
Contributor

Choose a reason for hiding this comment

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

we could consider renaming the const to INTERNAL_PREFIX with the value ".internal" and use it on line 37 in rule_data_plugin_service/index_info.ts

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const createRuleDataClientMock = (
indexName,
kibanaVersion: '7.16.0',
isWriteEnabled: jest.fn(() => true),
indexNameWithNamespace: jest.fn((namespace: string) => indexName + namespace),

// @ts-ignore 4.3.5 upgrade
getReader: jest.fn((_options?: { namespace?: string }) => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export class RuleDataClient implements IRuleDataClient {
return this.options.indexInfo.kibanaVersion;
}

public indexNameWithNamespace(namespace: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

return this.options.indexInfo.getPrimaryAlias(namespace);
}

private get writeEnabled(): boolean {
return this._isWriteEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { TechnicalRuleDataFieldName } from '../../common/technical_rule_data_fie

export interface IRuleDataClient {
indexName: string;
indexNameWithNamespace(namespace: string): string;
kibanaVersion: string;
isWriteEnabled(): boolean;
getReader(options?: { namespace?: string }): IRuleDataReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { INDEX_PREFIX, INDEX_PREFIX_FOR_BACKING_INDICES } from '../config';
import { INDEX_PREFIX } from '../config';
import { IndexOptions } from './index_options';
import { joinWithDash } from './utils';

Expand All @@ -23,16 +23,16 @@ interface ConstructorOptions {
export class IndexInfo {
constructor(options: ConstructorOptions) {
const { indexOptions, kibanaVersion } = options;
const { registrationContext, dataset } = indexOptions;
const { registrationContext, dataset, additionalPrefix } = indexOptions;

this.indexOptions = indexOptions;
this.kibanaVersion = kibanaVersion;
this.baseName = joinWithDash(INDEX_PREFIX, `${registrationContext}.${dataset}`);
this.basePattern = joinWithDash(this.baseName, '*');
this.baseNameForBackingIndices = joinWithDash(
INDEX_PREFIX_FOR_BACKING_INDICES,
this.baseName = joinWithDash(
`${additionalPrefix ?? ''}${INDEX_PREFIX}`,
`${registrationContext}.${dataset}`
);
this.basePattern = joinWithDash(this.baseName, '*');
this.baseNameForBackingIndices = `.internal${this.baseName}`;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ export interface IndexOptions {
* @example '.siem-signals', undefined
*/
secondaryAlias?: string;

/**
* Optional prefix name that will be prepended to indices in addition to
* primary dataset and context naming convention.
*
* Currently used only for creating a preview index for the purpose of
* previewing alerts from a rule. The documents are identical to alerts, but
* shouldn't exist on an alert index and shouldn't be queried together with
* real alerts in any way, because the rule that created them doesn't exist
*/
additionalPrefix?: string;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const DEFAULT_APP_TIME_RANGE = 'securitySolution:timeDefaults' as const;
export const DEFAULT_APP_REFRESH_INTERVAL = 'securitySolution:refreshIntervalDefaults' as const;
export const DEFAULT_ALERTS_INDEX = '.alerts-security.alerts' as const;
export const DEFAULT_SIGNALS_INDEX = '.siem-signals' as const;
export const DEFAULT_PREVIEW_INDEX = '.siem-preview-signals' as const;
export const DEFAULT_PREVIEW_INDEX = '.preview.alerts-security.alerts' as const;
Copy link
Contributor

Choose a reason for hiding this comment

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

is it not possible to create these DEFAULT_ALERTS_INDEX and DEFAULT_PREVIEW_INDEX by using the logic from the rule registry server by supplying 'security' on this side only? that way we can ensure that nothing ever gets out of sync

Copy link
Contributor

Choose a reason for hiding this comment

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

@ecezalp I'm not sure I follow; are you asking whether we can auto-create both of these indexes by some mechanism internal to the rule registry? E.g.

// creates both the alerts index and the preview index
ruleRegistry.create('security');

?

Copy link
Contributor Author

@dplumlee dplumlee Dec 2, 2021

Choose a reason for hiding this comment

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

What you're describing currently happens at runtime within a constructor in the rule registry plugin so there's no existing way to do that. I don't think it'd be a bad idea to do something like that down the line but for now, using this as the single source of truth for our needs seems like a solid approach

export const DEFAULT_LISTS_INDEX = '.lists' as const;
export const DEFAULT_ITEMS_INDEX = '.items' as const;
// The DEFAULT_MAX_SIGNALS value exists also in `x-pack/plugins/cases/common/constants.ts`
Expand Down Expand Up @@ -256,8 +256,6 @@ export const DETECTION_ENGINE_PREPACKAGED_RULES_STATUS_URL =
export const DETECTION_ENGINE_RULES_BULK_ACTION =
`${DETECTION_ENGINE_RULES_URL}/_bulk_action` as const;
export const DETECTION_ENGINE_RULES_PREVIEW = `${DETECTION_ENGINE_RULES_URL}/preview` as const;
export const DETECTION_ENGINE_RULES_PREVIEW_INDEX_URL =
`${DETECTION_ENGINE_RULES_PREVIEW}/index` as const;

/**
* Internal detection engine routes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
* 2.0.
*/

import { useEffect } from 'react';
import { createPreviewIndex } from './api';

export const usePreviewIndex = () => {
useEffect(() => {
createPreviewIndex();
}, []);
};
export enum RULE_PREVIEW_INVOCATION_COUNT {
HOUR = 20,
DAY = 24,
WEEK = 168,
MONTH = 30,
}
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ export const previewRulesSchema = t.intersection([
createTypeSpecific,
t.type({ invocationCount: t.number }),
]);
export type PreviewRulesSchema = t.TypeOf<typeof previewRulesSchema>;

type UpdateSchema<T> = SharedUpdateSchema & T;
export type EqlUpdateSchema = UpdateSchema<t.TypeOf<typeof eqlCreateParams>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ describe('Detection rules, threshold', () => {
cy.get(ALERT_GRID_CELL).contains(rule.name);
});

it('Preview results of keyword using "host.name"', () => {
it.skip('Preview results of keyword using "host.name"', () => {
dplumlee marked this conversation as resolved.
Show resolved Hide resolved
rule.index = [...rule.index, '.siem-signals*'];

createCustomRuleActivated(getNewRule());
Expand All @@ -188,7 +188,7 @@ describe('Detection rules, threshold', () => {
cy.get(PREVIEW_HEADER_SUBTITLE).should('have.text', '3 unique hits');
});

it('Preview results of "ip" using "source.ip"', () => {
it.skip('Preview results of "ip" using "source.ip"', () => {
const previewRule: ThresholdRule = {
...rule,
thresholdField: 'source.ip',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ export const DEFINE_INDEX_INPUT =

export const EQL_TYPE = '[data-test-subj="eqlRuleType"]';

export const EQL_QUERY_INPUT = '[data-test-subj="eqlQueryBarTextInput"]';
export const PREVIEW_HISTOGRAM = '[data-test-subj="preview-histogram-panel"]';

export const EQL_QUERY_PREVIEW_HISTOGRAM = '[data-test-subj="queryPreviewEqlHistogram"]';
export const EQL_QUERY_INPUT = '[data-test-subj="eqlQueryBarTextInput"]';

export const EQL_QUERY_VALIDATION_SPINNER = '[data-test-subj="eql-validation-loading"]';

Expand Down Expand Up @@ -170,7 +170,7 @@ export const RISK_OVERRIDE =

export const RULES_CREATION_FORM = '[data-test-subj="stepDefineRule"]';

export const RULES_CREATION_PREVIEW = '[data-test-subj="ruleCreationQueryPreview"]';
export const RULES_CREATION_PREVIEW = '[data-test-subj="rule-preview"]';

export const RULE_DESCRIPTION_INPUT =
'[data-test-subj="detectionEngineStepAboutRuleDescription"] [data-test-subj="input"]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
DEFAULT_RISK_SCORE_INPUT,
DEFINE_CONTINUE_BUTTON,
EQL_QUERY_INPUT,
EQL_QUERY_PREVIEW_HISTOGRAM,
EQL_QUERY_VALIDATION_SPINNER,
EQL_TYPE,
FALSE_POSITIVES_INPUT,
Expand Down Expand Up @@ -92,6 +91,7 @@ import {
EMAIL_CONNECTOR_USER_INPUT,
EMAIL_CONNECTOR_PASSWORD_INPUT,
EMAIL_CONNECTOR_SERVICE_SELECTOR,
PREVIEW_HISTOGRAM,
} from '../screens/create_new_rule';
import { TOAST_ERROR } from '../screens/shared';
import { SERVER_SIDE_EVENT_COUNT } from '../screens/timeline';
Expand Down Expand Up @@ -324,12 +324,12 @@ export const fillDefineEqlRuleAndContinue = (rule: CustomRule) => {
.find(QUERY_PREVIEW_BUTTON)
.should('not.be.disabled')
.click({ force: true });
cy.get(EQL_QUERY_PREVIEW_HISTOGRAM)
cy.get(PREVIEW_HISTOGRAM)
.invoke('text')
.then((text) => {
if (text !== 'Hits') {
cy.get(RULES_CREATION_PREVIEW).find(QUERY_PREVIEW_BUTTON).click({ force: true });
cy.get(EQL_QUERY_PREVIEW_HISTOGRAM).should('contain.text', 'Hits');
cy.get(PREVIEW_HISTOGRAM).should('contain.text', 'Hits');
}
});
cy.get(TOAST_ERROR).should('not.exist');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { MatrixHistogramType } from '../../../../common/search_strategy/security
import { UpdateDateRange } from '../charts/common';
import { GlobalTimeArgs } from '../../containers/use_global_time';
import { DocValueFields } from '../../../../common/search_strategy';
import { Threshold } from '../../../detections/components/rules/query_preview';
import { FieldValueThreshold } from '../../../detections/components/rules/threshold_input';

export type MatrixHistogramMappingTypes = Record<
string,
Expand Down Expand Up @@ -77,7 +77,7 @@ export interface MatrixHistogramQueryProps {
stackByField: string;
startDate: string;
histogramType: MatrixHistogramType;
threshold?: Threshold;
threshold?: FieldValueThreshold;
skip?: boolean;
isPtrIncluded?: boolean;
includeMissingData?: boolean;
Expand Down

This file was deleted.

Loading