Skip to content

[Fleet] fix force delete package, updated used by agents check - #166623

Merged
juliaElastic merged 3 commits into
elastic:mainfrom
juliaElastic:delete-package-fix
Sep 19, 2023
Merged

juliaElastic merged 3 commits into
elastic:mainfrom
juliaElastic:delete-package-fix

Conversation

@juliaElastic

@juliaElastic juliaElastic commented Sep 18, 2023 •

Copy link
Copy Markdown
Contributor

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:

  • 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

@ghost

ghost commented Sep 18, 2023

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!)

pkgVersion,
esClient,
force: request.body?.force,
force: request.query?.force,

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 support both request.query?.force and request.body?.force before we remove the deprecated API?

@juliaElastic juliaElastic Sep 18, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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,

@juliaElastic juliaElastic Sep 18, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I could move the populate function to the service.

@kibana-ci

Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

✅ unchanged

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

cc @juliaElastic

@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 🚀

@juliaElastic
juliaElastic merged commit 44ecd64 into elastic:main Sep 19, 2023
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Sep 19, 2023
…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)
@kibanamachine

Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
✅ 8.10

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

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Sep 19, 2023
…#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>
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] Package rollbacks don't work if an integration policy is already using it

4 participants