GoogleNeeraj AgrawalTutorial
How to securely connect internal Cloud Run MCP servers to Gemini Enterprise
Summary
Enterprise teams using Gemini Enterprise build custom MCP servers on Cloud Run to connect AI agents to internal APIs, databases, and workflows. Three challenges arise: internal-only ingress blocks public calls, Cloud Run IAM and user OAuth 2.0 must both be verified, and Shared VPCs cannot use wildcard *.run.app DNS zones without breaking other services. The solution uses an Egress Agent Gateway with Private Service Connect to route traffic privately into the VPC, then to Cloud Run via Private Google Access or a global PSC endpoint. FQDN-scoped Private Cloud DNS resolves only the MCP server hostname to a private VIP, avoiding DNS collisions. Gemini Enterprise sends two authorization headers: an OIDC ID token for Cloud Run IAM and the user’s OAuth 2.0 access token for application-level validation. A companion GitHub repository provides a runnable Python MCP server with OAuth 2.0 middleware and step-by-step setup scripts.
Context
Enterprise teams using Gemini Enterprise build custom MCP servers on Cloud Run to connect AI agents to internal APIs and databases. Three challenges arise: internal-only ingress blocks public calls, Cloud Run IAM and user OAuth 2.0 must both be verified, and Shared VPCs cannot use wildcard *.run.app DNS zones without breaking other services.
Approach / What changed
Deploy an Egress Agent Gateway in Agent-to-Anywhere mode, attach it to a PSC Network Attachment in the enterprise VPC, and use FQDN-scoped Private Cloud DNS to resolve the Cloud Run MCP server hostname to a private VIP (199.36.153.8/30 or 240.0.0.10). Gemini Enterprise sends two authorization headers: X-Serverless-Authorization (OIDC ID token for Cloud Run IAM) and Authorization Bearer (user OAuth 2.0 token). The MCP server validates both at the infrastructure and application layers.
Takeaways
Private routing to internal Cloud Run MCP servers requires two bridges: a PSC Network Attachment into the VPC, then Private Google Access or a global PSC endpoint to reach Cloud Run’s serverless frontend.
FQDN-scoped Private Cloud DNS zones override only the exact MCP server hostname, preventing DNS hijacking of other Cloud Run services in a Shared VPC.
Gemini Enterprise sends two separate authorization headers: X-Serverless-Authorization for Cloud Run IAM and Authorization Bearer for user OAuth 2.0 validation in the MCP application code.
FAQ
How do I avoid DNS collisions in a Shared VPC?
Create a Private Cloud DNS zone scoped to the exact FQDN of your MCP service, not a wildcard *.run.app zone. Cloud DNS uses longest-suffix matching, so only that single hostname is overridden; all other Cloud Run services in the Shared VPC continue resolving normally.
How does dual-header authentication work?
Gemini Enterprise sends an X-Serverless-Authorization header with a Google-signed OIDC ID token for the service agent, which Cloud Run IAM verifies against the Cloud Run Invoker role. The Authorization Bearer header carries the signed-in user's OAuth 2.0 access token untouched, which your MCP application code validates for per-user permissions.
What if my VPC has no default internet route?
Use Option B: a global PSC Endpoint for Google APIs (240.0.0.10). Google Cloud injects a dedicated /32 internal route into your VPC, so private Cloud Run routing works even when the 0.0.0.0/0 default internet route is deleted.
Source and freshness
- Source
- developers.googleblog.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.