Identity-Aware Proxy (IAP) lets you secure Model Context Protocol (MCP) servers deployed on Cloud Run with centralized identity verification. You can then configure clients such as the Gemini CLI or AI agents to authenticate through IAP and securely run tools on your remote server.
Before you begin
Enable Cloud Run in your project.
Enable IAP in your project.
Required roles
To get the permissions that you need to configure IAP authentication for Cloud Run MCP servers, ask your administrator to grant you the following IAM roles:
- Cloud Run Admin (
roles/run.admin) on the project - IAP Admin (
roles/iap.admin) on the project -
Deploy a new service or deploy a new revision of an existing service:
- Service Account User (
roles/iam.serviceAccountUser) on the runtime service account - Artifact Registry Reader (
roles/artifactregistry.reader) on the container image repository
- Service Account User (
-
Create and configure an OAuth client:
OAuth Config Editor (
roles/oauthconfig.editor) on the project -
Connect to or call the IAP-secured MCP server:
IAP-secured Web App User (
roles/iap.httpsResourceAccessor) on the project or Cloud Run service
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
Configure IAP on a Cloud Run service
To configure IAP on your Cloud Run MCP server, do the following:
Grant the Cloud Run Invoker role (
roles/run.invoker) to the IAP service agent:gcloud beta run services add-iam-policy-binding SERVICE_NAME \ --member='serviceAccount:service-PROJECT_NUMBER@gcp-sa-iap.iam.gserviceaccount.com' \ --role='roles/run.invoker'Replace the following:
SERVICE_NAME: the service namePROJECT_NUMBER: your Google Cloud project number
Enable IAP when you deploy a new service or deploy a new revision of an existing service:
New service
To deploy a new service with IAP enabled, run the
gcloud beta run deploycommand:gcloud beta run deploy SERVICE_NAME \ --image=CONTAINER_IMAGE \ --region=REGION \ --project=PROJECT_ID \ --allow-unauthenticated \ --iap \ --functional-type=mcp-server
Replace the following:
SERVICE_NAME: the service nameCONTAINER_IMAGE: your container imageREGION: the region where you deploy your servicePROJECT_ID: the ID of the project where Cloud Run is enabled
Existing service
To deploy a new revision of an existing service with IAP enabled, run the
gcloud beta run services updatecommand:gcloud beta run services update SERVICE_NAME \ --region=REGION \ --iap \ --functional-type=mcp-server
Replace the following:
SERVICE_NAME: the service nameREGION: the region where you deploy your service
Create and configure an OAuth client:
To register your OAuth client's universal client ID for use with IAP, see Sharing OAuth clients for programmatic access.
Record the following values:
- OAuth client ID
- OAuth client secret
- Redirect URI
To connect a client such as the Gemini CLI or your agent to your deployed MCP server, edit the
~/.gemini/settings.jsonfile.Add the following configuration to your
settings.jsonfile:{ "mcpServers": { "my_mcp_server": { "httpUrl": "https://SERVICE_URL", "oauth": { "enabled": "true", "clientId": "OAUTH_CLIENT_ID", "clientSecret": "OAUTH_CLIENT_SECRET", "scopes": [ "email", "openid" ], "redirectUri": "REDIRECT_URI" } } } }Replace the following:
SERVICE_URL: your Cloud Run service URLOAUTH_CLIENT_ID: the client ID from the OAuth client configurationOAUTH_CLIENT_SECRET: the client secret from the OAuth client configurationREDIRECT_URI: the redirect URI from the OAuth client configuration
Verify the connection
To verify that your client can authenticate through IAP and connect to the MCP server, do the following:
In your terminal, start the Gemini CLI:
gemini
When prompted in your browser, complete the IAP authentication flow.
Verify that the Gemini CLI successfully discovers and lists the tools provided by your MCP server.