Stay organized with collections Save and categorize content based on your preferences.
There are two ways to enable IAP for your Cloud Run services, directly on a Cloud Run service or on the backend service fronting the Cloud Run services.
We recommend that you enable IAP directly on Cloud Run. This protects the run.app
endpoint and if you configure a load balancer, the load balancer endpoint as well.
If you require central access management, or want to route traffic to multiple regions, continue with the following procedures.
This page explains how to secure a Cloud Run service with IAP from a backend service or load balancer. If you're running Cloud Run in multiple regions attached to the same load balancer global backend service, follow the instructions on this page to configure IAP once for the backend service.
Known limitationsWhen you enable IAP on a load balancer, IAP secures traffic only through the load balancer and not with traffic that might reach the Cloud Run service through its run.app
URL. To only allow IAP-authorized traffic, see Configuring Cloud Run to limit access.
IAP authenticates to Cloud Run using the X-Serverless-Authorization
header. Cloud Run passes this header to your service after stripping its signature. If your service is designed to forward the request to another Cloud Run service that requires IAM authentication, update your service to remove this header first.
IAP is incompatible with Cloud CDN.
IAP increases latency. Enable IAP only for instances that are not latency-sensitive.
To enable IAP for Cloud Run resources in IAP, you need the following:
IAP uses a Google-managed OAuth client to authenticate users. Only users within the organization can access the IAP-enabled application. If you want to allow access to users outside of your organization, see Enable IAP for external applications.
Note: The ability to authenticate users with a Google-managed OAuth client is available in Preview. Enabling IAP from a backend service or load balancerTo enable IAP from IAP behind a backend service or load balancer, use the following instructions.
ConsoleThe Google-managed OAuth client is not available when enabling IAP using the Google Cloud console.
If you haven't configured your project's OAuth consent screen, you'll be prompted to do so. To configure your OAuth consent screen, see Setting up your OAuth consent screen.
Setting up IAP accessIn the Add Principal dialog, enter the accounts of groups or individuals who should have the IAP-secured Web App User role for the project. The following kinds of accounts can be members:
Select Cloud IAP > IAP-secured Web App User from the Roles drop-down list.
Click Save.
compute.backendServices.update
, clientauthconfig.clients.create
, and clientauthconfig.clients.getWithSecret
permissions. These permissions are granted by roles, such as the Project Editor role. To learn more, see Managing access to IAP-secured resources.Follow the instructions at Access control with IAM to authorize IAP to send traffic to the backend Cloud Run service.
service-[PROJECT-NUMBER]@gcp-sa-iap.iam.gserviceaccount.com
The IAP service account is created when IAP is enabled. If the IAP service account is not in the list of principals, you can create it by running the following gcloud command:
gcloud beta services identity create
--service=iap.googleapis.com
--project=PROJECT_ID
gcloud beta services identity create --service=iap.googleapis.com --project=[PROJECT_ID]
gcloud run services add-iam-policy-binding [SERVICE-NAME] \
--member='serviceAccount:service-[PROJECT-NUMBER]@gcp-sa-iap.iam.gserviceaccount.com' \
--role='roles/run.invoker'
Enable IAP by running either the globally or regionally scoped command, depending on whether your load balancer backend service is global or regional. Use the OAuth client ID and secret from the previous step.
Global scope
gcloud compute backend-services update BACKEND_SERVICE_NAME --global --iap=enabled
Regional scope
gcloud compute backend-services update BACKEND_SERVICE_NAME --region REGION_NAME --iap=enabledReplace the following:
After you enable IAP, you can use the Google Cloud CLI to manipulate an IAP access policy using the Identity and Access Management role roles/iap.httpsResourceAccessor
. See Managing access to IAP-secured resources for more information.
resource "google_project_service" "project" {
project = "your-project-id"
service = "iap.googleapis.com"
}
resource "google_cloud_run_service_iam_binding" "binding" {
location = google_cloud_run_v2_service.default.location
service = google_cloud_run_v2_service.default.name
role = "roles/run.invoker"
members = [
"serviceAccount:service-[PROJECT-NUMBER]@gcp-sa-iap.iam.gserviceaccount.com",
]
}
Enable IAP by running either the global or the regional command depending on your load balancer. Use the OAuth client ID and secret from the previous step.
Global scope
resource "google_compute_backend_service" "default" {
name = "tf-test-backend-service-external"
protocol = "HTTPS"
load_balancing_scheme = "EXTERNAL_MANAGED"
iap {
enabled = true
oauth2_client_id = "abc"
oauth2_client_secret = "xyz"
}
}
Regional scope
resource "google_compute_region_backend_service" "default" {
name = "tf-test-backend-service-external"
protocol = "HTTPS"
load_balancing_scheme = "EXTERNAL_MANAGED"
iap {
enabled = true
oauth2_client_id = "abc"
oauth2_client_secret = "xyz"
}
}
To prevent traffic from routing through a Cloud Run service's default run.app
URL, Disable the default URL. Otherwise, configure your ingress settings to Restrict network ingress for Cloud Run.
Your client does not have permission to get URL from this server
IAP uses the IAP service account permissions to invoke your Cloud Run service. Be sure that you have granted the Cloud Run Invoker role to the following service account: service-[PROJECT-NUMBER]@gcp-sa-iap.iam.gserviceaccount.com
.
If you have granted the Cloud Run Invoker role to the preceding service account and you are still facing this issue, redeploy your Cloud Run service.
Enabling IAP on a new project for the first time can cause the following error:
Setting IAM permissions failed
This because the Cloud Run Service Agent failed. To resolve the issue, either enable IAP again or set the IAM policy manually.
Can't set up IAP through the gcloud CLI The IAP service account is not provisioned
If you are seeing this error, run the following command:
gcloud beta services identity create --service=iap.googleapis.com --project=[PROJECT_ID]
run.routes.invoke
permission
During the IAP with Cloud Run Preview, Cloud Run didn't perform the run.routes.invoke
permission check for calls from IAP that use the Cloud Run Invoker role. With General Availability (GA), Cloud Run performs this permission check.
To avoid breaking changes, some customer projects that depended on this behavior during Preview were placed into an allowlist so that the permission wasn't checked. Contact Cloud Run support to remove such projects from the Preview-only allowlist.
What's nextTo help set up IAP for Cloud Run with Terraform, explore a Terraform code sample.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-07-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-07-02 UTC."],[[["This guide outlines how to secure a Cloud Run service using Identity-Aware Proxy (IAP), requiring users to authenticate before accessing the service through a load balancer."],["IAP relies on IAM authentication for Cloud Run services, and the IAP service account (`service-[PROJECT_NUMBER]@gcp-sa-iap.iam.gserviceaccount.com`) must be granted the Cloud Run Invoker role to access the service."],["The Cloud Run service must have its ingress setting configured to \"Internal and Cloud Load Balancing\" to prevent direct public access, ensuring all traffic is routed through the load balancer."],["IAP does not secure the default domain provided by Cloud Run, and is incompatible with Cloud CDN."],["To properly setup IAP and avoid issues, setting up an OAuth consent screen, and enabling IAP through the gcloud CLI requires the use of the command: `gcloud beta services identity create --service=iap.googleapis.com --project=[PROJECT_ID]` to provision a service account."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4