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

[UII] Restrict agentless integrations to deployments with agentless enabled #194885

Merged
merged 27 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3412a60
Move useAgentless to top-level hook
jen-huang Oct 1, 2024
91bec0a
Fix setup technology tests
jen-huang Oct 2, 2024
41702be
Remove agentless only packages and integrations from browse page if a…
jen-huang Oct 3, 2024
9e0dd25
Prevent agentless integrations from being installed when agentless is…
jen-huang Oct 3, 2024
2d41a3b
Merge remote-tracking branch 'upstream/main' into feat/hide-agentless…
jen-huang Oct 3, 2024
2cc3a0e
Merge remote-tracking branch 'upstream/main' into feat/hide-agentless…
jen-huang Oct 7, 2024
0b7b867
Fix tests by adding condition to getCloud
jen-huang Oct 7, 2024
894674e
Move filtering of deployment mode to separate fn
jen-huang Oct 7, 2024
f896293
Try to fix tests
jen-huang Oct 8, 2024
b46ba6c
Merge remote-tracking branch 'upstream/main' into feat/hide-agentless…
jen-huang Oct 11, 2024
5f058fb
Fix integrations list not being returned 🤠
jen-huang Oct 11, 2024
c036bfe
Fix return
jen-huang Oct 11, 2024
7e922ad
Revert "Move useAgentless to top-level hook"
jen-huang Oct 11, 2024
8aa91e0
Revert "Fix setup technology tests"
jen-huang Oct 11, 2024
0a89826
Try reverting file moves
jen-huang Oct 11, 2024
32691a6
Fix test and imports
jen-huang Oct 11, 2024
822a53e
Add unit tests for install path
jen-huang Oct 11, 2024
42a9af2
Merge remote-tracking branch 'upstream/main' into feat/hide-agentless…
jen-huang Oct 14, 2024
ee69611
Fix test
jen-huang Oct 14, 2024
c849bfc
Fix test attempt 2
jen-huang Oct 14, 2024
3f1dc66
Allow fleet config to be null
jen-huang Oct 14, 2024
44e7db5
Allow fleet config to be read from start dependencies
jen-huang Oct 14, 2024
7a565ae
Revert "Allow fleet config to be null"
jen-huang Oct 14, 2024
c0372a5
Fix plugin start mock
jen-huang Oct 14, 2024
12a439b
Merge branch 'main' into feat/hide-agentless-integrations
jen-huang Oct 15, 2024
8921098
Merge branch 'main' into feat/hide-agentless-integrations
jen-huang Oct 15, 2024
c7aa1f2
Merge branch 'main' into feat/hide-agentless-integrations
jen-huang Oct 15, 2024
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
275 changes: 275 additions & 0 deletions x-pack/plugins/fleet/common/services/agentless_helper.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
/*
* 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 type { RegistryPolicyTemplate } from '../types';

import {
isAgentlessIntegration,
getAgentlessAgentPolicyNameFromPackagePolicyName,
isOnlyAgentlessIntegration,
isOnlyAgentlessPolicyTemplate,
} from './agentless_helper';

describe('agentless_helper', () => {
describe('isAgentlessIntegration', () => {
it('should return true if packageInfo is defined and has at least one agentless integration', () => {
const packageInfo = {
policy_templates: [
{
name: 'template1',
title: 'Template 1',
description: '',
deployment_modes: {
default: {
enabled: true,
},
agentless: {
enabled: true,
},
},
},
{
name: 'template2',
title: 'Template 2',
description: '',
deployment_modes: {
default: {
enabled: true,
},
},
},
] as RegistryPolicyTemplate[],
};

const result = isAgentlessIntegration(packageInfo);

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

it('should return false if packageInfo is defined but does not have agentless integrations', () => {
const packageInfo = {
policy_templates: [
{
name: 'template1',
title: 'Template 1',
description: '',
deployment_modes: {
default: {
enabled: true,
},
agentless: {
enabled: false,
},
},
},
{
name: 'template2',
title: 'Template 2',
description: '',
deployment_modes: {
default: {
enabled: false,
},
agentless: {
enabled: false,
},
},
},
] as RegistryPolicyTemplate[],
};

const result = isAgentlessIntegration(packageInfo);

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

it('should return false if packageInfo has no policy templates', () => {
const packageInfo = {
policy_templates: [],
};

const result = isAgentlessIntegration(packageInfo);

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

it('should return false if packageInfo is undefined', () => {
const packageInfo = undefined;

const result = isAgentlessIntegration(packageInfo);

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

describe('getAgentlessAgentPolicyNameFromPackagePolicyName', () => {
it('should return the agentless agent policy name based on the package policy name', () => {
const packagePolicyName = 'example-package-policy';

const result = getAgentlessAgentPolicyNameFromPackagePolicyName(packagePolicyName);

expect(result).toBe('Agentless policy for example-package-policy');
});
});

describe('isOnlyAgentlessIntegration', () => {
it('should return true if packageInfo is defined and has only agentless integration', () => {
const packageInfo = {
policy_templates: [
{
name: 'template1',
title: 'Template 1',
description: '',
deployment_modes: {
default: {
enabled: false,
},
agentless: {
enabled: true,
},
},
},
{
name: 'template2',
title: 'Template 2',
description: '',
deployment_modes: {
agentless: {
enabled: true,
},
},
},
] as RegistryPolicyTemplate[],
};

const result = isOnlyAgentlessIntegration(packageInfo);

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

it('should return false if packageInfo is defined but has other deployment types', () => {
const packageInfo = {
policy_templates: [
{
name: 'template1',
title: 'Template 1',
description: '',
deployment_modes: {
default: {
enabled: true,
},
agentless: {
enabled: true,
},
},
},
{
name: 'template2',
title: 'Template 2',
description: '',
deployment_modes: {
default: {
enabled: true,
},
},
},
] as RegistryPolicyTemplate[],
};

const result = isOnlyAgentlessIntegration(packageInfo);

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

it('should return false if packageInfo has no policy templates', () => {
const packageInfo = {
policy_templates: [],
};

const result = isOnlyAgentlessIntegration(packageInfo);

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

it('should return false if packageInfo is undefined', () => {
const packageInfo = undefined;

const result = isOnlyAgentlessIntegration(packageInfo);

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

describe('isOnlyAgentlessPolicyTemplate', () => {
it('should return true if the policy template is only agentless', () => {
const policyTemplate = {
name: 'template1',
title: 'Template 1',
description: '',
deployment_modes: {
default: {
enabled: false,
},
agentless: {
enabled: true,
},
},
};
const policyTemplate2 = {
name: 'template2',
title: 'Template 2',
description: '',
deployment_modes: {
agentless: {
enabled: true,
},
},
};

const result = isOnlyAgentlessPolicyTemplate(policyTemplate);
const result2 = isOnlyAgentlessPolicyTemplate(policyTemplate2);

expect(result).toBe(true);
expect(result2).toBe(true);
});

it('should return false if the policy template has other deployment types', () => {
const policyTemplate = {
name: 'template1',
title: 'Template 1',
description: '',
deployment_modes: {
default: {
enabled: true,
},
agentless: {
enabled: true,
},
},
};
const policyTemplate2 = {
name: 'template2',
title: 'Template 2',
description: '',
deployment_modes: {
default: {
enabled: true,
},
agentless: {
enabled: false,
},
},
};

const result = isOnlyAgentlessPolicyTemplate(policyTemplate);
const result2 = isOnlyAgentlessPolicyTemplate(policyTemplate2);

expect(result).toBe(false);
expect(result2).toBe(false);
});
});
});
52 changes: 52 additions & 0 deletions x-pack/plugins/fleet/common/services/agentless_helper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 type { PackageInfo, RegistryPolicyTemplate } from '../types';

export const isAgentlessIntegration = (
packageInfo: Pick<PackageInfo, 'policy_templates'> | undefined
) => {
if (
packageInfo?.policy_templates &&
packageInfo?.policy_templates.length > 0 &&
!!packageInfo?.policy_templates.find(
(policyTemplate) => policyTemplate?.deployment_modes?.agentless.enabled === true
)
) {
return true;
}
return false;
};

export const getAgentlessAgentPolicyNameFromPackagePolicyName = (packagePolicyName: string) => {
return `Agentless policy for ${packagePolicyName}`;
};

export const isOnlyAgentlessIntegration = (
packageInfo: Pick<PackageInfo, 'policy_templates'> | undefined
) => {
if (
packageInfo?.policy_templates &&
packageInfo?.policy_templates.length > 0 &&
packageInfo?.policy_templates.every((policyTemplate) =>
isOnlyAgentlessPolicyTemplate(policyTemplate)
)
) {
return true;
}
return false;
};

export const isOnlyAgentlessPolicyTemplate = (policyTemplate: {
deployment_modes?: RegistryPolicyTemplate['deployment_modes'];
}) => {
return (
policyTemplate.deployment_modes?.agentless.enabled === true &&
(!policyTemplate.deployment_modes?.default ||
policyTemplate.deployment_modes?.default.enabled === false)
);
};
10 changes: 0 additions & 10 deletions x-pack/plugins/fleet/common/services/agentless_policy_helper.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type {
} from '../../../../../../types';
import type { PackagePolicyInputValidationResults } from '../../../services';
import { hasInvalidButRequiredVar, countValidationErrors } from '../../../services';
import { useAgentless } from '../../../single_page_layout/hooks/setup_technology';
import { useAgentless } from '../../../../../../hooks';

import { PackagePolicyInputConfig } from './package_policy_input_config';
import { PackagePolicyInputStreamConfig } from './package_policy_input_stream';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import {
EuiSpacer,
} from '@elastic/eui';

import { useAgentless } from '../hooks/setup_technology';

import { useAgentless } from '../../../../../hooks';
import { WithHeaderLayout } from '../../../../../layouts';
import type { AgentPolicy, PackageInfo, RegistryPolicyTemplate } from '../../../../../types';
import { PackageIcon } from '../../../../../components';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
sendBulkInstallPackages,
sendGetPackagePolicies,
useMultipleAgentPolicies,
useAgentless,
} from '../../../../../hooks';
import { isVerificationError, packageToPackagePolicy } from '../../../../../services';
import {
Expand All @@ -49,8 +50,6 @@ import {
getCloudShellUrlFromPackagePolicy,
} from '../../../../../../../components/cloud_security_posture/services';

import { useAgentless } from './setup_technology';

export async function createAgentPolicy({
packagePolicy,
newAgentPolicy,
Expand Down
Loading