This repository has been archived by the owner on Jan 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 68
Add Elastic Agent #1005
Merged
Merged
Add Elastic Agent #1005
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1e6d775
bare minimum
graphaelli b9bba2f
stub healthcheck
graphaelli c6f0967
enroll elastic agent
graphaelli 355a3ed
restrict agent version
graphaelli b3e5723
use elastic-agent.yml
graphaelli 1ee384c
fix kibana url option
graphaelli b9a659e
Revert "use elastic-agent.yml"
graphaelli 48a1607
provide docker.sock
graphaelli 3ef764a
help agent find kibana and es
graphaelli 0c77461
more agent tests
graphaelli d067c77
fix test
graphaelli 356ce54
clarify text per review feedback
graphaelli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
import json | ||
import os | ||
|
||
from .helpers import curl_healthcheck, try_to_set_slowlog | ||
from .helpers import curl_healthcheck, try_to_set_slowlog, urlparse | ||
from .service import StackService, Service, DEFAULT_APM_SERVER_URL | ||
|
||
|
||
|
@@ -587,6 +587,69 @@ def render_tee(self): | |
return {self.name(): content} | ||
|
||
|
||
class ElasticAgent(StackService, Service): | ||
docker_path = "beats" | ||
|
||
def __init__(self, **options): | ||
super(ElasticAgent, self).__init__(**options) | ||
if not self.at_least_version("7.8"): | ||
raise Exception("Elastic Agent is only available in 7.8+") | ||
|
||
# build deps | ||
self.depends_on = {"kibana": {"condition": "service_healthy"}} if options.get("enable_kibana", True) else {} | ||
|
||
# build environment | ||
# Environment variables consumed by the Elastic Agent entrypoint | ||
# https://github.com/elastic/beats/blob/4f4a5536b72f4a25962d56262f31e3b8533b252e/dev-tools/packaging/templates/docker/docker-entrypoint.elastic-agent.tmpl | ||
# FLEET_ENROLLMENT_TOKEN - existing enrollment token to be used for enroll | ||
# FLEET_ENROLL - if set to 1 enroll will be performed | ||
# FLEET_ENROLL_INSECURE - if set to 1, agent will enroll with fleet using --insecure flag | ||
# FLEET_SETUP - if set to 1 fleet setup will be performed | ||
# FLEET_TOKEN_NAME - token name for a token to be created | ||
# KIBANA_HOST - actual kibana host [http://localhost:5601] | ||
# KIBANA_PASSWORD - password for accessing kibana API [changeme] | ||
# KIBANA_USERNAME - username for accessing kibana API [elastic] | ||
kibana_url = options.get("elastic_agent_kibana_url") | ||
if not kibana_url: | ||
kibana_scheme = "https" if self.options.get("kibana_enable_tls", False) else "http" | ||
# TODO(gr): add default elastic-agent user | ||
kibana_url = kibana_scheme + "://admin:changeme@" + self.DEFAULT_KIBANA_HOST | ||
|
||
kibana_parsed_url = urlparse(kibana_url) | ||
self.environment = { | ||
"FLEET_ENROLL": "1", | ||
"FLEET_SETUP": "1", | ||
"KIBANA_HOST": kibana_url, | ||
} | ||
if kibana_parsed_url.password: | ||
self.environment["KIBANA_PASSWORD"] = kibana_parsed_url.password | ||
if kibana_parsed_url.username: | ||
self.environment["KIBANA_USERNAME"] = kibana_parsed_url.username | ||
if not kibana_url.startswith("https://"): | ||
self.environment["FLEET_ENROLL_INSECURE"] = 1 | ||
|
||
def _content(self): | ||
return dict( | ||
depends_on=self.depends_on, | ||
environment=self.environment, | ||
healthcheck={ | ||
"test": ["CMD", "/bin/true"], | ||
}, | ||
volumes=[ | ||
"/var/run/docker.sock:/var/run/docker.sock", | ||
] | ||
) | ||
|
||
@classmethod | ||
def add_arguments(cls, parser): | ||
super(ElasticAgent, cls).add_arguments(parser) | ||
parser.add_argument( | ||
"--elastic-agent-kibana-url", | ||
default="http://admin:changeme@" + cls.DEFAULT_KIBANA_HOST, | ||
help="Elastic Agent's Kibana URL, including username:password" | ||
) | ||
|
||
|
||
class Elasticsearch(StackService, Service): | ||
default_environment = [ | ||
"bootstrap.memory_lock=true", | ||
|
@@ -859,6 +922,10 @@ def __init__(self, **options): | |
if self.at_least_version("7.7"): | ||
self.environment["XPACK_SECURITY_ENCRYPTIONKEY"] = "fhjskloppd678ehkdfdlliverpoolfcr" | ||
self.environment["XPACK_ENCRYPTEDSAVEDOBJECTS_ENCRYPTIONKEY"] = "fhjskloppd678ehkdfdlliverpoolfcr" | ||
if self.at_least_version("7.8"): | ||
self.environment["XPACK_FLEET_AGENTS_ELASTICSEARCH_HOST"] = urls[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Elastic Agent container crashes in 7.8, and I suspect it might be because these settings were named differently. I just can't find it, https://www.elastic.co/guide/en/kibana/7.10/fleet-settings-kb.html doesn't exist for previous versions... We might just as well support >=7.10 only and revisit if needed for earlier version? The error is pretty clear, thou:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
self.environment["XPACK_FLEET_AGENTS_KIBANA_HOST"] = "{}://kibana:{}".format( | ||
"https" if self.kibana_tls else "http", self.SERVICE_PORT) | ||
if options.get("xpack_secure"): | ||
self.environment["ELASTICSEARCH_PASSWORD"] = "changeme" | ||
self.environment["ELASTICSEARCH_USERNAME"] = "kibana_system_user" | ||
|
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't that
admin
instead ofelastic
?