Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent mode support for bootstrap output #3506

Merged
merged 8 commits into from
May 21, 2024

Conversation

michel-laterman
Copy link
Contributor

@michel-laterman michel-laterman commented Apr 30, 2024

What is the problem this PR solves?

When running under the elastic-agent fleet-server is not able to use output settings from it's policy.

How does this PR solve the problem?

This PR requires elastic/elastic-agent#4643 to work.

The elastic-agent will inject enrollment configuration options in output.elasticsearch.bootstrap instead of overwriting matching keys in output.elasticsearch.
When running under agent mode, fleet-server will inject specific keys in bootstrap that are not in output.elasticsearch, then test the resulting output to see if it can connect to Elasticsearch, if so it is used. If not then bootstrap is used instead and the output is periodically retested in case the failure was caused by a temporary network issue.

How to test this PR locally

Create an elastic-agent package from: elastic/elastic-agent#4643
replace the fleet-server component using one generated from this pr.

If testing with docker images docker.elastic.co/observability-ci/elastic-agent:8.15.0-SNAPSHOT-dd4c89e-1715633206 can be used as the BASE_IMAGE for generating a new image/deployment with the make cloud-deploy target in dev-tools/cloud.
Or the docker.elastic.co/observability-ci/elastic-agent:8.15.0-SNAPSHOT-laterman-1715705581 image can be used as it contains the changes from both PRs.

I've verified that the following behaviours work:

When deployed to ESS:

  • fleet-server is available/healthy
  • logging level for fleet-server can be changed with no issues
  • diagnostics can be collected
  • e2e cypress tests for defender succeed (thanks @tomsonpl!)

When deployed locally:

  • fleet-server is available/healthy
  • logging level for fleet-server can be changed with no issues
  • diagnostics can be collected
  • multiple hosts can be added to Elasticasearch output (in Kibana) and show up in fleet-server.yml when a diagnostics bundle is collected

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

Related issues

@michel-laterman michel-laterman added enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team labels Apr 30, 2024
@michel-laterman michel-laterman force-pushed the fleet-bootstrap-output branch 4 times, most recently from 79978ac to fcec504 Compare May 1, 2024 16:31
Add support for a bootstrap attribute in the output when running in
agent mode. If this attribute is missing the output block is used
directly. If the attribute is provided, then any attributes within
bootstrap that are not in the parent (output) object are recursivly
injected and the resulting output is tested. If the resulting config
works it is used, if it fails the test the bootstrap config is passed.
@michel-laterman michel-laterman changed the title wip Agent mode support for bootstrap output May 1, 2024
@michel-laterman
Copy link
Contributor Author

Testing progress: elastic/elastic-agent#4643 (comment)

i'll now try to implement the areas of improvement above:

  1. skip injecting verification_mode: none if a CA or CA fingerprint is in the retrieved policy.
  2. async period output testing if the bootstap block has been passed

@michel-laterman michel-laterman marked this pull request as ready for review May 14, 2024 18:34
@michel-laterman michel-laterman requested a review from a team as a code owner May 14, 2024 18:34
@ycombinator ycombinator removed the request for review from AndersonQ May 16, 2024 20:49
Copy link
Contributor

@pchila pchila left a comment

Choose a reason for hiding this comment

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

Just a couple of comments, looks good overall

internal/pkg/server/agent.go Show resolved Hide resolved
@michel-laterman michel-laterman enabled auto-merge (squash) May 21, 2024 16:49
@cmacknz
Copy link
Member

cmacknz commented May 21, 2024

I think we need an automated test proving that Elastic Agent can bootstrap Fleet Server in one of the repositories before this or elastic/elastic-agent#4643 are merged.

If the coordination of the two PRs with the test is annoying enough I'd be fine with the test being added a separate PR, but not closing the implementation issue until it exists.

@michel-laterman
Copy link
Contributor Author

buildkite test this

@michel-laterman michel-laterman merged commit 12d1b4a into elastic:main May 21, 2024
8 checks passed
@michel-laterman michel-laterman deleted the fleet-bootstrap-output branch May 21, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

separate "bootstrap" from retrieved config when running in agent mode
3 participants