This is the 2nd in a series of getting started guides for using Envoy and Open Policy Agent to authorize API requests. Later on as we start to develop authorization rules it may be handy to have all of the logs aggregated and displayed in one place for your development and troubleshooting activies. In this article we will walk through how to setup the EFK stack to pull your logs together from all of the docker containers in your local development environment.
Here is a list of the Getting Started Guides that are currently available.
- Using Envoy as a Front Proxy --- Learn how to set up Envoy as a front proxy with docker
- Adding Observability Tools --- Learn how to add ElasticSearch and Kibana to your Envoy front proxy environment
- Plugging Open Policy Agent into Envoy --- Learn how to use Open Policy Agent with Envoy for more powerful authorization rules
- Using the Open Policy Agent CLI --- Learn how to use Open Policy Agent Command Line Interface
- JWS Signature Validation with OPA --- Learn how to validate JWS signatures with Open Policy Agent
- JWS Signature Validation with Envoy --- Learn how to validate JWS signatures natively with Envoy
- Putting It All Together with Composite Authorization --- Learn how to Implement Application Specific Authorization Rules
- Configuring Envoy Logs Taps and Traces --- Learn how to configure Envoy's access logs taps for capturing full requests & responses and traces
- Sign / Verify HTTP Requests --- Learn how to use Envoy & OPA to sign and validate HTTP Requests
We will be using Fluent Bit in this example because it is lite weight and simpler to deal with than Logstash or full fledged FluentD. Below is a Dockerfile with a very basic configuration and no special optimizations. Lines 9 and 30 use the depend_on
property to cause docker to start elasticSearch first and then the other containers that depend on elasticSearch.
fluentbit:
image: fluent/fluent-bit:1.5.2
volumes:
- ./fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
restart: always
ports:
- "24224:24224"
- "24224:24224/udp"
depends_on:
- elasticsearch
# Elasticsearch Docker Images: https://www.docker.elastic.co/
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.4.2
restart: always
environment:
- "xpack.security.enabled=false"
- "discovery.type=single-node"
ports:
- "9200:9200"
- "9300:9300"
kibana:
image: docker.elastic.co/kibana/kibana:7.4.2
restart: always
environment:
- ELASTICSEARCH_HOSTS=http://elasticsearch:9200
ports:
- 5601:5601
depends_on:
- elasticsearch
With the log aggregation containers added to our docker-compose file, we now need to wire them into the other containers in our environment. The Dockerfile below shows a couple of small changes that we needed to make to our compose file from Getting Started Guide #1. We added the property at line 14 below which expresses our dependency on elasticSeach. Additionally, we need to wire standard out and standard error from our containers to fluentBit. This is done through the logging properties on lines 17 and 27. The driver line tells docker which log driver to use and the tag help make it more clear which container is the source of the logs.
version: "3.8"
services:
envoy:
build: ./compose/envoy
ports:
- "8080:80"
- "8001:8001"
volumes:
- ./envoy.yaml:/config/envoy.yaml
environment:
- DEBUG_LEVEL=debug
- SERVICE_NAME=app
- SERVICE_PORT=80
depends_on:
- fluentbit
- elasticsearch
logging:
driver: fluentd
options:
tag: envoy
app:
image: kennethreitz/httpbin:latest
depends_on:
- fluentbit
- elasticsearch
logging:
driver: fluentd
options:
tag: httpbin
The demonstration script spins everything up for us. Just run ./demonstrate_front_proxy.sh
to get things going:
- It downloads and spins up all of our containers.
- Then it waits 30 seconds to give elasticSearch some time to get ready and some time for Kibana to know that elasticSearch is ready.
- A curl command sends Envoy a request to make sure the end-to-end flow is working.
- If that worked, proceed forward. If not wait a bit longer to make sure elasticSearch and Kibana are both ready.
- If you are running on Mac OS X then the next step will open a browser and take you to the page to setup your Kibana index. If it doesn't work, simply open your browser and go to
http://localhost:5601/app/kibana#/management/kibana/index_pattern?_g=()
you should see something like this: - I simply used
log*
as my index and clicked next. Which should bring up a screen to select the timestamp field name.
Select@timestamp
and click create index. - You should see some field information about your newly created index.
- The script then uses the Open command to navigate to the log search interface. If it doesn't work on your operating system then simply navigate to
http://localhost:5601/app/kibana#/discover
. You should see something like this with some log results already coming in. - If you have an interest, you may want to select the
container_name
andlog
columns to make it easier to read through the debug logs and results of your testing efforts. - The script sends another request through envoy and you should be able to see the logs coming into EFK.
- The script with then take down the environment.
In the next getting started guide, we will add in Open Policy Agent and begin experimenting with a simple authorization rule.