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:

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

  1. Enableiap.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.com
  2. The cluster that you are updating must have the--addons=HttpLoadBalancingoption set. TheHttpLoadBalancing add-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=ENABLED
  3. By default, theiap-operator.yaml file 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:

    Important: You must use akpt version earlier than v1.0.
    kpt cfg set asm gcloud.container.cluster.ingress.statusPortSTATUS_PORT

    If 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_PORT
  4. Follow 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-operator

    For 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-operator

    When you install Cloud Service Mesh, theiap-operator.yamlfile sets thetype field on theistio-ingressgateway service 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.

  5. If you are installing managed Cloud Service Mesh, then also complete thefollowing steps:

    1. Add the revision labelto theistio-system namespace.

    2. Download theIstio ingress gateway service spec for IAPand name itiap_operator.yaml.

    3. 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 enablediap.googleapis.com on your project and theHttpLoadBalancing add-onon your cluster. Skip to step 3, to download theasm package 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.

  1. Enableiap.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.com
  2. The cluster that you are updating must have the--addons=HttpLoadBalancingoption set. TheHttpLoadBalancing add-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=ENABLED
  3. If you are updating an existing, functioning HTTP Cloud Load Balancer, runthe following to preserve your existing http and status ports:

    Important: You must use akpt version 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}')
  4. Follow the steps inUpgrading Cloud Service Meshto use a Google-provided script to upgrade Cloud Service Mesh.

    When you upgrade Cloud Service Mesh, theiap-operator.yaml file sets thetype field on theistio-ingressgateway service 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, theiap-operator.yaml file 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-operator

    For 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-operator
  5. Complete 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.

  1. Reserve a static external IP address:

    gcloudcomputeaddressescreateexample-static-ip--global
  2. Get the static IP address:

    gcloudcomputeaddressesdescribeexample-static-ip--global
  3. In your domain name registrar, configure a fully qualified domain name(FQDN) with the static IP address. Typically, you add anA record 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

  1. 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:

    name:projects/[PROJECT_NUMBER]/brands/[BRAND_ID]applicationTitle:[APPLICATION_TITLE]supportEmail:[SUPPORT_EMAIL]orgInternalOnly:true
    Note: If a brand already exists for a project and has been configured forexternal users (orgInternalOnly: 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.
  2. 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:

    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

  1. Use the create command tocreate a client. Usethe brandname from previous step.

    gcloudiapoauth-clientscreateprojects/PROJECT_NUMBER/brands/BRAND-ID--display_name=NAME

    The response contains the following fields:

    name:projects/[PROJECT_NUMBER]/brands/[BRAND_NAME]/identityAwareProxyClients/[CLIENT_ID]secret:[CLIENT_SECRET]displayName:[NAME]
  2. Use the client ID (CLIENT_ID in the above step) andCLIENT_SECRET toenable 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.

  1. Create a ManagedCertificate resource. This resource specifies the domain forthe SSL certificate. Thespec.domains list must contain only one domain.Wildcard domains aren't supported. In the following YAML, replaceDOMAIN_NAME with 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
  2. 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-secretEOF
  3. Annotate 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}'
  4. Create the load balancer by defining the Ingress resource.

    • Set thenetworking.gke.io/managed-certificates annotation to the nameof the certificate you created in the previous step,example-certificate.

    • Set thekubernetes.io/ingress.global-static-ip-name annotation to thename of the static IP address you reserved,example-static-ip.

    • Set theserviceName toistio-ingressgateway, which is used inthe Gateway resource for the Bookinfo sample.

    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
    Note: It can take up to 10-20 minutes for the load balancer to befunctional.
  5. 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.

  1. Test the load balancer. Point your browser to:

    http://DOMAIN_NAME/productpage

    whereDOMAIN_NAME is the domain name that youconfigured with the external static IP address.

    You should see the Bookinfo application'sproductpage. 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 testhttps access 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:

  1. Create an environment variable for the RCToken audience. This can beany string that you want.

    exportRCTOKEN_AUD="your-rctoken-aud"
  2. Optional: The following step requires theBACKEND_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_ID in this example isk8s-be-31224--51f3b55cd1457fb6.

  3. Fetch the existingIAP settings.

    gcloud iap settings get --format json \--project=${PROJECT_ID} --resource-type=compute --service=BACKEND_SERVICE_ID > iapSettings.json
  4. UpdateIapSettings with the RCToken audience.

    cat iapSettings.json | jq --arg RCTOKEN_AUD_STR $RCTOKEN_AUD \'. + {applicationSettings: {csmSettings: {rctokenAud: $RCTOKEN_AUD_STR}}}' \> updatedIapSettings.json
    gcloud iap settings set updatedIapSettings.json --format json \--project=${PROJECT_ID} --resource-type=compute --service=BACKEND_SERVICE_ID
  5. Enable 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:trueEOF
  6. Optional: 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

  7. Make sure requests to the Bookinfoproductpage are still successful:

    http://DOMAIN_NAME/productpage

To test the policy:

  1. Create anIapSettings requestobject, but set therctokenAud to a different string:

    cat iapSettings.json | jq --arg RCTOKEN_AUD_STR wrong-rctoken-aud \'. + {applicationSettings: {csmSettings: {rctokenAud: $RCTOKEN_AUD_STR}}}' \> wrongIapSettings.json
  2. Call theIapSettings API to set the RCtoken audience.

    gcloud beta iap settings set wrongIapSettings.json --project=PROJECT_ID --resource-type=compute --service=BACKEND_SERVICE
  3. Make a request to the Bookinfoproductpage and it should fail:

    http://DOMAIN_NAME/productpage

Cleaning up

After completing this tutorial, remove the following resources to preventunwanted charges incurring on your account:

  1. Delete the managed certificate:

    kubectldeletemanagedcertificatesexample-certificate
  2. Delete the Ingress, which deallocates the load balancing resources:

    kubectl -n istio-system delete ingress example-ingress

  3. 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.

  4. 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.