The Simplest Way to Make Elasticsearch and Traefik Work Like They Should
Running elasticsearch and traefik together lets you route traffic to search nodes while storing router logs. Traefik directs incoming network calls to backend search endpoints, and Elasticsearch stores those request records for fast queries. Teams use this pair for two distinct tasks in production. First, Traefik sits in front of the search cluster to manage TLS and balance incoming requests. Second, Traefik exports its own request logs and metrics to the search cluster for analysis. Both paths
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
Running elasticsearch and traefik together lets you route traffic to search nodes while storing router logs. Traefik directs incoming network calls to backend search endpoints, and Elasticsearch stores those request records for fast queries.
Teams use this pair for two distinct tasks in production. First, Traefik sits in front of the search cluster to manage TLS and balance incoming requests. Second, Traefik exports its own request logs and metrics to the search cluster for analysis. Both paths need strict access rules and clear network routing.
How traffic and logins flow between elasticsearch and traefik
When a user or app sends a search query, Traefik receives the request first. It checks the host rules, handles TLS encryption, and forwards the call to a healthy search node. You can also add basic auth or forward auth in Traefik to check user identity before passing the request along.
Once the request reaches the search cluster, internal role rules take over. The search engine checks the API key or token attached to the request header. It then allows or blocks the query based on index permissions.
Data also flows in the other direction for log storage. Traefik creates a JSON record for every incoming web request it handles. A log collector reads those records and writes them into a dedicated index inside the search cluster. Engineers then query those indices to check response times, status codes, and error rates.
Common failure modes and how to scope roles
The biggest risk with this setup is exposing the search cluster with overly broad rules. Many teams put Traefik in front of their search nodes without requiring user login on the route. Anyone who reaches that network path can then run heavy queries or delete indices.
Shared API keys create another common failure mode. Teams often generate one admin key for log shippers and app services alike. If that single key leaks, an attacker gains full write and delete rights across every index. When everyone shares one account, the audit log cannot show which person ran a destructive command.
Elasticsearch Security + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Unfiltered log shipping can also leak private data into your search indices. Request URLs and headers sometimes hold emails, phone numbers, card numbers, or national IDs. If you store raw router logs without a filter, those fields land in plain text inside your search cluster. Data masking rewrites matched fields in results so sensitive values do not spill into broad search queries.
To fix these issues, split your traffic paths and scope every role down to the minimum needed. Create a write-only role for your log shipper so it can only add records to daily log indices. Give each app its own read role restricted to specific index patterns. Never expose cluster management routes on public entry points.
Keeping search queries and routing rules secure
Good network boundaries make day-to-day operations much safer for your team. Keep your search nodes on a private internal network that only accepts traffic from your router nodes. Configure Traefik to reject requests that lack valid auth headers before they ever touch the backend cluster.
Review your index roles and routing rules on a regular schedule. Rotate the keys used by your log collectors and remove old tokens that teams no longer use. Log every search query and admin action alongside the user identity so you always have a clear audit trail.
Check database and API queries on the wire
Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.
Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.
Frequently asked questions
Can Traefik send access logs straight to Elasticsearch?
Traefik writes access logs to standard output or a local file in JSON format. You then run a lightweight log shipper to read those files and index them into your search cluster.
Should I expose Elasticsearch cluster admin routes through Traefik?
No, you should block cluster settings and node management paths on public routers. Keep admin routes on a private network and require strict user identity checks for every session.
How do I stop sensitive data from appearing in search results?
Strip sensitive headers in your router config before logging, and apply data masking on query responses. Masking rewrites matched fields like emails, phone numbers, and card numbers in results.
Related guides
In this post