Secure service to service communication using Istio

We will use Istio to authentication and authorize services during communication using mutualTLS.

One of the main challenges of managing microservices based solutions is how to properly secure not just the microservices themselves but also the communication between them. We will use Istioarrow-up-right that can help us secure this communication without making changes to the application code itself.

We will first need to enable Istio for our cluster running on IBM Cloud. IBM provides managed Istio which allows seamless installation of Istio with other benefits such as automatic updates and lifecycle management of different components.

To enable Istio, navigate to your cluster and click on the Add-ons tab.

You will then see a tile for Managed Istio. Click on install to install istio in your cluster.

Wait for the installation to be ready. You will see Add on ready status as shown below

Once the add on is ready, Setup default configuration profile for Istio by running the following command in your terminal

Authentication

Istio offers mutual TLSarrow-up-right as a full stack solution for transport authentication, which can be enabled without requiring service code changes. This solution:

  • Provides each service with a strong identity representing its role to enable interoperability across clusters and clouds.

  • Secures service-to-service communication.

  • Provides a key management system to automate key and certificate generation, distribution, and rotation.

We will now create few services in our cluster and see how authentication works when we enable Istio.

To see how authentication works we will create 3 namespaces (foo, bar and legacy) with different services (sleep and httpbin) running as shown below. Foo and Bar namespaces are running services with an Envoyarrow-up-right proxy to add istio capabilities while legacy namespace is running a service without an istio capabilities.

Step 1: Create namespaces

Create namespace foo, bar and legacy

Step 2: Create services

Before running the following commands, make sure to change directory to istio-workflow in the cloned github repository

We will create the httpbinarrow-up-right service in the foo

Next let's create sleep arrow-up-rightservice in the bar (with istio) and legacy (without istio) namespace.

Make sure that the services are running in each namespace as shown below.

The output should be as follows

Step 3: Send request from bar to foo

By default (from version 1.4 onwards), Istio tracks the server workloads migrated to Istio proxies, and configures client proxies to send mutual TLS traffic to those workloads automatically, and to send plain text traffic to workloads without sidecars.

Thus, all traffic between workloads with proxies uses mutual TLS, without you doing anything. For example, take the response from a request to httpbin/header. When using mutual TLS, the proxy injects the X-Forwarded-Client-Cert header to the upstream request to the backend. That header’s presence is evidence that mutual TLS is used.

Replace <pod-name-in-bar> with the name of the pod running in bar namespace.

The output will be as follows and you can see the X-Forwarded-Client-Cert towards the end.

Step 4: Send request from legacy to foo

Let's now send a request from legacy to foo and we will see how the X-Forwarded-Client-Cert header will be excluded.

Replace <pod-name-in-bar> with the name of the pod running in legacy namespace.

The output will be as follows

Step 5: Enabling Istio mutual TLS in STRICT mode

While Istio automatically upgrades all traffic between the proxies and the workloads to mutual TLS between, workloads can still receive plain text traffic. To prevent non-mutual TLS for the whole mesh, set a mesh-wide peer authentication policy to set mutual TLS mode to STRICT.

Once the authentication policy is enabled, request from legacy to foo should not be allowed.

Output will be as follows

Authorization

Each Envoy proxy runs an authorization engine that authorizes requests at runtime. When a request comes to the proxy, the authorization engine evaluates the request context against the current authorization policies, and returns the authorization result, either ALLOW or DENY. Operators specify Istio authorization policies using .yaml files.

Step 1: Setup sample application

The sample application shows information about books. The services communicate as shown below:

We will first set up a sample application to understand how authorization works

Confirm all services and pods are correctly defined and running:

Now that the Bookinfo services are up and running, you need to make the application accessible from outside of your Kubernetes cluster, e.g., from a browser. An Istio Gatewayarrow-up-right is used for this purpose.

Confirm the gateway has been created:

Follow the following to set the INGRESS_HOST and INGRESS_PORT variables for accessing the gateway.

Set GATEWAY_URL:

You can now point your browser to http://$GATEWAY_URL/productpage to view the Bookinfo web page. You will see the page properly loaded with details and reviews of the book.

Step 2: Deny all traffic between services.

We will now apply a policy to deny all traffic.

Reload http://$GATEWAY_URL/productpage and you not be able to access the page anymore (it might take few seconds for the policy to take effect).

Step 3: Allow access to product service.

Run the following command to create a productpage-viewer policy to allow access withGET method to the productpage workload.

Reload http://$GATEWAY_URL/productpage and you will be able to access the product service without access to details and reviews (it might take few seconds for the policy to take effect).

Step 4: Allow product service to access details service

Run the following command to create the details-viewer policy to allow the productpage workload, which issues requests using the cluster.local/ns/default/sa/bookinfo-productpage service account, to access the details workload through GET methods:

Reload http://$GATEWAY_URL/productpage and you will be able to access the product service with access to details (it might take few seconds for the policy to take effect).

You can do the same for reviews to be accessed by product service.

Last updated

Was this helpful?