Skip to content

Ensure fleet deployment uses fleet url provided by fleet_server_host_id#225699

Merged
MichelLosier merged 4 commits intoelastic:mainfrom
MichelLosier:ensure-agentless-uses-correct-fleet-server-url
Jun 30, 2025
Merged

Ensure fleet deployment uses fleet url provided by fleet_server_host_id#225699
MichelLosier merged 4 commits intoelastic:mainfrom
MichelLosier:ensure-agentless-uses-correct-fleet-server-url

Conversation

@MichelLosier
Copy link
Contributor

@MichelLosier MichelLosier commented Jun 27, 2025

Summary

Resolves: #221900

In an ECH environment, if a user creates a new fleet server and sets it as default, a new agentless deployment can be created that uses the url of the new default fleet server, but the enrollment API key of the expected preconfigured fleet server. For agentless deployments, we'll want to use the default managed fleet server provided in the cloud environment

To reproduce (on main):

Ensure the kibana.dev.yml is setup to enable agentless, and to think its in a cloud environment, specifically ECH

xpack.cloud.id: 'anything-here-is-valid'
xpack.fleet.agentless.enabled: true
xpack.fleet.agentless.api.url: 'http://localhost:3000'
xpack.fleet.agentless.api.tls.certificate: './config/certs/ess-client.crt'
xpack.fleet.agentless.api.tls.key: './config/certs/ess-client.key'
xpack.fleet.agentless.api.tls.ca: './config/certs/ca.crt'

Make sure the default fleet server host id and output ids match what is expected for ECH:

xpack.fleet.fleetServerHosts:
  - id: fleet-default-fleet-server-host
    name: Default Fleet server
    is_default: true
    host_urls: ['https://your-local-ip:8220']

xpack.fleet.outputs:
  - id: fleet-default-output
    name: Default output
    type: elasticsearch
    is_default: true
    is_default_monitoring: true
    hosts: ['http://your-local-ip:9200']

Steps:

  • Add a new fleet server in the UI, and set is as default. Use a host url that you can easily distinguish from the preconfigured default fleet server
  • Add the Okta integration as agentless
  • Observe the log line from Kibana fleet api server [Agentless API] Creating agentless agent with fleetUrl ${fleetUrl} and fleet_token: [REDACTED] show the fleetUrl for the new default fleet server.

Then try the same steps on this branch and observe the same log line. You should see the fleetUrl match the preconfigured one.

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support
  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the docker list
  • This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The release_note:breaking label should be applied in these situations.
  • Flaky Test Runner was used on any tests changed
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

Identify risks

Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss.

Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging.

@MichelLosier
Copy link
Contributor Author

This draft PR at this point is to more so demo the issue and a "for now" path we could take, but @jen-huang given the underlying issue for this, it seems that maybe the more durable solution, and what I lean towards, would be to have agentPolicyService.create for agentless policies always use the ID constants for the default output and fleet server host for the cloud environments by extracting and reusing this bit of logic here:

When I was working in this area I came across the code comment linking to:

which led me to the draft that you put up recently related to that here:

If I take the path I'm proposing (using constants and not relying in req params for agentless), I don't want to create too much merge conflict for what you are setting up there. That said, I could just branch off your draft instead and work towards that direction and PR to your branch.

What do you think?

@jen-huang
Copy link
Contributor

it seems that maybe the more durable solution, and what I lean towards, would be to have agentPolicyService.create for agentless policies always use the ID constants for the default output and fleet server host for the cloud environments

I would be in favor of continuing with the patch you have here that reads from the policy's fleet_server_host_id. With the work in #218905, the client-side request that creates the agent policy should always be made with this field set, and the code executed at setup (in agentless_settings_ids.ts should correct any policy that doesn't have this set.

This will ensure that the fleet_server_host_id field is always the source of truth. If we use constants on server-side during create time, instead of using this field, may cause confusion if the two ever diverge for whatever reason.

@MichelLosier MichelLosier marked this pull request as ready for review June 27, 2025 22:51
@MichelLosier MichelLosier requested a review from a team as a code owner June 27, 2025 22:51
@MichelLosier MichelLosier added the release_note:skip Skip the PR/issue when compiling release notes label Jun 27, 2025
@jen-huang jen-huang added Team:Fleet Team label for Observability Data Collection Fleet team backport:version Backport to applied version labels v9.1.0 labels Jun 27, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/fleet (Team:Fleet)

Copy link
Contributor

@jen-huang jen-huang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix! 🚀

@jen-huang jen-huang added backport:prev-minor v9.2.0 and removed backport:version Backport to applied version labels labels Jun 27, 2025
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

@MichelLosier MichelLosier merged commit 09abd61 into elastic:main Jun 30, 2025
10 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 9.1

https://github.com/elastic/kibana/actions/runs/15976933896

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 30, 2025
…id (elastic#225699)

## Summary

Resolves: elastic#221900

In an ECH environment, if a user creates a new fleet server and sets it
as default, a new agentless deployment can be created that uses the url
of the new default fleet server, but the enrollment API key of the
expected preconfigured fleet server. For agentless deployments, we'll
want to use the default managed fleet server provided in the cloud
environment. This PR ensures we use the fleet server id provided in the request to obtain the url.

---------

Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
(cherry picked from commit 09abd61)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
9.1

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jun 30, 2025
…_host_id (#225699) (#225871)

# Backport

This will backport the following commits from `main` to `9.1`:
- [Ensure fleet deployment uses fleet url provided by
fleet_server_host_id
(#225699)](#225699)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Michel
Losier","email":"michel.losier@elastic.co"},"sourceCommit":{"committedDate":"2025-06-30T15:19:45Z","message":"Ensure
fleet deployment uses fleet url provided by fleet_server_host_id
(#225699)\n\n## Summary\n\nResolves:
https://github.com/elastic/kibana/issues/221900\n\nIn an ECH
environment, if a user creates a new fleet server and sets it\nas
default, a new agentless deployment can be created that uses the url\nof
the new default fleet server, but the enrollment API key of
the\nexpected preconfigured fleet server. For agentless deployments,
we'll\nwant to use the default managed fleet server provided in the
cloud\nenvironment. This PR ensures we use the fleet server id provided
in the request to obtain the url.\n\n---------\n\nCo-authored-by: Julia
Bardi
<90178898+juliaElastic@users.noreply.github.com>","sha":"09abd61c5b2bebf0ab48b2098458a30ba02ab02a","branchLabelMapping":{"^v9.2.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Fleet","backport:prev-minor","v9.1.0","v9.2.0"],"title":"Ensure
fleet deployment uses fleet url provided by
fleet_server_host_id","number":225699,"url":"https://github.com/elastic/kibana/pull/225699","mergeCommit":{"message":"Ensure
fleet deployment uses fleet url provided by fleet_server_host_id
(#225699)\n\n## Summary\n\nResolves:
https://github.com/elastic/kibana/issues/221900\n\nIn an ECH
environment, if a user creates a new fleet server and sets it\nas
default, a new agentless deployment can be created that uses the url\nof
the new default fleet server, but the enrollment API key of
the\nexpected preconfigured fleet server. For agentless deployments,
we'll\nwant to use the default managed fleet server provided in the
cloud\nenvironment. This PR ensures we use the fleet server id provided
in the request to obtain the url.\n\n---------\n\nCo-authored-by: Julia
Bardi
<90178898+juliaElastic@users.noreply.github.com>","sha":"09abd61c5b2bebf0ab48b2098458a30ba02ab02a"}},"sourceBranch":"main","suggestedTargetBranches":["9.1"],"targetPullRequestStates":[{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.2.0","branchLabelMappingKey":"^v9.2.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/225699","number":225699,"mergeCommit":{"message":"Ensure
fleet deployment uses fleet url provided by fleet_server_host_id
(#225699)\n\n## Summary\n\nResolves:
https://github.com/elastic/kibana/issues/221900\n\nIn an ECH
environment, if a user creates a new fleet server and sets it\nas
default, a new agentless deployment can be created that uses the url\nof
the new default fleet server, but the enrollment API key of
the\nexpected preconfigured fleet server. For agentless deployments,
we'll\nwant to use the default managed fleet server provided in the
cloud\nenvironment. This PR ensures we use the fleet server id provided
in the request to obtain the url.\n\n---------\n\nCo-authored-by: Julia
Bardi
<90178898+juliaElastic@users.noreply.github.com>","sha":"09abd61c5b2bebf0ab48b2098458a30ba02ab02a"}}]}]
BACKPORT-->

Co-authored-by: Michel Losier <michel.losier@elastic.co>
Co-authored-by: Julia Bardi <90178898+juliaElastic@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes Team:Fleet Team label for Observability Data Collection Fleet team v9.1.0 v9.2.0

5 participants