Retain output secret when agent update fails - #7533
Conversation
Avoid deleting a newly-created output API key secret when the corresponding agent update returns an error because Elasticsearch may have committed the write before the client observed a timeout.
blakerouse
left a comment
There was a problem hiding this comment.
Actually after reviewing #7534 I am okay with this actually.
|
Tick the box to add this pull request to the merge queue (same as
|
|
@Mergifyio backport 9.5 9.4 9.3 8.19 |
✅ Backports have been createdDetails
Cherry-pick of 7fb25fd has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of 7fb25fd has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of 7fb25fd has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Cherry-pick of 7fb25fd has failed: To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally |
…7547) * fix: retain output secret when agent update fails (#7533) Avoid deleting a newly-created output API key secret when the corresponding agent update returns an error because Elasticsearch may have committed the write before the client observed a timeout. (cherry picked from commit 7fb25fd) # Conflicts: # internal/pkg/policy/policy_output.go # internal/pkg/policy/policy_output_test.go * fix: resolve conflict markers in backport of #7533 * fix: drop extraneous test not part of #7533 --------- Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
…7546) * fix: retain output secret when agent update fails (#7533) Avoid deleting a newly-created output API key secret when the corresponding agent update returns an error because Elasticsearch may have committed the write before the client observed a timeout. (cherry picked from commit 7fb25fd) # Conflicts: # internal/pkg/policy/policy_output.go # internal/pkg/policy/policy_output_test.go * fix: resolve conflict markers in backport of #7533 * fix: drop extraneous test not part of #7533 --------- Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
…7545) * fix: retain output secret when agent update fails (#7533) Avoid deleting a newly-created output API key secret when the corresponding agent update returns an error because Elasticsearch may have committed the write before the client observed a timeout. (cherry picked from commit 7fb25fd) # Conflicts: # internal/pkg/policy/policy_output.go # internal/pkg/policy/policy_output_test.go * fix: resolve conflict markers in backport of #7533 * fix: drop extraneous test not part of #7533 --------- Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
Avoid deleting a newly-created output API key secret when the corresponding agent update returns an error because Elasticsearch may have committed the write before the client observed a timeout. (cherry picked from commit 7fb25fd) # Conflicts: # internal/pkg/policy/policy_output.go # internal/pkg/policy/policy_output_test.go
…7544) * fix: retain output secret when agent update fails (#7533) Avoid deleting a newly-created output API key secret when the corresponding agent update returns an error because Elasticsearch may have committed the write before the client observed a timeout. (cherry picked from commit 7fb25fd) # Conflicts: # internal/pkg/policy/policy_output.go # internal/pkg/policy/policy_output_test.go * fix: resolve conflict markers in backport of #7533 * fix: drop extraneous test not part of #7533 --------- Co-authored-by: Shaunak Kashyap <ycombinator@gmail.com>
What is the problem this PR solves?
When Fleet Server creates an output API key, it stores the encoded key in
.fleet-secretsand then updates the agent document in.fleet-agentswith the secret reference. Elasticsearch can commit that update while the client still receives an error, for example when the request context expires while waiting for the response. This can happen under scale load and was observed during a 100k-agent scale test.The existing error path immediately deleted the secret. In the ambiguous-commit case, this left the agent document pointing at a missing secret and subsequent check-ins failed while resolving the output API key.
How does this PR solve the problem?
Retain the newly created secret whenever the agent update returns an error. This chooses a possible orphaned secret over damaging an agent document with a dangling reference.
A follow-up PR adds conservative, out-of-band reconciliation for these retained candidates.
How to test
go test ./internal/pkg/policy -run TestPolicyOutputESPrepare -count=1mage test:unitmage check:allcurrently reports 58 pre-existing linter findings in unrelated files under the repository's pinned Go/toolchain configuration. The files changed by this PR are clean.Design Checklist
Checklist
CHANGELOG.mdDocumentation and configuration changes are not applicable. The changelog entry is supplied as a fragment.