You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Retire API keys for ES output when user switches to non-ES output - #8382
When a user switched from ES output to logstash/kafka, we never retire the api keys of ES output. In this PR, we fix that.
How does this PR solve the problem?
// Explain HOW you solved the problem in your code. It is possible that during PR reviews this changes and then this section should be updated.
This PR retires and deletes all stored api keys if the new policy does not contain ES output.
The case where a user simply switches to another ES output, the api keys are already retired correctly on main.
How to test this PR locally
Design Checklist
I have ensured my design is stateless and will work when multiple fleet-server instances are behind a load balancer.
I have or intend to scale test my changes, ensuring it will work reliably with 100K+ agents connected.
I have included fail safe mechanisms to limit the load on fleet-server: rate limiting, circuit breakers, caching, load shedding, etc.
Checklist
I have commented my code, particularly in hard-to-understand areas
I have made corresponding changes to the documentation
I have made corresponding change to the default configuration files
I have added tests that prove my fix is effective or that my feature works
I have added an entry in ./changelog/fragments using the changelog tool
This pull request does not have a backport label. Could you fix it @khushijain21? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:
backport-./d./d is the label to automatically backport to the 8./d branch. /d is the digit
backport-active-all is the label that automatically backports to all active branches.
backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The new test cannot compile, and credential retirement can prematurely stop ingestion or discard records needed to retry invalidation of still-valid remote keys.
This PR extends Fleet Server’s output credential cleanup to retire Elasticsearch API keys when agents switch to non-ES outputs such as Logstash or Kafka.
Changes:
Adds cleanup when no API-key-bearing output remains and handles output-type changes when another keyed output survives.
Shares key invalidation and secret cleanup helpers between policy processing and acknowledgement handlers.
Adds regression tests and a bug-fix changelog entry.
File
Description
internal/pkg/policy/retire_outputs.go
Adds retirement logic and shared credential cleanup helpers.
internal/pkg/policy/policy_output.go
Handles outputs changing to types without API keys.
internal/pkg/policy/policy_output_test.go
Tests retirement and output-type transitions.
internal/pkg/api/handleCheckin.go
Invokes retirement during policy preparation.
internal/pkg/api/handleCheckin_test.go
Tests retirement records on a surviving output.
internal/pkg/api/handleAck.go
Uses shared cleanup helpers and renames the policy-ack handler.
khushijain21
changed the title
Retire API keys of ES output when user switch to non-ES output
Retire API keys for ES output when user switches to non-ES output
Nov 26, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
A critical issue leaves the old remote Elasticsearch API key valid after an output-type change when the remote-client cache is empty, because invalidation targets the primary cluster instead of the original remote cluster.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Key retirement can leave remote Elasticsearch credentials valid after a restart or invalidate still-live keys on a delayed acknowledgement because retirement records lack a durable reference to the original remote configuration and the target policy revision.
Gate key retirement on confirmation of the target policy revision
internal/pkg/policy/policy_output.go:332
The retirement record is not tied to the policy revision that removes this key. If the stored revision is 1 and revision 3 switches to Logstash, a delayed acknowledgement of revision 2 (still using Elasticsearch) passes the acknowledgement gate and invalidates the still-live key, interrupting ingestion. Persist the target policy ID/revision with the retirement record and make both acknowledgement and check-in cleanup wait until that transition is confirmed.
Test cleanup of keyless outputs through both cleanup paths
internal/pkg/policy/policy_output.go:120
The new tests verify that preparation parks keys, but do not exercise acknowledgement or check-in cleanup for the resulting keyless Logstash/Kafka entries. A regression that skips those entries during cleanup would leave the key leak undetected. Add regression coverage using reloaded agent state to verify that keys remain valid before the output switch is confirmed, then are invalidated and their stored secrets deleted through both cleanup paths.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
An in-place remote Elasticsearch-to-Logstash/Kafka switch loses the original cluster routing information, so key invalidation after a restart or on another instance targets the primary cluster and leaves the old remote key valid.
Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.
Queue this pull request once it meets the queue conditions
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Retiring keys after a same-name remote Elasticsearch output switches to Logstash or Kafka can fall back to the primary cluster without a cached remote client, leaving the old remote API key valid.
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
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.
What is the problem this PR solves?
When a user switched from ES output to logstash/kafka, we never retire the api keys of ES output. In this PR, we fix that.
How does this PR solve the problem?
// Explain HOW you solved the problem in your code. It is possible that during PR reviews this changes and then this section should be updated.
This PR retires and deletes all stored api keys if the new policy does not contain ES output.
The case where a user simply switches to another ES output, the api keys are already retired correctly on main.
How to test this PR locally
Design Checklist
Checklist
./changelog/fragmentsusing the changelog toolRelated issues