I think one of the biggest issue with fleet and elastic-agent was that it was limited on the outputs so if you had tons and tons of elastic-agents in the wild it would all connect back to your elasticsearch and can overwhelm the cluster.
Starting 8.2 of elasticsearch logstash output type was introduced.. it is still in BETA at this time but I just tried it and it worked very nicely!
The steps to setup the logstash output is listed on https://www.elastic.co/guide/en/fleet/8.2/secure-logstash-connections.html but I wanted to try it out and document it.
Install & configure logstash
Install yum install logstash-8.2.2 -y
Lets find a server that has elasticsearch so that we can use elasticsearch-certutil
to create our certs.
Create the CA
cd /usr/share/elasticsearch
bin/elasticsearch-certutil ca --pem
This will create elastic-stack-ca.zip
Lets unzip it and you will find
./ca/ca.crt
& ./ca/ca.key
Lets create the certificate
bin/elasticsearch-certutil cert --name something --ca-cert ./ca/ca.crt --ca-key ./ca/ca.key --dns your.fqdn --ip x.x.x.x --pem
This will create certificate-bundle.zip and when you unzip it you will find
./something/something.crt
& ./something/something.key
Placing the certificates and reformat the logstash key to pkcs8
mkdir -p /etc/logstash/certs
mv ca/ca.* /etc/logstash/certs/
mv something/something.* /etc/logstash/certs/
cd /etc/logstash/certs
openssl pkcs8 -inform PEM -in something.key -topk8 -nocrypt -outform PEM -out something.pkcs8.key
Create logstash pipeline
create elastic-agent-pipeline.conf
in /etc/logstash/conf.d
with:
input {
elastic_agent {
port => 5044
ssl => true
ssl_certificate_authorities => ["/etc/logstash/certs/ca.crt"]
ssl_certificate => "/etc/logstash/certs/something.crt"
ssl_key => "/etc/logstash/certs/something.pkcs8.key"
ssl_verify_mode => "force_peer"
}
}
output {
elasticsearch {
hosts => "https://xxxxxx:9200"
api_key => "xxxxxx:yyyyy"
data_stream => true
ssl => true
}
}
You can generate your API key from Kibana -> Stack management -> APIKeys
Lets start logstash and monitor it to ensure that the pipeline starts.
systemctl start logstash
journalctl -u logstash -f
Configure the new output
Kibana -> Fleet -> Settings -> Add new output
mine looks like
One word of caution: Client SSL certificate key
is the something.key
NOT something.pkcs8.key
If your SAN is not set properly you might want to add the following into advanced YAML configuration
ssl:
verification_mode: none
Lets create a new policy and for Output for integrations
& Output for agent monitoring
select our logstash output.
SAVE!!
Enroll and start your elastic-agents
elastic-agent enroll -f --url=https://xxxxxx:8220 --enrollment-token=xxxxxxxxxxxxxxxxxxxx
Wait until the agent is healthy and then goto /var/lib/elastic-agent/data/elastic-agent-xxxxxx
and look at state.yml
The output section should look like
outputs:
211025e0-dd3e-11ec-b7c0-993e284ab2dc:
hosts:
- xxxxxxxxx:5044
ssl:
certificate: |-
-----BEGIN CERTIFICATE-----
MIIDXDCCAkSgAwIBAgIVAJUSUSKS8BNbsmhY8nblVbD9kNocMA0GCSqGSIb3DQEB
CwUAMDQxMjAwBgNVBAMTKUVsYXN0aWMgQ2VydGlmaWNhdGUgVG9vbCBBdXRvZ2Vu
ZXJhdGVkIENBMB4XDTIyMDUyNjIxNDE1MVoXDTI1MDUyNTIxNDE1MVowETEPMA0G
A1UEAxMGY2xpZW50MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAp0U3
EBAB4GPLRRW/X/XU60rdTgn8G4aGfl6gKYEdgLOhmMd6StaI7AyhXsv0r/tFje2y
2LgyKYs4QFnYEe+1k8nAs5ndpLxKFG/Ac8XsKMGTPsU7XFzzFoRI1fZEQNa/R95I
v3Q3iKOa/VRZwqBD3Rzigj7/8rK8jQ/lz5Q5AyOV/r6bj38IR8/Zgu88APlU3ymR
ds8YZQyHNM9r05J4iFtjH8heOjmyoZo+31u1hwC+jXPcv8Nx1AaGpNpy7J4sQDOJ
V/XU4WBGoEaQ/WxuixKt3HVfpVJXxLbzJ0Q6u0rpliWaMrqHVAxlPjO3qNdePcGT
qhxRBRU69FgNIOZzYwIDAQABo4GHMIGEMB0GA1UdDgQWBBQcDd9qpqLD50x7yHjM
m6FT6LQRaDAfBgNVHSMEGDAWgBTde4R72qfhbJ9EqngJ31qmSJZUGDA3BgNVHREE
MDAuhwQiR3mkgiYxNjQuMTIxLjcxLjM0LmJjLmdvb2dsZXVzZXJjb250ZW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
Ug0ArMV93jT86zzS76U229AvC3PgKeEzayWYAZbo+NedmdbYHAta+A==
-----END RSA PRIVATE KEY-----
type: logstash
revision: 2
Now to check the status of the agent
# elastic-agent status
Status: HEALTHY
Message: (no message)
Applications:
* filebeat_monitoring (HEALTHY)
Running
* metricbeat_monitoring (HEALTHY)
Running
* metricbeat (HEALTHY)
Running
* filebeat (HEALTHY)
Running
and to verify in kibana
and we are alive!!!!
This will be very useful to improve the performance of large amount of elastic agents sending events to Elasticsearch directly which could overwhelm the ES cluster. Good to know this new feature, thanks for writing this up!
Hey Justin! Hope you’re well! So now that Logstash output is generally available via Fleet….how would it be possible to perform -conditional- Logstash output to different sets of Logstash servers? For instance, if I tagged a bunch of registered agent client systems, I would like to have clients tagged with a specific tag to use a specific Logstash output. I’m just now looking at this and haven’t done much research (in v8.7), and though it seems like fairly basic functionality, I don’t immediately see a way to do it….
You can create multiple outputs in fleet settings and would need to create multiple policies using different outputs and enroll specific agents onto specific outputs for the ones you want