You are viewing archived v1.24 Service Mesh documentation.
Available versions
Cloud Service Mesh latest
Cloud Service Mesh 1.26 archive
Cloud Service Mesh 1.24 archive
Cloud Service Mesh 1.24 archive
Cloud Service Mesh 1.23 archive
Cloud Service Mesh 1.22 archive
Cloud Service Mesh 1.21 archive
Cloud Service Mesh 1.20 archive
Anthos Service Mesh 1.19 archive
Integrating IAP with Cloud Service Mesh
This guide describes how to integrateIdentity-Aware Proxy (IAP) with Cloud Service Mesh. TheIAP integration with Cloud Service Meshenables you to safely access services based on Google'sBeyondCorp principles. IAP verifies user identityand context of the request to determine if a user should be allowed to access anapplication or resource. The IAP integration with Cloud Service Meshprovides you with the following benefits:
Completecontext-aware access control to theworkloads running on Cloud Service Mesh. You can set fine-grainedaccess policiesbased on attributes of the originating request, such as user identity, the IPaddress, and device type. You can combine your access policies withrestrictions based on thehostname and path of a request URL.
Enable support for context-aware claims in Cloud Service Mesh authorization.
Scalable, secure, and highly available access to your application through aGoogle Cloud load balancer. High performance load balancing provides built-inprotection of distributed denial-of-service (DDoS) attacks and support forglobalanycast IP addressing.
Prerequisites
Warning: HTTP Load Balancing with Cloud Service Mesh requires GKE 1.17.6-gke.11 or later.Follow the steps inInstall dependent tools and validate clusterto:- Install required tools
- Download
asmcli - Grant cluster admin permissions
- Validate your project and cluster
Additionally, this guide assumes that you have:
Setting up a cluster with Cloud Service Mesh
This section explains how to get set up for the IAP integrationfor both new installations of Cloud Service Mesh and upgrades.
New installations
Enable
iap.googleapis.com. In the following command, replacePROJECT_IDwith the project that you will installCloud Service Mesh in:gcloud services enable \ --project=PROJECT_ID \ iap.googleapis.comThe cluster that you are updating must have the
--addons=HttpLoadBalancingoption set. TheHttpLoadBalancingadd-on enables an HTTP (L7) loadbalancing controller for the cluster. Run the following command toupdate the cluster with the options required by Cloud Service Mesh. Unless you'veset a default zone or region, you need to supply the region(--region=REGION) or zone (--zone=ZONE) in the command.gcloud container clusters updateCLUSTER_NAME \ --project=PROJECT_ID \ --update-addons=HttpLoadBalancing=ENABLEDBy default, the
Important: You must use aiap-operator.yamlfile has port 31223 set as the statusport, and port 31224 set as the http port. If port 31223 is already in usein your cluster, run the following to set another status port:kptversion earlier than v1.0.kpt cfg set asm gcloud.container.cluster.ingress.statusPortSTATUS_PORTIf port 31224 is already in use in your cluster, run the following to setanother http port:
kpt cfg set asm gcloud.container.cluster.ingress.httpPortHTTP_PORTFollow the steps inInstall default features and Mesh CAto use a Google-provided script to install Cloud Service Mesh. When you run thescript, include the following option:
--option iap-operatorFor example:
./asmcli install \ --project_id "PROJECT_ID" \ --cluster_name "CLUSTER_NAME" \ --cluster_location "CLUSTER_LOCATION" \ --fleet_idFLEET_PROJECT_ID \ --output_dirDIR_PATH \ --enable_all \ --option iap-operatorWhen you install Cloud Service Mesh, the
iap-operator.yamlfile sets thetypefield on theistio-ingressgatewayservice toNodePort, which configures the gateway to open a specific port on theservice mesh. This allows you to set up a load balancer, which routestraffic sent to your domain name to this port.If you are installing managed Cloud Service Mesh, then also complete thefollowing steps:
Add the revision labelto the
istio-systemnamespace.Download theIstio ingress gateway service spec for IAPand name it
iap_operator.yaml.Install the ingress as a NodePort service. For more information, seeMigrate from IstioOperator.
asmcli experimental mcp-migrate-check -f iap_operator.yamlistioctl install -f /asm-generated-configs/gateways-istiooperator/"GATEWAY_NAME".yaml
After installing Cloud Service Mesh, return to this guide and continue with thenext section to set up the integration with IAP.
Upgrades
This section covers the following upgrade use cases:
You have already set up the IAP integration and you areupgrading Cloud Service Mesh. In this case, you have already enabled
iap.googleapis.comon your project and theHttpLoadBalancingadd-onon your cluster. Skip to step 3, to download theasmpackage andupgrade Cloud Service Mesh.You are upgrading Cloud Service Mesh and you want to set up the integration withIAP for the first time. In this case, you need to completeall of the following steps, upgrade Cloud Service Mesh, and return to this guideafter the upgrade to complete the integration.
Enable
iap.googleapis.com. In the following command, replacePROJECT_IDwith the project that you will installCloud Service Mesh in.gcloud services enable \ --project=PROJECT_ID \ iap.googleapis.comThe cluster that you are updating must have the
--addons=HttpLoadBalancingoption set. TheHttpLoadBalancingadd-on enables an HTTP (L7) loadbalancing controller for the cluster. Run the following command toupdate the cluster with the options required by Cloud Service Mesh. Unless you'veset a default zone or region, you need to supply the region(--region=REGION) or zone (--zone=ZONE) in the command.gcloud container clusters updateCLUSTER_NAME \ --project=PROJECT_ID --update-addons=HttpLoadBalancing=ENABLEDIf you are updating an existing, functioning HTTP Cloud Load Balancer, runthe following to preserve your existing http and status ports:
Important: You must use akptversion earlier than v1.0.kpt cfg set asm gcloud.container.cluster.ingress.httpPort $(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')kpt cfg set asm gcloud.container.cluster.ingress.statusPort $(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="status-port")].nodePort}')Follow the steps inUpgrading Cloud Service Meshto use a Google-provided script to upgrade Cloud Service Mesh.
When you upgrade Cloud Service Mesh, the
iap-operator.yamlfile sets thetypefield on theistio-ingressgatewayservice toNodePort, whichconfigures the gateway to open a specific port on the service mesh. Thisallows you to set up a load balancer, which routes traffic sent to yourdomain name to this port.By default, the
iap-operator.yamlfile has port 31223 set as the statusport, and port 31224 set as the http port.When you run the script, include the following option:
--option iap-operatorFor example:
./asmcli install \ --project_id "PROJECT_ID" \ --cluster_name "CLUSTER_NAME" \ --cluster_location "CLUSTER_LOCATION" \ --fleet_idFLEET_PROJECT_ID \ --output_dirDIR_PATH \ --enable_all \ --option iap-operatorComplete the upgrade by triggering automatic sidecar proxy injection onyour workloads. For details, seeDeploying and redeploying workloads.
After completing the upgrade, return to this guide and continue with thenext section to set up the integration with IAP.
Reserving a static IP address and configuring DNS
To integrate Identity-Aware Proxy with Cloud Service Mesh, you have to set up aGoogle Cloud HTTP(S) load balancer, which requires a domain name that pointsto a static IP address. You canreserve a static external IP address,which assigns the address to your project indefinitely until you explicitlyrelease it.
Reserve a static external IP address:
gcloudcomputeaddressescreateexample-static-ip--globalGet the static IP address:
gcloudcomputeaddressesdescribeexample-static-ip--globalIn your domain name registrar, configure a fully qualified domain name(FQDN) with the static IP address. Typically, you add an
Arecord to yourDNS settings. The configuration steps and terminology for adding anArecord for a FQDN vary depending on your domain name registrar.It can take 24 to 48 hours for the DNS setting to propagate. You cancontinue setting up everything in this guide, but you won't be able totest the setup until the DNS settings propagate.
Deploying a sample application
Before you enable IAP, you need an application running onyour GKE cluster so you can verify that all requests have anidentity. This guide uses the Bookinfo sample to demonstrate how to setup theHTTP(S) load balancer and enable IAP.
Follow the steps todeploy Bookinfo. Untilyou deploy the load balancer, the Bookinfo application isn't accessible outsideof your GKE cluster (such as from a browser).
External requests
Bookinfo's Gateway resource (defined insamples/bookinfo/networking/bookinfo-gateway.yaml) uses the preconfiguredistio-ingressgateway.Recall that when you deployed Cloud Service Mesh, you specifiedNodePort for theistio-ingressgateway, which opens a specific port on the service mesh.Although the nodes in your cluster have external IP addresses, requests comingfrom outside your cluster are blocked by Google Cloud firewall rules. WithIAP, the correct way to expose applications to the publicinternet is by using a load balancer. Don't expose the node addresses usingfirewall rules, which would bypass IAP.
To route requests to Bookinfo, you set up an HTTP(S) load balancer in yourGoogle Cloud project. Because the load balancer is in your project, it isinside of the firewall and can access the nodes in your cluster. After youconfigure the load balancer with the static IP address and your domain name,you can send requests to the domain name, and the load balancer forwards therequests to the nodes in the cluster.
Enabling IAP
The following steps describe how to enable IAP.
Note: OAuth clients for IAP can be created using gcloud CLI, but there are a few limitations to how these clients can be used. Learn morehere. Alternatively, you can followthese steps to create a client with more relaxed restrictions.Configuring consent screen
Check if you already have an existing brand by using thelist command. You mayonly have one brand per project.
gcloudiapoauth-brandslist
The following is an example gcloud response, if the brand exists:
Note: If a brand already exists for a project and has been configured forexternal users (name:projects/[PROJECT_NUMBER]/brands/[BRAND_ID]applicationTitle:[APPLICATION_TITLE]supportEmail:[SUPPORT_EMAIL]orgInternalOnly:trueorgInternalOnly: false), but you want to restrict it tointernal users, you must make that change manually from theOAuth consent screen in order to create OAuthclients with this API.If no brand exists, use thecreate command:
gcloudiapoauth-brandscreate--application_title=APPLICATION_TITLE--support_email=SUPPORT_EMAIL
The above fields are required when calling this API:
Note: The user issuing the request must be an owner of the specified supportemail address.supportEmail: The support email displayed on the OAuth consent screen.This email address can either be a user's address or a Google Groups alias.While service accounts also have an email address, they are not actualvalid email addresses, and cannot be used when creating a brand. However,a service account can be the owner of a Google Group. Either create anew Google Group or configure an existing group and set the desired serviceaccount as an owner of the group.applicationTitle: The application name displayed on OAuth consentscreen.
The response contains the following fields:
name:projects/[PROJECT_NUMBER]/brands/[BRAND_ID]applicationTitle:[APPLICATION_TITLE]supportEmail:[SUPPORT_EMAIL]orgInternalOnly:true
Creating an IAP OAuth Client
Use the create command tocreate a client. Usethe brand
namefrom previous step.gcloudiapoauth-clientscreateprojects/PROJECT_NUMBER/brands/BRAND-ID--display_name=NAMEThe response contains the following fields:
name:projects/[PROJECT_NUMBER]/brands/[BRAND_NAME]/identityAwareProxyClients/[CLIENT_ID]secret:[CLIENT_SECRET]displayName:[NAME]Use the client ID (
CLIENT_IDin the above step) andCLIENT_SECRETtoenable IAP. Create a kubernetes secret with the materialsfrom your OAuth Client:kubectl create secret generic -n istio-system my-secret --from-literal=client_id=CLIENT_ID \--from-literal=client_secret=CLIENT_SECRET
Deploying the load balancer
You can use anIngress resource to create anHTTP(S) load balancer with automatically configuredSSL certificates.Managed SSL certificates areprovisioned, renewed, and managed for your domain.
Create a ManagedCertificate resource. This resource specifies the domain forthe SSL certificate. The
spec.domainslist must contain only one domain.Wildcard domains aren't supported. In the following YAML, replaceDOMAIN_NAMEwith the domain name that you configuredfor the external static IP address.cat <<EOF | kubectl apply -f -apiVersion: networking.gke.io/v1kind: ManagedCertificatemetadata: name: example-certificate namespace: istio-systemspec: domains: -DOMAIN_NAMEEOF
Create a BackendConfig resource. This resource instructs GCLB how to performHealth Checks on the Ingress Gateway, as well as configure Identity-AwareProxy. First, collect a few values from the Ingress Gateway about healthchecks:
Health check ingress port: This is the health check port of istio-ingress.
export HC_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="status-port")].nodePort}')Health check ingress path: This is the health check path of istio-ingress.
export HC_INGRESS_PATH=$(kubectl get pods -n istio-system -l app=istio-ingressgateway -o jsonpath='{.items[0].spec.containers[?(@.name=="istio-proxy")].readinessProbe.httpGet.path}')
cat <<EOF | kubectl apply -n istio-system -f -apiVersion: cloud.google.com/v1kind: BackendConfigmetadata: name: http-hc-configspec: healthCheck: checkIntervalSec: 2 timeoutSec: 1 healthyThreshold: 1 unhealthyThreshold: 10 port: ${HC_INGRESS_PORT} type: HTTP requestPath: ${HC_INGRESS_PATH} iap: enabled: true oauthclientCredentials: secretName: my-secretEOFAnnotate the ingress service with your BackendConfig.
kubectl annotate -n istio-system service/istio-ingressgateway --overwrite \ cloud.google.com/backend-config='{"default": "http-hc-config"}' \ cloud.google.com/neg='{"ingress":false}'Create the load balancer by defining the Ingress resource.
Set the
networking.gke.io/managed-certificatesannotation to the nameof the certificate you created in the previous step,example-certificate.Set the
kubernetes.io/ingress.global-static-ip-nameannotation to thename of the static IP address you reserved,example-static-ip.Set the
serviceNametoistio-ingressgateway, which is used inthe Gateway resource for the Bookinfo sample.
Note: It can take up to 10-20 minutes for the load balancer to befunctional.cat <<EOF | kubectl apply -f -apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: example-ingress namespace: istio-system annotations: kubernetes.io/ingress.global-static-ip-name: example-static-ip networking.gke.io/managed-certificates: example-certificatespec: defaultBackend: service: name: istio-ingressgateway port: number: 80EOF
In the Google Cloud console, go to theKubernetes Engine >Services& Ingress page.
Go to the Services & Ingress page
You should see the "Creating ingress" message in theStatus column.Wait for GKE to fully provision the Ingress beforecontinuing. Refresh the page every few minutes to get the most up-to-datestatus on the Ingress. After the Ingress is provisioned, you might see the"Ok" status, or the error "All backend services are in UNHEALTHY state."One of the resources that GKE provisions is a default healthcheck. If you see the error message, that indicates that the Ingress isprovisioned and that the default health check ran. When you see either the"Ok" status or the error, continue with the next section to configure thehealth checks for the load balancer.
Configure the IAP access list
Add a user to the access policy for IAP:
Caution: The below commands configure IAP settings and IAP policies at the project level. Therefore, the configurations will be applicable to all IAP resources in the project, including non-Cloud Service Mesh resources. This is required because the resources are deleted and recreated with every upgrade, and configuring IAP at project level allows us to persist IAP configuration across upgrades.gcloud beta iap web add-iam-policy-binding \ --member=user:EMAIL_ADDRESS \ --role=roles/iap.httpsResourceAccessor
whereEMAIL_ADDRESS is the user's full email addresssuch asalice@example.com.
Test the load balancer. Point your browser to:
http://DOMAIN_NAME/productpage
where
DOMAIN_NAMEis the domain name that youconfigured with the external static IP address.You should see the Bookinfo application's
productpage. If you refresh thepage several times, you should see different versions of reviews, presentedin a round robin style: red stars, black stars, no stars.You should also test
httpsaccess to Bookinfo.
Enable RCToken support on the service mesh
By default, IAP generates aJSON Web Token (JWT) that is scoped to the OAuth client.For Cloud Service Mesh, you can configure IAP to generate aRequestContextToken (RCToken), which is a JWT but with a configurable audience.RCToken lets you configure the audience of the JWT to an arbitrary string, whichcan be used in the Cloud Service Mesh policies for fine-grained authorization.
To configure the RCToken:
Create an environment variable for the RCToken audience. This can beany string that you want.
exportRCTOKEN_AUD="your-rctoken-aud"Optional: The following step requires the
BACKEND_SERVICE_ID. If you need to find out theBACKEND_SERVICE_ID, run the following command:kubectl -n istio-system get Ingress example-ingress -o json | jq \ '.metadata.annotations."ingress.kubernetes.io/backends"'The expected output is similar to
"{\"BACKEND_SERVICE_ID\":\"HEALTHY\"}".For example,"ingress.kubernetes.io/backends": "{\"k8s-be-31224--51f3b55cd1457fb6\":\"HEALTHY\"}".TheBACKEND_SERVICE_IDin this example isk8s-be-31224--51f3b55cd1457fb6.Fetch the existingIAP settings.
gcloud iap settings get --format json \--project=${PROJECT_ID} --resource-type=compute --service=BACKEND_SERVICE_ID > iapSettings.jsonUpdate
IapSettingswith the RCToken audience.cat iapSettings.json | jq --arg RCTOKEN_AUD_STR $RCTOKEN_AUD \'. + {applicationSettings: {csmSettings: {rctokenAud: $RCTOKEN_AUD_STR}}}' \> updatedIapSettings.jsongcloud iap settings set updatedIapSettings.json --format json \--project=${PROJECT_ID} --resource-type=compute --service=BACKEND_SERVICE_IDEnable RCToken authentication on the Istio ingress gateway.
cat <<EOF | kubectl apply -f -apiVersion:"security.istio.io/v1beta1"kind:"RequestAuthentication"metadata:name:"ingressgateway-jwt-policy"namespace:"istio-system"spec:selector:matchLabels:app:istio-ingressgatewayjwtRules:-issuer:"https://cloud.google.com/iap"jwksUri:"https://www.gstatic.com/iap/verify/public_key-jwk"audiences:-$RCTOKEN_AUDfromHeaders:-name:ingress-authorizationprefix:"Istio"outputPayloadToHeader:"verified-jwt"forwardOriginalToken:trueEOFOptional: Ensure requests that don't have valid JWTs are rejected:
Note: For more information, seeRequire a valid token.cat <<EOF | kubectl apply -f - apiVersion: security.istio.io/v1beta1 kind: AuthorizationPolicy metadata: name: iap-gateway-require-jwt namespace: istio-system spec: selector: matchLabels: app: istio-iap-ingressgateway action: DENY rules: - from: - source: notRequestPrincipals: ["*"] EOF
Make sure requests to the Bookinfo
productpageare still successful:http://DOMAIN_NAME/productpage
To test the policy:
Create an
IapSettingsrequestobject, but set therctokenAudto a different string:cat iapSettings.json | jq --arg RCTOKEN_AUD_STR wrong-rctoken-aud \'. + {applicationSettings: {csmSettings: {rctokenAud: $RCTOKEN_AUD_STR}}}' \> wrongIapSettings.jsonCall the
IapSettingsAPI to set the RCtoken audience.gcloud beta iap settings set wrongIapSettings.json --project=PROJECT_ID --resource-type=compute --service=BACKEND_SERVICE
Make a request to the Bookinfo
productpageand it should fail:http://DOMAIN_NAME/productpage
Cleaning up
After completing this tutorial, remove the following resources to preventunwanted charges incurring on your account:
Delete the managed certificate:
kubectldeletemanagedcertificatesexample-certificate
Delete the Ingress, which deallocates the load balancing resources:
kubectl -n istio-system delete ingress example-ingress
Delete the static IP address:
gcloud compute addresses delete example-static-ip --global
If you do this, be sure to delete the IP address from your domain registrar.
Delete the cluster, which deletes the resources that make up thecluster, such as the compute instances, disks and network resources:
gcloud container clusters deleteCLUSTER_NAME
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.