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

[Fleet] Prevent deletion of agent policies with inactive agents from UI #175815

Merged
merged 7 commits into from
Feb 1, 2024

Conversation

criamico
Copy link
Contributor

@criamico criamico commented Jan 29, 2024

Fixes #155925

Summary

Prevent deleting an agent policy that has inactive agents assigned. The workaround to fix existing "orphaned" agents is outlined here.

API

Adding check for inactive agents to the agent policy "delete" endpoint - It will now fail if the policy has either active or inactive agents:

  POST /api/fleet/agent_policies/delete
  {
    agentPolicyId: 1234534,
  }

UI

Warning added to the "delete" action in the UI when trying to delete a policy that has active or inactive agents.

Testing

  • Have a policy with many inactive agents assigned to it
  • Try to delete it from the agent policy list or settings
  • The deletion is prevented and a warning is raised:

Screenshot 2024-01-31 at 12 03 11

Checklist

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@criamico criamico self-assigned this Jan 29, 2024
@criamico criamico added the Team:Fleet Team label for Observability Data Collection Fleet team label Jan 29, 2024
@criamico
Copy link
Contributor Author

/ci

@criamico criamico force-pushed the 155925_prevent_deletion_policies branch from ec5b043 to 06e2015 Compare January 31, 2024 10:37
@criamico
Copy link
Contributor Author

@elasticmachine merge upstream

@criamico criamico changed the title 155925 prevent deletion policies [Fleet] Prevent deletion of agent policies with inactive agents from UI Jan 31, 2024
@criamico
Copy link
Contributor Author

/ci

@criamico criamico marked this pull request as ready for review January 31, 2024 16:51
@criamico criamico requested a review from a team as a code owner January 31, 2024 16:51
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

@nchaulet nchaulet self-requested a review January 31, 2024 17:08
const { total } = await getAgentsByKuery(esClient, soClient, {
showInactive: false,
showInactive: true,
perPage: 0,
page: 1,
kuery: `${AGENTS_PREFIX}.policy_id:${id}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add the unenrolled condition here too and not status: unenrolled?

@criamico
Copy link
Contributor Author

criamico commented Feb 1, 2024

@elasticmachine merge upstream

Copy link
Member

@nchaulet nchaulet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@criamico criamico added the backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) label Feb 1, 2024
@criamico
Copy link
Contributor Author

criamico commented Feb 1, 2024

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
fleet 1.2MB 1.2MB +61.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @criamico

@criamico criamico merged commit 222e894 into elastic:main Feb 1, 2024
20 checks passed
@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.12 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 175815

Questions ?

Please refer to the Backport tool documentation

@criamico
Copy link
Contributor Author

criamico commented Feb 2, 2024

💚 All backports created successfully

Status Branch Result
8.12

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

criamico added a commit to criamico/kibana that referenced this pull request Feb 2, 2024
…UI (elastic#175815)

Fixes elastic#155925

## Summary
Prevent deleting an agent policy that has inactive agents assigned. The
workaround to fix existing "orphaned" agents is outlined
[here](elastic#155925 (comment)).

### API
Adding check for inactive agents to the agent policy "delete" endpoint -
It will now fail if the policy has either active or inactive agents:

```
  POST /api/fleet/agent_policies/delete
  {
    agentPolicyId: 1234534,
  }
```

### UI
Warning added to the "delete" action in the UI when trying to delete a
policy that has active or inactive agents.

## Testing
- Have a policy with many inactive agents assigned to it
- Try to delete it from the agent policy list or settings
- The deletion is prevented and a warning is raised:

![Screenshot 2024-01-31 at 12 03
11](https://github.com/elastic/kibana/assets/16084106/644c9e9e-9820-4251-81fb-58f74ab57377)

### Checklist

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Kibana Machine <[email protected]>
(cherry picked from commit 222e894)

# Conflicts:
#	x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/components/agent_policy_delete_provider.tsx
#	x-pack/plugins/fleet/server/services/agent_policy.ts
criamico added a commit that referenced this pull request Feb 2, 2024
…s from UI (#175815) (#176131)

# Backport

This will backport the following commits from `main` to `8.12`:
- [[Fleet] Prevent deletion of agent policies with inactive agents from
UI (#175815)](#175815)

<!--- Backport version: 8.9.8 -->

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

<!--BACKPORT [{"author":{"name":"Cristina
Amico","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-02-01T20:25:45Z","message":"[Fleet]
Prevent deletion of agent policies with inactive agents from UI
(#175815)\n\nFixes
https://github.com/elastic/kibana/issues/155925\r\n\r\n##
Summary\r\nPrevent deleting an agent policy that has inactive agents
assigned. The\r\nworkaround to fix existing \"orphaned\" agents is
outlined\r\n[here](https://github.com/elastic/kibana/issues/155925#issuecomment-1919250162).\r\n\r\n###
API\r\nAdding check for inactive agents to the agent policy \"delete\"
endpoint -\r\nIt will now fail if the policy has either active or
inactive agents:\r\n\r\n```\r\n POST
/api/fleet/agent_policies/delete\r\n {\r\n agentPolicyId: 1234534,\r\n
}\r\n```\r\n\r\n### UI \r\nWarning added to the \"delete\" action in the
UI when trying to delete a\r\npolicy that has active or inactive
agents.\r\n\r\n## Testing\r\n- Have a policy with many inactive agents
assigned to it\r\n- Try to delete it from the agent policy list or
settings\r\n- The deletion is prevented and a warning is
raised:\r\n\r\n![Screenshot 2024-01-31 at 12
03\r\n11](https://github.com/elastic/kibana/assets/16084106/644c9e9e-9820-4251-81fb-58f74ab57377)\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<[email protected]>","sha":"222e894b8a483cd4a22c81dfcd2bec633a45e421","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:prev-minor","v8.13.0"],"number":175815,"url":"https://github.com/elastic/kibana/pull/175815","mergeCommit":{"message":"[Fleet]
Prevent deletion of agent policies with inactive agents from UI
(#175815)\n\nFixes
https://github.com/elastic/kibana/issues/155925\r\n\r\n##
Summary\r\nPrevent deleting an agent policy that has inactive agents
assigned. The\r\nworkaround to fix existing \"orphaned\" agents is
outlined\r\n[here](https://github.com/elastic/kibana/issues/155925#issuecomment-1919250162).\r\n\r\n###
API\r\nAdding check for inactive agents to the agent policy \"delete\"
endpoint -\r\nIt will now fail if the policy has either active or
inactive agents:\r\n\r\n```\r\n POST
/api/fleet/agent_policies/delete\r\n {\r\n agentPolicyId: 1234534,\r\n
}\r\n```\r\n\r\n### UI \r\nWarning added to the \"delete\" action in the
UI when trying to delete a\r\npolicy that has active or inactive
agents.\r\n\r\n## Testing\r\n- Have a policy with many inactive agents
assigned to it\r\n- Try to delete it from the agent policy list or
settings\r\n- The deletion is prevented and a warning is
raised:\r\n\r\n![Screenshot 2024-01-31 at 12
03\r\n11](https://github.com/elastic/kibana/assets/16084106/644c9e9e-9820-4251-81fb-58f74ab57377)\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<[email protected]>","sha":"222e894b8a483cd4a22c81dfcd2bec633a45e421"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/175815","number":175815,"mergeCommit":{"message":"[Fleet]
Prevent deletion of agent policies with inactive agents from UI
(#175815)\n\nFixes
https://github.com/elastic/kibana/issues/155925\r\n\r\n##
Summary\r\nPrevent deleting an agent policy that has inactive agents
assigned. The\r\nworkaround to fix existing \"orphaned\" agents is
outlined\r\n[here](https://github.com/elastic/kibana/issues/155925#issuecomment-1919250162).\r\n\r\n###
API\r\nAdding check for inactive agents to the agent policy \"delete\"
endpoint -\r\nIt will now fail if the policy has either active or
inactive agents:\r\n\r\n```\r\n POST
/api/fleet/agent_policies/delete\r\n {\r\n agentPolicyId: 1234534,\r\n
}\r\n```\r\n\r\n### UI \r\nWarning added to the \"delete\" action in the
UI when trying to delete a\r\npolicy that has active or inactive
agents.\r\n\r\n## Testing\r\n- Have a policy with many inactive agents
assigned to it\r\n- Try to delete it from the agent policy list or
settings\r\n- The deletion is prevented and a warning is
raised:\r\n\r\n![Screenshot 2024-01-31 at 12
03\r\n11](https://github.com/elastic/kibana/assets/16084106/644c9e9e-9820-4251-81fb-58f74ab57377)\r\n\r\n\r\n\r\n###
Checklist\r\n\r\n- [
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<[email protected]>","sha":"222e894b8a483cd4a22c81dfcd2bec633a45e421"}}]}]
BACKPORT-->

---------

Co-authored-by: Kibana Machine <[email protected]>
@mistic
Copy link
Member

mistic commented Feb 7, 2024

This PR didn't make it on time to the latest build candidate of v8.12.1. Updating the labels.

@mistic mistic added v8.12.2 and removed v8.12.1 labels Feb 7, 2024
fkanout pushed a commit to fkanout/kibana that referenced this pull request Feb 7, 2024
…UI (elastic#175815)

Fixes elastic#155925

## Summary
Prevent deleting an agent policy that has inactive agents assigned. The
workaround to fix existing "orphaned" agents is outlined
[here](elastic#155925 (comment)).

### API
Adding check for inactive agents to the agent policy "delete" endpoint -
It will now fail if the policy has either active or inactive agents:

```
  POST /api/fleet/agent_policies/delete
  {
    agentPolicyId: 1234534,
  }
```

### UI 
Warning added to the "delete" action in the UI when trying to delete a
policy that has active or inactive agents.

## Testing
- Have a policy with many inactive agents assigned to it
- Try to delete it from the agent policy list or settings
- The deletion is prevented and a warning is raised:

![Screenshot 2024-01-31 at 12 03
11](https://github.com/elastic/kibana/assets/16084106/644c9e9e-9820-4251-81fb-58f74ab57377)



### Checklist

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Kibana Machine <[email protected]>
CoenWarmer pushed a commit to CoenWarmer/kibana that referenced this pull request Feb 15, 2024
…UI (elastic#175815)

Fixes elastic#155925

## Summary
Prevent deleting an agent policy that has inactive agents assigned. The
workaround to fix existing "orphaned" agents is outlined
[here](elastic#155925 (comment)).

### API
Adding check for inactive agents to the agent policy "delete" endpoint -
It will now fail if the policy has either active or inactive agents:

```
  POST /api/fleet/agent_policies/delete
  {
    agentPolicyId: 1234534,
  }
```

### UI 
Warning added to the "delete" action in the UI when trying to delete a
policy that has active or inactive agents.

## Testing
- Have a policy with many inactive agents assigned to it
- Try to delete it from the agent policy list or settings
- The deletion is prevented and a warning is raised:

![Screenshot 2024-01-31 at 12 03
11](https://github.com/elastic/kibana/assets/16084106/644c9e9e-9820-4251-81fb-58f74ab57377)



### Checklist

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Kibana Machine <[email protected]>
fkanout pushed a commit to fkanout/kibana that referenced this pull request Mar 4, 2024
…UI (elastic#175815)

Fixes elastic#155925

## Summary
Prevent deleting an agent policy that has inactive agents assigned. The
workaround to fix existing "orphaned" agents is outlined
[here](elastic#155925 (comment)).

### API
Adding check for inactive agents to the agent policy "delete" endpoint -
It will now fail if the policy has either active or inactive agents:

```
  POST /api/fleet/agent_policies/delete
  {
    agentPolicyId: 1234534,
  }
```

### UI 
Warning added to the "delete" action in the UI when trying to delete a
policy that has active or inactive agents.

## Testing
- Have a policy with many inactive agents assigned to it
- Try to delete it from the agent policy list or settings
- The deletion is prevented and a warning is raised:

![Screenshot 2024-01-31 at 12 03
11](https://github.com/elastic/kibana/assets/16084106/644c9e9e-9820-4251-81fb-58f74ab57377)



### Checklist

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Kibana Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (8.x) the previous minor version (i.e. one version back from main) release_note:fix Team:Fleet Team label for Observability Data Collection Fleet team v8.12.2 v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Fleet] Cannot unenroll offline Agent after deleting agent policy
7 participants