[9.0] [UII] Allow creating a new agentless integration to open status flyout automatically (#214503) (#214670)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[UII] Allow creating a new agentless integration to open status
flyout automatically
(#214503)](https://github.com/elastic/kibana/pull/214503)

<!--- Backport version: 9.6.6 -->

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

<!--BACKPORT [{"author":{"name":"Jen
Huang","email":"its.jenetic@gmail.com"},"sourceCommit":{"committedDate":"2025-03-14T22:10:38Z","message":"[UII]
Allow creating a new agentless integration to open status flyout
automatically (#214503)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/213958.\nRelated to
https://github.com/elastic/kibana/pull/199567.\n\nThis PR makes it so
that after adding an agentless integration, the\nagentless status flyout
is opened automatically on the policies page.\nThis is done by passing
the query parameter\n`?openEnrollmentFlyout=<agent policy id>` after
successful creation:\n\n<img width=\"1440\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/720caab3-10dc-4c1e-bb9a-6a65eb5b5a48\"\n/>\n\n##
Testing\n1. Add the following to kibana.dev.yml:\n```\nxpack.cloud.id:
'anything-to-pass-cloud-validation-checks'\nxpack.fleet.agentless.enabled:
true\nxpack.fleet.agentless.api.url:
'https://localhost:8443'\nxpack.fleet.agentless.api.tls.certificate:
'./config/certs/ess-client.crt'\nxpack.fleet.agentless.api.tls.key:
'./config/certs/ess-client.key'\nxpack.fleet.agentless.api.tls.ca:
'./config/certs/ca.crt'\n```\n2. Apply
[this\npatch](https://gist.github.com/jen-huang/dfc3e02ceb63976ad54bd1f50c524cb4)\nto
prevent attempt to create agentless pod\n3. Enroll a Fleet Server as
usual\n4. Go to CSPM integration, select agentless deployment mode\n5.
After saving, you should be redirected to CSPM integration >
Policies\ntable with the agentless status flyout open for the one that
you just\ncreated\n\nDo some regression testing around other redirect
scenarios, such as:\n* Agent-based CSPM -> manual (not cloudformation)
should redirect to\nagent policy details page with enrollment flyout
open after clicking\n\"Add agent now\"\n* Editing various integration
policies redirect as expected (from\nintegration > policies table should
redirect back to integration page,\nfrom agent policy details should
redirect back to agent policy)\n* Creating various integration policies
with none/one/multiple agent\npolicies should redirect as expected (none
should redirect to\nintegrations page, one/multiple should redirect back
to first
agent\npolicy)","sha":"eb9e8173784aeecbcb4e6ab0828dd58a75b8ddb1","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","v9.0.0","backport:version","v8.18.0","v9.1.0"],"title":"[UII]
Allow creating a new agentless integration to open status flyout
automatically","number":214503,"url":"https://github.com/elastic/kibana/pull/214503","mergeCommit":{"message":"[UII]
Allow creating a new agentless integration to open status flyout
automatically (#214503)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/213958.\nRelated to
https://github.com/elastic/kibana/pull/199567.\n\nThis PR makes it so
that after adding an agentless integration, the\nagentless status flyout
is opened automatically on the policies page.\nThis is done by passing
the query parameter\n`?openEnrollmentFlyout=<agent policy id>` after
successful creation:\n\n<img width=\"1440\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/720caab3-10dc-4c1e-bb9a-6a65eb5b5a48\"\n/>\n\n##
Testing\n1. Add the following to kibana.dev.yml:\n```\nxpack.cloud.id:
'anything-to-pass-cloud-validation-checks'\nxpack.fleet.agentless.enabled:
true\nxpack.fleet.agentless.api.url:
'https://localhost:8443'\nxpack.fleet.agentless.api.tls.certificate:
'./config/certs/ess-client.crt'\nxpack.fleet.agentless.api.tls.key:
'./config/certs/ess-client.key'\nxpack.fleet.agentless.api.tls.ca:
'./config/certs/ca.crt'\n```\n2. Apply
[this\npatch](https://gist.github.com/jen-huang/dfc3e02ceb63976ad54bd1f50c524cb4)\nto
prevent attempt to create agentless pod\n3. Enroll a Fleet Server as
usual\n4. Go to CSPM integration, select agentless deployment mode\n5.
After saving, you should be redirected to CSPM integration >
Policies\ntable with the agentless status flyout open for the one that
you just\ncreated\n\nDo some regression testing around other redirect
scenarios, such as:\n* Agent-based CSPM -> manual (not cloudformation)
should redirect to\nagent policy details page with enrollment flyout
open after clicking\n\"Add agent now\"\n* Editing various integration
policies redirect as expected (from\nintegration > policies table should
redirect back to integration page,\nfrom agent policy details should
redirect back to agent policy)\n* Creating various integration policies
with none/one/multiple agent\npolicies should redirect as expected (none
should redirect to\nintegrations page, one/multiple should redirect back
to first
agent\npolicy)","sha":"eb9e8173784aeecbcb4e6ab0828dd58a75b8ddb1"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/214503","number":214503,"mergeCommit":{"message":"[UII]
Allow creating a new agentless integration to open status flyout
automatically (#214503)\n\n## Summary\n\nResolves
https://github.com/elastic/kibana/issues/213958.\nRelated to
https://github.com/elastic/kibana/pull/199567.\n\nThis PR makes it so
that after adding an agentless integration, the\nagentless status flyout
is opened automatically on the policies page.\nThis is done by passing
the query parameter\n`?openEnrollmentFlyout=<agent policy id>` after
successful creation:\n\n<img width=\"1440\"
alt=\"image\"\nsrc=\"https://github.com/user-attachments/assets/720caab3-10dc-4c1e-bb9a-6a65eb5b5a48\"\n/>\n\n##
Testing\n1. Add the following to kibana.dev.yml:\n```\nxpack.cloud.id:
'anything-to-pass-cloud-validation-checks'\nxpack.fleet.agentless.enabled:
true\nxpack.fleet.agentless.api.url:
'https://localhost:8443'\nxpack.fleet.agentless.api.tls.certificate:
'./config/certs/ess-client.crt'\nxpack.fleet.agentless.api.tls.key:
'./config/certs/ess-client.key'\nxpack.fleet.agentless.api.tls.ca:
'./config/certs/ca.crt'\n```\n2. Apply
[this\npatch](https://gist.github.com/jen-huang/dfc3e02ceb63976ad54bd1f50c524cb4)\nto
prevent attempt to create agentless pod\n3. Enroll a Fleet Server as
usual\n4. Go to CSPM integration, select agentless deployment mode\n5.
After saving, you should be redirected to CSPM integration >
Policies\ntable with the agentless status flyout open for the one that
you just\ncreated\n\nDo some regression testing around other redirect
scenarios, such as:\n* Agent-based CSPM -> manual (not cloudformation)
should redirect to\nagent policy details page with enrollment flyout
open after clicking\n\"Add agent now\"\n* Editing various integration
policies redirect as expected (from\nintegration > policies table should
redirect back to integration page,\nfrom agent policy details should
redirect back to agent policy)\n* Creating various integration policies
with none/one/multiple agent\npolicies should redirect as expected (none
should redirect to\nintegrations page, one/multiple should redirect back
to first
agent\npolicy)","sha":"eb9e8173784aeecbcb4e6ab0828dd58a75b8ddb1"}}]}]
BACKPORT-->

Co-authored-by: Jen Huang <its.jenetic@gmail.com>
This commit is contained in:
Kibana Machine 2025-03-19 23:58:47 +01:00 committed by GitHub
parent 1c10748cf4
commit f6876a4349
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 67 additions and 27 deletions

View file

@ -86,38 +86,56 @@ export const useOnSaveNavigate = (params: UseOnSaveNavigateParams) => {
return;
}
const hasNoAgentPolicies = policy.policy_ids.length === 0;
const packagePolicyPath =
hasNoAgentPolicies || policy.supports_agentless
? getPath('integration_details_policies', {
pkgkey: pkgKeyFromPackageInfo(policy.package!),
})
: getPath('policy_details', {
policyId: policy.policy_ids[0], // TODO navigates to first policy
});
const [onSaveNavigateTo, onSaveQueryParams]: [
Parameters<ApplicationStart['navigateToApp']>,
CreatePackagePolicyRouteState['onSaveQueryParams']
] = routeState?.onSaveNavigateTo
? [routeState.onSaveNavigateTo, routeState?.onSaveQueryParams]
: [
[
hasNoAgentPolicies || policy.supports_agentless ? INTEGRATIONS_PLUGIN_ID : PLUGIN_ID,
{
path: packagePolicyPath,
},
],
let onSaveNavigateTo: Parameters<ApplicationStart['navigateToApp']>;
let onSaveQueryParams: CreatePackagePolicyRouteState['onSaveQueryParams'];
if (routeState?.onSaveNavigateTo) {
onSaveNavigateTo = routeState.onSaveNavigateTo;
onSaveQueryParams = routeState?.onSaveQueryParams;
} else {
// If agentless or no agent policies, navigate to the integration's policies table
if ((policy.supports_agentless || hasNoAgentPolicies) && !queryParamsPolicyId) {
onSaveNavigateTo = [
INTEGRATIONS_PLUGIN_ID,
{
showAddAgentHelp: true,
openEnrollmentFlyout: true,
path: getPath('integration_details_policies', {
pkgkey: pkgKeyFromPackageInfo(policy.package!),
}),
},
];
if (policy.supports_agentless) {
onSaveQueryParams = {
openEnrollmentFlyout: { policyIdAsValue: true },
};
} else {
onSaveQueryParams = routeState?.onSaveQueryParams;
}
}
// Otherwise, navigate to the policy's first agent policy details page
// or the overridden policy id from query param instead
// TODO: handle case where package policy belongs to multiple agent policies
else {
onSaveNavigateTo = [
PLUGIN_ID,
{
path: getPath('policy_details', {
policyId: queryParamsPolicyId || policy.policy_ids[0],
}),
},
];
onSaveQueryParams = {
showAddAgentHelp: true,
openEnrollmentFlyout: true,
};
}
}
const [appId, options] = onSaveNavigateTo;
if (options?.path) {
const pathWithQueryString = appendOnSaveQueryParamsToPath({
// In cases where we want to navigate back to a new/existing policy, we need to override the initial `path`
// value and navigate to the actual agent policy instead
path: queryParamsPolicyId ? packagePolicyPath : options.path,
path: options.path,
policy,
mappingOptions: onSaveQueryParams,
paramsToApply,

View file

@ -465,7 +465,12 @@ export function useOnSubmit({
setFormState('SUBMITTED_NO_AGENTS');
return;
}
onSaveNavigate(data!.item);
if (isAgentlessConfigured) {
onSaveNavigate(data!.item, ['openEnrollmentFlyout']);
} else {
onSaveNavigate(data!.item);
}
notifications.toasts.addSuccess({
title: i18n.translate('xpack.fleet.createPackagePolicy.addedNotificationTitle', {

View file

@ -464,7 +464,7 @@ describe('When on the package policy create page', () => {
await setupSaveNavigate(routeState, queryParamsPolicyId);
expect(useStartServices().application.navigateToApp).toHaveBeenCalledWith(PLUGIN_ID, {
path: '/policies/agent-policy-1?openEnrollmentFlyout=true',
path: '/save/url/here?openEnrollmentFlyout=true',
});
});

View file

@ -10,6 +10,8 @@ import { EuiBadge, EuiBasicTable, EuiLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedRelative, FormattedMessage } from '@kbn/i18n-react';
import { useLocation } from 'react-router-dom';
import type {
Agent,
AgentPolicy,
@ -109,9 +111,24 @@ export const AgentlessPackagePoliciesTable = ({
}, [agentsKuery, canReadAgents, notifications.toasts]);
// Flyout state
const { search } = useLocation();
const queryParams = useMemo(() => new URLSearchParams(search), [search]);
const [flyoutOpenForPolicyId, setFlyoutOpenForPolicyId] = useState<string>();
const [flyoutPackagePolicy, setFlyoutPackagePolicy] = useState<PackagePolicy>();
const [flyoutAgentPolicy, setFlyoutAgentPolicy] = useState<AgentPolicy>();
useEffect(() => {
const flyoutAgentPolicyIdFromQuery = queryParams.get('openEnrollmentFlyout');
if (flyoutAgentPolicyIdFromQuery) {
const pp = packagePolicies.find((p) =>
p.packagePolicy.policy_ids.includes(flyoutAgentPolicyIdFromQuery)
);
if (pp) {
setFlyoutOpenForPolicyId(flyoutAgentPolicyIdFromQuery);
setFlyoutPackagePolicy(pp.packagePolicy);
setFlyoutAgentPolicy(pp.agentPolicies[0]);
}
}
}, [packagePolicies, queryParams]);
return (
<>