Skip to content

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

Merged
criamico merged 7 commits into
elastic:mainfrom
criamico:155925_prevent_deletion_policies
Feb 1, 2024
Merged

criamico merged 7 commits into
elastic:mainfrom
criamico:155925_prevent_deletion_policies

Conversation

@criamico

@criamico criamico commented Jan 29, 2024 •

Copy link
Copy Markdown
Member

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

@ghost

ghost commented Jan 29, 2024

Copy link
Copy Markdown

🤖 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

Copy link
Copy Markdown
Member 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
Copy Markdown
Member 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
Copy Markdown
Member 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
Copy Markdown
Contributor

Pinging @elastic/fleet (Team:Fleet)

@nchaulet
nchaulet self-requested a review January 31, 2024 17:08
showInactive: true,
perPage: 0,
page: 1,
kuery: `${AGENTS_PREFIX}.policy_id:${id}`,

Copy link
Copy Markdown
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

criamico commented Feb 1, 2024

Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

@nchaulet nchaulet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM 🚀

@criamico

criamico commented Feb 1, 2024

Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

@kibana-ci

Copy link
Copy Markdown

💚 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
@kibanamachine

Copy link
Copy Markdown
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

criamico commented Feb 2, 2024

Copy link
Copy Markdown
Member Author

💚 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 <42973632+kibanamachine@users.noreply.github.com>
(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":"criamico@users.noreply.github.com"},"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
<42973632+kibanamachine@users.noreply.github.com>","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
<42973632+kibanamachine@users.noreply.github.com>","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
<42973632+kibanamachine@users.noreply.github.com>","sha":"222e894b8a483cd4a22c81dfcd2bec633a45e421"}}]}]
BACKPORT-->

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@mistic

mistic commented Feb 7, 2024

Copy link
Copy Markdown
Contributor

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 <42973632+kibanamachine@users.noreply.github.com>
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 <42973632+kibanamachine@users.noreply.github.com>
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 <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Fleet] Cannot unenroll offline Agent after deleting agent policy

6 participants