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] Custom renderers for Group by Resource, Cloud account and CVE #174950

Merged
Merged
25 changes: 22 additions & 3 deletions x-pack/plugins/cloud_security_posture/common/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,37 @@ export const getBenchmarkCisName = (benchmarkId: BenchmarksCisId) => {
}
};

const CLOUD_PROVIDER_NAMES = {
AWS: 'Amazon Web Services',
AZURE: 'Microsoft Azure',
GCP: 'Google Cloud Platform',
};

export const getBenchmarkApplicableTo = (benchmarkId: BenchmarksCisId) => {
switch (benchmarkId) {
case 'cis_k8s':
return 'Kubernetes';
case 'cis_azure':
return 'Microsoft Azure';
return CLOUD_PROVIDER_NAMES.AZURE;
case 'cis_aws':
return 'Amazon Web Services';
return CLOUD_PROVIDER_NAMES.AWS;
case 'cis_eks':
return 'Amazon Elastic Kubernetes Service';
case 'cis_gcp':
return 'Google Cloud Provider';
return CLOUD_PROVIDER_NAMES.GCP;
}
};

export const getCloudProviderNameFromAbbreviation = (cloudProvider: string) => {
switch (cloudProvider) {
case 'azure':
return CLOUD_PROVIDER_NAMES.AZURE;
case 'aws':
return CLOUD_PROVIDER_NAMES.AWS;
case 'gcp':
return CLOUD_PROVIDER_NAMES.GCP;
default:
return cloudProvider;
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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 { EuiIcon, EuiToolTip, IconSize } from '@elastic/eui';
import { CSSInterpolation } from '@emotion/serialize';
import { getCloudProviderNameFromAbbreviation } from '../../common/utils/helpers';
import googleCloudLogo from '../assets/icons/google_cloud_logo.svg';

interface Props {
cloudProvider: string;
style?: CSSInterpolation;
size?: IconSize;
}

const getCloudProviderIcon = (cloudProvider: string) => {
switch (cloudProvider) {
case 'azure':
return 'logoAzure';
case 'aws':
return 'logoAWS';
case 'gcp':
return googleCloudLogo;
default:
return undefined;
}
};

export const CloudProviderIcon = ({ cloudProvider, size, style }: Props) => {
const iconType = getCloudProviderIcon(cloudProvider);

if (!iconType) {
return null;
}

const name = getCloudProviderNameFromAbbreviation(cloudProvider);

return (
<EuiToolTip content={name}>
<EuiIcon type={iconType} size={size || 'xl'} css={style} />
</EuiToolTip>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
} from '@elastic/eui';
import { PaletteColorStop } from '@elastic/eui/src/components/color_picker/color_palette_picker';
import { i18n } from '@kbn/i18n';
import { getSeverityStatusColor } from '../../../common/utils/get_vulnerability_colors';
import { VulnSeverity } from '../../../../common/types_old';
import { SeverityStatusBadge } from '../../../components/vulnerability_badges';
import { getSeverityStatusColor } from '../common/utils/get_vulnerability_colors';
import { VulnSeverity } from '../../common/types_old';
import { SeverityStatusBadge } from './vulnerability_badges';

interface Props {
total: number;
Expand Down Expand Up @@ -50,7 +50,7 @@ const formatPercentage = (percentage: number) => {
return `${percentage.toFixed(1)}%`;
};

export const SeverityMap = ({ severityMap, total }: Props) => {
export const VulnerabilitySeverityMap = ({ severityMap, total }: Props) => {
const { euiTheme } = useEuiTheme();

const severityMapPallet: PaletteColorStop[] = [];
Expand Down Expand Up @@ -87,10 +87,7 @@ export const SeverityMap = ({ severityMap, total }: Props) => {
width: 256px;
`}
anchorClassName={css`
height: ${euiTheme.size.xl};
flex-grow: 1;
display: flex;
align-items: center;
margin-left: ${euiTheme.size.xs};
`}
position="left"
title={i18n.translate('xpack.csp.vulnerabilitiesByResource.severityMap.tooltipTitle', {
Expand All @@ -102,7 +99,8 @@ export const SeverityMap = ({ severityMap, total }: Props) => {
type="fixed"
palette={severityMapPallet}
className={css`
width: 100%;
width: 80px;
height: 6px;
`}
/>
</EuiToolTip>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,30 @@ export const VULNERABILITY_FIELDS = {
PACKAGE_NAME: 'package.name',
PACKAGE_VERSION: 'package.version',
PACKAGE_FIXED_VERSION: 'package.fixed_version',
CLOUD_ACCOUNT_NAME: 'cloud.account.name',
CLOUD_PROVIDER: 'cloud.provider',
DESCRIPTION: 'vulnerability.description',
} as const;

export const GROUPING_OPTIONS = {
RESOURCE_NAME: VULNERABILITY_FIELDS.RESOURCE_NAME,
CLOUD_ACCOUNT_NAME: VULNERABILITY_FIELDS.CLOUD_ACCOUNT_NAME,
CVE: VULNERABILITY_FIELDS.VULNERABILITY_ID,
};

export const defaultGroupingOptions: GroupOption[] = [
{
label: GROUPING_LABELS.RESOURCE_NAME,
key: GROUPING_OPTIONS.RESOURCE_NAME,
},
{
label: GROUPING_LABELS.CLOUD_ACCOUNT_NAME,
key: GROUPING_OPTIONS.CLOUD_ACCOUNT_NAME,
},
{
label: 'CVE',
key: GROUPING_OPTIONS.CVE,
},
];

export const getDefaultQuery = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ export interface VulnerabilitiesGroupingAggregation {
buckets?: GenericBuckets[];
};
isLoading?: boolean;
critical?: {
doc_count?: NumberOrNull;
};
high?: {
doc_count?: NumberOrNull;
};
medium?: {
doc_count?: NumberOrNull;
};
low?: {
doc_count?: NumberOrNull;
};
cloudProvider?: {
buckets?: GenericBuckets[];
};
}

export type VulnerabilitiesRootGroupingAggregation =
Expand Down

This file was deleted.

Loading