From 60fbd76bc36fcdff7cf5119e0d5c15d60cd6c61f Mon Sep 17 00:00:00 2001 From: Ricky Ang Date: Thu, 20 Apr 2023 23:09:17 -0700 Subject: [PATCH 1/8] edited fleet managed message to not show Kubernetes message on KSPM --- x-pack/plugins/fleet/common/constants/epm.ts | 2 + x-pack/plugins/fleet/common/index.ts | 2 + .../agent_enrollment_flyout/hooks.tsx | 66 ++++++++++++++++--- .../agent_enrollment_flyout/index.tsx | 6 +- .../agent_enrollment_flyout/instructions.tsx | 2 +- .../steps/compute_steps.tsx | 4 ++ .../steps/install_managed_agent_step.tsx | 5 +- .../agent_enrollment_flyout/types.ts | 5 ++ .../install_section.tsx | 5 +- .../public/components/platform_selector.tsx | 8 ++- 10 files changed, 91 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/fleet/common/constants/epm.ts b/x-pack/plugins/fleet/common/constants/epm.ts index a1d73b452cf72..f714730fe5e69 100644 --- a/x-pack/plugins/fleet/common/constants/epm.ts +++ b/x-pack/plugins/fleet/common/constants/epm.ts @@ -18,6 +18,8 @@ export const FLEET_SYNTHETICS_PACKAGE = 'synthetics'; export const FLEET_KUBERNETES_PACKAGE = 'kubernetes'; export const FLEET_CLOUD_SECURITY_POSTURE_PACKAGE = 'cloud_security_posture'; export const FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE = 'kspm'; +export const FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE = 'cspm'; +export const FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE = 'cnvm'; export const PACKAGE_TEMPLATE_SUFFIX = '@package'; export const USER_SETTINGS_TEMPLATE_SUFFIX = '@custom'; diff --git a/x-pack/plugins/fleet/common/index.ts b/x-pack/plugins/fleet/common/index.ts index 3ca552966a7c5..79e4589e8bf6a 100644 --- a/x-pack/plugins/fleet/common/index.ts +++ b/x-pack/plugins/fleet/common/index.ts @@ -18,6 +18,8 @@ export { FLEET_KUBERNETES_PACKAGE, FLEET_CLOUD_SECURITY_POSTURE_PACKAGE, FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE, + FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE, + FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE, FLEET_ENDPOINT_PACKAGE, // Saved object type AGENT_POLICY_SAVED_OBJECT_TYPE, diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx index 46341042102f0..3785ccfd1156b 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx @@ -13,9 +13,11 @@ import { FLEET_KUBERNETES_PACKAGE, FLEET_CLOUD_SECURITY_POSTURE_PACKAGE, FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE, + FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE, + FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE, } from '../../../common'; -import type { K8sMode } from './types'; +import type { K8sMode, CSPMode } from './types'; // Packages that requires custom elastic-agent manifest const K8S_PACKAGES = new Set([FLEET_KUBERNETES_PACKAGE]); @@ -51,6 +53,7 @@ export function useAgentPolicyWithPackagePolicies(policyId?: string) { export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { const [isK8s, setIsK8s] = useState('IS_LOADING'); + const [isCSP, setIsCSP] = useState('IS_LOADING'); useEffect(() => { async function checkifK8s() { if (!agentPolicy) { @@ -64,20 +67,67 @@ export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { : 'IS_NOT_KUBERNETES' ); } + + async function checkifCSP() { + if (!agentPolicy) { + setIsCSP('IS_LOADING'); + return; + } + + const pkgArray = agentPolicy?.package_policies?.map((e) => isCSPPackage(e)); + + if (pkgArray?.includes('IS_CSP_KSPM')) { + setIsCSP('IS_CSP_KSPM'); + } else if (pkgArray?.includes('IS_CSP_CSPM')) { + setIsCSP('IS_CSP_CSPM'); + } else if (pkgArray?.includes('IS_CSP_CNVM')) { + setIsCSP('IS_CSP_CNVM'); + } else { + setIsCSP('IS_NOT_CSP'); + } + } + checkifK8s(); + checkifCSP(); }, [agentPolicy]); - return { isK8s }; + return { isK8s, isCSP }; } const isK8sPackage = (pkg: PackagePolicy) => { const name = pkg.package?.name as string; - if (name === FLEET_CLOUD_SECURITY_POSTURE_PACKAGE) { - return pkg.inputs.some( - (input) => - input.enabled && input.policy_template === FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE - ); - } return K8S_PACKAGES.has(name); }; + +const isCSPPackage = (pkg: PackagePolicy) => { + const name = pkg.package?.name as string; + if (name === FLEET_CLOUD_SECURITY_POSTURE_PACKAGE) { + if ( + pkg.inputs.some( + (input) => + input.enabled && + input.policy_template === FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE + ) + ) { + return 'IS_CSP_KSPM'; + } else if ( + pkg.inputs.some( + (input) => + input.enabled && + input.policy_template === FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE + ) + ) { + return 'IS_CSP_CSPM'; + } else if ( + pkg.inputs.some( + (input) => + input.enabled && + input.policy_template === FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE + ) + ) { + return 'IS_CSP_CNVM'; + } + } + return 'IS_NOT_CSP'; +}; diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx index 1cb9b058e12cc..5bcc009e07923 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx @@ -99,7 +99,10 @@ export const AgentEnrollmentFlyout: React.FunctionComponent = ({ } }, [selectedPolicy, isFleetServerPolicySelected]); - const { isK8s } = useIsK8sPolicy(selectedPolicy ? selectedPolicy : undefined); + const { isK8s, isCSP } = useIsK8sPolicy(selectedPolicy ? selectedPolicy : undefined); + + console.log('isK8S: ', isK8s) + console.log('isCSP: ', isCSP) return ( @@ -197,6 +200,7 @@ export const AgentEnrollmentFlyout: React.FunctionComponent = ({ agentPolicies={agentPolicies} isFleetServerPolicySelected={isFleetServerPolicySelected} isK8s={isK8s} + isCSP={isCSP} refreshAgentPolicies={refreshAgentPolicies} isLoadingAgentPolicies={isLoadingAgentPolicies} mode={mode} diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx index ad2a5339aeea1..b5dbf16475111 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx @@ -37,7 +37,7 @@ export const Instructions = (props: InstructionProps) => { const fleetStatus = useFleetStatus(); const { isUnhealthy: isFleetServerUnhealthy, isLoading: isLoadingFleetServerHealth } = useFleetServerUnhealthy(); - +console.log('INSTR props: ', props) const { isFleetServerStandalone } = useFleetServerStandalone(); useEffect(() => { diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx index f5f993231d7b1..4fbf80868ce22 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx @@ -51,6 +51,7 @@ export const StandaloneSteps: React.FunctionComponent = ({ selectedApiKeyId, setSelectedAPIKeyId, isK8s, + isCSP, }) => { const core = useStartServices(); const { notifications } = core; @@ -194,6 +195,7 @@ export const ManagedSteps: React.FunctionComponent = ({ selectionType, onClickViewAgents, isK8s, + isCSP, installedPackagePolicy, }) => { const kibanaVersion = useKibanaVersion(); @@ -247,6 +249,7 @@ export const ManagedSteps: React.FunctionComponent = ({ apiKeyData, selectedApiKeyId, isK8s, + isCSP, enrollToken, }) ); @@ -283,6 +286,7 @@ export const ManagedSteps: React.FunctionComponent = ({ refreshAgentPolicies, selectionType, isK8s, + isCSP, installManagedCommands, apiKeyData, enrolledAgentIds, diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_managed_agent_step.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_managed_agent_step.tsx index 7656c40a07f71..274153d061738 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_managed_agent_step.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_managed_agent_step.tsx @@ -16,13 +16,14 @@ import type { GetOneEnrollmentAPIKeyResponse } from '../../../../common/types/re import { InstallSection } from '../../enrollment_instructions/install_section'; import type { CommandsByPlatform } from '../../../applications/fleet/components/fleet_server_instructions/utils/install_command_utils'; -import type { K8sMode } from '../types'; +import type { K8sMode, CSPMode } from '../types'; export const InstallManagedAgentStep = ({ installCommand, selectedApiKeyId, apiKeyData, isK8s, + isCSP, enrollToken, isComplete, fullCopyButton, @@ -31,6 +32,7 @@ export const InstallManagedAgentStep = ({ selectedApiKeyId?: string; apiKeyData?: GetOneEnrollmentAPIKeyResponse | null; isK8s?: K8sMode; + isCSP?: CSPMode; enrollToken?: string; installCommand: CommandsByPlatform; isComplete?: boolean; @@ -48,6 +50,7 @@ export const InstallManagedAgentStep = ({ = ({ installCommand, isK8s, + isCSP, enrollToken, fullCopyButton = false, isManaged = true, @@ -44,6 +46,7 @@ export const InstallSection: React.FunctionComponent = ({ linuxRpmCommand={installCommand.rpm} k8sCommand={installCommand.kubernetes} hasK8sIntegration={isK8s === 'IS_KUBERNETES' || isK8s === 'IS_KUBERNETES_MULTIPAGE'} + typeOfCSPIntegration={isCSP} hasK8sIntegrationMultiPage={isK8s === 'IS_KUBERNETES_MULTIPAGE'} isManaged={isManaged} enrollToken={enrollToken} diff --git a/x-pack/plugins/fleet/public/components/platform_selector.tsx b/x-pack/plugins/fleet/public/components/platform_selector.tsx index d0058185171ab..efcabed8ce579 100644 --- a/x-pack/plugins/fleet/public/components/platform_selector.tsx +++ b/x-pack/plugins/fleet/public/components/platform_selector.tsx @@ -32,6 +32,7 @@ interface Props { linuxRpmCommand: string; k8sCommand: string; hasK8sIntegration: boolean; + typeOfCSPIntegration?: string; hasK8sIntegrationMultiPage: boolean; isManaged?: boolean; hasFleetServer?: boolean; @@ -53,6 +54,7 @@ export const PlatformSelector: React.FunctionComponent = ({ linuxRpmCommand, k8sCommand, hasK8sIntegration, + typeOfCSPIntegration, hasK8sIntegrationMultiPage, isManaged, enrollToken, @@ -63,8 +65,10 @@ export const PlatformSelector: React.FunctionComponent = ({ const { platform, setPlatform } = usePlatform(); useEffect(() => { - setPlatform(hasK8sIntegration ? 'kubernetes' : 'linux'); - }, [hasK8sIntegration, setPlatform]); + setPlatform( + hasK8sIntegration || typeOfCSPIntegration === 'IS_CSP_KSPM' ? 'kubernetes' : 'linux' + ); + }, [hasK8sIntegration, typeOfCSPIntegration, setPlatform]); // In case of fleet server installation or standalone agent without // Kubernetes integration in the policy use reduced platform options From b9e00cf650405d0460b4f6610eface1c697d25ce Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 21 Apr 2023 07:13:19 +0000 Subject: [PATCH 2/8] [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' --- .../fleet/public/components/agent_enrollment_flyout/index.tsx | 4 ++-- .../components/agent_enrollment_flyout/instructions.tsx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx index 5bcc009e07923..d4d8b37a6e974 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx @@ -101,8 +101,8 @@ export const AgentEnrollmentFlyout: React.FunctionComponent = ({ const { isK8s, isCSP } = useIsK8sPolicy(selectedPolicy ? selectedPolicy : undefined); - console.log('isK8S: ', isK8s) - console.log('isCSP: ', isCSP) + console.log('isK8S: ', isK8s); + console.log('isCSP: ', isCSP); return ( diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx index b5dbf16475111..4c6016f9931b6 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx @@ -37,7 +37,7 @@ export const Instructions = (props: InstructionProps) => { const fleetStatus = useFleetStatus(); const { isUnhealthy: isFleetServerUnhealthy, isLoading: isLoadingFleetServerHealth } = useFleetServerUnhealthy(); -console.log('INSTR props: ', props) + console.log('INSTR props: ', props); const { isFleetServerStandalone } = useFleetServerStandalone(); useEffect(() => { From 551a633f36387674d5c7d3843edf94f1e2a2b6d5 Mon Sep 17 00:00:00 2001 From: Ricky Ang Date: Mon, 24 Apr 2023 13:35:40 -0700 Subject: [PATCH 3/8] change csp status into object, added placeholder for new message prompt, PR comments --- x-pack/plugins/fleet/common/constants/epm.ts | 2 +- .../agent_enrollment_flyout/hooks.tsx | 20 ++++++++++++----- .../agent_enrollment_flyout/index.tsx | 2 +- .../public/components/platform_selector.tsx | 22 +++++++++++++++++++ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/fleet/common/constants/epm.ts b/x-pack/plugins/fleet/common/constants/epm.ts index f714730fe5e69..f6bd2744219cb 100644 --- a/x-pack/plugins/fleet/common/constants/epm.ts +++ b/x-pack/plugins/fleet/common/constants/epm.ts @@ -19,7 +19,7 @@ export const FLEET_KUBERNETES_PACKAGE = 'kubernetes'; export const FLEET_CLOUD_SECURITY_POSTURE_PACKAGE = 'cloud_security_posture'; export const FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE = 'kspm'; export const FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE = 'cspm'; -export const FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE = 'cnvm'; +export const FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE = 'vuln_mgmt'; export const PACKAGE_TEMPLATE_SUFFIX = '@package'; export const USER_SETTINGS_TEMPLATE_SUFFIX = '@custom'; diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx index 3785ccfd1156b..e1091b3072916 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx @@ -19,6 +19,11 @@ import { import type { K8sMode, CSPMode } from './types'; +interface CSPObject { + status: CSPMode; + cloudformationUrl: string; +} + // Packages that requires custom elastic-agent manifest const K8S_PACKAGES = new Set([FLEET_KUBERNETES_PACKAGE]); @@ -53,7 +58,10 @@ export function useAgentPolicyWithPackagePolicies(policyId?: string) { export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { const [isK8s, setIsK8s] = useState('IS_LOADING'); - const [isCSP, setIsCSP] = useState('IS_LOADING'); + const [isCSP, setIsCSP] = useState({ + status: 'IS_LOADING', + cloudformationUrl: 'PlaceHolder', + }); useEffect(() => { async function checkifK8s() { if (!agentPolicy) { @@ -70,20 +78,20 @@ export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { async function checkifCSP() { if (!agentPolicy) { - setIsCSP('IS_LOADING'); + setIsCSP({ status: 'IS_LOADING', cloudformationUrl: 'PlaceHolder' }); return; } const pkgArray = agentPolicy?.package_policies?.map((e) => isCSPPackage(e)); if (pkgArray?.includes('IS_CSP_KSPM')) { - setIsCSP('IS_CSP_KSPM'); + setIsCSP({ status: 'IS_CSP_KSPM', cloudformationUrl: 'PlaceHolder' }); } else if (pkgArray?.includes('IS_CSP_CSPM')) { - setIsCSP('IS_CSP_CSPM'); + setIsCSP({ status: 'IS_CSP_CSPM', cloudformationUrl: 'PlaceHolder' }); } else if (pkgArray?.includes('IS_CSP_CNVM')) { - setIsCSP('IS_CSP_CNVM'); + setIsCSP({ status: 'IS_CSP_CNVM', cloudformationUrl: 'PlaceHolder' }); } else { - setIsCSP('IS_NOT_CSP'); + setIsCSP({ status: 'IS_NOT_CSP', cloudformationUrl: 'PlaceHolder' }); } } diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx index 5bcc009e07923..4d1f7f587ea7a 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx @@ -200,7 +200,7 @@ export const AgentEnrollmentFlyout: React.FunctionComponent = ({ agentPolicies={agentPolicies} isFleetServerPolicySelected={isFleetServerPolicySelected} isK8s={isK8s} - isCSP={isCSP} + isCSP={isCSP.status} refreshAgentPolicies={refreshAgentPolicies} isLoadingAgentPolicies={isLoadingAgentPolicies} mode={mode} diff --git a/x-pack/plugins/fleet/public/components/platform_selector.tsx b/x-pack/plugins/fleet/public/components/platform_selector.tsx index efcabed8ce579..3ff9f36772a9a 100644 --- a/x-pack/plugins/fleet/public/components/platform_selector.tsx +++ b/x-pack/plugins/fleet/public/components/platform_selector.tsx @@ -98,6 +98,16 @@ export const PlatformSelector: React.FunctionComponent = ({ /> ); + const placeHolderCallout = ( + + ); + const commandsByPlatform: Record = { linux: linuxCommand, mac: macCommand, @@ -135,6 +145,18 @@ export const PlatformSelector: React.FunctionComponent = ({ )} + {platform === 'mac' && typeOfCSPIntegration === 'IS_CSP_CSPM' && ( + <> + {placeHolderCallout} + + + )} + {platform === 'kubernetes' && typeOfCSPIntegration === 'IS_CSP_CSPM' && ( + <> + {placeHolderCallout} + + + )} {platform === 'kubernetes' && !hasK8sIntegration && ( <> {k8sCallout} From 45781f4381427e51e34ee34acc3133ad475ee90f Mon Sep 17 00:00:00 2001 From: Ricky Ang Date: Tue, 25 Apr 2023 13:06:11 -0700 Subject: [PATCH 4/8] edited standalone instructions + PR comments --- .../steps/compute_steps.tsx | 2 ++ .../steps/install_standalone_agent_step.tsx | 5 +++- .../public/components/platform_selector.tsx | 28 +++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx index 4fbf80868ce22..a4176042439d3 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx @@ -156,6 +156,7 @@ export const StandaloneSteps: React.FunctionComponent = ({ InstallStandaloneAgentStep({ installCommand: standaloneInstallCommands, isK8s, + isCSP, }) ); @@ -163,6 +164,7 @@ export const StandaloneSteps: React.FunctionComponent = ({ }, [ kibanaVersion, isK8s, + isCSP, agentPolicy, selectedPolicy, agentPolicies, diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_standalone_agent_step.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_standalone_agent_step.tsx index e972e5a99a1e2..a04817c0d70f6 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_standalone_agent_step.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_standalone_agent_step.tsx @@ -14,17 +14,19 @@ import type { CommandsByPlatform } from '../../../applications/fleet/components/ import { InstallSection } from '../../enrollment_instructions/install_section'; -import type { K8sMode } from '../types'; +import type { CSPMode, K8sMode } from '../types'; export const InstallStandaloneAgentStep = ({ installCommand, isK8s, + isCSP, isComplete, fullCopyButton, onCopy, }: { installCommand: CommandsByPlatform; isK8s?: K8sMode; + isCSP?: CSPMode; isComplete?: boolean; fullCopyButton?: boolean; onCopy?: () => void; @@ -37,6 +39,7 @@ export const InstallStandaloneAgentStep = ({ = ({ )} - {platform === 'mac' && typeOfCSPIntegration === 'IS_CSP_CSPM' && ( - <> - {placeHolderCallout} - - - )} - {platform === 'kubernetes' && typeOfCSPIntegration === 'IS_CSP_CSPM' && ( - <> - {placeHolderCallout} - - - )} + {platform === 'mac' && + (typeOfCSPIntegration === 'IS_CSP_CSPM' || + typeOfCSPIntegration === 'IS_CSP_CNVM' || + typeOfCSPIntegration === 'IS_CSP_KSPM') && ( + <> + {placeHolderCallout} + + + )} + {platform === 'kubernetes' && + (typeOfCSPIntegration === 'IS_CSP_CSPM' || typeOfCSPIntegration === 'IS_CSP_CNVM') && ( + <> + {placeHolderCallout} + + + )} {platform === 'kubernetes' && !hasK8sIntegration && ( <> {k8sCallout} From d329d70f9eb788ffaae8d0f913f0a940c9d9fd8a Mon Sep 17 00:00:00 2001 From: Ricky Ang Date: Tue, 16 May 2023 16:44:11 -0700 Subject: [PATCH 5/8] pr comments + refactor cloudformation url to be included on cspObject --- .../agent_enrollment_flyout/hooks.tsx | 30 +++++++++---------- .../agent_enrollment_flyout/index.tsx | 2 +- .../agent_enrollment_flyout/instructions.tsx | 16 ++++------ .../steps/compute_steps.tsx | 4 +-- .../agent_enrollment_flyout/types.ts | 7 ++++- .../install_section.tsx | 2 +- .../public/components/platform_selector.tsx | 2 +- 7 files changed, 31 insertions(+), 32 deletions(-) diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx index c756d3aabd547..769f591686d61 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx @@ -16,13 +16,9 @@ import { FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE, FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE, } from '../../../common'; +import { getCloudFormationTemplateUrlFromPackagePolicy } from '../../services'; -import type { K8sMode, CSPMode } from './types'; - -interface CSPObject { - status: CSPMode; - cloudformationUrl: string; -} +import type { K8sMode, CSPObject } from './types'; // Packages that requires custom elastic-agent manifest const K8S_PACKAGES = new Set([FLEET_KUBERNETES_PACKAGE]); @@ -83,16 +79,20 @@ export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { return; } - const pkgArray = agentPolicy?.package_policies?.map((e) => isCSPPackage(e)); + const cspPackageObj = agentPolicy?.package_policies?.map((pkgPolicy) => + getCSPPackageType(pkgPolicy) + ); + + const cloudFormationTemplateUrl = getCloudFormationTemplateUrlFromPackagePolicy(agentPolicy); - if (pkgArray?.includes('IS_CSP_KSPM')) { - setIsCSP({ status: 'IS_CSP_KSPM', cloudformationUrl: 'PlaceHolder' }); - } else if (pkgArray?.includes('IS_CSP_CSPM')) { - setIsCSP({ status: 'IS_CSP_CSPM', cloudformationUrl: 'PlaceHolder' }); - } else if (pkgArray?.includes('IS_CSP_CNVM')) { - setIsCSP({ status: 'IS_CSP_CNVM', cloudformationUrl: 'PlaceHolder' }); + if (cspPackageObj?.includes('IS_CSP_KSPM')) { + setIsCSP({ status: 'IS_CSP_KSPM', cloudformationUrl: cloudFormationTemplateUrl }); + } else if (cspPackageObj?.includes('IS_CSP_CSPM')) { + setIsCSP({ status: 'IS_CSP_CSPM', cloudformationUrl: cloudFormationTemplateUrl }); + } else if (cspPackageObj?.includes('IS_CSP_CNVM')) { + setIsCSP({ status: 'IS_CSP_CNVM', cloudformationUrl: cloudFormationTemplateUrl }); } else { - setIsCSP({ status: 'IS_NOT_CSP', cloudformationUrl: 'PlaceHolder' }); + setIsCSP({ status: 'IS_NOT_CSP', cloudformationUrl: cloudFormationTemplateUrl }); } } @@ -109,7 +109,7 @@ const isK8sPackage = (pkg: PackagePolicy) => { return K8S_PACKAGES.has(name); }; -const isCSPPackage = (pkg: PackagePolicy) => { +const getCSPPackageType = (pkg: PackagePolicy) => { const name = pkg.package?.name as string; if (name === FLEET_CLOUD_SECURITY_POSTURE_PACKAGE) { if ( diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx index 78d780882b673..7b401d8cebc58 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx @@ -197,7 +197,7 @@ export const AgentEnrollmentFlyout: React.FunctionComponent = ({ agentPolicies={agentPolicies} isFleetServerPolicySelected={isFleetServerPolicySelected} isK8s={isK8s} - isCSP={isCSP.status} + isCSP={isCSP} refreshAgentPolicies={refreshAgentPolicies} isLoadingAgentPolicies={isLoadingAgentPolicies} mode={mode} diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx index 816750b473448..7c5d4cee927d9 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx @@ -14,10 +14,7 @@ import { FleetServerRequirementPage } from '../../applications/fleet/sections/ag import { AGENTS_PREFIX, FLEET_SERVER_PACKAGE, SO_SEARCH_LIMIT } from '../../constants'; import { useFleetServerUnhealthy } from '../../applications/fleet/sections/agents/hooks/use_fleet_server_unhealthy'; import { Loading } from '..'; -import { - getCloudFormationTemplateUrlFromPackagePolicy, - policyHasFleetServer, -} from '../../services'; +import { policyHasFleetServer } from '../../services'; import { AdvancedTab } from '../../applications/fleet/components/fleet_server_instructions/advanced_tab'; import type { InstructionProps } from './types'; @@ -36,6 +33,7 @@ export const Instructions = (props: InstructionProps) => { setMode, isIntegrationFlow, refreshAgentPolicies, + isCSP, } = props; const fleetStatus = useFleetStatus(); const { isUnhealthy: isFleetServerUnhealthy, isLoading: isLoadingFleetServerHealth } = @@ -82,20 +80,16 @@ export const Instructions = (props: InstructionProps) => { isFleetServerUnhealthy || (fleetStatus.missingRequirements ?? []).some((r) => r === FLEET_SERVER_PACKAGE)); - const cloudFormationTemplateUrl = getCloudFormationTemplateUrlFromPackagePolicy( - props.selectedPolicy - ); - useEffect(() => { // If we have a cloudFormationTemplateUrl, we want to hide the selection type - if (cloudFormationTemplateUrl) { + if (isCSP?.cloudformationUrl) { setSelectionType(undefined); } else if (!isIntegrationFlow && showAgentEnrollment) { setSelectionType('radio'); } else { setSelectionType('tabs'); } - }, [isIntegrationFlow, showAgentEnrollment, setSelectionType, cloudFormationTemplateUrl]); + }, [isIntegrationFlow, showAgentEnrollment, setSelectionType, isCSP?.cloudformationUrl]); if (isLoadingAgents || isLoadingAgentPolicies || isLoadingFleetServerHealth) return ; @@ -124,7 +118,7 @@ export const Instructions = (props: InstructionProps) => { {isFleetServerPolicySelected ? ( undefined} /> ) : ( - + )} ); diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx index 8f2dac73504a1..2797197759ff7 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx @@ -157,7 +157,7 @@ export const StandaloneSteps: React.FunctionComponent = ({ InstallStandaloneAgentStep({ installCommand: standaloneInstallCommands, isK8s, - isCSP, + isCSP: isCSP?.status, }) ); @@ -263,7 +263,7 @@ export const ManagedSteps: React.FunctionComponent = ({ apiKeyData, selectedApiKeyId, isK8s, - isCSP, + isCSP: isCSP?.status, enrollToken, }) ); diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/types.ts b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/types.ts index e446c497a1313..c337092fe7fdd 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/types.ts +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/types.ts @@ -20,6 +20,11 @@ export type CSPMode = 'IS_LOADING' | 'IS_NOT_CSP' | 'IS_CSP_KSPM' | 'IS_CSP_CNVM export type FlyoutMode = 'managed' | 'standalone'; export type SelectionType = 'tabs' | 'radio' | undefined; +export interface CSPObject { + status: CSPMode; + cloudformationUrl: string | undefined; +} + export interface BaseProps { /** * The user selected policy to be used. If this value is `undefined` a value must be provided for `agentPolicies`. @@ -30,7 +35,7 @@ export interface BaseProps { isK8s?: K8sMode; - isCSP?: CSPMode; + isCSP?: CSPObject; /** * There is a step in the agent enrollment process that allows users to see the data from an integration represented in the UI diff --git a/x-pack/plugins/fleet/public/components/enrollment_instructions/install_section.tsx b/x-pack/plugins/fleet/public/components/enrollment_instructions/install_section.tsx index 62adb8747407c..0126e252816be 100644 --- a/x-pack/plugins/fleet/public/components/enrollment_instructions/install_section.tsx +++ b/x-pack/plugins/fleet/public/components/enrollment_instructions/install_section.tsx @@ -17,7 +17,7 @@ import { PlatformSelector } from '../platform_selector'; interface Props { installCommand: CommandsByPlatform; isK8s: K8sMode | undefined; - isCSP?: CSPMode | undefined; + isCSP: CSPMode | undefined; enrollToken?: string; fullCopyButton?: boolean; isManaged?: boolean; diff --git a/x-pack/plugins/fleet/public/components/platform_selector.tsx b/x-pack/plugins/fleet/public/components/platform_selector.tsx index fb983fb2f3b09..9ebf2dc862bfc 100644 --- a/x-pack/plugins/fleet/public/components/platform_selector.tsx +++ b/x-pack/plugins/fleet/public/components/platform_selector.tsx @@ -119,7 +119,7 @@ export const PlatformSelector: React.FunctionComponent = ({ Date: Tue, 16 May 2023 19:09:05 -0700 Subject: [PATCH 6/8] fix failed test --- .../public/components/agent_enrollment_flyout/hooks.tsx | 4 ++-- .../components/agent_enrollment_flyout/instructions.tsx | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx index 769f591686d61..5147ad18418cc 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx @@ -56,7 +56,7 @@ export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { const [isK8s, setIsK8s] = useState('IS_LOADING'); const [isCSP, setIsCSP] = useState({ status: 'IS_LOADING', - cloudformationUrl: 'PlaceHolder', + cloudformationUrl: undefined, }); useEffect(() => { @@ -75,7 +75,7 @@ export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { async function checkifCSP() { if (!agentPolicy) { - setIsCSP({ status: 'IS_LOADING', cloudformationUrl: 'PlaceHolder' }); + setIsCSP({ status: 'IS_LOADING', cloudformationUrl: undefined }); return; } diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx index 7c5d4cee927d9..7fabe6b0767c5 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx @@ -33,7 +33,6 @@ export const Instructions = (props: InstructionProps) => { setMode, isIntegrationFlow, refreshAgentPolicies, - isCSP, } = props; const fleetStatus = useFleetStatus(); const { isUnhealthy: isFleetServerUnhealthy, isLoading: isLoadingFleetServerHealth } = @@ -82,14 +81,14 @@ export const Instructions = (props: InstructionProps) => { useEffect(() => { // If we have a cloudFormationTemplateUrl, we want to hide the selection type - if (isCSP?.cloudformationUrl) { + if (props.isCSP?.cloudformationUrl) { setSelectionType(undefined); } else if (!isIntegrationFlow && showAgentEnrollment) { setSelectionType('radio'); } else { setSelectionType('tabs'); } - }, [isIntegrationFlow, showAgentEnrollment, setSelectionType, isCSP?.cloudformationUrl]); + }, [isIntegrationFlow, showAgentEnrollment, setSelectionType, props.isCSP]); if (isLoadingAgents || isLoadingAgentPolicies || isLoadingFleetServerHealth) return ; @@ -118,7 +117,7 @@ export const Instructions = (props: InstructionProps) => { {isFleetServerPolicySelected ? ( undefined} /> ) : ( - + )} ); From 4d30247ed5a1ed76615918730a40756d64cd692a Mon Sep 17 00:00:00 2001 From: Ricky Ang Date: Wed, 17 May 2023 01:17:14 -0700 Subject: [PATCH 7/8] PR Comments --- .../agent_enrollment_flyout/hooks.tsx | 88 +++++-------------- .../agent_enrollment_flyout/index.tsx | 6 +- .../agent_enrollment_flyout/instructions.tsx | 9 +- .../steps/compute_steps.tsx | 12 +-- .../steps/install_managed_agent_step.tsx | 8 +- .../steps/install_standalone_agent_step.tsx | 8 +- .../agent_enrollment_flyout/types.ts | 8 +- .../install_section.tsx | 8 +- .../public/components/platform_selector.tsx | 37 +++++--- 9 files changed, 80 insertions(+), 104 deletions(-) diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx index 5147ad18418cc..6b2207eeb5e46 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx @@ -4,21 +4,15 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ -import { useState, useEffect } from 'react'; +import { useState, useEffect, useMemo } from 'react'; import { i18n } from '@kbn/i18n'; import type { PackagePolicy, AgentPolicy } from '../../types'; import { sendGetOneAgentPolicy, useStartServices } from '../../hooks'; -import { - FLEET_KUBERNETES_PACKAGE, - FLEET_CLOUD_SECURITY_POSTURE_PACKAGE, - FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE, - FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE, - FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE, -} from '../../../common'; +import { FLEET_KUBERNETES_PACKAGE, FLEET_CLOUD_SECURITY_POSTURE_PACKAGE } from '../../../common'; import { getCloudFormationTemplateUrlFromPackagePolicy } from '../../services'; -import type { K8sMode, CSPObject } from './types'; +import type { K8sMode } from './types'; // Packages that requires custom elastic-agent manifest const K8S_PACKAGES = new Set([FLEET_KUBERNETES_PACKAGE]); @@ -54,10 +48,6 @@ export function useAgentPolicyWithPackagePolicies(policyId?: string) { export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { const [isK8s, setIsK8s] = useState('IS_LOADING'); - const [isCSP, setIsCSP] = useState({ - status: 'IS_LOADING', - cloudformationUrl: undefined, - }); useEffect(() => { async function checkifK8s() { @@ -73,34 +63,24 @@ export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { ); } - async function checkifCSP() { - if (!agentPolicy) { - setIsCSP({ status: 'IS_LOADING', cloudformationUrl: undefined }); - return; - } - - const cspPackageObj = agentPolicy?.package_policies?.map((pkgPolicy) => - getCSPPackageType(pkgPolicy) - ); - - const cloudFormationTemplateUrl = getCloudFormationTemplateUrlFromPackagePolicy(agentPolicy); + checkifK8s(); + }, [agentPolicy]); - if (cspPackageObj?.includes('IS_CSP_KSPM')) { - setIsCSP({ status: 'IS_CSP_KSPM', cloudformationUrl: cloudFormationTemplateUrl }); - } else if (cspPackageObj?.includes('IS_CSP_CSPM')) { - setIsCSP({ status: 'IS_CSP_CSPM', cloudformationUrl: cloudFormationTemplateUrl }); - } else if (cspPackageObj?.includes('IS_CSP_CNVM')) { - setIsCSP({ status: 'IS_CSP_CNVM', cloudformationUrl: cloudFormationTemplateUrl }); - } else { - setIsCSP({ status: 'IS_NOT_CSP', cloudformationUrl: cloudFormationTemplateUrl }); - } + const cloudSecurityIntegration = useMemo(() => { + if (!agentPolicy) { + return undefined; } - checkifK8s(); - checkifCSP(); + const integrationType = getCloudSecurityIntegrationTypeFromPackagePolicy(agentPolicy); + const cloudformationUrl = getCloudFormationTemplateUrlFromPackagePolicy(agentPolicy); + + return { + integrationType, + cloudformationUrl, + }; }, [agentPolicy]); - return { isK8s, isCSP }; + return { isK8s, cloudSecurityIntegration }; } const isK8sPackage = (pkg: PackagePolicy) => { @@ -109,34 +89,10 @@ const isK8sPackage = (pkg: PackagePolicy) => { return K8S_PACKAGES.has(name); }; -const getCSPPackageType = (pkg: PackagePolicy) => { - const name = pkg.package?.name as string; - if (name === FLEET_CLOUD_SECURITY_POSTURE_PACKAGE) { - if ( - pkg.inputs.some( - (input) => - input.enabled && - input.policy_template === FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE - ) - ) { - return 'IS_CSP_KSPM'; - } else if ( - pkg.inputs.some( - (input) => - input.enabled && - input.policy_template === FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE - ) - ) { - return 'IS_CSP_CSPM'; - } else if ( - pkg.inputs.some( - (input) => - input.enabled && - input.policy_template === FLEET_CLOUD_SECURITY_POSTURE_CNVM_POLICY_TEMPLATE - ) - ) { - return 'IS_CSP_CNVM'; - } - } - return 'IS_NOT_CSP'; +const getCloudSecurityIntegrationTypeFromPackagePolicy = (agentPolicy: AgentPolicy) => { + const packagePolicy = agentPolicy?.package_policies?.find( + (input) => input.package?.name === FLEET_CLOUD_SECURITY_POSTURE_PACKAGE + ); + if (!packagePolicy) return undefined; + return packagePolicy?.inputs?.find((input) => input.enabled)?.policy_template; }; diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx index 7b401d8cebc58..cc5c59662ab2a 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx @@ -99,7 +99,9 @@ export const AgentEnrollmentFlyout: React.FunctionComponent = ({ } }, [selectedPolicy, isFleetServerPolicySelected]); - const { isK8s, isCSP } = useIsK8sPolicy(selectedPolicy ? selectedPolicy : undefined); + const { isK8s, cloudSecurityIntegration } = useIsK8sPolicy( + selectedPolicy ? selectedPolicy : undefined + ); return ( @@ -197,7 +199,7 @@ export const AgentEnrollmentFlyout: React.FunctionComponent = ({ agentPolicies={agentPolicies} isFleetServerPolicySelected={isFleetServerPolicySelected} isK8s={isK8s} - isCSP={isCSP} + cloudSecurityIntegration={cloudSecurityIntegration} refreshAgentPolicies={refreshAgentPolicies} isLoadingAgentPolicies={isLoadingAgentPolicies} mode={mode} diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx index 7fabe6b0767c5..b602b9fd8931d 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/instructions.tsx @@ -81,14 +81,14 @@ export const Instructions = (props: InstructionProps) => { useEffect(() => { // If we have a cloudFormationTemplateUrl, we want to hide the selection type - if (props.isCSP?.cloudformationUrl) { + if (props.cloudSecurityIntegration?.cloudformationUrl) { setSelectionType(undefined); } else if (!isIntegrationFlow && showAgentEnrollment) { setSelectionType('radio'); } else { setSelectionType('tabs'); } - }, [isIntegrationFlow, showAgentEnrollment, setSelectionType, props.isCSP]); + }, [isIntegrationFlow, showAgentEnrollment, setSelectionType, props.cloudSecurityIntegration]); if (isLoadingAgents || isLoadingAgentPolicies || isLoadingFleetServerHealth) return ; @@ -117,7 +117,10 @@ export const Instructions = (props: InstructionProps) => { {isFleetServerPolicySelected ? ( undefined} /> ) : ( - + )} ); diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx index 2797197759ff7..fca803b8785a4 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/compute_steps.tsx @@ -52,7 +52,7 @@ export const StandaloneSteps: React.FunctionComponent = ({ selectedApiKeyId, setSelectedAPIKeyId, isK8s, - isCSP, + cloudSecurityIntegration, }) => { const core = useStartServices(); const { notifications } = core; @@ -157,7 +157,7 @@ export const StandaloneSteps: React.FunctionComponent = ({ InstallStandaloneAgentStep({ installCommand: standaloneInstallCommands, isK8s, - isCSP: isCSP?.status, + cloudSecurityIntegration, }) ); @@ -165,7 +165,7 @@ export const StandaloneSteps: React.FunctionComponent = ({ }, [ kibanaVersion, isK8s, - isCSP, + cloudSecurityIntegration, agentPolicy, selectedPolicy, agentPolicies, @@ -198,7 +198,7 @@ export const ManagedSteps: React.FunctionComponent = ({ selectionType, onClickViewAgents, isK8s, - isCSP, + cloudSecurityIntegration, installedPackagePolicy, cloudFormationTemplateUrl, }) => { @@ -263,7 +263,7 @@ export const ManagedSteps: React.FunctionComponent = ({ apiKeyData, selectedApiKeyId, isK8s, - isCSP: isCSP?.status, + cloudSecurityIntegration, enrollToken, }) ); @@ -302,7 +302,7 @@ export const ManagedSteps: React.FunctionComponent = ({ refreshAgentPolicies, selectionType, isK8s, - isCSP, + cloudSecurityIntegration, installManagedCommands, apiKeyData, enrolledAgentIds, diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_managed_agent_step.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_managed_agent_step.tsx index 00588fcaa3a40..6c2ff29894925 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_managed_agent_step.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/steps/install_managed_agent_step.tsx @@ -16,14 +16,14 @@ import type { GetOneEnrollmentAPIKeyResponse } from '../../../../common/types/re import { InstallSection } from '../../enrollment_instructions/install_section'; import type { CommandsByPlatform } from '../../../applications/fleet/components/fleet_server_instructions/utils/install_command_utils'; -import type { K8sMode, CSPMode } from '../types'; +import type { K8sMode, CloudSecurityIntegration } from '../types'; export const InstallManagedAgentStep = ({ installCommand, selectedApiKeyId, apiKeyData, isK8s, - isCSP, + cloudSecurityIntegration, enrollToken, isComplete, fullCopyButton, @@ -32,7 +32,7 @@ export const InstallManagedAgentStep = ({ selectedApiKeyId?: string; apiKeyData?: GetOneEnrollmentAPIKeyResponse | null; isK8s?: K8sMode; - isCSP?: CSPMode; + cloudSecurityIntegration?: CloudSecurityIntegration | undefined; enrollToken?: string; installCommand: CommandsByPlatform; isComplete?: boolean; @@ -51,7 +51,7 @@ export const InstallManagedAgentStep = ({ void; @@ -39,7 +39,7 @@ export const InstallStandaloneAgentStep = ({ = ({ installCommand, isK8s, - isCSP, + cloudSecurityIntegration, enrollToken, fullCopyButton = false, isManaged = true, @@ -46,7 +46,7 @@ export const InstallSection: React.FunctionComponent = ({ linuxRpmCommand={installCommand.rpm} k8sCommand={installCommand.kubernetes} hasK8sIntegration={isK8s === 'IS_KUBERNETES' || isK8s === 'IS_KUBERNETES_MULTIPAGE'} - typeOfCSPIntegration={isCSP} + cloudSecurityIntegration={cloudSecurityIntegration} hasK8sIntegrationMultiPage={isK8s === 'IS_KUBERNETES_MULTIPAGE'} isManaged={isManaged} enrollToken={enrollToken} diff --git a/x-pack/plugins/fleet/public/components/platform_selector.tsx b/x-pack/plugins/fleet/public/components/platform_selector.tsx index 9ebf2dc862bfc..777f9d6bc38e3 100644 --- a/x-pack/plugins/fleet/public/components/platform_selector.tsx +++ b/x-pack/plugins/fleet/public/components/platform_selector.tsx @@ -19,10 +19,15 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; +import { + FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE, + FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE, +} from '../../common/constants/epm'; import { type PLATFORM_TYPE } from '../hooks'; import { REDUCED_PLATFORM_OPTIONS, PLATFORM_OPTIONS, usePlatform } from '../hooks'; import { KubernetesInstructions } from './agent_enrollment_flyout/kubernetes_instructions'; +import type { CloudSecurityIntegration } from './agent_enrollment_flyout/types'; interface Props { linuxCommand: string; @@ -32,7 +37,7 @@ interface Props { linuxRpmCommand: string; k8sCommand: string; hasK8sIntegration: boolean; - typeOfCSPIntegration?: string; + cloudSecurityIntegration?: CloudSecurityIntegration | undefined; hasK8sIntegrationMultiPage: boolean; isManaged?: boolean; hasFleetServer?: boolean; @@ -54,7 +59,7 @@ export const PlatformSelector: React.FunctionComponent = ({ linuxRpmCommand, k8sCommand, hasK8sIntegration, - typeOfCSPIntegration, + cloudSecurityIntegration, hasK8sIntegrationMultiPage, isManaged, enrollToken, @@ -63,10 +68,15 @@ export const PlatformSelector: React.FunctionComponent = ({ onCopy, }) => { const getInitialPlatform = useCallback(() => { - if (hasK8sIntegration || typeOfCSPIntegration === 'IS_CSP_KSPM') return 'kubernetes'; + if ( + hasK8sIntegration || + cloudSecurityIntegration?.integrationType === + FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE + ) + return 'kubernetes'; return 'linux'; - }, [hasK8sIntegration, typeOfCSPIntegration]); + }, [hasK8sIntegration, cloudSecurityIntegration?.integrationType]); const { platform, setPlatform } = usePlatform(getInitialPlatform()); @@ -164,18 +174,23 @@ export const PlatformSelector: React.FunctionComponent = ({ )} {platform === 'mac' && - (typeOfCSPIntegration === 'IS_CSP_CSPM' || typeOfCSPIntegration === 'IS_CSP_KSPM') && ( + (cloudSecurityIntegration?.integrationType === + FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE || + cloudSecurityIntegration?.integrationType === + FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE) && ( <> {macCallout} )} - {platform === 'kubernetes' && typeOfCSPIntegration === 'IS_CSP_CSPM' && ( - <> - {k8sCSPMCallout} - - - )} + {platform === 'kubernetes' && + cloudSecurityIntegration?.integrationType === + FLEET_CLOUD_SECURITY_POSTURE_CSPM_POLICY_TEMPLATE && ( + <> + {k8sCSPMCallout} + + + )} {platform === 'kubernetes' && !hasK8sIntegration && ( <> {k8sCallout} From 3536d22b9814def397156a9edbd3fc132cb3244c Mon Sep 17 00:00:00 2001 From: Ricky Ang Date: Wed, 17 May 2023 10:13:12 -0700 Subject: [PATCH 8/8] CI Fix, PR Comments, still waiting for new message prompt --- .../components/agent_enrollment_flyout/hooks.tsx | 15 +++++++++++---- .../components/agent_enrollment_flyout/index.tsx | 11 +++++++---- .../components/agent_enrollment_flyout/types.ts | 2 +- .../fleet/public/components/platform_selector.tsx | 7 ++++--- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx index 6b2207eeb5e46..65600c4e9b6ff 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/hooks.tsx @@ -12,7 +12,7 @@ import { sendGetOneAgentPolicy, useStartServices } from '../../hooks'; import { FLEET_KUBERNETES_PACKAGE, FLEET_CLOUD_SECURITY_POSTURE_PACKAGE } from '../../../common'; import { getCloudFormationTemplateUrlFromPackagePolicy } from '../../services'; -import type { K8sMode } from './types'; +import type { K8sMode, CloudSecurityIntegrationType } from './types'; // Packages that requires custom elastic-agent manifest const K8S_PACKAGES = new Set([FLEET_KUBERNETES_PACKAGE]); @@ -66,6 +66,10 @@ export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { checkifK8s(); }, [agentPolicy]); + return { isK8s }; +} + +export function useCloudSecurityIntegration(agentPolicy?: AgentPolicy) { const cloudSecurityIntegration = useMemo(() => { if (!agentPolicy) { return undefined; @@ -80,7 +84,7 @@ export function useIsK8sPolicy(agentPolicy?: AgentPolicy) { }; }, [agentPolicy]); - return { isK8s, cloudSecurityIntegration }; + return { cloudSecurityIntegration }; } const isK8sPackage = (pkg: PackagePolicy) => { @@ -89,10 +93,13 @@ const isK8sPackage = (pkg: PackagePolicy) => { return K8S_PACKAGES.has(name); }; -const getCloudSecurityIntegrationTypeFromPackagePolicy = (agentPolicy: AgentPolicy) => { +const getCloudSecurityIntegrationTypeFromPackagePolicy = ( + agentPolicy: AgentPolicy +): CloudSecurityIntegrationType | undefined => { const packagePolicy = agentPolicy?.package_policies?.find( (input) => input.package?.name === FLEET_CLOUD_SECURITY_POSTURE_PACKAGE ); if (!packagePolicy) return undefined; - return packagePolicy?.inputs?.find((input) => input.enabled)?.policy_template; + return packagePolicy?.inputs?.find((input) => input.enabled) + ?.policy_template as CloudSecurityIntegrationType; }; diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx index cc5c59662ab2a..869b2326b6f47 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/index.tsx @@ -38,7 +38,11 @@ import { Instructions } from './instructions'; import { MissingFleetServerHostCallout } from './missing_fleet_server_host_callout'; import type { FlyOutProps, SelectionType, FlyoutMode } from './types'; -import { useIsK8sPolicy, useAgentPolicyWithPackagePolicies } from './hooks'; +import { + useIsK8sPolicy, + useAgentPolicyWithPackagePolicies, + useCloudSecurityIntegration, +} from './hooks'; export * from './agent_policy_selection'; export * from './agent_policy_select_create'; @@ -99,9 +103,8 @@ export const AgentEnrollmentFlyout: React.FunctionComponent = ({ } }, [selectedPolicy, isFleetServerPolicySelected]); - const { isK8s, cloudSecurityIntegration } = useIsK8sPolicy( - selectedPolicy ? selectedPolicy : undefined - ); + const { isK8s } = useIsK8sPolicy(selectedPolicy ?? undefined); + const { cloudSecurityIntegration } = useCloudSecurityIntegration(selectedPolicy ?? undefined); return ( diff --git a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/types.ts b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/types.ts index a4890ed6a9ff4..79c8029e4ec01 100644 --- a/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/types.ts +++ b/x-pack/plugins/fleet/public/components/agent_enrollment_flyout/types.ts @@ -15,7 +15,7 @@ export type K8sMode = | 'IS_NOT_KUBERNETES' | 'IS_KUBERNETES_MULTIPAGE'; -export type CloudSecurityIntegrationType = 'kspm' | 'vuln_mgmt' | 'cspm' | undefined; +export type CloudSecurityIntegrationType = 'kspm' | 'vuln_mgmt' | 'cspm'; export type FlyoutMode = 'managed' | 'standalone'; export type SelectionType = 'tabs' | 'radio' | undefined; diff --git a/x-pack/plugins/fleet/public/components/platform_selector.tsx b/x-pack/plugins/fleet/public/components/platform_selector.tsx index 777f9d6bc38e3..eb8b9d898855e 100644 --- a/x-pack/plugins/fleet/public/components/platform_selector.tsx +++ b/x-pack/plugins/fleet/public/components/platform_selector.tsx @@ -70,13 +70,14 @@ export const PlatformSelector: React.FunctionComponent = ({ const getInitialPlatform = useCallback(() => { if ( hasK8sIntegration || - cloudSecurityIntegration?.integrationType === - FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE + (cloudSecurityIntegration?.integrationType === + FLEET_CLOUD_SECURITY_POSTURE_KSPM_POLICY_TEMPLATE && + isManaged) ) return 'kubernetes'; return 'linux'; - }, [hasK8sIntegration, cloudSecurityIntegration?.integrationType]); + }, [hasK8sIntegration, cloudSecurityIntegration?.integrationType, isManaged]); const { platform, setPlatform } = usePlatform(getInitialPlatform());