peasead / elastic-container

Stand up a simple Elastic container with Kibana, Fleet, and the Detection Engine
Apache License 2.0
395 stars 71 forks source link

[ENHANCEMENT] Get FLEET_ENROLLMENT_TOKEN #39

Closed PfiatDe closed 8 months ago

PfiatDe commented 8 months ago

First this is really a wonderful project. Thanks for it!

Is your feature request related to a problem? Please describe. When automating the deployment it is always a small hassle to get the enrollment token for the fleet, as it involves connecting the UI.

Describe the solution you'd like There would be serveral solutions: a) A way to get it via the API. I did not find the correct APIs to talk to to get them. This seems only to work for Cloud? https://www.elastic.co/guide/en/cloud-enterprise/current/get-enrollment-tokens.html

b) Define the FLEET_ENROLLMENT_TOKEN via an ENV Variable in the docker-compose / .env As this is only a test system this might be fine

c) Get it somewhere else and log or print it during the setup / start phase

I am talking about this Token: image

peasead commented 8 months ago

Thanks for checking out the project, @PfiatDe

Because there are a lot of nuance in what policy someone might want and for what OS, I think it'd be best to not build that into the script, but provide it in the README as a way to do it. I'll do that and I think it's a great idea.

I haven't tried it yet, but I think this will work that way? I'm going to try it in a bit.

curl -k -u elastic --request GET \
  --url 'https://kibana:5601/api/fleet/enrollment_api_keys' \
  --header 'Content-Type: application/json' \
  --header 'kbn-xsrf: xx'

Ref: https://www.elastic.co/guide/en/fleet/current/fleet-api-docs.html#get-enrollment-token-api

PfiatDe commented 8 months ago

This is working great, thanks! So my Selenium automation got obsolete within a day, nice :) Created a PR with some documentation. Feel free to edit or adjust as you want. https://github.com/peasead/elastic-container/pull/40

Thanks for keeping this project up :)

peasead commented 8 months ago

40 merged.

Thanks for the contribution!