Pre-fetch enrollment token for all agent deployers#3757
Draft
mrodm wants to merge 1 commit into
Draft
Conversation
The enrollment token was previously only pre-fetched by elastic-package when config.ElasticsearchAPIKey was set (i.e. the environment provider). For the compose and Kubernetes providers the container was left to fetch it from Kibana itself via FLEET_TOKEN_POLICY_NAME, which requires a broad /api/fleet/enrollment_api_keys query inside the container with a ~90s context deadline. Under sustained CI load (many sequential test runs), Kibana can fail to respond within that window, causing every agent container to wait the full ~90s before falling back to fleet-server enrollment. Pre-fetch the token unconditionally using the policy-scoped kuery (active:true and policy_id:<ID>) so FLEET_ENROLLMENT_TOKEN is always passed directly to the container, bypassing the in-container Kibana fetch entirely. Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Contributor
Author
|
/test |
1 similar comment
Contributor
Author
|
/test |
💚 Build Succeeded
History
cc @mrodm |
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.
Summary
Previously,
elastic-packageonly pre-fetched the Fleet enrollment token from Kibana whenconfig.ElasticsearchAPIKeywas set (i.e. the serverless/environment provider). For the DockerCompose and Kubernetes providers, the agent container was left to retrieve it itself viaFLEET_TOKEN_POLICY_NAME, which triggers a broad/api/fleet/enrollment_api_keysquery inside the container with a ~90s context deadline.Under sustained CI load (many sequential test runs), Kibana can fail to respond within that window, causing each agent container to wait the full ~90s before falling back to fleet-server enrollment — contributing to flaky and slow CI runs.
Changes
This PR removes the
if config.ElasticsearchAPIKey != ""guard in both deployers and unconditionally pre-fetches the enrollment token using the policy-scoped kuery (active:true and policy_id:<ID>) before the container starts. The token is then passed directly asFLEET_ENROLLMENT_TOKEN, bypassing the in-container Kibana fetch entirely.Files changed:
internal/agentdeployer/agent.go— DockerCompose deployerinternal/agentdeployer/kubernetes.go— Kubernetes deployerProposed commit