
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Anthos Service Mesh security helps you mitigate insider threats and reduce the risk of a data breach by ensuring that all communications between workloads are encrypted, mutually authenticated, and authorized.
In this lab, you learn how PERMISSIVE mode mTLS allows services to receive both plaintext and mTLS traffic from clients, allowing you to incrementally adopt mTLS. You also enabled STRICT mode mTLS across your service mesh effectively blocking plaintext traffic to all your Istio injected services and then you scoped STRICT mode mTLS down to a single namespace
In this lab, you learn how to perform the following tasks:
In this task, you use Qwiklabs and perform initialization steps for your lab.
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00
), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
After you complete the initial sign-in steps, the project dashboard appears.
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
This lab environment has already been partially configured. A GKE cluster with 2 nodes has been provisioned for you. If you would like to investigate how the cluster creation process happened, look at the setup-vm startup-script.
Set the Zone environment variable:
Set environment variables for the zone and cluster name:
In Cloud Shell, configure kubectl command line access by running:
Check that your cluster is up and running:
Output:
Ensure the following Kubernetes istiod services are deployed:
Output:
Ensure the corresponding Kubernetes istiod-* pods are deployed and all containers are up and running:
Output:
In this task, you create a set of namespaces to host the httpbin, and sleep services. You will use those services to explore the impact of mTLS on traffic. The sleep service acts as the client and will call the httpbin service, which acts as a server.
You will deploy this example configuration and then use it to explore the authentication options that Istio offers:
In Cloud Shell, create namespaces for the example clients and services. Traffic in the legacy-* namespaces takes place over plain text, while traffic in the mtls-* namespaces happens over mTLS:
Output:
Deploy the legacy services in the legacy-* namespaces. You call them legacy because they are not part of the mesh:
Enable auto-injection of the Istio sidecar proxy on the mtls-* namespaces:
Deploy the services in the mtls-* namespaces:
Verify that the sleep service and the httpbin service are each deployed in both the mtls-service and legacy-service namespaces:
Output:
Verify that a sleep pod is running in the mtls-client and legacy-client namespaces and that an httpbin pod is running in the mtls-service and legacy-service namespaces:
Output:
Use Cloud Shell to run this nested command loop:
Output:
Now you're ready to enforce security policies for this application.
In the console, go to Navigation Menu > Kubernetes Engine > Service Mesh.
In the Anthos Service Mesh dashboard, you will see the 2 services that were created in the mtls-service
and mtls-client/sleep
namespaces. You don't see the legacy services because you did not label their namespace, and therefore they remain outside of the mesh.
In the list view section Click on > icon next to httpbin (mtls-service/httpbin) namespace.
Click on Go to dashboard
In the left side panel, go to Connected Services.
Notice that you have 2 services:
sleep
service in the mtls-client
namespace, which is part of the
mesh and has a sidecar proxy. Therefore you see the real name and
communication goes over mTLS, as it's the default behavior in Istio.unknown
service, which represents the sleep
service in the
legacy-client
, which is not part of the mesh and has no sidecar proxy.
Therefore you do not see the real name and the communication goes over plain
text.Use your mouse to hover over the lock symbol in the Request port column, and verify that green means mTLS and red means plain text.
By default, Istio configures destination workloads in PERMISSIVE
mode. When
PERMISSIVE
mode is enabled a service can accept both plaintext and mTLS
traffic. mTLS is used when the request contains the X-Forwarded-Client-Cert
header.
Use the Cloud Shell to send a request from the sleep service in the mtls-client namespace to the httpbin service in the mtls-service namespace:
Output:
The traffic included the X-Forwarded-Client-Cert header and therefore was mutually authenticated and encrypted
Now send a request from the sleep service in the mtls-client namespace to the httpbin service in the legacy-service namespace:
The X-Forwarded-Client-Cert header isn't present so the traffic was sent and received in plaintext.
Finally, send a request from the sleep service in the legacy-client namespace to the httpbin service in the mtls-service namespace:
The X-Forwarded-Client-Cert header isn't present so the traffic was sent and received in plaintext
In STRICT
mode, services injected with the Istio proxy will not accept
plaintext traffic and will mutually authenticate with their clients.
You can enforce STRICT
mTLS mode across the whole mesh or on a per-namespace
basis by creating PeerAuthentication resources.
Create a Peer Authentication resources for the entire Service Mesh:
Run this nested command loop:
Output:
Remove the mesh wide mTLS PeerAuthentication resource by running this command in Cloud Shell:
In Cloud Shell create a namespace for STRICT
mTLS:
Enable auto-injection of the Istio sidecar proxy on the new namespace:
Use Cloud Shell to deploy another instance of the httpbin service in the strict-mtls-service namespace:
Create a PeerAuthentication resource for the strict-mtls-service namespace:
Verify that the httpbin service in the mtls-service namespace still accepts plaintext traffic:
Output:
Now check to see that the strict-mtls-service namespace httpbin service does not accept plaintext traffic:
Output:
Verify that the httpbin service in the strict-mtls-service namespace does accept mTLS traffic:
Output:
In the Google Cloud console, select Navigation Menu > Kubernetes Engine > > Service Mesh.
In Anthos Service Mesh dashboard, you will see that you have 3 services now.
In the list view section Click on > icon next to strict-mtls-service/httpbin namespace.
Click on Go to dashboard
In the left side panel, click on Connected Services.
Use your mouse to hover over the lock symbol in the Request Port column
to see that only mTLS traffic has been received. Traffic might take a
couple of minutes to be reflected in the dashboard. If you don't see the
sleep
service, wait 1-2 minutes and refresh the dashboard.
Now check out the Security tab in the left side panel. Again only mTLS traffic has been received.
Remove the strict-mtls-service peer authentication policy by running this command in Cloud Shell:
This task shows you how to set up and use RequestAuthentication and AuthorizationPolicy resources. Ultimately, you will allow requests that have an approved JWT, and deny requests that don't.
A RequestAuthentication resource defines the request authentication methods that are supported by a workload. Requests with invalid authentication information will be rejected. Requests with no authentication credentials will be accepted but will not have any authenticated identity.
Create a RequestAuthentication resource for the httpbin
workload in the
mtls-service
namespace. This policy allows the workload to accept requests
with a JWT issued by testing@secure.istio.io
.
Verify that a request with an invalid JWT is denied:
Output:
Verify that a request without any JWT is allowed:
Output:
Create an AuthorizationPolicy resource for the httpbin
workload in the
mtls-service
namespace:
The policy requires all requests to the httpbin
workload to have a valid
JWT with requestPrincipal
set to testing@secure.istio.io/testing@secure.istio.io
.
Istio constructs the requestPrincipal
by combining the iss
and sub
of
the JWT token with a / separator as shown:
Download a legitimate JWT that can be used to send accepted requests:
Output:
Note that the iss
and sub
keys are set to testing@secure.istio.io
.
This causes Istio to generate the attribute requestPrincipal
with the
value testing@secure.istio.io/testing@secure.istio.io
:
Verify that a request with a valid JWT is allowed:
Output:
Verify that a request without a JWT is denied:
Output:
This task shows you how to control access to workloads by using an AuthorizationPolicy that evaluates the request type and URL.
Update the require-jwt
authorization policy for the httpbin
workload in
the mtls-service
namespace. The new policy will still have the JWT
requirement that you set up in the previous task. In addition, you are going
to limit the type of HTTP requests, so that clients can only perform GET
requests to the /ip
endpoint:
Verify that a request to the httpbin
's /ip
endpoint works:
Output:
Verify that a request to the httpbin
's /headers
endpoint is denied:
Output:
Remove the require-jwt authorization policy by running this command:
In this lab, you explored mutual TLS authentication in Istio. You saw how PERMISSIVE mode mTLS allows services to receive both plaintext and mTLS traffic from clients, allowing you to incrementally adopt mTLS. You also enabled STRICT mode mTLS across your service mesh effectively blocking plaintext traffic to all your Istio injected services and then you scoped STRICT mode mTLS down to a single namespace.
In addition, you explored RequestAuthentication and AuthorizationPolicy resources in Istio.
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one