<?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 Ash Narkar on Medium]]></title>
        <description><![CDATA[Stories by Ash Narkar on Medium]]></description>
        <link>https://medium.com/@ashumania?source=rss-cf2fbda690bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kz_9FAIUnXGc-C9g5R3lhg.jpeg</url>
            <title>Stories by Ash Narkar on Medium</title>
            <link>https://medium.com/@ashumania?source=rss-cf2fbda690bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 15 Nov 2026 02:54:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ashumania/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[Envoy External Authorization with OPA]]></title>
            <link>https://medium.com/open-policy-agent/envoy-external-authorization-with-opa-578213ed567c?source=rss-cf2fbda690bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/578213ed567c</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[open-policy-agent]]></category>
            <category><![CDATA[spire]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[envoy]]></category>
            <dc:creator><![CDATA[Ash Narkar]]></dc:creator>
            <pubDate>Tue, 07 May 2019 21:28:27 GMT</pubDate>
            <atom:updated>2021-03-09T18:00:40.537Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*phRLhBrIw6CQK927gXySWg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QRLypUMMFELf8pYVTE2CYQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5Rl5FxrUj5YsVQXjKoKcBA.png" /><figcaption>Envoy-OPA-SPIRE</figcaption></figure><p>Microservices improve productivity of individual development teams by breaking down applications into smaller, standalone parts. However, microservices alone do not solve age-old distributed systems problems like service discovery, authentication, and authorization. In fact, these problems are often more acute due to the heterogenous and ephemeral nature of microservice environments.</p><p>As more organizations adopt microservice architectures, the need for decoupled authentication and authorization has become apparent. This post dives into how you can leverage <a href="https://github.com/envoyproxy/envoy"><strong>Envoy</strong></a>, <a href="https://github.com/spiffe"><strong>SPIFFE/SPIRE</strong></a>, and the <a href="https://github.com/open-policy-agent/opa"><strong>Open Policy Agent</strong></a><strong> (OPA)</strong> to enforce important security policies in microservice environments.</p><h3>Background</h3><p><a href="https://www.envoyproxy.io/docs/envoy/latest/intro/what_is_envoy"><strong>Envoy</strong></a> is a L7 proxy and communication bus designed for large modern service oriented architectures. Envoy (v1.7.0+) supports an <a href="https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/security/ext_authz_filter.html">External Authorization filter</a> which calls an authorization service to check if the incoming request is authorized or not. This feature makes it possible to delegate authorization decisions to an external service and also makes the request context available to the service. The request context contains information such as the source of a network activity, destination of a network activity, the network request (eg. http request). All this information can be used by the external service to make an informed decision about the fate of the incoming request received by Envoy.</p><p><a href="https://spiffe.io/spiffe/"><strong>SPIFFE</strong></a>, the Secure Production Identity Framework for Everyone, is a set of open-source standards for securely identifying software systems in dynamic and heterogeneous environments. Systems that adopt SPIFFE can easily and reliably mutually authenticate wherever they are running. <a href="https://spiffe.io/spire/"><strong>SPIRE</strong></a> (the SPIFFE Runtime Environment) is a toolchain for establishing trust between workloads across a wide variety of platforms.</p><p>The <a href="https://www.openpolicyagent.org/docs/v0.10.7/get-started/"><strong>Open Policy Agent</strong></a><strong> (OPA)</strong> is an open source, general-purpose policy engine that enables unified, context-aware policy enforcement across the entire stack. OPA’s high-level<strong> </strong>declarative language <a href="https://www.openpolicyagent.org/docs/v0.10.7/how-do-i-write-policies/">Rego</a> allows authoring of fine-grained security policies and is purpose built for reasoning about information represented in structured documents.</p><h3>OPA as an External Authorization Service</h3><p>We will walkthrough an example of using Envoy’s <a href="https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/ext_authz_filter">External authorization filter</a> with OPA as an authorization service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XyfX8PPbOxiz-kkogIyioA.png" /><figcaption>Envoy-OPA External Authorization</figcaption></figure><p>The example consists of three services (web, backend and db) colocated with a running service Envoy. Each service uses the external authorization filter to call its respective OPA instance for checking if an incoming request is allowed or not.</p><p>The web service receives all inbound requests from api-server-1 and api-server-2 which are deployed in different subnets. The request is forwarded to the backend service which then calls the db service.</p><p>Secure communication between the web, backend and db service is established by configuring the Envoy proxies in each container to establish a mTLS connection with each other. Envoy retrieves client and server TLS certificates and trusted CA roots for mTLS communication from a SPIRE Agent which implements an Envoy <a href="https://www.envoyproxy.io/docs/envoy/v1.10.0/configuration/secret#">SDS</a>. The agent in-turn fetches this information from the SPIRE Server and makes it available to an identified workload. In the following example, SPIRE provides each workload an identity, in the form of a <em>SPIFFE ID</em> embedded in the TLS certificate, to facilitate mTLS communication. The <em>SPIFFE ID</em> of each workload can then be used by OPA to build the authorization policy. More information on SPIRE can be found <a href="https://spiffe.io/spire/overview/">here</a>.</p><ul><li>Envoy is listening for ingress on port 8001 in each container.</li><li>api-server-1 and api-server-2 are flask apps running on port 5000 and 5001 respectively and forward requests to the web service.</li><li>api-server-1 has a static IP in the 172.28.0.0/16 subnet while api-server-2 has one in the 192.28.0.0/16 subnet.</li><li>OPA is extended with a GRPC server that implements the <a href="https://www.envoyproxy.io/docs/envoy/v1.10.0/intro/arch_overview/ext_authz_filter.html">Envoy External authorization API</a>.</li><li>data.envoy.authz.allow is the default OPA policy that decides whether a request is allowed or not.</li><li>Both the GRPC server port and default OPA policy that is queried are configurable.</li></ul><h3>Running the Example</h3><h4>Step 1: Install Docker</h4><p>Ensure that you have recent versions of docker and docker-compose installed.</p><h4>Step 2: Clone the repo and Start containers</h4><p>Clone the OPA-Envoy-SPIRE repo with git clone git@github.com:ashutosh-narkar/opa-envoy-spire-ext-authz.git</p><pre>$ cd opa-envoy-spire-ext-authz<br>$ docker-compose up --build -d<br>$ docker-compose ps</pre><p>The following containers should be running:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9ba021282f9a4a3ffbaccbb710183682/href">https://medium.com/media/9ba021282f9a4a3ffbaccbb710183682/href</a></iframe><h4>Step 3: Start SPIRE Infrastructure</h4><p>Start the SPIRE Agents and register the web, backend and db servers with the SPIRE Server. More information on the registration process can be found <a href="https://spiffe.io/spire/overview/#workload-registration">here</a>.</p><pre>$ ./configure-spire.sh</pre><h4>Step 4: Exercise Ingress Policy</h4><p>The Ingress Policy states that the web service can <strong>ONLY</strong> be accessed from the subnet 172.28.0.0/16.</p><p>Check that api-server-1 can access the web service.</p><pre>$ curl -i localhost:5000/hello<br>HTTP/1.0 200 OK<br>Content-Type: text/html; charset=utf-8<br>Content-Length: 29<br>Server: Werkzeug/0.15.2 Python/2.7.15<br>Date: Thu, 02 May 2019 21:21:48 GMT</pre><pre>Hello from the web service !</pre><p>Check that api-server-2 <strong>cannot</strong> access the web service.</p><pre>$ curl -i localhost:5001/hello<br>HTTP/1.0 403 FORBIDDEN<br>Content-Type: text/html; charset=utf-8<br>Content-Length: 40<br>Server: Werkzeug/0.15.2 Python/2.7.15<br>Date: Thu, 02 May 2019 21:22:12 GMT</pre><pre>Access to the Web service is forbidden.</pre><h4>Step 5: Exercise Service-To-Service Policy</h4><p>The Service-To-Service Policy policy states that a request can flow from the web to backend to db service.</p><p>Check that this flow is honored.</p><pre>$ curl -i localhost:5000/the/good/path<br>HTTP/1.0 200 OK<br>Content-Type: text/html; charset=utf-8<br>Content-Length: 35<br>Server: Werkzeug/0.15.2 Python/2.7.15<br>Date: Thu, 02 May 2019 21:22:50 GMT</pre><pre>Allowed path: WEB -&gt; BACKEND -&gt; DB</pre><p>Check that the web service is NOT allowed to directly call the db service.</p><pre>$ curl -i localhost:5000/the/bad/path<br>HTTP/1.0 403 FORBIDDEN<br>Content-Type: text/html; charset=utf-8<br>Content-Length: 26<br>Server: Werkzeug/0.15.2 Python/2.7.15<br>Date: Thu, 02 May 2019 21:23:22 GMT</pre><pre>Forbidden path: WEB -&gt; DB</pre><h3>Example OPA Policy</h3><p>Each service calls its respective OPA instance for a decision and loads its desired policies into OPA. To see the OPA policies loaded by a service checkout the <em>docker</em> directory in the repo.</p><h4>Example Policy — 1</h4><p>The following OPA policy used in the example above is loaded into the OPA called by the web service.</p><ul><li>web service can <strong>ONLY</strong> be accessed from the subnet 172.28.0.0/16</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b8eb343a0b5e43f89f086cd64587246/href">https://medium.com/media/0b8eb343a0b5e43f89f086cd64587246/href</a></iframe><blockquote>Try the <strong><em>OPA-Envoy Ingress</em></strong> policy in the <a href="https://play.openpolicyagent.org/p/aHjJBMqpjC"><strong><em>Rego Playground</em></strong></a> !</blockquote><h4>Example Policy — 2</h4><p>Another policy used in the example states that:</p><ul><li>a request can flow from the web to backend to db service</li></ul><p>Below is a policy snippet that is loaded into the OPA called by the db service. This policy allows requests to the db service from <strong>ONLY</strong> the backend service.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb97ce243391e12a1dd0ee06d77fc3ad/href">https://medium.com/media/bb97ce243391e12a1dd0ee06d77fc3ad/href</a></iframe><blockquote>Try the <strong><em>OPA-Envoy Service-Service</em></strong> policy in the <a href="https://play.openpolicyagent.org/p/6iSVIkK8zW"><strong><em>Rego Playground</em></strong></a> !</blockquote><p>X-Forwarded-Client-Cert header is injected by the Envoy proxy of the originating service and validated by the Envoy proxy of the destination service. Envoy is configured to forward the URI field in the client certificate. To identify the service making the request, this policy uses the URI field of the X-Forwarded-Client-Cert header which in this case is the SPIFFE ID of the backend server.</p><blockquote><em>x-forwarded-client-cert (XFCC) is a proxy header which indicates certificate information of part or all of the clients or proxies that a request has flowed through, on its way from the client to the server. More information about the header and it&#39;s supported keys can be found </em><a href="https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_conn_man/headers#x-forwarded-client-cert"><em>here</em></a><em>.</em></blockquote><h3>Example Envoy configuration</h3><p>Here’s an example configuration for an Envoy proxy that listens for HTTP client connections on port 80 and then calls OPA’s gRPC server that implements the <a href="https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/ext_authz_filter">Envoy External Authorization API</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e0f56a0d797c4f6c1daaae9546bb2e53/href">https://medium.com/media/e0f56a0d797c4f6c1daaae9546bb2e53/href</a></iframe><h3>And that’s it !</h3><p>And that’s how you use OPA as an External authorization service to enforce ingress and service-to-service security policies using Envoy’s External authorization filter. OPA leverages the authentication framework provided by SPIFFE/SPIRE and by configuring Envoy to forward client certificate details, OPA is able to make authorization decisions based on the SPIFFE ID included in the URI SAN of the client X.509 certificate.</p><h3>Source Code</h3><p>The code for the example can be found at <a href="https://github.com/open-policy-agent/opa-envoy-spire-ext-authz">https://github.com/open-policy-agent/opa-envoy-spire-ext-authz</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=578213ed567c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/open-policy-agent/envoy-external-authorization-with-opa-578213ed567c">Envoy External Authorization with OPA</a> was originally published in <a href="https://medium.com/open-policy-agent">Open Policy Agent</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Rego Playground]]></title>
            <link>https://medium.com/open-policy-agent/the-rego-playground-977566855cec?source=rss-cf2fbda690bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/977566855cec</guid>
            <category><![CDATA[rego]]></category>
            <category><![CDATA[declarative-programming]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[authorization]]></category>
            <category><![CDATA[policy]]></category>
            <dc:creator><![CDATA[Ash Narkar]]></dc:creator>
            <pubDate>Fri, 08 Mar 2019 18:46:21 GMT</pubDate>
            <atom:updated>2019-03-08T18:51:40.779Z</atom:updated>
            <content:encoded><![CDATA[<p>OPA helps you implement policy as code using a high-level declarative language called Rego. Today we are excited to release an online interactive playground that you can use to experiment with Rego policies. The initial version of <a href="https://play.openpolicyagent.org/">The Rego Playground</a> has support for:</p><ul><li><strong>Syntax highlighting</strong> that makes policies easier to read and write.</li><li><strong>Interactive</strong> <strong>evaluation</strong> of expressions, queries, rules, and packages.</li><li><strong>Input dialog</strong> to specify complex JSON inputs for your policy.</li><li><strong>Sharing</strong> so that you can link to policies online.</li></ul><p>We hope the playground makes it easy for people to try out new policies and learn the language. We look forward to improving the playground over time and embedding it in places like the OPA documentation.</p><p>For a demo of the Rego Playground and some of its features check out the video below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fnzcnf83NvxE%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dnzcnf83NvxE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fnzcnf83NvxE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/504ceb95c35faea9e577acfa9e7c7755/href">https://medium.com/media/504ceb95c35faea9e577acfa9e7c7755/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=977566855cec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/open-policy-agent/the-rego-playground-977566855cec">The Rego Playground</a> was originally published in <a href="https://medium.com/open-policy-agent">Open Policy Agent</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>