[8.19](backport #7533) Retain output secret when agent update fails - #7547
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. (cherry picked from commit 7fb25fd) # Conflicts: # internal/pkg/policy/policy_output.go # internal/pkg/policy/policy_output_test.go
|
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 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
TL;DRThe current failures are no longer consistent with the prior Remediation
Investigation detailsRoot CauseI could not extract the exact failing test name from the provided Buildkite logs because each pre-fetched log file only contains the tail and ends at:
However, on PR head
This points to a test expectation mismatch around FIPS-mode detection/behavior in:
Evidence
Verification
Follow-upNo open What is this? | From workflow: PR Buildkite Detective Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not. |
…rets WriteSecret is not called in prepareElasticsearch on this branch so the Once() expectation caused AssertExpectations to fail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.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.
This is an automatic backport of pull request #7533 done by [Mergify](https://mergify.com).