Skip to content

Commit

Permalink
[Cloud Security]Added Beta tag + improvements for CIS GCP (#163663)
Browse files Browse the repository at this point in the history
## Summary

- Added Beta tag for GCP option on CSPM
- Fix a bug where setup_access is stuck on google_cloud_shell ( This bug
occur when user clicks on Manual option, click the start of Project ID
name, and then click google cloud shell option again)
- Added unit test for getCspmCloudShellDefaultValue to help with
refactor later
<img width="950" alt="Screenshot 2023-08-10 at 2 02 46 PM"
src="https://github.com/elastic/kibana/assets/8703149/ccd45ed1-8b6c-4631-8a01-22d35d1b62aa">
  • Loading branch information
animehart authored Aug 11, 2023
1 parent 3762df1 commit 349972c
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export interface CloudPostureIntegrationProps {
disabled?: boolean;
icon?: string;
tooltip?: string;
isBeta?: boolean;
}>;
}

Expand Down Expand Up @@ -91,6 +92,7 @@ export const cloudPostureIntegrations: CloudPostureIntegrations = {
defaultMessage: 'CIS GCP',
}),
icon: 'logoGCP',
isBeta: true,
},
{
type: CLOUDBEAT_AZURE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { useEuiTheme, EuiButton, EuiRadio, EuiToolTip } from '@elastic/eui';
import { useEuiTheme, EuiButton, EuiRadio, EuiToolTip, EuiBetaBadge } from '@elastic/eui';
import { css } from '@emotion/react';

export interface CspRadioGroupProps {
Expand All @@ -23,6 +23,7 @@ interface CspRadioOption {
label: string;
icon?: string;
tooltip?: string;
isBeta?: boolean;
}

export const RadioGroup = ({
Expand Down Expand Up @@ -57,7 +58,7 @@ export const RadioGroup = ({
content={option.tooltip}
anchorProps={{
style: {
flexGrow: 1,
flex: '1 1 0',
},
}}
>
Expand Down Expand Up @@ -105,6 +106,15 @@ export const RadioGroup = ({
checked={isChecked}
onChange={() => {}}
/>
{option.isBeta && (
<div
css={css`
margin: auto;
`}
>
<EuiBetaBadge label="Beta" alignment="middle" />
</div>
)}
</EuiButton>
</EuiToolTip>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,8 @@ export const GcpCredentialsForm = ({
updatePolicy(
getPosturePolicy(newPolicy, input.type, {
setup_access: {
// Restoring last manual credentials type or defaulting to the first option
value: lastSetupAccessType.current || SETUP_ACCESS_MANUAL,
// Restoring last manual credentials type
value: SETUP_ACCESS_MANUAL,
type: 'text',
},
// Restoring fields from manual setup format if any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
* 2.0.
*/

import { getMaxPackageName, getPostureInputHiddenVars, getPosturePolicy } from './utils';
import {
getMaxPackageName,
getPostureInputHiddenVars,
getPosturePolicy,
getCspmCloudShellDefaultValue,
} from './utils';
import { getMockPolicyAWS, getMockPolicyK8s, getMockPolicyEKS } from './mocks';
import type { PackageInfo } from '@kbn/fleet-plugin/common';

describe('getPosturePolicy', () => {
for (const [name, getPolicy, expectedVars] of [
Expand Down Expand Up @@ -123,3 +129,126 @@ describe('getMaxPackageName', () => {
expect(result).toBe('kspm-1');
});
});

describe('getCspmCloudShellDefaultValue', () => {
it('should return empty string when policy_templates is missing', () => {
const packagePolicy = { name: 'test' } as PackageInfo;

const result = getCspmCloudShellDefaultValue(packagePolicy);

expect(result).toBe('');
});

it('should return empty string when policy_templates.name is not cspm', () => {
const packagePolicy = { name: 'test', policy_templates: [{ name: 'kspm' }] } as PackageInfo;

const result = getCspmCloudShellDefaultValue(packagePolicy);

expect(result).toBe('');
});

it('should return empty string when policy_templates.inputs is missing', () => {
const packagePolicy = { name: 'test', policy_templates: [{ name: 'cspm' }] } as PackageInfo;

const result = getCspmCloudShellDefaultValue(packagePolicy);

expect(result).toBe('');
});

it('should return empty string when policy_templates.inputs is empty', () => {
const packagePolicy = {
name: 'test',
policy_templates: [
{
title: '',
description: '',
name: 'cspm',
inputs: [{}],
},
],
} as PackageInfo;

const result = getCspmCloudShellDefaultValue(packagePolicy);

expect(result).toBe('');
});

it('should return empty string when policy_templates.inputs is undefined', () => {
const packagePolicy = {
name: 'test',
policy_templates: [
{
title: '',
description: '',
name: 'cspm',
inputs: undefined,
},
],
} as PackageInfo;

const result = getCspmCloudShellDefaultValue(packagePolicy);

expect(result).toBe('');
});

it('should return empty string when policy_templates.inputs.vars does not have cloud_shell_url', () => {
const packagePolicy = {
name: 'test',
policy_templates: [
{
title: '',
description: '',
name: 'cspm',
inputs: [{ vars: [{ name: 'cloud_shell_url_FAKE' }] }],
},
],
} as PackageInfo;

const result = getCspmCloudShellDefaultValue(packagePolicy);

expect(result).toBe('');
});

it('should return empty string when policy_templates.inputs.varshave cloud_shell_url but no default', () => {
const packagePolicy = {
name: 'test',
policy_templates: [
{
title: '',
description: '',
name: 'cspm',
inputs: [{ vars: [{ name: 'cloud_shell_url' }] }],
},
],
} as PackageInfo;

const result = getCspmCloudShellDefaultValue(packagePolicy);

expect(result).toBe('');
});

it('should cloud shell url when policy_templates.inputs.vars have cloud_shell_url', () => {
const packagePolicy = {
name: 'test',
policy_templates: [
{
title: '',
description: '',
name: 'cspm',
inputs: [
{
vars: [
{ name: 'cloud_shell_url_FAKE', default: 'URL_FAKE' },
{ name: 'cloud_shell_url', default: 'URL' },
],
},
],
},
],
} as PackageInfo;

const result = getCspmCloudShellDefaultValue(packagePolicy);

expect(result).toBe('URL');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export const getPolicyTemplateInputOptions = (policyTemplate: CloudSecurityPolic
label: o.name,
icon: o.icon,
disabled: o.disabled,
isBeta: o.isBeta,
}));

export const getMaxPackageName = (
Expand Down

0 comments on commit 349972c

Please sign in to comment.