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

[8.x] [Cloud Security] Default CSPM integration to use Agentless as the setup technology. (#205965) #206985

Open
wants to merge 1 commit into
base: 8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* 2.0.
*/

import type { MonitoringType } from '../types';

export const AGENTLESS_AGENT_POLICY_INACTIVITY_TIMEOUT = 3600;
export const AGENTLESS_AGENT_POLICY_MONITORING: MonitoringType = ['logs', 'metrics'];
export const AGENTLESS_GLOBAL_TAG_NAME_ORGANIZATION = 'organization';
export const AGENTLESS_GLOBAL_TAG_NAME_DIVISION = 'division';
export const AGENTLESS_GLOBAL_TAG_NAME_TEAM = 'team';
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ export function useOnSubmit({
if (packageInfo) {
setHasAgentPolicyError(false);
}

// eslint-disable-next-line no-console
console.debug('Agent policy updated', updatedAgentPolicies);
},
[packageInfo, agentPolicies]
);
Expand All @@ -208,8 +205,6 @@ export function useOnSubmit({
spaceSettings
);
setValidationResults(newValidationResult);
// eslint-disable-next-line no-console
console.debug('Package policy validation results', newValidationResult);

return newValidationResult;
}
Expand All @@ -225,8 +220,6 @@ export function useOnSubmit({
};
setPackagePolicy(newPackagePolicy);

// eslint-disable-next-line no-console
console.debug('Package policy updated', newPackagePolicy);
const newValidationResults = updatePackagePolicyValidation(newPackagePolicy);
const hasPackage = newPackagePolicy.package;
const hasValidationErrors = newValidationResults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,11 @@ describe('useSetupTechnology', () => {
})
);

expect(generateNewAgentPolicyWithDefaults).toHaveBeenCalled();

act(() => {
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS);
});
await waitFor(() => {
expect(generateNewAgentPolicyWithDefaults).toHaveBeenCalled();
expect(updatePackagePolicyMock).toHaveBeenCalledWith({ supports_agentless: true });
expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS);
expect(setNewAgentPolicy).toHaveBeenCalledWith({
Expand Down Expand Up @@ -290,13 +289,12 @@ describe('useSetupTechnology', () => {
initialProps,
});

expect(generateNewAgentPolicyWithDefaults).toHaveBeenCalled();

act(() => {
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS);
});

expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS);
expect(generateNewAgentPolicyWithDefaults).toHaveBeenCalled();
expect(updatePackagePolicyMock).toHaveBeenCalledWith({ supports_agentless: true });
expect(setNewAgentPolicy).toHaveBeenCalledWith({
inactivity_timeout: 3600,
Expand Down Expand Up @@ -450,6 +448,7 @@ describe('useSetupTechnology', () => {
updateAgentPolicies: updateAgentPoliciesMock,
setSelectedPolicyTab: setSelectedPolicyTabMock,
packagePolicy: packagePolicyMock,
packageInfo: packageInfoMock,
updatePackagePolicy: updatePackagePolicyMock,
})
);
Expand All @@ -469,6 +468,11 @@ describe('useSetupTechnology', () => {
name: 'Agentless policy for endpoint-1',
supports_agentless: true,
inactivity_timeout: 3600,
global_data_tags: [
{ name: 'organization', value: 'org' },
{ name: 'division', value: 'div' },
{ name: 'team', value: 'team' },
],
});
expect(updatePackagePolicyMock).toHaveBeenCalledWith({ supports_agentless: true });
});
Expand Down Expand Up @@ -512,7 +516,7 @@ describe('useSetupTechnology', () => {
);

act(() => {
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS, 'cspm');
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS);
});

await waitFor(() => {
Expand Down Expand Up @@ -544,23 +548,48 @@ describe('useSetupTechnology', () => {
},
});

const packageInfoWithoutGlobalDataTags = {
policy_templates: [
{
name: 'cspm',
title: 'Template 1',
description: '',
deployment_modes: {
default: {
enabled: true,
},
agentless: {
enabled: true,
},
},
},
{
name: 'not-cspm',
title: 'Template 2',
description: '',
deployment_modes: {
default: {
enabled: true,
},
},
},
] as RegistryPolicyTemplate[],
} as PackageInfo;

const { result } = renderHook(() =>
useSetupTechnology({
setNewAgentPolicy,
newAgentPolicy: newAgentPolicyMock,
updateAgentPolicies: updateAgentPoliciesMock,
setSelectedPolicyTab: setSelectedPolicyTabMock,
packagePolicy: packagePolicyMock,
packageInfo: packageInfoMock,
packageInfo: packageInfoWithoutGlobalDataTags,
updatePackagePolicy: updatePackagePolicyMock,
})
);

act(() => {
result.current.handleSetupTechnologyChange(
SetupTechnology.AGENTLESS,
'never-gonna-give-you-up'
);
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS);
});

await waitFor(() => {
Expand Down Expand Up @@ -594,14 +623,42 @@ describe('useSetupTechnology', () => {
},
});

const packageInfoWithoutGlobalDataTags = {
policy_templates: [
{
name: 'cspm',
title: 'Template 1',
description: '',
deployment_modes: {
default: {
enabled: true,
},
agentless: {
enabled: true,
},
},
},
{
name: 'not-cspm',
title: 'Template 2',
description: '',
deployment_modes: {
default: {
enabled: true,
},
},
},
] as RegistryPolicyTemplate[],
} as PackageInfo;

const { result } = renderHook(() =>
useSetupTechnology({
setNewAgentPolicy,
newAgentPolicy: newAgentPolicyMock,
updateAgentPolicies: updateAgentPoliciesMock,
setSelectedPolicyTab: setSelectedPolicyTabMock,
packagePolicy: packagePolicyMock,
packageInfo: packageInfoMock,
packageInfo: packageInfoWithoutGlobalDataTags,
updatePackagePolicy: updatePackagePolicyMock,
})
);
Expand Down Expand Up @@ -653,7 +710,7 @@ describe('useSetupTechnology', () => {
);

act(() => {
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS, 'cspm');
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS);
});

await waitFor(() => {
Expand Down Expand Up @@ -700,10 +757,11 @@ describe('useSetupTechnology', () => {
);

act(() => {
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS, 'cspm');
result.current.handleSetupTechnologyChange(SetupTechnology.AGENTLESS);
});

await waitFor(() => {
expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENTLESS);
expect(setNewAgentPolicy).toHaveBeenCalledWith(
expect.objectContaining({
supports_agentless: true,
Expand All @@ -721,6 +779,7 @@ describe('useSetupTechnology', () => {
});

await waitFor(() => {
expect(result.current.selectedSetupTechnology).toBe(SetupTechnology.AGENT_BASED);
expect(setNewAgentPolicy).toHaveBeenCalledWith(newAgentPolicyMock);
expect(setNewAgentPolicy).not.toHaveBeenCalledWith({
global_data_tags: [
Expand Down
Loading