[9.4] [Fleet] Force-revoke agents when deleting an agentless policy (#290181) - #290447
Merged
Merged
Conversation
…c#290181) ## Summary Closes elastic#289381 The removal of an agentless policy leads to destruction of the managed deployment via `deleteAgentlessAgent()` following the graceful unenroll. Since the deletion happens instantly, there is no way for the agent to check in and acknowledge the `UNENROLL` action which leaves the agent document `active: true` indefinitely, with no way to clean up. ## Fix Revoke the agent forcibly before removing the deployment, similar to what we do in `deleteVerifierPolicy`: ```ts await unenrollForAgentPolicyId(soClient, esClient, id, { revoke: true }); ``` That sets `active: false` and `unenrolled_at` synchronously, invalidating API keys without waiting for an impossible check-in. The call does not have a try/catch block around it, so any error here prevents the deployment/SO from being deleted, keeping retries safe. ## Testing - Added unit tests ensuring that the call happens with `{ revoke: true }` and before `deleteAgentlessAgent()` - verified they fail without the fix and pass with it. - Added an FTR test, verifying that an agentless policy deletion results in an agent document having `active: false` and `unenrolled_at` set. - Verified that the fix is limited to `supports_agentless` policies. - Ran all unit tests for `agent_policy.test.ts`, lint and typing. (cherry picked from commit 777b80c)
|
Pinging @elastic/fleet (Team:Fleet) |
Contributor
Author
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]
Test Failures |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport
This will backport the following commits from
mainto9.4:Questions ?
Please refer to the Backport tool documentation