Standing Up the Elastic SIEM with Docker Compose

Standing Up the Elastic SIEM with Docker Compose

Building a single-node Elasticsearch, Kibana and Fleet Server stack on Debian with TLS everywhere, and untangling the four things that kept it from starting.

Endpoints are great, but without somewhere to send their logs, they’re just talking to themselves.

Every SOC has a SIEM at the center of it. It’s where the logs from every endpoint, server and firewall end up, and it’s where the detections run. For this lab, that’s Elastic: Elasticsearch to store everything, Kibana to search it, and Fleet Server to manage the agents that ship the data in.

I wanted two things out of this build. First, the whole stack should live in one docker-compose.yml in the repo, so if elk01 ever dies I can rebuild it from Git plus one .env file. Second, it should be locked down properly. The SIEM holds every other system’s logs, and every agent in the lab is going to trust its certificate authority. If anything in this lab deserves to be built carefully, it’s this box.

Elastic’s reference compose file gets you most of the way there. Getting it the rest of the way took a few more tries than I expected.

Why Fleet and Elastic Agent?

The older way to get logs into Elastic is Beats: Winlogbeat for Windows event logs, Filebeat for files, Auditbeat for audit data, each installed and configured separately on every host. That gets old fast.

Elastic Agent replaces all of that with one agent per host, and Fleet lets me manage every agent’s policy centrally from Kibana. It’s also where Elastic is putting its effort. A lot of what I have planned for this lab (Elastic Defend on Linux, Defender XDR, M365, threat intel feeds) ships as Agent integrations. Beats still work, but new integrations target Agent, so that’s what we’re going with.

Environment Overview

  • elk01: Debian 13.7 netinst with only the SSH server and standard utilities. No desktop, nothing extra. Less installed means less to attack.
  • 4 vCPU / 6 GB RAM / 150 GB disk: With memory ballooning turned off. Elasticsearch sizes its Java heap when it starts, and ballooning would let Proxmox take that memory back out from under it.
  • Servers VLAN (20): Static DHCP reservation and a local DNS record, so endpoints reach it by name. That name matters later, because it’s baked into the TLS certificates.
  • Elastic 9.1.0, Basic license: The free tier covers the SIEM, detection rules and Fleet, which is everything this lab needs.
  • Docker Engine 26+: Needed for read-only volume subpath mounts. More on why in a second.

The 6 GB gets split up as roughly 3 GB for Elasticsearch (2 GB heap), 1 GB for Kibana, and the rest for Fleet Server and the OS.

NOTE: The firewall has to let this traffic through. On OPNsense, the Endpoints and Atomic Red VLANs can reach elk01 on TCP 8220 (Fleet) and 9200 (Elasticsearch), and only my admin PC and the VPN get 5601 (Kibana) and 22 (SSH). The Servers VLAN itself only gets DNS, NTP and outbound HTTP/HTTPS for package mirrors and image registries.

Part 1: Designing for a compromised container

Before writing any YAML, I asked myself: if one of these containers got popped, what could the attacker reach? Most of the design falls out of that question.

ControlHowWhat it stops
TLS everywhereElasticsearch, Kibana and Fleet Server all serve HTTPS from a lab CA, and every client verifies itSniffing credentials or impersonating a service on the wire
CA key isolationca.key lives in a volume that only the one-shot certs job mounts; setup zips are deleted after extractionA compromised Kibana minting certs that every agent would trust
Least-privilege cert mountsEach service mounts only ca.crt and its own cert and key, read-only (640 files, 750 dirs, root:root)One service reading another’s private key
No superuser in Fleet ServerA scoped elastic/fleet-server service token, written to a volume only Fleet Server mountsThe elastic password sitting in a long-running container’s environment
Agents pin the CAThe Fleet output carries the CA’s SHA-256 fingerprintAgents shipping logs to an impostor Elasticsearch
Retention limitsILM deletes logs after 30 days and metrics after 14The disk filling up and ingestion grinding to a halt

The CA key one is the one I care about most. Every agent in the lab trusts that CA. If the key leaked, an attacker could issue a certificate for anything and the whole lab would believe it. So it only ever exists inside a container that runs once, does its job, and exits.

Part 2: Build the stack

Prep the host

Install Docker and raise the memory-map limit Elasticsearch needs to start:

curl -fsSL https://get.docker.com | sudo sh
echo 'vm.max_map_count=262144' | sudo tee /etc/sysctl.d/99-elasticsearch.conf && sudo sysctl --system

Then copy the elk/ folder from the repo to /opt/elk and create .env from .env.example. That’s where the passwords, an ENCRYPTION_KEY (openssl rand -hex 32), and ELK_FQDN/ELK_IP go. Get the FQDN right. It ends up in the certificates, and I’ll show you what happens when it’s wrong.

Bring it up

docker compose config -q && docker compose up -d

That one command kicks off a chain of containers, each waiting on the one before it:

  1. certs (runs once) creates the CA and a cert for each service, then locks down the permissions.
  2. es01 starts Elasticsearch on 9200.
  3. setup (runs once, after Elasticsearch is healthy) sets the kibana_system password and creates Fleet Server’s service token.
  4. kibana starts on 5601 with a kibana.yml that preconfigures the Fleet Server policy.
  5. fleet-server starts once Kibana is healthy and listens on 8220.

When it all works, docker compose ps -a looks like this: the two one-shot jobs exited cleanly, and everything else is up and healthy.

docker compose ps -a output showing certs and setup exited 0, es01 and kibana healthy, fleet-server up Two jobs done, three services running.

Point Fleet at Elasticsearch

Last step: tell Fleet where agents should send their data. Pull the CA’s fingerprint out of the container:

docker compose cp es01:/usr/share/elasticsearch/config/certs/ca/ca.crt .
openssl x509 -fingerprint -sha256 -noout -in ca.crt | cut -d= -f2 | tr -d :

Then in Kibana under Fleet → Settings → Outputs, set the default output to https://<ELK_FQDN>:9200 and paste in the fingerprint.

Fleet output settings with the Elasticsearch host and CA fingerprint redacted Every agent will pin this CA before it sends a single log.

Finally, apply the retention policies (lab-logs and lab-metrics) from the repo’s elk/ilm/ folder in Dev Tools.

Part 3: Everything that went wrong

That’s the clean version. Here’s how it actually went.

Problem 1: Kibana stuck on “starting” forever

Kibana was clearly running. I could see logins succeeding in its log. But Docker kept it at health: starting, so Fleet Server never started.

The culprit was the health check. It was grepping for HTTP/1.1 302 Found, but Kibana 9 negotiates HTTP/2 when TLS is on and answers with HTTP/2 302. Same response, different version string, so the check never passed.

The fix was to match either version:

grep -qE '^HTTP/[0-9.]+ 302'

Problem 2: It only worked the first time

The first docker compose up was fine. Every one after that failed with:

container elk-setup-1 exited (0)
dependency failed to start

Exited with code 0 means it succeeded, so why is that a failure? Elastic’s reference compose makes Elasticsearch wait for the setup container to be healthy. That works while setup is still running. Once it exits, Docker will never call it healthy again, so on every restart Elasticsearch is waiting on something that can’t happen.

I split setup into two one-shot jobs, certs before Elasticsearch and setup after it, and had everything that depends on them wait on service_completed_successfully instead of healthy. A job that’s finished is finished, and Docker now understands that.

Problem 3: Fleet Server waiting on a policy that never showed up

Fleet Server came up and then just sat there logging:

Waiting on default policy with Fleet Server integration

Turns out recent versions of Kibana no longer create a Fleet Server policy for you, so the agent was waiting for something nobody was ever going to make.

The fix is a kibana.yml that preconfigures Fleet: a fleet-server-policy with the fleet_server package, plus the Fleet Server host URL. The Fleet Server container then enrolls straight into it with FLEET_SERVER_POLICY_ID.

This file gets mounted over Kibana’s default config, not merged with it. So it also has to repeat server.host: "0.0.0.0", or Kibana only listens inside its own container.

Problem 4: Certs for the wrong hostname

Remember when I said to get the FQDN right? I didn’t. ELK_FQDN didn’t match the record actually published in my local DNS, so every cert was issued for a name nobody would use. Agents connecting by the real name would fail TLS hostname verification.

The nice part is how cheap this was to fix. I corrected ELK_FQDN, deleted only the service certs, and reran certs. Because the CA itself was kept, the fingerprint I’d already put into Fleet stayed valid. Nothing downstream had to change.

Part 4: Verify

  • Done: docker compose ps -a shows certs and setup exited 0, es01 and kibana healthy, and fleet-server running.
  • Done: Fleet shows one healthy Fleet Server.
  • Done: Kibana loads over HTTPS by FQDN from my admin PC.
  • Done: docker compose exec kibana ls config/certs/ca lists only ca.crt. No CA key anywhere near Kibana.
  • Done: GET _security/service/elastic/fleet-server/credential lists only the one compose token.
  • Done: GET _ilm/policy/lab-logs returns the retention policy.

Fleet agents list showing fleet-server on Fleet Server Policy, Healthy, version 9.1.0 One Fleet Server, healthy and waiting for agents.

Loose ends

It runs, and it’s locked down about as well as a single box can be. But there’s still a list:

  • Single node. No replicas, so a dead disk means lost data. Fine for a lab, but snapshots to another host are the obvious next step.
  • Retention is a guess. 30 days of logs and 14 of metrics is a placeholder until I know real ingest rates. I’ll check GET _cat/allocation?v weekly and adjust.
  • Self-signed CA. Browsers and agents only trust it after ca.crt is imported. Once AD CS is up on dc01, that could take over.
  • Secrets in container environments. The Elastic and Kibana passwords and the encryption key are visible to anyone with Docker access on elk01. That’s already root-equivalent, so it’s an accepted risk, but it’s still on the list.
  • Manual deploy. Files get to the VM over scp, which means the VM can drift from the repo. A git pull on the box, or Ansible, would fix that.
  • No firewall logs yet. OPNsense isn’t forwarding anything to the SIEM yet. That’s coming with the log-shipping work.

Wrapping up

The SOC finally has a brain. Elasticsearch is storing, Kibana is searching, and Fleet Server is sitting there ready to hand out policies, all over TLS, all rebuildable from the repo.

The one thing it doesn’t have yet is data. Next up is enrolling the first Elastic Agent on win11-01 and getting real Windows telemetry flowing into the stack.