<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mike Dunn on Medium]]></title>
        <description><![CDATA[Stories by Mike Dunn on Medium]]></description>
        <link>https://medium.com/@mikedunn-36274?source=rss-5fad607d9b70------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*7L-dz7yiJlJPd3kI.</url>
            <title>Stories by Mike Dunn on Medium</title>
            <link>https://medium.com/@mikedunn-36274?source=rss-5fad607d9b70------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 12:19:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mikedunn-36274/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Using Open Policy Agent with Envoy]]></title>
            <link>https://mikedunn-36274.medium.com/using-open-policy-agent-with-envoy-41648200fe65?source=rss-5fad607d9b70------2</link>
            <guid isPermaLink="false">https://medium.com/p/41648200fe65</guid>
            <category><![CDATA[open-policy-agent]]></category>
            <category><![CDATA[envoy-proxy]]></category>
            <dc:creator><![CDATA[Mike Dunn]]></dc:creator>
            <pubDate>Tue, 01 Sep 2020 21:34:13 GMT</pubDate>
            <atom:updated>2021-06-21T23:43:12.578Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BUwn6IkGHe-lJ9a6.jpg" /></figure><h3>Photo by <a href="https://unsplash.com/@kutanural?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Kutan Ural</a> on <a href="https://unsplash.com/s/photos/guard-door?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></h3><p>This is the 3rd Envoy &amp; Open Policy Agent Getting Started Guide. Each guide is intended to explore a single feature and walk through a simple implementation. Each guide builds on the concepts explored in the previous guide with the end goal of building a very powerful authorization service by the end of the series.</p><p>All of the source code for this getting started example is located on GitHub. → <a href="https://github.com/helpfulBadger/envoy_getting_started/tree/master/03_opa_integration">Envoy &amp; OPA GS # 3</a></p><h3>Envoy’s External Authorization API</h3><p>Envoy has the capability to call out to an external authorization service. There are 2 protocols supported. The authorization service can be either a RESTful API endpoint or using Envoy’s new gRPC protocol. Envoy sends all of the request details to the authorization service including the method, URI, parameters, headers, and request body. The authorization service simply needs to return 200 OK to permit the request to go through.</p><p>In this example we will be using a pre-built Open Policy Agent container that already understands Envoy’s authorization protocol.</p><h3>Open Policy Agent Overview</h3><p>The Open Policy Agent site describes it very succinctly.</p><blockquote>The <a href="https://www.openpolicyagent.org/">Open Policy Agent (OPA)</a> is an open source, general-purpose policy engine. OPA provides a declarative language that lets you specify policy as code and APIs to offload policy decision-making from your software. OPA to enforce policies in micro-services, Kubernetes, CI/CD pipelines, API gateways, or nearly any other software.</blockquote><p>OPA focuses exclusively on making policy decisions and not on policy enforcement. OPA pairs with Envoy for policy enforcement. OPA can run as:</p><ul><li>A standalone service accessible via an API</li><li>A library that can be compiled into your code</li></ul><p>It has an extremely flexible programming model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MTdgw2PJ68Pu3wvJ.png" /></figure><p>Additionally, the company behind OPA, Styra, offers control plane products to author policies and manage a fleet of OPA instances.</p><p>OPA decouples policy decision-making from policy enforcement. When your software needs to make policy decisions it queries OPA and supplies structured data (e.g., JSON) as input. OPA will accept arbitrary structured data as input.</p><p>OPA generates policy decisions by evaluating the query input against policies and data. OPA expresses policies in a language called Rego. OPA has exploded in popularity and has become a Cloud Native Computing Foundation incubating project. Typical use cases are deciding:</p><ul><li>Which users can access which resources</li><li>Which subnets egress traffic is allowed</li><li>Which clusters a workload can be deployed to</li><li>Which registries binaries can be downloaded from</li><li>Which OS capabilities a container can execute with</li><li>The time of day the system can be accessed</li></ul><p>Policy decisions are not limited to simple yes/no or allow/deny answers. Policies can generate any arbitrary structured data as output.</p><p>This getting started example is based on and expands <a href="https://www.openpolicyagent.org/docs/latest/envoy-authorization/">the official envoy OPA example</a>. For simplicity, this article uses docker-compose instead of Kubernetes.</p><h3>SOLUTION OVERVIEW</h3><p>In this article, we take the super simple envoy environment that was created in the article, “Using Envoy as a Front Proxy” and adds the simplest possible authorization rule using Open Policy Agent.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EXEIYJOXmH1aP3ZwuLUrWw.png" /></figure><h3>Docker Compose</h3><p>The starting point is the docker compose file used in the “Using Envoy as a Front Proxy” article. There are a few modifications.</p><p>Line 15 in the docker-compose file, adds a reference to the Open Policy Agent container. This is a special version of the Open Policy Agent containers published on DockerHub. This version is designed to integrate with Envoy and has an API exposed that complies with Envoy’s gRPC specification.</p><p>There are also some differences in the configuration file to make note of in the highlighted section of the image below:</p><ul><li>Debug level logging is set on line 21</li><li>The gRPC service for Envoy is configured on line 23</li><li>The logs are sent to the console for a log aggregation solution to pickup on line 24</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pwIXtP5ukGNQXy6U.png" /><figcaption>docker-compose file</figcaption></figure><h3>ENVOY CONFIG CHANGES</h3><p>The envoy configuration file is shown below. There are a few things that were added to the configuration to enable external authorization:</p><ul><li>The external authorization filter is added at line 23.</li><li>The failure_mode_allow property on line 26 determines whether envoy fails open or closed when the authorization service fails.</li><li>The with_request_body property determines if the request body is sent to the authorization service.</li><li>The max_request_bytes property determines how large of a request body Envoy will permit.</li><li>The allow_partial_message property determines if a partial body is sent or not when a buffer maximum is reached.</li><li>The grpc_service object on line 30 specifies how to reach the Open Policy Agent endpoint to make an authorization decision.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YBHDgvkksCE_3GDo.png" /><figcaption>envoy configuration file</figcaption></figure><h3>Rego: OPA’s Policy Language</h3><p>There are a lot of examples of how to write Rego policies on other sites. Rego is covered in this walkthrough to extent required to show how to use it in making Envoy authorization decisions:</p><p><strong>Line 1: </strong>The package statement on the first line determines where the policy is loaded into OPA. When an application requests a policy decision from OPA, the package name is used as the prefix to locate the named decision.</p><p><strong>Line 3: </strong>The import statement on line 3 assigns a much shorter alias to the heavily nested data structure that Envoy sends OPA. The alias is used in the rest of the Rego policy.</p><p><strong>Line 5:</strong> The default keyword, sets the value returned for a rule in case no other rule explicitly defines the result. This line declares that there is a rule and gives it the name allow. It also assigns a default value for the rule. The data structure shown is defined in the API contract for Envoy’s Authorization API. The</p><p>Envoy contract specifies the following properties:</p><ul><li>The allowed property determines if the request is permitted to go through or not.</li><li>The headers property allows us to set headers on either the forwarded request (if approved) or on the rejected request (if denied). OPA does not marshal any Rego data types to a string on your behalf. Therefore all header values must be specified as a string.</li><li>The body property can be used to communicate authorization error details to the requestor. It does NOT override the request body sent upstream for approved requests. OPA does not marshal any Rego data types to a string on your behalf. So, the body value must be specified as a string.</li><li>The http_status property can be set on any rejected requests to any value as desired.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*baFy89-bIix_BYns.png" /><figcaption>Rego Policy file</figcaption></figure><p>The last section starts at line 12. It defines the logic for approving the request.</p><ul><li><strong>Line 12:</strong> Defines an authorization rule. It is given the name allow. Its result is defined as equal to the variable named response. The variable response is defined in the body of the rule on line 14.</li><li><strong>Line 13 </strong>is a logical expression. If the variable http_request.method equals POST then the result of the expression is true.</li><li><strong>Line 14</strong> assigns the object defined on lines 15 and 16 to the variable named response.</li></ul><p>If the execution of every expression in the body of the rule is true, then the value of the response variable is assigned as result of the allow rule. Since this is there are no other rules to execute in our policy, then this result is sent back to Envoy as the authorization decision.</p><h3>Envoy asks OPA for an Authorization Decision</h3><p>Below is an example of an authorization request sent from envoy.</p><p>The request sent from Envoy is a JSON object that is heavily nested and very deep. Let’s dive into the details of the data structure.</p><p><strong>Line 3</strong> is an object called destination. This is where Envoy will send the request if it is authorized. The destination object contains both the IP address and port where the request is going.</p><p>If approved, <strong>line 10</strong> has a complete copy of the request object that will be sent to the destination. This is included so that it can be taken into account for the authorization decision. The body is present and encoded as a string. Other information about the request is included as well:</p><ul><li>request headers</li><li>hostname where the original request was sent</li><li>a unique request ID assigned by Envoy</li><li>request method</li><li>unparsed path</li><li>protocol</li><li>request size</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Lbqu8DC7skqp4TEk.png" /><figcaption>Request Object for an Authorization Decision</figcaption></figure><p><strong>Line 34</strong> is an object that describes where the request came from. It contains the IP address and port where the request originated.</p><p><strong>Line 45</strong> contains the results of Envoy’s processing of the request. If Envoy was able to parse the body, it is included here as JSON. The developer has the option to configure whether the body is forwarded or not.</p><p><strong>Line 46 and 47</strong> contains the results of Envoy’s analysis of the request path and query parameters respectively.</p><p>Finally, <strong>line 48</strong> communicates whether the complete request body is present or not. There are a couple of reasons that the entire request body might not be present. One reason is if Envoy’s request buffer was exceeded. The size of the request buffer is defined in the Envoy configuration file. Another reason that the body may be truncated is if chunked encoding is used and all chunks have not be received yet.</p><h3>Reviewing the Request Flow in Envoy’s Logs</h3><p>In debug mode, there is a lot of information that Envoy logs to help determine what may be going wrong as we develop our system. Below is an example screen shot of envoy logs.</p><ul><li><strong>Line 1</strong> shows the connection request first coming in</li><li><strong>Lines 4 through 12 </strong>shows the request headers that envoy received</li><li><strong>Line 13 through 14</strong> indicates that envoy is buffering the request until it reaches the buffer limit that is set in the configuration file</li><li><strong>Line 16–20</strong> shows that Envoy forwarded the request to the authorization service and got an approval to forward the request</li><li>The remainder of the logs show envoy forwarding the request to its destination and then forwarding the response back to the originating client</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zaxoFccpN-paPNoC.png" /><figcaption>Envoy log file</figcaption></figure><h3>Reviewing OPA’s Decision Log</h3><p>The open policy agent decision logs include the input that we just reviewed and some other information that we can use for debugging, troubleshooting or audit logging. The interesting parts that we haven’t reviewed yet include:</p><ul><li>The decision ID on <strong>line 2</strong> can be matched against other OPA log entries to find other log lines that are related to this decision</li><li><strong>Line 4, </strong>the attributes property contains the full authorization request that OPA received from Envoy</li><li><strong>Line 37</strong> has the labels that describe the specific envoy instance the authorization request came from</li><li><strong>Line 42</strong> is an object that describe how long OPA took to make the decision</li><li><strong>Line 50 </strong>shows the response that OPA sent back to Envoy</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iB_OljMORNDUjLVb.png" /><figcaption>OPA Decision Log File</figcaption></figure><h3>Taking the Example Solution for a Spin</h3><p>You can see all of the above working on your own local machine. With docker installed and configured properly, clone the example repository and run the example by executing the script ./demonstrate_opa_integration.sh</p><ol><li>The script starts several containers. It starts the envoy front proxy, HTTPBIN and Open Policy Agent.</li><li>Next the script prints out the docker container status to allow the user to make sure everything is up and running.</li><li>Curl is used to issue a request. The request sent should be valid. It should be approved, forwarded to HTTPBin instance and the script should display the results.</li><li>The OPA decision logs are sent to the terminal screen to let user explore the information available for development debugging and troubleshooting.</li><li>The script also has a test case that shows an un-authorized request. The next request should fail the simple authorization rule check.</li><li>The user can inspect the decision logs to see how they differ from the authorized transaction use case.</li><li>Finally the example is brought down and cleaned up.</li></ol><p>In the next getting started guide we will explore Open Policy Agent’s command line interface and unit testing support.</p><p><em>Originally published at </em><a href="https://helpfulbadger.github.io/blog/envoy_opa_3_adding_open_policy_agent/"><em>https://helpfulbadger.github.io</em></a><em> on September 1, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41648200fe65" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Observability Tools with Envoy]]></title>
            <link>https://mikedunn-36274.medium.com/using-observability-tools-with-envoy-c60c6e9bc2c9?source=rss-5fad607d9b70------2</link>
            <guid isPermaLink="false">https://medium.com/p/c60c6e9bc2c9</guid>
            <category><![CDATA[fluentbit]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <category><![CDATA[kibana]]></category>
            <category><![CDATA[envoy-proxy]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Mike Dunn]]></dc:creator>
            <pubDate>Tue, 01 Sep 2020 19:59:54 GMT</pubDate>
            <atom:updated>2021-06-22T01:05:11.008Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h5wXDTZMYJ8h1jpL.jpg" /></figure><h4>Photo by <a href="https://unsplash.com/@alexeckermann?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Alex Eckermann</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></h4><p>This is the 2nd Envoy &amp; Open Policy Agent (OPA) Getting Started Guide. Each guide is intended to explore a single Envoy or OPA feature and walk through a simple implementation. Each guide builds on the concepts explored in the previous guide with the goal of creating a very powerful authorization service by the end of the series.</p><p>While our solution is still very simple, it is a great time to show how to make our solution observable with log aggregation. This makes it easier to think about how to scale and productionize our solution. As we start to develop and apply authorization rules at scale it will be handy to have all of the logs aggregated and displayed in one place for development and troubleshooting activities. In this article we will walk through how to setup the ElasticSearch FluentBit, Kibana (EFK) stack to pull your logs together from all of the docker containers in your local development environment.</p><p>All of the source code for this getting started example is located on GitHub. → <a href="https://github.com/helpfulBadger/envoy_getting_started/tree/master/02_front_proxy_kibana">Envoy &amp; OPA GS # 2</a></p><h3>SOLUTION OVERVIEW</h3><p>The solution that we will build in this blog is shown below. We will send docker logs into an EFK stack that is also running inside docker. Each of the containers in our solution simply send logs to Standard out and / or Standard Error. No agents nor other special software is requirements are imposed on the observed applications.</p><figure><img alt="A picture of the EFK stack running inside docker on a local machine and accessible from both a web browser and the command line in a terminal" src="https://cdn-images-1.medium.com/max/1024/1*1rBqjff81hpSHrdwpVg8Ug.png" /></figure><h3>Adding EFK containers</h3><p>We will be using Fluent Bit in this example because it is lite weight and simpler than Logstash or full fledged FluentD. Below is a very basic configuration with no special optimizations. Lines 18 through 49 add the EFK stack to our environment. Lines 16 and 47 begin the configuration of the Fluent Bit and Kibana containers. The depends_on property tells docker to start ElasticSearch first and then Kibana and Fluent Bit once it is ready.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/0*0qIXcBzGPc1mIRWg.png" /></figure><h3>Wiring our containers into EFK</h3><p>With the EFK log aggregation containers added to our docker-compose file, we now need to wire them together with the other containers in our environment. The changes below show a couple of small changes that we needed to make to our compose file. The picture shows the changes we are making from where we left off in Getting Started Guide #1, Using Envoy as a Front Proxy.</p><ul><li>The depends_on property at line 14 in the picture below declares that the Envoy container depends on ElasticSearch and FluentBit.</li><li>Additionally, we need to direct standard out and standard error from our containers to Fluent Bit. This is done through the logging properties that were added on lines 17 and 27 of the updated configuration file.</li><li>The driver line tells docker which log driver to use and the tag describes more clearly which container is the source of the logs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/0*VE8OxfKemFM0sIK2.png" /></figure><h3>TAKING THINGS FOR A SPIN</h3><p>The demonstration script spins everything up for us. Just run ./demonstrate_front_proxy.sh to get things going:</p><ol><li>The demonstration script downloads and spins up all of our containers.</li><li>Then the demonstration script waits 30 seconds to give ElasticSearch some time to get ready and some time for Kibana to know that ElasticSearch is ready.</li><li>A curl command sends Envoy a request to make sure the end-to-end flow is working.</li><li>If that worked, hit enter to proceed forward. If not, wait a bit longer to make sure ElasticSearch and Kibana are both ready.</li><li>If you are running on Mac OS X, then the next step in the script 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:</li></ol><figure><img alt="picture of the kibana screen to manage indexes" src="https://cdn-images-1.medium.com/max/1024/0*uxkYH0pqewb-aRRL.png" /></figure><p>6. I simply used log* as my index and clicked next. Which should bring up a screen to select the timestamp field name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vqw2P7eB5mCPkZhA.png" /></figure><p>7. Select timestamp from the time-filter drop down menu and click create index.</p><p>8. You should see some autogenerated field definitions about your newly created index.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3FH5m-FQU9agz1ep.png" /></figure><p>9. The script then uses the operating system’s Open command to navigate to Kibana’s 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.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lmCniqQ8Q5MRMkUR.png" /></figure><p>10. If you have an interest, you may want to select the container_name and log columns to make it easier to read through the debug logs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tD1uYwD43SXQO2SG.png" /></figure><p>11. The script sends another request through envoy. This should be visible in Kibana.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DLlLbTNFz9jPDujZ.png" /></figure><p>12. The script with then take down the environment.</p><p>The next getting started guide will add Open Policy Agent and begin experimenting with a simple authorization rule.</p><p><em>Originally published at </em><a href="https://helpfulbadger.github.io/blog/envoy_opa_2_adding_observability/"><em>https://helpfulbadger.github.io</em></a><em> on September 1, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c60c6e9bc2c9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Envoy as a Front Proxy]]></title>
            <link>https://mikedunn-36274.medium.com/using-envoy-as-a-front-proxy-65c2b66c2291?source=rss-5fad607d9b70------2</link>
            <guid isPermaLink="false">https://medium.com/p/65c2b66c2291</guid>
            <category><![CDATA[envoy-proxy]]></category>
            <category><![CDATA[sidecar-pattern]]></category>
            <category><![CDATA[forward-proxy]]></category>
            <dc:creator><![CDATA[Mike Dunn]]></dc:creator>
            <pubDate>Mon, 31 Aug 2020 17:27:14 GMT</pubDate>
            <atom:updated>2021-06-21T20:46:14.878Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wvDficOAwDHiknu4.jpg" /></figure><p>Photo by <a href="https://unsplash.com/@mattserra13?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Mattia Serrani</a> on <a href="https://unsplash.com/?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a></p><p>This is the first Envoy &amp; Open Policy Agent (OPA) Getting Started Guide. Each guide is intended to explore a single Envoy or OPA feature and walk through a simple implementation. Each guide builds on the concepts explored in the previous guide with the end goal of building a very powerful authorization service by the end of the series.</p><p>The source code for this getting started example is located on <a href="https://github.com/helpfulBadger/envoy_getting_started/tree/master/01_front_proxy">GitHub</a>.</p><h3>Overview</h3><p><a href="https://www.envoyproxy.io/">Envoy</a> is an open-source edge and service proxy that has become extremely popular as the backbone underneath most of the leading service mesh products (both open-source and commercial). This article is intended to demystify it a bit and help people understand how to use it on its own in a minimalist fashion.</p><p>Envoy is just like any other proxy. It receives requests and forwards them to services that are located behind it. The 2 ways to deploy Envoy are:</p><ol><li><strong>Front Proxy</strong></li></ol><figure><img alt="Picture of a cluster of envoy proxies routing traffic to 3 clusters of different services behind it" src="https://cdn-images-1.medium.com/max/1024/0*mpJnrduEhzO8vcDk.png" /></figure><p>In a front proxy deployment Envoy is very similar to NGINX, HAProxy, or an Apache web server. The Envoy server has its own IP address and is a separate server on the network from the services that it protects. Traffic comes in and get forwarded to a number of different services that are located behind it. Envoy supports a variety of methods for making routing decisions.</p><p><strong>Path based routing:</strong> One mechanism is to use path-based routing to determine the service of interest. For instance, a couple of requests coming in as:</p><p>someserver.com/service1/some/other/stuff</p><p>someserver.com/service2/my/application/path</p><p>The first URI path element can be used as a routing key. /service1/ can be used to route requests to service 1. Additionally, /service2/ can be used to route the request to a set of servers that support service 2. The path can be rewritten as it goes through Envoy to trim off the routing prefix (e.g., /service1/).</p><p><strong>Server Name Indication (SNI): </strong>Another mechanism is to use Server Name Indication (SNI) which is a TLS extension that can be used to determine where to forward a request.</p><p>service1.com/some/other/stuff</p><p>service2.com/my/application/path</p><p>Using this technique, the first URL above would use the server name service1.com/ to route the request to the upstream servers for service1. Additionally, the first part of the URL for the 2nd request would use service2.com/ to route the request to the upstream servers for service2.</p><p><strong>2. Sidecar Proxy</strong></p><figure><img alt="picture of several services that can only be reached by going through an envoy proxy" src="https://cdn-images-1.medium.com/max/1024/0*oM6Hn1r5Fyyf8Mgz.png" /></figure><p>In a sidecar deployment, the Envoy server is located at the same IP address as the service that it protects. The Envoy server when deployed as a sidecar only has a single instance of a service behind it. The sidecar approach can intercept all inbound traffic and optionally all outbound traffic on behalf of the service. <a href="https://en.wikipedia.org/wiki/Iptables">IP Tables</a> rules are typically used to configure the operating system to capture and redirect this traffic to Envoy.</p><p>In this article and example project, we will create the simplest possible Envoy deployment. This example just uses docker compose to show how to get Envoy up and running. There will be a number of subsequent articles that expand on this simple approach to demonstrate more Envoy capabilities. Later in the series, Open Policy Agent will also be introduced to handle more complex authorization use cases that cannot be handled by Envoy alone.</p><p>The diagram below shows the environment that will be built and deploy locally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*M5NRpxU6EjLWVjub.png" /></figure><h3>Building an Envoy Front Proxy</h3><p>The <a href="https://github.com/helpfulBadger/envoy_getting_started/tree/master/01_front_proxy">code for the complete working example</a> can be found on Github. The Envoy container images are specified on line 1. The Envoy images are pulled from D<a href="https://hub.docker.com/r/envoyproxy/envoy/tags">ocker hub</a>. Docker-compose ensures that local setup dependencies are minimal. It also allows us to configure some envoy behavior through environment variables.</p><p><strong>The Dockerfile</strong></p><figure><img alt="picture of the Dockerfile that creates the envoy instance" src="https://cdn-images-1.medium.com/max/1024/0*i7lIN5dUgglL0bkf.png" /></figure><p>In the Dockerfile, a custom image is created based on the official envoy container images. A custom bash script acts as the entry point when the container runs. The entrypoint.sh file is where the magic happens.</p><p><strong>Entrypoint.sh</strong></p><p>Looking at the entrypoint.sh bash script below, you can see that environment variables are used to determine which service (SERVICE_NAME) Envoy will route to and the port (SERVICE_PORT) required for that service. Additionally, the amount of detail to capture in the logs is determined by the DEBUG_LEVEL environment variable. As you can see from the script below on line 3, sed replaces those environment variables in Envoy’s configuration file before starting Envoy.</p><figure><img alt="picture of the entry point dot sh script file that runs when the container starts." src="https://cdn-images-1.medium.com/max/1024/0*td5Jp3it9Zdcle2Z.png" /></figure><p><strong>Envoy Configuration (via envoy.yaml)</strong></p><p>There is no configuration file yet. So, we will create that next. Envoy is very flexible and powerful. There is an enormous amount of expressiveness that the Envoy API and its configuration files support. With this flexibility and power, Envoy configuration files can become quite complicated with deep nesting of configuration sections in the YAML hierarchy. Additionally, each feature has a lot of parameters available. The documentation can only cover so much of that functionality with an open-source community of volunteers.</p><p>One of the challenges that I have when reading through the documentation and trying to apply it, is that the documentation has a variety of YAML snippets. There are very few places that these YAML snippets are pulled together into a functioning example. There are a few examples in the source code examples directory but they are far from comprehensive. That leaves a lot of tinkering for engineers to figure out how to compose a functional configuration while interpreting sometimes unclear error messages. That is the reason that I am writing a series of getting started guides. These articles are intended to give folks a known-to-work starting point for Envoy authorization features and extensions like Open Policy Agent.</p><p>The Envoy configuration (shown below) starts with defining a listener on line 2. The listener’s first property is the address and port to accept traffic on (lines 3 through 6). The next property is a filter chain. Filter chains are very powerful and enable a wide variety of possible behaviors. The filter chain in the example is as simple as it gets. It accepts any HTTP traffic with any URI pattern and routes it to the cluster named service.</p><p>The http_connection_manager component does this for us. It’s configuration starts on line 9 and extends to line 24. Execution order of each filter is determined by the order they are listed in the configuration file. The important part for this discussion begins on line 14 with the route_config. This sets up routing requests for any domain (line 18) and any request URI that begins with a slash (line 20) to go to the cluster named service. The cluster definitions are in a separate section to make them reusable destination across a variety of rules. rules.</p><figure><img alt="picture of the envoy configuration file" src="https://cdn-images-1.medium.com/max/1024/0*xs_ORdD2DvbeZuoQ.png" /></figure><p>In the configuration file above, the cluster definitions begin on line 25. You can see that there is only a single cluster defined. It has the name service. Envoy uses DNS to find server instances and uses round robin to direct traffic across multiple instances. The hostname is on line 32 and the port is on line 33. These are the environment variables that will be replaced when the entry.sh script runs.</p><p>The last section of the configuration file tells Envoy where to listen for admin traffic. The admin GUI is a handy little tool that is not covered in this guide. It is definitely worth poking around in to observe what is going on inside an individual Envoy instance.</p><p><strong>Docker Compose Configuration</strong></p><p>Now that we understand the Envoy configuration, let’s move on to understanding the rest of the simple environment. Line 4, in the configuration file show below, triggers docker to build the custom Envoy image. Docker will only build the custom Envoy image the first time (when it sees that an image does not exist). If you want to force rebuilding the Envoy container on subsequent runs add the --build parameter to your docker compose command. Envoy is exposed to the host network on lines 6 and 7. The envoy configuration file created in the previous step of this article is specified on line 9.</p><figure><img alt="picture of the docker compose configuration file" src="https://cdn-images-1.medium.com/max/1024/0*ODTBKFDBlJJKXCzm.png" /></figure><p>The upstream service name and the service’s port are defined in the environment variables on lines 12 and 13. Notice that the service name ‘<strong><em>app’</em></strong> matches the name of the container created by the configuration starting at line 15. This example uses HTTPBIN to reflect any inbound request back to client.</p><p><strong>Running The Example</strong></p><p>The last step to getting our front proxy up is running the included script. The test.sh script builds and runs example. The script explains what it is about to do. This ensures you know what you are about to see scrolling across the terminal screen.</p><ul><li>Line 3 starts the environment.</li><li>Line 8 lets you check to make sure both containers are running before trying to send a request.</li><li>Line 10 simply calls Envoy using a curl command with the --verbose parameter to show the headers and request details.</li><li>Line 12 tears down the whole environment.</li></ul><figure><img alt="picture of the demo script that shows the working example" src="https://cdn-images-1.medium.com/max/1024/0*pSxB2eKrTuQoimS9.png" /></figure><p><strong>Results</strong></p><p>After you run the test.sh script, you should see something like this if everything works correctly:</p><figure><img alt="screen shot of the results the test script prints." src="https://cdn-images-1.medium.com/max/1024/0*A2iQ4_fadtizeo1X.png" /></figure><p>😊 Congratulations!!! You have successfully stood up your first Envoy instance and configured it to forward traffic! This is the simplest possible Envoy configuration. It doesn’t have any security configured yet or any other features that Envoy is famous for. Those will be covered in future articles. Feel free to explore further by using <a href="https://www.postman.com/">postman</a> to send other requests to envoy. Additionally, don’t forget to try Envoy’s admin console by pointing your web browser to <a href="http://localhost:8001/">http://localhost:8001</a></p><p><em>Originally published at </em><a href="https://helpfulbadger.github.io/blog/envoy_opa_1_front_proxy/"><em>https://helpfulbadger.github.io</em></a><em> on August 31, 2020.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65c2b66c2291" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>