Skip to content

Commit

Permalink
[8.10] [Cloud Security][CIS GCP] Add Agent flyout updates for CIS GCP (
Browse files Browse the repository at this point in the history
…elastic#163910) (elastic#164771)

# Backport

This will backport the following commits from `main` to `8.10`:
- [[Cloud Security][CIS GCP] Add Agent flyout updates for CIS GCP
(elastic#163910)](elastic#163910)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Rickyanto
Ang","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-08-24T18:38:39Z","message":"[Cloud
Security][CIS GCP] Add Agent flyout updates for CIS GCP (elastic#163910)\n\n##
Summary\r\nThis PR is for changing how Cloud Shell flyout looks when
adding agent.\r\nPreviously it shows tabs for other installation method,
now it no longer\r\nshows that (similar to what we have we Cloud
Formation)\r\nWe also updated the steps and command to copy.\r\n<img
width=\"836\" alt=\"Screenshot 2023-08-22 at 10 28 05
AM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/8703149/f312431a-e0fa-470e-896b-04324a160fdb\">\r\n<img
width=\"857\" alt=\"Screenshot 2023-08-22 at 10 29 12
AM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/8703149/51b33fcd-11b9-4691-946c-83cab6fd4f5a\">\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"c66f58ae0cbbb1c35a8f023f5507e60aff94dda4","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","Team:Cloud
Security","backport:prev-minor","v8.10.0","v8.11.0"],"number":163910,"url":"https://github.com/elastic/kibana/pull/163910","mergeCommit":{"message":"[Cloud
Security][CIS GCP] Add Agent flyout updates for CIS GCP (elastic#163910)\n\n##
Summary\r\nThis PR is for changing how Cloud Shell flyout looks when
adding agent.\r\nPreviously it shows tabs for other installation method,
now it no longer\r\nshows that (similar to what we have we Cloud
Formation)\r\nWe also updated the steps and command to copy.\r\n<img
width=\"836\" alt=\"Screenshot 2023-08-22 at 10 28 05
AM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/8703149/f312431a-e0fa-470e-896b-04324a160fdb\">\r\n<img
width=\"857\" alt=\"Screenshot 2023-08-22 at 10 29 12
AM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/8703149/51b33fcd-11b9-4691-946c-83cab6fd4f5a\">\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"c66f58ae0cbbb1c35a8f023f5507e60aff94dda4"}},"sourceBranch":"main","suggestedTargetBranches":["8.10"],"targetPullRequestStates":[{"branch":"8.10","label":"v8.10.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/163910","number":163910,"mergeCommit":{"message":"[Cloud
Security][CIS GCP] Add Agent flyout updates for CIS GCP (elastic#163910)\n\n##
Summary\r\nThis PR is for changing how Cloud Shell flyout looks when
adding agent.\r\nPreviously it shows tabs for other installation method,
now it no longer\r\nshows that (similar to what we have we Cloud
Formation)\r\nWe also updated the steps and command to copy.\r\n<img
width=\"836\" alt=\"Screenshot 2023-08-22 at 10 28 05
AM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/8703149/f312431a-e0fa-470e-896b-04324a160fdb\">\r\n<img
width=\"857\" alt=\"Screenshot 2023-08-22 at 10 29 12
AM\"\r\nsrc=\"https://github.com/elastic/kibana/assets/8703149/51b33fcd-11b9-4691-946c-83cab6fd4f5a\">\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"c66f58ae0cbbb1c35a8f023f5507e60aff94dda4"}}]}]
BACKPORT-->

Co-authored-by: Rickyanto Ang <[email protected]>
Co-authored-by: Paulo Henrique <[email protected]>
  • Loading branch information
3 people authored Aug 29, 2023
1 parent edcfc35 commit 7e257d0
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ function getArtifact(platform: PLATFORM_TYPE, kibanaVersion: string) {
kubernetes: {
downloadCommand: '',
},
googleCloudShell: {
downloadCommand: '',
},
};

return artifactMap[platform];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
AgentEnrollmentConfirmationStep,
InstallManagedAgentStep,
InstallCloudFormationManagedAgentStep,
InstallGoogleCloudShellManagedAgentStep,
IncomingDataConfirmationStep,
} from '.';

Expand Down Expand Up @@ -255,6 +256,15 @@ export const ManagedSteps: React.FunctionComponent<InstructionProps> = ({
cloudSecurityIntegration,
})
);
} else if (cloudSecurityIntegration?.cloudShellUrl) {
steps.push(
InstallGoogleCloudShellManagedAgentStep({
apiKeyData,
selectedApiKeyId,
cloudShellUrl: cloudSecurityIntegration.cloudShellUrl,
cloudShellCommand: installManagedCommands.googleCloudShell,
})
);
} else {
steps.push(
InstallManagedAgentStep({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export * from './agent_policy_selection_step';
export * from './configure_standalone_agent_step';
export * from './incoming_data_confirmation_step';
export * from './install_cloud_formation_managed_agent_step';
export * from './install_google_cloud_shell_managed_agent_step';
export * from './install_managed_agent_step';
export * from './install_standalone_agent_step';
export * from './installation_mode_selection_step';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 { i18n } from '@kbn/i18n';

import type { EuiContainedStepProps } from '@elastic/eui/src/components/steps/steps';

import type { GetOneEnrollmentAPIKeyResponse } from '../../../../common/types/rest_spec/enrollment_api_key';

import { GoogleCloudShellInstructions } from '../google_cloud_shell_instructions';

export const InstallGoogleCloudShellManagedAgentStep = ({
selectedApiKeyId,
apiKeyData,
isComplete,
cloudShellUrl,
cloudShellCommand,
}: {
selectedApiKeyId?: string;
apiKeyData?: GetOneEnrollmentAPIKeyResponse | null;
isComplete?: boolean;
cloudShellUrl?: string | undefined;
cloudShellCommand?: string;
}): EuiContainedStepProps => {
const nonCompleteStatus = selectedApiKeyId ? undefined : 'disabled';
const status = isComplete ? 'complete' : nonCompleteStatus;

return {
status,
title: i18n.translate('xpack.fleet.agentEnrollment.cloudShell.stepEnrollAndRunAgentTitle', {
defaultMessage: 'Install Elastic Agent on your cloud',
}),
children:
selectedApiKeyId && apiKeyData && cloudShellUrl ? (
<GoogleCloudShellInstructions
cloudShellUrl={cloudShellUrl || ''}
cloudShellCommand={cloudShellCommand || ''}
/>
) : (
<React.Fragment />
),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export const InstallSection: React.FunctionComponent<Props> = ({
windowsCommand={installCommand.windows}
linuxDebCommand={installCommand.deb}
linuxRpmCommand={installCommand.rpm}
googleCloudShellCommand={installCommand.googleCloudShell}
k8sCommand={installCommand.kubernetes}
hasK8sIntegration={isK8s === 'IS_KUBERNETES' || isK8s === 'IS_KUBERNETES_MULTIPAGE'}
cloudSecurityIntegration={cloudSecurityIntegration}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ sudo elastic-agent enroll ${enrollArgs} \nsudo systemctl enable elastic-agent \n
sudo rpm -vi elastic-agent-${kibanaVersion}-x86_64.rpm
sudo elastic-agent enroll ${enrollArgs} \nsudo systemctl enable elastic-agent \nsudo systemctl start elastic-agent`;

const googleCloudShellCommand = `FLEET_URL=${fleetServerUrl} ENROLLMENT_TOKEN=${enrollmentToken} STACK_VERSION=${kibanaVersion} ./deploy.sh`;
const googleCloudShellCommand = `gcloud config set project <PROJECT_ID> && \nFLEET_URL=${fleetServerUrl} ENROLLMENT_TOKEN=${enrollmentToken} STACK_VERSION=${kibanaVersion} ./deploy.sh`;

return {
linux: linuxCommand,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ cd elastic-agent-${kibanaVersion}-windows-x86_64
deb: linuxDebCommand,
rpm: linuxRpmCommand,
kubernetes: k8sCommand,
googleCloudShell: '',
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Link = ({ children, url }: { children: React.ReactNode; url: string }) =>
export const GoogleCloudShellGuide = (props: { commandText: string }) => {
return (
<>
<EuiSpacer size="m" />
<EuiSpacer size="xs" />
<EuiText size="s" color="subdued">
<p>
<FormattedMessage
Expand All @@ -46,17 +46,11 @@ export const GoogleCloudShellGuide = (props: { commandText: string }) => {
</p>
<EuiText size="s" color="subdued">
<ol>
<li>
<FormattedMessage
id="xpack.fleet.googleCloudShell.guide.steps.login"
defaultMessage="Log into your Google Cloud Console"
/>
</li>
<li>
<>
<FormattedMessage
id="xpack.fleet.googleCloudShell.guide.steps.copy"
defaultMessage="Copy the command below"
defaultMessage="Copy the following command and replace <PROJECT_ID> with your project ID."
/>
<EuiSpacer size="m" />
<EuiCodeBlock language="bash" isCopyable>
Expand All @@ -67,7 +61,7 @@ export const GoogleCloudShellGuide = (props: { commandText: string }) => {
<li>
<FormattedMessage
id="xpack.fleet.googleCloudShell.guide.steps.launch"
defaultMessage="Click the Launch Google Cloud Shell button below and then execute the command you copied earlier in google cloud shell."
defaultMessage="Click Launch Google Cloud Shell, then run the command"
/>
</li>
</ol>
Expand Down
62 changes: 16 additions & 46 deletions x-pack/plugins/fleet/public/components/platform_selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,9 @@ import {
FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE,
} from '../../common/constants/epm';
import { type PLATFORM_TYPE } from '../hooks';
import {
REDUCED_PLATFORM_OPTIONS,
PLATFORM_OPTIONS,
PLATFORM_OPTIONS_CLOUD_SHELL,
usePlatform,
} from '../hooks';
import { REDUCED_PLATFORM_OPTIONS, PLATFORM_OPTIONS, usePlatform } from '../hooks';

import { KubernetesInstructions } from './agent_enrollment_flyout/kubernetes_instructions';
import { GoogleCloudShellInstructions } from './agent_enrollment_flyout/google_cloud_shell_instructions';
import type { CloudSecurityIntegration } from './agent_enrollment_flyout/types';

interface Props {
Expand All @@ -42,7 +36,6 @@ interface Props {
linuxDebCommand: string;
linuxRpmCommand: string;
k8sCommand: string;
googleCloudShellCommand?: string | undefined;
hasK8sIntegration: boolean;
cloudSecurityIntegration?: CloudSecurityIntegration | undefined;
hasK8sIntegrationMultiPage: boolean;
Expand All @@ -65,7 +58,6 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
linuxDebCommand,
linuxRpmCommand,
k8sCommand,
googleCloudShellCommand,
hasK8sIntegration,
cloudSecurityIntegration,
hasK8sIntegrationMultiPage,
Expand All @@ -76,9 +68,6 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
onCopy,
}) => {
const getInitialPlatform = useCallback(() => {
if (cloudSecurityIntegration?.cloudShellUrl) {
return 'googleCloudShell';
}
if (
hasK8sIntegration ||
(cloudSecurityIntegration?.integrationType ===
Expand All @@ -88,12 +77,7 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
return 'kubernetes';

return 'linux';
}, [
hasK8sIntegration,
cloudSecurityIntegration?.integrationType,
isManaged,
cloudSecurityIntegration?.cloudShellUrl,
]);
}, [hasK8sIntegration, cloudSecurityIntegration?.integrationType, isManaged]);

const { platform, setPlatform } = usePlatform(getInitialPlatform());

Expand All @@ -104,12 +88,9 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({

const getPlatformOptions = useCallback(() => {
const platformOptions = isReduced ? REDUCED_PLATFORM_OPTIONS : PLATFORM_OPTIONS;
const platformOptionsWithCloudShell = cloudSecurityIntegration?.cloudShellUrl
? PLATFORM_OPTIONS_CLOUD_SHELL
: platformOptions;

return platformOptionsWithCloudShell;
}, [isReduced, cloudSecurityIntegration?.cloudShellUrl]);
return platformOptions;
}, [isReduced]);

const [copyButtonClicked, setCopyButtonClicked] = useState(false);

Expand Down Expand Up @@ -164,7 +145,6 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
deb: linuxDebCommand,
rpm: linuxRpmCommand,
kubernetes: k8sCommand,
googleCloudShell: k8sCommand,
};
const onTextAreaClick = () => {
if (onCopy) onCopy();
Expand Down Expand Up @@ -229,15 +209,6 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
<EuiSpacer size="s" />
</>
)}
{platform === 'googleCloudShell' && isManaged && (
<>
<GoogleCloudShellInstructions
cloudShellUrl={cloudSecurityIntegration?.cloudShellUrl || ''}
cloudShellCommand={googleCloudShellCommand || ''}
/>
<EuiSpacer size="s" />
</>
)}
{!hasK8sIntegrationMultiPage && (
<>
{platform === 'kubernetes' && (
Expand All @@ -250,19 +221,18 @@ export const PlatformSelector: React.FunctionComponent<Props> = ({
<EuiSpacer size="m" />
</EuiText>
)}
{platform !== 'googleCloudShell' && (
<EuiCodeBlock
onClick={onTextAreaClick}
fontSize="m"
isCopyable={!fullCopyButton}
paddingSize="m"
css={`
max-width: 1100px;
`}
>
<CommandCode>{commandsByPlatform[platform]}</CommandCode>
</EuiCodeBlock>
)}

<EuiCodeBlock
onClick={onTextAreaClick}
fontSize="m"
isCopyable={!fullCopyButton}
paddingSize="m"
css={`
max-width: 1100px;
`}
>
<CommandCode>{commandsByPlatform[platform]}</CommandCode>
</EuiCodeBlock>

<EuiSpacer size="s" />
{fullCopyButton && (
Expand Down
9 changes: 1 addition & 8 deletions x-pack/plugins/fleet/public/hooks/use_platform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@
import { useState } from 'react';
import { i18n } from '@kbn/i18n';

export type PLATFORM_TYPE =
| 'linux'
| 'mac'
| 'windows'
| 'rpm'
| 'deb'
| 'kubernetes'
| 'googleCloudShell';
export type PLATFORM_TYPE = 'linux' | 'mac' | 'windows' | 'rpm' | 'deb' | 'kubernetes';

export const REDUCED_PLATFORM_OPTIONS: Array<{
label: string;
Expand Down

0 comments on commit 7e257d0

Please sign in to comment.