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

[Cloud Security] [Vulnerabilities] Add grouping capabilities #174413

Merged
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ebbf0c5
wip: vulnerabilities datatable
opauloh Dec 19, 2023
4e90034
Merge branch 'main' into findings-enhancements/vulnerabilities-table
opauloh Dec 19, 2023
0a0b005
WIP: Vulnerabilities DataTable
opauloh Dec 20, 2023
528df5e
Merge branch 'main' into findings-enhancements/vulnerabilities-table
opauloh Jan 4, 2024
4c33137
adding data view context
opauloh Jan 6, 2024
0878bbb
handling null data
opauloh Jan 6, 2024
243d46f
updating findings table with new dataview context
opauloh Jan 6, 2024
8004701
vulnerabilities datatable and grouping
opauloh Jan 6, 2024
23caa12
empty component condition
opauloh Jan 6, 2024
a72df4b
FTR tests
opauloh Jan 6, 2024
0a3b17d
fixing unit tests / removing unused
opauloh Jan 9, 2024
43df0e5
Merge branch 'main' into findings-enhancements/vulnerabilities-table
opauloh Jan 9, 2024
466de2c
removing unused
opauloh Jan 9, 2024
5f2669b
Fixing variable names
opauloh Jan 9, 2024
d6757e8
show timestamp on the field selector modal
opauloh Jan 9, 2024
c5188fa
remove unused hook
opauloh Jan 9, 2024
e77452b
adding fields to constant
opauloh Jan 9, 2024
ba611e9
removing unused code fixing tsc checks
opauloh Jan 10, 2024
daf4953
remove unused translations
opauloh Jan 10, 2024
aafa7bc
fix FTR tests
opauloh Jan 10, 2024
0016729
fixing ftr test vulnerability
opauloh Jan 10, 2024
7680749
Merge branch 'main' into findings-enhancements/vulnerabilities-table
opauloh Jan 10, 2024
4f3de1f
remove comment
opauloh Jan 10, 2024
f86902d
Merge branch 'findings-enhancements/vulnerabilities-table' of https:/…
opauloh Jan 10, 2024
80eb3e6
adding skip description
opauloh Jan 10, 2024
0e16728
Merge branch 'main' into findings-enhancements/vulnerabilities-table
opauloh Jan 10, 2024
8414c13
split grouping local storage key
opauloh Jan 10, 2024
1c741a8
make severity sorting behavior to match the sorting text
opauloh Jan 11, 2024
a8375c1
Addressing PR comments
opauloh Jan 11, 2024
26753f9
Merge branch 'main' into findings-enhancements/vulnerabilities-table
opauloh Jan 11, 2024
a32e1f6
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Jan 12, 2024
71777df
share renderers grouping components
opauloh Jan 12, 2024
0abccc4
Merge branch 'findings-enhancements/vulnerabilities-table' of https:/…
opauloh Jan 12, 2024
a03865e
Merge branch 'main' into findings-enhancements/vulnerabilities-table
opauloh Jan 12, 2024
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 @@ -87,7 +87,7 @@ export interface Vulnerability {
id: string;
title: string;
reference: string;
severity: VulnSeverity;
severity?: VulnSeverity;
cvss: {
nvd: VectorScoreBase;
redhat?: VectorScoreBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import { useQuery } from '@tanstack/react-query';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import type { DataView } from '@kbn/data-plugin/common';
import { i18n } from '@kbn/i18n';
import { LATEST_FINDINGS_INDEX_PATTERN } from '../../../common/constants';
import {
LATEST_FINDINGS_INDEX_PATTERN,
LATEST_VULNERABILITIES_INDEX_PATTERN,
} from '../../../common/constants';
import { CspClientPluginStartDeps } from '../../types';

/**
* TODO: Remove this static labels once https://github.com/elastic/kibana/issues/172615 is resolved
*/
const cloudSecurityFieldLabels: Record<string, string> = {
'result.evaluation': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.resultColumnLabel',
Expand Down Expand Up @@ -45,6 +51,30 @@ const cloudSecurityFieldLabels: Record<string, string> = {
'xpack.csp.findings.findingsTable.findingsTableColumn.lastCheckedColumnLabel',
{ defaultMessage: 'Last Checked' }
),
'vulnerability.id': i18n.translate(
opauloh marked this conversation as resolved.
Show resolved Hide resolved
'xpack.csp.findings.findingsTable.findingsTableColumn.vulnerabilityIdColumnLabel',
{ defaultMessage: 'Vulnerability' }
),
'vulnerability.score.base': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.vulnerabilityScoreColumnLabel',
{ defaultMessage: 'CVSS' }
),
'vulnerability.severity': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.vulnerabilitySeverityColumnLabel',
{ defaultMessage: 'Severity' }
),
'package.name': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.packageNameColumnLabel',
{ defaultMessage: 'Package' }
),
'package.version': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.packageVersionColumnLabel',
{ defaultMessage: 'Version' }
),
'package.fixed_version': i18n.translate(
'xpack.csp.findings.findingsTable.findingsTableColumn.packageFixedVersionColumnLabel',
{ defaultMessage: 'Fix Version' }
),
} as const;

/**
Expand All @@ -61,7 +91,13 @@ export const useLatestFindingsDataView = (dataView: string) => {
throw new Error(`Data view not found [Name: {${dataView}}]`);
}

if (dataView === LATEST_FINDINGS_INDEX_PATTERN) {
/**
* TODO: Remove this update logic once https://github.com/elastic/kibana/issues/172615 is resolved
*/
if (
dataView === LATEST_FINDINGS_INDEX_PATTERN ||
opauloh marked this conversation as resolved.
Show resolved Hide resolved
dataView === LATEST_VULNERABILITIES_INDEX_PATTERN
) {
let shouldUpdate = false;
Object.entries(cloudSecurityFieldLabels).forEach(([field, label]) => {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export const LOCAL_STORAGE_DASHBOARD_BENCHMARK_SORT_KEY =
'cloudPosture:complianceDashboard:benchmarkSort';
export const LOCAL_STORAGE_FINDINGS_LAST_SELECTED_TAB_KEY = 'cloudPosture:findings:lastSelectedTab';

export const LOCAL_STORAGE_VULNERABILITIES_GROUPING_KEY = 'cspLatestVulnerabilitiesGrouping';
export const LOCAL_STORAGE_FINDINGS_GROUPING_KEY = 'cspLatestFindingsGrouping';

export const SESSION_STORAGE_FIELDS_MODAL_SHOW_SELECTED = 'cloudPosture:fieldsModal:showSelected';

export type CloudPostureIntegrations = Record<
Expand Down Expand Up @@ -225,3 +228,5 @@ export const NO_FINDINGS_STATUS_REFRESH_INTERVAL_MS = 10000;

export const DETECTION_ENGINE_RULES_KEY = 'detection_engine_rules';
export const DETECTION_ENGINE_ALERTS_KEY = 'detection_engine_alerts';

export const DEFAULT_GROUPING_TABLE_HEIGHT = 512;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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 { createContext, useContext } from 'react';
import { DataView } from '@kbn/data-views-plugin/common';

interface DataViewContextValue {
dataView: DataView;
dataViewRefetch?: () => void;
dataViewIsRefetching?: boolean;
}

export const DataViewContext = createContext<DataViewContextValue | undefined>(undefined);

/**
* Retrieve context's properties
*/
export const useDataViewContext = (): DataViewContextValue => {
const contextValue = useContext(DataViewContext);

if (!contextValue) {
throw new Error('useDataViewContext can only be used within DataViewContext provider');
}

return contextValue;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@
* 2.0.
*/

import { DataView } from '@kbn/data-views-plugin/common';
import { buildEsQuery, EsQueryConfig } from '@kbn/es-query';
import { i18n } from '@kbn/i18n';
import { useEffect, useMemo } from 'react';
import { FindingsBaseESQueryConfig, FindingsBaseProps, FindingsBaseURLQuery } from '../../types';
import { useDataViewContext } from '../../contexts/data_view_context';
import { FindingsBaseESQueryConfig, FindingsBaseURLQuery } from '../../types';
import { useKibana } from '../use_kibana';

const getBaseQuery = ({
dataView,
query,
filters,
config,
}: FindingsBaseURLQuery & FindingsBaseProps & FindingsBaseESQueryConfig) => {
}: FindingsBaseURLQuery &
FindingsBaseESQueryConfig & {
dataView: DataView;
}) => {
try {
return {
query: buildEsQuery(dataView, query, filters, config), // will throw for malformed query
Expand All @@ -30,18 +35,18 @@ const getBaseQuery = ({
};

export const useBaseEsQuery = ({
dataView,
filters = [],
query,
nonPersistedFilters,
}: FindingsBaseURLQuery & FindingsBaseProps) => {
}: FindingsBaseURLQuery) => {
const {
notifications: { toasts },
data: {
query: { filterManager, queryString },
},
uiSettings,
} = useKibana().services;
const { dataView } = useDataViewContext();
const allowLeadingWildcards = uiSettings.get('query:allowLeadingWildcards');
const config: EsQueryConfig = useMemo(() => ({ allowLeadingWildcards }), [allowLeadingWildcards]);
const baseEsQuery = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* 2.0.
*/
import { Dispatch, SetStateAction, useCallback } from 'react';
import { type DataView } from '@kbn/data-views-plugin/common';
import { BoolQuery, Filter } from '@kbn/es-query';
import { CriteriaWithPagination } from '@elastic/eui';
import { DataTableRecord } from '@kbn/discover-utils/types';
Expand Down Expand Up @@ -46,13 +45,11 @@ export interface CloudPostureDataTableResult {
*/
export const useCloudPostureDataTable = ({
defaultQuery = getDefaultQuery,
dataView,
paginationLocalStorageKey,
columnsLocalStorageKey,
nonPersistedFilters,
}: {
defaultQuery?: (params: FindingsBaseURLQuery) => FindingsBaseURLQuery;
dataView: DataView;
paginationLocalStorageKey: string;
columnsLocalStorageKey?: string;
nonPersistedFilters?: Filter[];
Expand Down Expand Up @@ -116,7 +113,6 @@ export const useCloudPostureDataTable = ({
* Page URL query to ES query
*/
const baseEsQuery = useBaseEsQuery({
dataView,
filters: urlQuery.filters,
query: urlQuery.query,
...(nonPersistedFilters ? { nonPersistedFilters } : {}),
Expand Down

This file was deleted.

This file was deleted.

Loading