Skip to content

Commit 720b3f6

Browse files
Migrate to EUI severity colors palette for CSP (#222246)
## Summary Fixes: - elastic/security-team#11606 this PR updates Cloud Risk Apps team owned flows to use new severity color palette ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <[email protected]>
1 parent d3079d7 commit 720b3f6

File tree

14 files changed

+208
-218
lines changed

14 files changed

+208
-218
lines changed

x-pack/solutions/security/packages/kbn-cloud-security-posture/public/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@ export type { NavFilter } from './src/utils/query_utils';
1111
export { showErrorToast } from './src/utils/show_error_toast';
1212
export { encodeQuery, decodeQuery } from './src/utils/query_utils';
1313
export { CspEvaluationBadge } from './src/components/csp_evaluation_badge';
14-
export {
15-
getSeverityStatusColor,
16-
getCvsScoreColor,
17-
getMisconfigurationStatusColor,
18-
} from './src/utils/get_finding_colors';
14+
export { getSeverityStatusColor, getCvsScoreColor } from './src/utils/get_finding_colors';
1915
export { getSeverityText } from './src/utils/get_vulnerability_text';
2016
export { getVulnerabilityStats, hasVulnerabilitiesData } from './src/utils/vulnerability_helpers';
2117
export { CVSScoreBadge, SeverityStatusBadge } from './src/components/vulnerability_badges';
18+
export { useGetMisconfigurationStatusColor } from './src/hooks/use_get_misconfiguration_status_color';
2219
export { getNormalizedSeverity } from './src/utils/get_normalized_severity';
2320
export { createMisconfigurationFindingsQuery } from './src/utils/findings_query_builders';
2421
export { ActionableBadge, type MultiValueCellAction } from './src/components/actionable_badge';

x-pack/solutions/security/packages/kbn-cloud-security-posture/public/src/components/csp_evaluation_badge.tsx

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
1111
import { css } from '@emotion/react';
1212
import { MISCONFIGURATION_STATUS } from '@kbn/cloud-security-posture-common';
1313
import type { MisconfigurationEvaluationStatus } from '@kbn/cloud-security-posture-common';
14-
import { getMisconfigurationStatusColor } from '../utils/get_finding_colors';
14+
import { useGetMisconfigurationStatusColor } from '../hooks/use_get_misconfiguration_status_color';
1515

1616
interface Props {
1717
type?: MisconfigurationEvaluationStatus;
@@ -21,31 +21,35 @@ interface Props {
2121
// 46px is used to make sure the badge is always the same width.
2222
const BADGE_WIDTH = '46px';
2323

24-
export const CspEvaluationBadge = ({ type }: Props) => (
25-
<EuiBadge
26-
color={getMisconfigurationStatusColor(type)}
27-
css={css`
28-
width: ${BADGE_WIDTH};
29-
display: flex;
30-
justify-content: center;
31-
`}
32-
data-test-subj={`${type}_finding`}
33-
>
34-
{type === MISCONFIGURATION_STATUS.FAILED ? (
35-
<FormattedMessage
36-
id="securitySolutionPackages.csp.cspEvaluationBadge.failLabel"
37-
defaultMessage="Fail"
38-
/>
39-
) : type === MISCONFIGURATION_STATUS.PASSED ? (
40-
<FormattedMessage
41-
id="securitySolutionPackages.csp.cspEvaluationBadge.passLabel"
42-
defaultMessage="Pass"
43-
/>
44-
) : (
45-
<FormattedMessage
46-
id="securitySolutionPackages.csp.cspEvaluationBadge.naLabel"
47-
defaultMessage="N/A"
48-
/>
49-
)}
50-
</EuiBadge>
51-
);
24+
export const CspEvaluationBadge = ({ type = MISCONFIGURATION_STATUS.UNKNOWN }: Props) => {
25+
const { getMisconfigurationStatusColor } = useGetMisconfigurationStatusColor();
26+
27+
return (
28+
<EuiBadge
29+
color={getMisconfigurationStatusColor(type)}
30+
css={css`
31+
width: ${BADGE_WIDTH};
32+
display: flex;
33+
justify-content: center;
34+
`}
35+
data-test-subj={`${type}_finding`}
36+
>
37+
{type === MISCONFIGURATION_STATUS.FAILED ? (
38+
<FormattedMessage
39+
id="securitySolutionPackages.csp.cspEvaluationBadge.failLabel"
40+
defaultMessage="Fail"
41+
/>
42+
) : type === MISCONFIGURATION_STATUS.PASSED ? (
43+
<FormattedMessage
44+
id="securitySolutionPackages.csp.cspEvaluationBadge.passLabel"
45+
defaultMessage="Pass"
46+
/>
47+
) : (
48+
<FormattedMessage
49+
id="securitySolutionPackages.csp.cspEvaluationBadge.naLabel"
50+
defaultMessage="N/A"
51+
/>
52+
)}
53+
</EuiBadge>
54+
);
55+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import { useEuiTheme } from '@elastic/eui';
9+
import type { MisconfigurationEvaluationStatus } from '@kbn/cloud-security-posture-common';
10+
import { getMisconfigurationStatusColor as getMisconfigurationStatusColorUtil } from '../utils/get_finding_colors';
11+
12+
export const useGetMisconfigurationStatusColor = () => {
13+
const { euiTheme } = useEuiTheme();
14+
const getMisconfigurationStatusColor = (status: MisconfigurationEvaluationStatus) => {
15+
return getMisconfigurationStatusColorUtil(status, euiTheme);
16+
};
17+
return { getMisconfigurationStatusColor };
18+
};

x-pack/solutions/security/packages/kbn-cloud-security-posture/public/src/utils/get_finding_colors.test.ts

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,68 @@
55
* 2.0.
66
*/
77

8-
import { getCvsScoreColor, getSeverityStatusColor, SEVERITY_COLOR } from './get_finding_colors';
8+
import { getCvsScoreColor, getSeverityStatusColor } from './get_finding_colors';
99
import { EuiThemeComputed } from '@elastic/eui';
1010

1111
const mockEuiThemeBorealis = {
1212
themeName: 'borialis',
13+
colors: {
14+
severity: {
15+
neutral: 'neutral',
16+
warning: 'warning',
17+
risk: 'risk',
18+
danger: 'danger',
19+
unknown: 'unknown',
20+
},
21+
},
1322
};
1423

1524
describe('getSeverityStatusColor', () => {
1625
it('should return the correct color for LOW severity', () => {
17-
expect(getSeverityStatusColor('LOW', mockEuiThemeBorealis as EuiThemeComputed)).toBe(
18-
SEVERITY_COLOR.low
19-
);
26+
expect(getSeverityStatusColor('LOW', mockEuiThemeBorealis as EuiThemeComputed)).toBe('neutral');
2027
});
2128

2229
it('should return the correct color for MEDIUM severity', () => {
2330
expect(getSeverityStatusColor('MEDIUM', mockEuiThemeBorealis as EuiThemeComputed)).toBe(
24-
SEVERITY_COLOR.medium
31+
'warning'
2532
);
2633
});
2734

2835
it('should return the correct color for HIGH severity', () => {
29-
expect(getSeverityStatusColor('HIGH', mockEuiThemeBorealis as EuiThemeComputed)).toBe(
30-
SEVERITY_COLOR.high
31-
);
36+
expect(getSeverityStatusColor('HIGH', mockEuiThemeBorealis as EuiThemeComputed)).toBe('risk');
3237
});
3338

3439
it('should return the correct color for CRITICAL severity', () => {
3540
expect(getSeverityStatusColor('CRITICAL', mockEuiThemeBorealis as EuiThemeComputed)).toBe(
36-
SEVERITY_COLOR.critical
41+
'danger'
3742
);
3843
});
3944

4045
it('should return the correct color for an unknown severity', () => {
4146
expect(getSeverityStatusColor('UNKNOWN', mockEuiThemeBorealis as EuiThemeComputed)).toBe(
42-
SEVERITY_COLOR.unknown
47+
'unknown'
4348
);
4449
});
4550
});
4651

4752
describe('getCvsScoreColor', () => {
4853
it('returns correct color for low severity score', () => {
49-
expect(getCvsScoreColor(1.5, mockEuiThemeBorealis as EuiThemeComputed)).toBe(
50-
SEVERITY_COLOR.low
51-
);
54+
expect(getCvsScoreColor(1.5, mockEuiThemeBorealis as EuiThemeComputed)).toBe('neutral');
5255
});
5356

5457
it('returns correct color for medium severity score', () => {
55-
expect(getCvsScoreColor(5.5, mockEuiThemeBorealis as EuiThemeComputed)).toBe(
56-
SEVERITY_COLOR.medium
57-
);
58+
expect(getCvsScoreColor(5.5, mockEuiThemeBorealis as EuiThemeComputed)).toBe('warning');
5859
});
5960

6061
it('returns correct color for high severity score', () => {
61-
expect(getCvsScoreColor(7.9, mockEuiThemeBorealis as EuiThemeComputed)).toBe(
62-
SEVERITY_COLOR.high
63-
);
62+
expect(getCvsScoreColor(7.9, mockEuiThemeBorealis as EuiThemeComputed)).toBe('risk');
6463
});
6564

6665
it('returns correct color for critical severity score', () => {
67-
expect(getCvsScoreColor(10.0, mockEuiThemeBorealis as EuiThemeComputed)).toBe(
68-
SEVERITY_COLOR.critical
69-
);
66+
expect(getCvsScoreColor(10.0, mockEuiThemeBorealis as EuiThemeComputed)).toBe('danger');
7067
});
7168

7269
it('returns correct color for low severity score for undefined value', () => {
73-
expect(getCvsScoreColor(-0.2, mockEuiThemeBorealis as EuiThemeComputed)).toBe(
74-
SEVERITY_COLOR.unknown
75-
);
70+
expect(getCvsScoreColor(-0.2, mockEuiThemeBorealis as EuiThemeComputed)).toBe('unknown');
7671
});
7772
});

x-pack/solutions/security/packages/kbn-cloud-security-posture/public/src/utils/get_finding_colors.ts

Lines changed: 10 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,28 @@
66
*/
77

88
import { EuiThemeComputed } from '@elastic/eui';
9-
import { euiThemeVars } from '@kbn/ui-theme'; // TODO: replace with euiTheme
109
import type { MisconfigurationEvaluationStatus } from '@kbn/cloud-security-posture-common';
1110
import {
1211
VULNERABILITIES_SEVERITY,
1312
MISCONFIGURATION_STATUS,
1413
} from '@kbn/cloud-security-posture-common';
1514

16-
const isAmsterdam = (euiThemeName: string) => {
17-
return euiThemeName?.toLowerCase().includes('amsterdam');
18-
};
19-
20-
// Designers blocked the migration to tokens from EUI during the Borealys theme migration.
21-
// We keep using hardcoded colors until security severity palette is ready https://github.com/elastic/kibana/issues/203387
22-
// TODO: Borealis migration - move from hardcoded values to severity palette https://github.com/elastic/security-team/issues/11606
23-
export const SEVERITY_COLOR = {
24-
critical: '#E7664C',
25-
high: '#DA8B45',
26-
medium: '#D6BF57',
27-
low: '#54B399',
28-
unknown: '#aaa',
29-
} as const;
30-
31-
// TODO: Borealis migration - migrate to security severity palette when it's ready https://github.com/elastic/security-team/issues/11606
3215
export const getSeverityStatusColor = (severity: string, euiTheme: EuiThemeComputed): string => {
33-
// TODO: Borealis migration - remove old mapping in main after Serverless switched to Borealis
34-
if (euiTheme && isAmsterdam(euiTheme.themeName)) {
35-
switch (severity) {
36-
case VULNERABILITIES_SEVERITY.LOW:
37-
return euiThemeVars.euiColorVis0;
38-
case VULNERABILITIES_SEVERITY.MEDIUM:
39-
return euiThemeVars.euiColorVis5_behindText;
40-
case VULNERABILITIES_SEVERITY.HIGH:
41-
return euiThemeVars.euiColorVis9_behindText;
42-
case VULNERABILITIES_SEVERITY.CRITICAL:
43-
return euiThemeVars.euiColorDanger;
44-
default:
45-
return '#aaa';
46-
}
47-
}
48-
4916
switch (severity) {
5017
case VULNERABILITIES_SEVERITY.LOW:
51-
return SEVERITY_COLOR.low;
18+
return euiTheme.colors.severity.neutral;
5219
case VULNERABILITIES_SEVERITY.MEDIUM:
53-
return SEVERITY_COLOR.medium;
20+
return euiTheme.colors.severity.warning;
5421
case VULNERABILITIES_SEVERITY.HIGH:
55-
return SEVERITY_COLOR.high;
22+
return euiTheme.colors.severity.risk;
5623
case VULNERABILITIES_SEVERITY.CRITICAL:
57-
return SEVERITY_COLOR.critical;
24+
return euiTheme.colors.severity.danger;
5825
default:
59-
return SEVERITY_COLOR.unknown;
26+
return euiTheme.colors.severity.unknown;
6027
}
6128
};
6229

6330
export const getCvsScoreColor = (score: number, euiTheme: EuiThemeComputed): string | undefined => {
64-
// TODO: Borealis migration - remove old mapping in main when Serverless switched to Borealis
65-
if (euiTheme && isAmsterdam(euiTheme.themeName)) {
66-
if (score <= 4) {
67-
return euiThemeVars.euiColorVis0; // low severity
68-
} else if (score >= 4 && score <= 7) {
69-
return euiThemeVars.euiColorVis7; // medium severity
70-
} else if (score >= 7 && score <= 9) {
71-
return euiThemeVars.euiColorVis9; // high severity
72-
} else if (score >= 9) {
73-
return euiThemeVars.euiColorDanger; // critical severity
74-
}
75-
}
76-
7731
if (score >= 0 && score <= 4) {
7832
return getSeverityStatusColor(VULNERABILITIES_SEVERITY.LOW, euiTheme);
7933
} else if (score >= 4 && score <= 7) {
@@ -87,16 +41,16 @@ export const getCvsScoreColor = (score: number, euiTheme: EuiThemeComputed): str
8741
}
8842
};
8943

90-
// TODO: Borealis migration - migrate to EUI color tokens when they are ready https://github.com/elastic/security-team/issues/11606
9144
export const getMisconfigurationStatusColor = (
92-
status?: MisconfigurationEvaluationStatus
45+
status: MisconfigurationEvaluationStatus,
46+
euiTheme: EuiThemeComputed
9347
): string => {
9448
switch (status) {
9549
case MISCONFIGURATION_STATUS.PASSED:
96-
return SEVERITY_COLOR.low;
50+
return euiTheme.colors.severity.success;
9751
case MISCONFIGURATION_STATUS.FAILED:
98-
return SEVERITY_COLOR.critical;
52+
return euiTheme.colors.severity.danger;
9953
default:
100-
return SEVERITY_COLOR.unknown;
54+
return euiTheme.colors.severity.unknown;
10155
}
10256
};

x-pack/solutions/security/packages/kbn-cloud-security-posture/public/src/utils/vulnerability_helpers.test.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@ import { i18n } from '@kbn/i18n';
99
import type { EuiThemeComputed } from '@elastic/eui';
1010
import type { VulnSeverity } from '@kbn/cloud-security-posture-common';
1111
import { getVulnerabilityStats } from './vulnerability_helpers';
12-
import {
13-
getSeverityStatusColor as getSeverityStatusColorUtil,
14-
SEVERITY_COLOR,
15-
} from './get_finding_colors';
12+
import { getSeverityStatusColor as getSeverityStatusColorUtil } from './get_finding_colors';
1613

1714
const getSeverityStatusColor = (status: VulnSeverity) => {
1815
const euiTheme = {
1916
themeName: 'borealis',
17+
colors: {
18+
severity: {
19+
danger: 'danger',
20+
risk: 'risk',
21+
warning: 'warning',
22+
neutral: 'neutral',
23+
unknown: 'unknown',
24+
},
25+
},
2026
};
2127

2228
return getSeverityStatusColorUtil(status, euiTheme as EuiThemeComputed);
@@ -52,7 +58,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
5258
}
5359
),
5460
count: 5,
55-
color: SEVERITY_COLOR.unknown,
61+
color: 'unknown',
5662
isCurrentFilter: false,
5763
},
5864
{
@@ -63,7 +69,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
6369
}
6470
),
6571
count: 4,
66-
color: SEVERITY_COLOR.low,
72+
color: 'neutral',
6773
isCurrentFilter: false,
6874
},
6975
{
@@ -74,7 +80,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
7480
}
7581
),
7682
count: 3,
77-
color: SEVERITY_COLOR.medium,
83+
color: 'warning',
7884
isCurrentFilter: false,
7985
},
8086
{
@@ -85,7 +91,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
8591
}
8692
),
8793
count: 2,
88-
color: SEVERITY_COLOR.high,
94+
color: 'risk',
8995
isCurrentFilter: false,
9096
},
9197
{
@@ -96,7 +102,7 @@ describe('getVulnerabilitiesAggregationCount', () => {
96102
}
97103
),
98104
count: 1,
99-
color: SEVERITY_COLOR.critical,
105+
color: 'danger',
100106
isCurrentFilter: false,
101107
},
102108
]);

x-pack/solutions/security/packages/kbn-cloud-security-posture/public/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
"@kbn/cloud-security-posture-common",
3333
"@kbn/i18n",
3434
"@kbn/search-types",
35-
"@kbn/ui-theme",
3635
"@kbn/i18n-react",
3736
"@kbn/rison",
3837
"@kbn/core-lifecycle-browser",

x-pack/solutions/security/plugins/cloud_security_posture/public/components/compliance_score_bar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { css, SerializedStyles } from '@emotion/react';
1010
import { i18n } from '@kbn/i18n';
1111
import React from 'react';
1212
import { MISCONFIGURATION_STATUS } from '@kbn/cloud-security-posture-common';
13-
import { getMisconfigurationStatusColor } from '@kbn/cloud-security-posture';
13+
import { useGetMisconfigurationStatusColor } from '@kbn/cloud-security-posture';
1414
import { calculatePostureScore } from '../../common/utils/helpers';
1515
import {
1616
CSP_FINDINGS_COMPLIANCE_SCORE,
@@ -34,6 +34,7 @@ export const ComplianceScoreBar = ({
3434
overrideCss?: SerializedStyles;
3535
}) => {
3636
const { euiTheme } = useEuiTheme();
37+
const { getMisconfigurationStatusColor } = useGetMisconfigurationStatusColor();
3738
const complianceScore = calculatePostureScore(totalPassed, totalFailed);
3839

3940
// ensures the compliance bar takes full width of its parent

0 commit comments

Comments
 (0)