-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] - Security solution ES|QL configurable via advanced setting #181616
Changes from all commits
02ae1c2
b7203e5
78acd00
a4f8e9e
9b73610
a9d0f08
9ec53fd
2d7f5c4
ca29241
9c1b4a4
800bc87
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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 { useMemo } from 'react'; | ||
import { useKibana } from '../../lib/kibana'; | ||
import { useIsExperimentalFeatureEnabled } from '../use_experimental_features'; | ||
|
||
export const useEsqlAvailability = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. even though this hook is pretty straightforward to understand, if you want I would add a short documentation to describe what the hook does. Up to you! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, will add a comment in the PR right after this! Hoping to make the next BC! |
||
const { uiSettings } = useKibana().services; | ||
const isEsqlAdvancedSettingEnabled = uiSettings?.get('discover:enableESQL'); | ||
const isEsqlRuleTypeEnabled = | ||
!useIsExperimentalFeatureEnabled('esqlRulesDisabled') && isEsqlAdvancedSettingEnabled; | ||
const isESQLTabInTimelineEnabled = | ||
!useIsExperimentalFeatureEnabled('timelineEsqlTabDisabled') && isEsqlAdvancedSettingEnabled; | ||
|
||
return useMemo( | ||
() => ({ | ||
isEsqlAdvancedSettingEnabled, | ||
isEsqlRuleTypeEnabled, | ||
isESQLTabInTimelineEnabled, | ||
}), | ||
[isESQLTabInTimelineEnabled, isEsqlAdvancedSettingEnabled, isEsqlRuleTypeEnabled] | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,12 +10,12 @@ import { mount, shallow } from 'enzyme'; | |||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
import { SelectRuleType } from '.'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
import { TestProviders, useFormFieldMock } from '../../../../common/mock'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
import { useIsEsqlRuleTypeEnabled } from '../../../../common/components/hooks'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
import { useEsqlAvailability } from '../../../../common/hooks/esql/use_esql_availability'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
jest.mock('../../../../common/components/hooks', () => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
useIsEsqlRuleTypeEnabled: jest.fn().mockReturnValue(true), | ||||||||||||||||||||||||||||||||||||||||||||||||||
jest.mock('../../../../common/hooks/esql/use_esql_availability', () => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||
useEsqlAvailability: jest.fn().mockReturnValue({ isEsqlRuleTypeEnabled: true }), | ||||||||||||||||||||||||||||||||||||||||||||||||||
})); | ||||||||||||||||||||||||||||||||||||||||||||||||||
const useIsEsqlRuleTypeEnabledMock = useIsEsqlRuleTypeEnabled as jest.Mock; | ||||||||||||||||||||||||||||||||||||||||||||||||||
const useEsqlAvailabilityMock = useEsqlAvailability as jest.Mock; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
describe('SelectRuleType', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
it('renders correctly', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -185,8 +185,30 @@ describe('SelectRuleType', () => { | |||||||||||||||||||||||||||||||||||||||||||||||||
expect(wrapper.find('[data-test-subj="esqlRuleType"]').exists()).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
it('renders selected card only when in update mode for "esql" and esql feature is disabled', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
useEsqlAvailabilityMock.mockReturnValueOnce(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||
const field = useFormFieldMock<unknown>({ value: 'esql' }); | ||||||||||||||||||||||||||||||||||||||||||||||||||
const wrapper = mount( | ||||||||||||||||||||||||||||||||||||||||||||||||||
<TestProviders> | ||||||||||||||||||||||||||||||||||||||||||||||||||
<SelectRuleType | ||||||||||||||||||||||||||||||||||||||||||||||||||
describedByIds={[]} | ||||||||||||||||||||||||||||||||||||||||||||||||||
field={field} | ||||||||||||||||||||||||||||||||||||||||||||||||||
isUpdateView={true} | ||||||||||||||||||||||||||||||||||||||||||||||||||
hasValidLicense={true} | ||||||||||||||||||||||||||||||||||||||||||||||||||
isMlAdmin={true} | ||||||||||||||||||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||||||||||||||||||
</TestProviders> | ||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||
expect(wrapper.find('[data-test-subj="customRuleType"]').exists()).toBeFalsy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
expect(wrapper.find('[data-test-subj="machineLearningRuleType"]').exists()).toBeFalsy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
expect(wrapper.find('[data-test-subj="thresholdRuleType"]').exists()).toBeFalsy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
expect(wrapper.find('[data-test-subj="eqlRuleType"]').exists()).toBeFalsy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
expect(wrapper.find('[data-test-subj="threatMatchRuleType"]').exists()).toBeFalsy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
expect(wrapper.find('[data-test-subj="esqlRuleType"]').exists()).toBeTruthy(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's also add unit test for the case covered in https://github.com/elastic/kibana/pull/181616/files#r1585195094 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thanks! |
||||||||||||||||||||||||||||||||||||||||||||||||||
it('should not render "esql" rule type if esql rule is not enabled', () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
useIsEsqlRuleTypeEnabledMock.mockReturnValueOnce(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||
useEsqlAvailabilityMock.mockReturnValueOnce(false); | ||||||||||||||||||||||||||||||||||||||||||||||||||
const Component = () => { | ||||||||||||||||||||||||||||||||||||||||||||||||||
const field = useFormFieldMock(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -9,6 +9,7 @@ import React, { useCallback, useMemo, memo } from 'react'; | |||
import { EuiCard, EuiFlexGrid, EuiFlexItem, EuiFormRow, EuiIcon } from '@elastic/eui'; | ||||
|
||||
import type { Type } from '@kbn/securitysolution-io-ts-alerting-types'; | ||||
import { useEsqlAvailability } from '../../../../common/hooks/esql/use_esql_availability'; | ||||
import { isMlRule } from '../../../../../common/machine_learning/helpers'; | ||||
import { | ||||
isThresholdRule, | ||||
|
@@ -21,7 +22,6 @@ import { | |||
import type { FieldHook } from '../../../../shared_imports'; | ||||
import * as i18n from './translations'; | ||||
import { MlCardDescription } from './ml_card_description'; | ||||
import { useIsEsqlRuleTypeEnabled } from '../../../../common/components/hooks'; | ||||
|
||||
interface SelectRuleTypeProps { | ||||
describedByIds: string[]; | ||||
|
@@ -48,7 +48,7 @@ export const SelectRuleType: React.FC<SelectRuleTypeProps> = memo( | |||
const setNewTerms = useCallback(() => setType('new_terms'), [setType]); | ||||
const setEsql = useCallback(() => setType('esql'), [setType]); | ||||
|
||||
const isEsqlRuleTypeEnabled = useIsEsqlRuleTypeEnabled(); | ||||
const { isEsqlRuleTypeEnabled } = useEsqlAvailability(); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rule type icon should be displayed when editing rule Line 197 in a4f8e9e
I think this change should do it {((!isUpdateView && isEsqlRuleTypeEnabled) || esqlSelectableConfig.isSelected) && ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great catch, thanks @vitaliidm ! Completed here: 9b73610 |
||||
|
||||
const eqlSelectableConfig = useMemo( | ||||
() => ({ | ||||
|
@@ -194,7 +194,7 @@ export const SelectRuleType: React.FC<SelectRuleTypeProps> = memo( | |||
/> | ||||
</EuiFlexItem> | ||||
)} | ||||
{isEsqlRuleTypeEnabled && (!isUpdateView || esqlSelectableConfig.isSelected) && ( | ||||
{((!isUpdateView && isEsqlRuleTypeEnabled) || esqlSelectableConfig.isSelected) && ( | ||||
<EuiFlexItem> | ||||
<EuiCard | ||||
data-test-subj="esqlRuleType" | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* 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 React from 'react'; | ||
|
||
import { createMockStore, mockGlobalState } from '../../../../common/mock'; | ||
import { TestProviders } from '../../../../common/mock/test_providers'; | ||
|
||
import { TabsContent } from '.'; | ||
import { TimelineId, TimelineTabs } from '../../../../../common/types/timeline'; | ||
import { TimelineType } from '../../../../../common/api/timeline'; | ||
import { useEsqlAvailability } from '../../../../common/hooks/esql/use_esql_availability'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
|
||
jest.mock('../../../../common/hooks/esql/use_esql_availability', () => ({ | ||
useEsqlAvailability: jest.fn().mockReturnValue({ | ||
isESQLTabInTimelineEnabled: true, | ||
}), | ||
})); | ||
|
||
const useEsqlAvailabilityMock = useEsqlAvailability as jest.Mock; | ||
|
||
describe('Timeline', () => { | ||
describe('esql tab', () => { | ||
const esqlTabSubj = `timelineTabs-${TimelineTabs.esql}`; | ||
const defaultProps = { | ||
renderCellValue: () => {}, | ||
rowRenderers: [], | ||
timelineId: TimelineId.test, | ||
timelineType: TimelineType.default, | ||
timelineDescription: '', | ||
}; | ||
|
||
it('should show the esql tab', () => { | ||
render( | ||
<TestProviders> | ||
<TabsContent {...defaultProps} /> | ||
</TestProviders> | ||
); | ||
expect(screen.getByTestId(esqlTabSubj)).toBeVisible(); | ||
}); | ||
|
||
it('should not show the esql tab when the advanced setting is disabled', async () => { | ||
useEsqlAvailabilityMock.mockReturnValue({ | ||
isESQLTabInTimelineEnabled: false, | ||
}); | ||
render( | ||
<TestProviders> | ||
<TabsContent {...defaultProps} /> | ||
</TestProviders> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.queryByTestId(esqlTabSubj)).toBeNull(); | ||
}); | ||
}); | ||
|
||
it('should show the esql tab when the advanced setting is disabled, but an esql query is present', async () => { | ||
useEsqlAvailabilityMock.mockReturnValue({ | ||
isESQLTabInTimelineEnabled: false, | ||
}); | ||
|
||
const stateWithSavedSearchId = structuredClone(mockGlobalState); | ||
stateWithSavedSearchId.timeline.timelineById[TimelineId.test].savedSearchId = 'test-id'; | ||
const mockStore = createMockStore(stateWithSavedSearchId); | ||
|
||
render( | ||
<TestProviders store={mockStore}> | ||
<TabsContent {...defaultProps} /> | ||
</TestProviders> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.queryByTestId(esqlTabSubj)).toBeVisible(); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to remove it from the serverless config
kibana/config/serverless.security.yml
Line 26 in 60c6cdb