Skip to content

[9.4] [Fleet] Force-revoke agents when deleting an agentless policy (#290181) - #290447

Merged
kibanamachine merged 1 commit into
elastic:9.4from
kibanamachine:backport/9.4/pr-290181
Sep 11, 2026
Merged

[9.4] [Fleet] Force-revoke agents when deleting an agentless policy (#290181)#290447
kibanamachine merged 1 commit into
elastic:9.4from
kibanamachine:backport/9.4/pr-290181

Conversation

@kibanamachine

Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 9.4:

Questions ?

Please refer to the Backport tool documentation

…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)
@kibanamachine kibanamachine added the backport This PR is a backport of another PR label Sep 11, 2026
@kibanamachine
kibanamachine enabled auto-merge (squash) September 11, 2026 07:37
@infra-vault-gh-plugin-prod

Copy link
Copy Markdown

Pinging @elastic/fleet (Team:Fleet)

@kibanamachine

Copy link
Copy Markdown
Contributor Author

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

✅ unchanged

Test Failures

  • [job] [logs] Scout Lane #7 - stateful-classic / default / local-stateful-classic - Attachments - adds and removes all attachments from the stream
  • [job] [logs] Jest Tests #5 / useQueryBar updates URL only when conditions are appropriate

@kibanamachine
kibanamachine merged commit f1acf4b into elastic:9.4 Sep 11, 2026
91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR Team:Fleet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants