Repository navigation
[Fleet] fix force delete package, updated used by agents check - #166623
Conversation
🤖 GitHub commentsExpand to view the GitHub comments
Just comment with:
|
| pkgVersion, | ||
| esClient, | ||
| force: request.body?.force, | ||
| force: request.query?.force, |
There was a problem hiding this comment.
Should we support both request.query?.force and request.body?.force before we remove the deprecated API?
There was a problem hiding this comment.
using request.body.force was always undefined, that's why the force flag didn't work
tested like this:
DELETE kbn:/api/fleet/epm/packages/system/1.38.2
{
"force": true
}
I think this was broken since we changed the API from POST to DELETE.
See https://stackoverflow.com/questions/37796227/body-is-empty-when-parsing-delete-request-with-express-and-body-parser
| kuery: `${PACKAGE_POLICY_SAVED_OBJECT_TYPE}.package.name:${pkgName}`, | ||
| page: 1, | ||
| perPage: options.force ? SO_SEARCH_LIMIT : 0, | ||
| withAgentCount: true, |
There was a problem hiding this comment.
I find it weird that the withAgentCount doesn't do anything in packagePolicyService.list, there is a function in the API handler that populates agent count.
There was a problem hiding this comment.
I could move the populate function to the service.
💚 Build Succeeded
Metrics [docs]
To update your PR or re-run it, just comment with: |
…ic#166623) ## Summary Closes elastic#126190 Found that the force flag didn't work when passed in the request body of the DELETE request (the value was undefined), it seems not supported by nodejs. Changed it to pass the force flag as a query param, left the body as deprecated for BWC. To test: - add an agent policy with system integration and enroll an agent - try to delete the package without force flag: shouldn't be allowed - try to delete with force flag, should be allowed - if there are no agents enrolled, the package will be deleted with package policies ``` DELETE kbn:/api/fleet/epm/packages/system/1.38.2?force=true ``` ### Checklist - [x] [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 (cherry picked from commit 44ecd64)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
…#166623) (#166690) # Backport This will backport the following commits from `main` to `8.10`: - [[Fleet] fix force delete package, updated used by agents check (#166623)](#166623) <!--- Backport version: 8.9.7 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Julia Bardi","email":"90178898+juliaElastic@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-09-19T08:30:44Z","message":"[Fleet] fix force delete package, updated used by agents check (#166623)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/126190\r\n\r\nFound that the force flag didn't work when passed in the request body of\r\nthe DELETE request (the value was undefined), it seems not supported by\r\nnodejs.\r\nChanged it to pass the force flag as a query param, left the body as\r\ndeprecated for BWC.\r\n\r\nTo test:\r\n- add an agent policy with system integration and enroll an agent\r\n- try to delete the package without force flag: shouldn't be allowed\r\n- try to delete with force flag, should be allowed\r\n- if there are no agents enrolled, the package will be deleted with\r\npackage policies\r\n\r\n```\r\nDELETE kbn:/api/fleet/epm/packages/system/1.38.2?force=true\r\n```\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [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","sha":"44ecd64f4fdd877d265c5eff190f507a258f0044","branchLabelMapping":{"^v8.11.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:Fleet","backport:prev-minor","v8.11.0"],"number":166623,"url":"https://github.com/elastic/kibana/pull/166623","mergeCommit":{"message":"[Fleet] fix force delete package, updated used by agents check (#166623)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/126190\r\n\r\nFound that the force flag didn't work when passed in the request body of\r\nthe DELETE request (the value was undefined), it seems not supported by\r\nnodejs.\r\nChanged it to pass the force flag as a query param, left the body as\r\ndeprecated for BWC.\r\n\r\nTo test:\r\n- add an agent policy with system integration and enroll an agent\r\n- try to delete the package without force flag: shouldn't be allowed\r\n- try to delete with force flag, should be allowed\r\n- if there are no agents enrolled, the package will be deleted with\r\npackage policies\r\n\r\n```\r\nDELETE kbn:/api/fleet/epm/packages/system/1.38.2?force=true\r\n```\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [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","sha":"44ecd64f4fdd877d265c5eff190f507a258f0044"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.11.0","labelRegex":"^v8.11.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/166623","number":166623,"mergeCommit":{"message":"[Fleet] fix force delete package, updated used by agents check (#166623)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/126190\r\n\r\nFound that the force flag didn't work when passed in the request body of\r\nthe DELETE request (the value was undefined), it seems not supported by\r\nnodejs.\r\nChanged it to pass the force flag as a query param, left the body as\r\ndeprecated for BWC.\r\n\r\nTo test:\r\n- add an agent policy with system integration and enroll an agent\r\n- try to delete the package without force flag: shouldn't be allowed\r\n- try to delete with force flag, should be allowed\r\n- if there are no agents enrolled, the package will be deleted with\r\npackage policies\r\n\r\n```\r\nDELETE kbn:/api/fleet/epm/packages/system/1.38.2?force=true\r\n```\r\n\r\n\r\n### Checklist\r\n\r\n- [x] [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","sha":"44ecd64f4fdd877d265c5eff190f507a258f0044"}}]}] BACKPORT--> Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
Summary
Closes #126190
Found that the force flag didn't work when passed in the request body of the DELETE request (the value was undefined), it seems not supported by nodejs.
Changed it to pass the force flag as a query param, left the body as deprecated for BWC.
To test:
Checklist