Skip to content

[Elastic Agent] Fix install with bootstrapping Fleet Server#24981

Merged
blakerouse merged 9 commits intoelastic:masterfrom
blakerouse:fix-install-fleet-server
Apr 8, 2021
Merged

[Elastic Agent] Fix install with bootstrapping Fleet Server#24981
blakerouse merged 9 commits intoelastic:masterfrom
blakerouse:fix-install-fleet-server

Conversation

@blakerouse
Copy link
Copy Markdown
Contributor

@blakerouse blakerouse commented Apr 8, 2021

What does this PR do?

This fixes the install command to allow Fleet Server to be bootstrapped properly. This also adds better logging to the enroll command (that is called by install) so its clear what might be causing the bootstrap of Fleet Server to fail.

This branch also uses a new feature from Fleet Server that removes the requirement of needing to pass the --enrollment-token to either install or enroll. Now Fleet Server will tell the Elastic Agent which enrollment token to use and Elastic Agent will use it to perform enrollment. This makes the installation of Elastic Agent with Fleet Server to just the following:

$ sudo ./elastic-agent install --fleet-server http://elastic:changeme@localhost:9200

This includes removing the requirement for the Docker container to even have to talk to Kibana when bootstrapping with Fleet Server. The following command would run the container and it would not even talk to Kibana at any point.

$ docker run -it -e ELASTICSEARCH_HOST=http://host.docker.internal:9200 -e FLEET_SERVER_ENABLE=1 docker.elastic.co/beats/elastic-agent:8.0.0-SNAPSHOT

This includes some fixes to the paths that was prevent Fleet Server from starting.

Why is it important?

So bootstrapping of Fleet Server works with the install command and to simplify the bootstrapping process by removing the requirement for --enrollment-token.

Checklist

  • My code follows the style guidelines of this project
  • 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.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Related issues

Logs

% sudo ./elastic-agent install --fleet-server http://elastic:changeme@localhost:9200
The Elastic Agent is currently in BETA and should not be used in production

Elastic Agent will be installed at /Library/Elastic/Agent and will run as a service. Do you want to continue? [Y/n]:Y
2021-04-07T19:48:27.703-0400    INFO    cmd/enroll_cmd.go:289   Generating self-signed certificate for Fleet Server
2021-04-07T19:48:29.005-0400    INFO    cmd/enroll_cmd.go:579   Waiting for Elastic Agent to start Fleet Server
2021-04-07T19:48:30.007-0400    INFO    cmd/enroll_cmd.go:619   Fleet Server - Starting
2021-04-07T19:48:33.020-0400    INFO    cmd/enroll_cmd.go:593   Fleet Server - Running on default policy with Fleet Server integration; missing config fleet.agent.id
2021-04-07T19:48:34.657-0400    INFO    cmd/enroll_cmd.go:193   Successfully triggered restart on running Elastic Agent.
Successfully enrolled the Elastic Agent.

… for the enrollment token when bootstrapping with Fleet Server.
@blakerouse blakerouse added Team:Elastic-Agent Label for the Agent team backport-v7.13.0 Automated backport with mergify labels Apr 8, 2021
@blakerouse blakerouse self-assigned this Apr 8, 2021
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/agent (Team:Agent)

@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Apr 8, 2021
@blakerouse
Copy link
Copy Markdown
Contributor Author

@ruflin @EricDavisX This removes the requirement of needing the --enrollment-token when bootstrapping with Fleet Server. All that is needed is:

sudo ./elastic-agent install --fleet-server http://elastic:changeme@localhost:9200

I am not marking this as breaking, because you can still provide one if you want. Its just no longer required to provide one.

@elasticmachine
Copy link
Copy Markdown
Contributor

elasticmachine commented Apr 8, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview

Expand to view the summary

Build stats

  • Build Cause: Pull request #24981 updated

  • Start Time: 2021-04-08T16:35:31.732+0000

  • Duration: 58 min 48 sec

  • Commit: 4da6d8f

Test stats 🧪

Test Results
Failed 0
Passed 6612
Skipped 16
Total 6628

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 6612
Skipped 16
Total 6628

kbn, ok := transpiler.Lookup(ast, "fleet.kibana")
if !ok {
return fmt.Errorf("failed to get kibana config key from fleet config")
if ok {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can do inline now to reduce scope

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed


if enroll {
if url == "" {
if url == "" && fleetServer == "" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could we just move this to enroll && fleetServer == "" and remove also from the if above
or if the goal here is to skip enroll for fleet server maybe we can just extract this up to the line 140 into a Fn and execute only when fleetServer == ""
these ifs are getting complicated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was able to simplify this by moving it up. The goal here is to ask for URL and Token in the case that it is not provided. The complexity comes from install being interactive.

@blakerouse
Copy link
Copy Markdown
Contributor Author

@michalpristas Ready for another look

@blakerouse blakerouse requested a review from michalpristas April 8, 2021 12:13
Copy link
Copy Markdown
Contributor

@michalpristas michalpristas left a comment

Choose a reason for hiding this comment

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

seems ok, tested with latest kibana

@blakerouse
Copy link
Copy Markdown
Contributor Author

/test

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 8, 2021

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b fix-install-fleet-server upstream/fix-install-fleet-server
git merge upstream/master
git push upstream fix-install-fleet-server

@blakerouse blakerouse merged commit a91bba5 into elastic:master Apr 8, 2021
@blakerouse blakerouse deleted the fix-install-fleet-server branch April 8, 2021 18:44
mergify bot pushed a commit that referenced this pull request Apr 8, 2021
* Fix install command to work with Fleet Server, remove the requirement for the enrollment token when bootstrapping with Fleet Server.

* Fix tests.

* Add changelog entry.

* Simplify if statements.

* Add installation success confirmation message.

* Fix leaderelection provider.

* Fix fleet decorator.

(cherry picked from commit a91bba5)
blakerouse added a commit that referenced this pull request Apr 8, 2021
…24998)

* Fix install command to work with Fleet Server, remove the requirement for the enrollment token when bootstrapping with Fleet Server.

* Fix tests.

* Add changelog entry.

* Simplify if statements.

* Add installation success confirmation message.

* Fix leaderelection provider.

* Fix fleet decorator.

(cherry picked from commit a91bba5)

Co-authored-by: Blake Rouse <blake.rouse@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-v7.13.0 Automated backport with mergify Team:Elastic-Agent Label for the Agent team

Projects

None yet

3 participants